{"id":2587,"date":"2010-04-19T15:19:21","date_gmt":"2010-04-19T14:19:21","guid":{"rendered":"http:\/\/www.walkingrandomly.com\/?p=2587"},"modified":"2010-04-19T15:19:21","modified_gmt":"2010-04-19T14:19:21","slug":"slow-multicore-performance-on-ubuntu-linux-and-how-to-fix-it","status":"publish","type":"post","link":"https:\/\/walkingrandomly.com\/?p=2587","title":{"rendered":"Slow multicore performance on Ubuntu Linux -and how to fix it"},"content":{"rendered":"<p>I was recently playing with some parallel code that used <a href=\"http:\/\/en.wikipedia.org\/wiki\/Gfortran\">gfortran<\/a> and <a href=\"http:\/\/openmp.org\/wp\/\">OpenMP<\/a> to parallelise a calculation over 4 threads and was getting some seriously odd timing results.\u00a0 The first time I ran the code it completed in 4.8 seconds, the next run took 4.8 seconds but the third run took 84 seconds (No, I haven&#8217;t missed off the decimal point).\u00a0 Subsequent timings were all over the place &#8211; 12 seconds, 4.8 seconds again, 14 seconds&#8230;.something weird was going on.<\/p>\n<p>I wouldn&#8217;t mind but all of these calculations had exactly the same input\/output and yet sometimes this parallel code took significantly longer to execute than the serial version.<\/p>\n<p>On drilling down I discovered that two of the threads had 100% CPU utilisation and the other two only had 50%.\u00a0 On a hunch I wondered if the CPU frequency &#8216;on demand&#8217; scaling thing was messing things (It has done so in the past) up so I did<\/p>\n<pre>sudo cpufreq-selector -c 0 -f 3000\r\nsudo cpufreq-selector -c 1 -f 3000\r\nsudo cpufreq-selector -c 2 -f 3000\r\nsudo cpufreq-selector -c 3 -f 3000<\/pre>\n<p>to set the cpu-frequency of all 4 cores to the maxium 3Ghz.\u00a0 This switched off the &#8216;on demand&#8217; setting that is standard in Ubuntu.<\/p>\n<p>Lo! it worked! 4.8 seconds every time.\u00a0 When I turned the governor back on<\/p>\n<pre>sudo cpufreq-selector --governor ondemand<\/pre>\n<p>I got back the &#8216;sometimes it&#8217;s fast, sometimes it&#8217;s slow&#8217; behaviour.  Oddly, one week and several reboots later I can&#8217;t get back the slow behaviour no matter what I set the governor to.<\/p>\n<p>Perhaps this was just a temporary glitch in my system but, as I said earlier, <a href=\"https:\/\/www.walkingrandomly.com\/?p=166\">I have seen this sort of behaviour<\/a> before so, just to be on the safe side, it might be worth switching off the automatic governor whenever you do parallel calculations in Linux.<\/p>\n<p>Does anyone have any insight into this?  Comments welcomed.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I was recently playing with some parallel code that used gfortran and OpenMP to parallelise a calculation over 4 threads and was getting some seriously odd timing results.\u00a0 The first time I ran the code it completed in 4.8 seconds, the next run took 4.8 seconds but the third run took 84 seconds (No, I [&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":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[5,41,7],"tags":[],"class_list":["post-2587","post","type-post","status-publish","format-standard","hentry","category-linux","category-parallel-programming","category-programming"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p3swhs-FJ","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts\/2587","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=2587"}],"version-history":[{"count":5,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts\/2587\/revisions"}],"predecessor-version":[{"id":2592,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts\/2587\/revisions\/2592"}],"wp:attachment":[{"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2587"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2587"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2587"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}