{"id":6507,"date":"2019-01-23T12:35:58","date_gmt":"2019-01-23T11:35:58","guid":{"rendered":"http:\/\/www.walkingrandomly.com\/?p=6507"},"modified":"2019-02-01T03:33:04","modified_gmt":"2019-02-01T02:33:04","slug":"installing-and-using-the-gnu-scientific-library-gsl-on-the-windows-subsystem-for-linux","status":"publish","type":"post","link":"https:\/\/walkingrandomly.com\/?p=6507","title":{"rendered":"Installing and using the GNU Scientific Library (GSL) on the Windows Subsystem for Linux"},"content":{"rendered":"<p>I have been an advocate of the Windows Subsytem for Linux ever since it was released (See <a href=\"https:\/\/www.walkingrandomly.com\/?p=6011\">Bash on Windows: The scripting game just changed<\/a>) since it allows me to use the best of Linux from my windows laptop.\u00a0 I no longer dual boot on my personal machines and rarely need to use Linux VMs on them either thanks to this technology.\u00a0 I still use full-blown Linux a lot of course but these days it tends to be only on servers and HPC systems.<\/p>\n<p>I recently needed to compile and play with some code that was based on the GNU Scientific Library. Using the <a href=\"https:\/\/www.microsoft.com\/en-gb\/p\/ubuntu-1804-lts\/9n9tngvndl3q?activetab=pivot:overviewtab\">Ubuntu 18.04 version of the WSL<\/a>\u00a0this is very easy. Install the GSL with<\/p>\n<pre>sudo apt-get install libgsl-dev\r\n<\/pre>\n<p>A simple code that evaluates <a href=\"https:\/\/en.wikipedia.org\/wiki\/Dawson_function\">Dawson&#8217;s integral<\/a> over a range of x values is shown below. Call this dawson.cpp<\/p>\n<pre>\r\n#include&lt;iostream&gt;\r\n#include&lt;vector&gt;\r\n#include&lt;gsl\/gsl_sf.h&gt;\r\n\r\nint main(){\r\n\r\ndouble range = 6; \/\/ max\/min values\r\nint N = 100000; \/\/ Number of evaluations\r\ndouble step = 2 * range \/ N;\r\nstd::vector&lt;double&gt; x(N);\r\nstd::vector&lt;double&gt; result(N);\r\n\r\nfor (int i=0;i<=N;i++){\r\n     x[i] = -range + i*step;\r\n     result[i] = gsl_sf_dawson(x[i]);\r\n}\r\n\r\n\r\nfor (int i=0;i&lt;=N;i++){\r\n\tstd::cout &lt;&lt; x[i] &lt;&lt; &quot;,&quot; &lt;&lt; result[i] &lt;&lt; std::endl;\r\n}\r\n\r\nreturn 0;\r\n}\r\n<\/pre>\n<p>Compile with<\/p>\n<pre>g++ -std=c++11 dawson.cpp -o .\/dawson -lgsl -lgslcblas -lm\r\n<\/pre>\n<p>Run it and generate some results<\/p>\n<pre>.\/dawson &gt; results.txt\r\n<\/pre>\n<p>If we plot results.txt we get<\/p>\n<p><a href=\"https:\/\/www.walkingrandomly.com\/wp-content\/uploads\/2019\/01\/dawson.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-6511\" src=\"https:\/\/www.walkingrandomly.com\/wp-content\/uploads\/2019\/01\/dawson-300x225.png\" alt=\"dawson\" width=\"300\" height=\"225\" srcset=\"https:\/\/walkingrandomly.com\/wp-content\/uploads\/2019\/01\/dawson-300x225.png 300w, https:\/\/walkingrandomly.com\/wp-content\/uploads\/2019\/01\/dawson.png 640w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>This code is also available on GitHub: <a href=\"https:\/\/github.com\/mikecroucher\/GSL_example\">https:\/\/github.com\/mikecroucher\/GSL_example<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have been an advocate of the Windows Subsytem for Linux ever since it was released (See Bash on Windows: The scripting game just changed) since it allows me to use the best of Linux from my windows laptop.\u00a0 I no longer dual boot on my personal machines and rarely need to use Linux VMs [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[65,5,7],"tags":[],"class_list":["post-6507","post","type-post","status-publish","format-standard","hentry","category-cc","category-linux","category-programming"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p3swhs-1GX","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts\/6507","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6507"}],"version-history":[{"count":9,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts\/6507\/revisions"}],"predecessor-version":[{"id":6521,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts\/6507\/revisions\/6521"}],"wp:attachment":[{"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6507"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6507"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6507"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}