<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic I forgot to mention something in Software Archive</title>
    <link>https://community.intel.com/t5/Software-Archive/Cilk-Fibonancci-doesn-t-work-properly/m-p/1113112#M73070</link>
    <description>&lt;P&gt;I forgot to mention something. &amp;nbsp;For small jobs, the Cilk startup overhead dominates the total time. &amp;nbsp;The Cilk runtime starts up its worker threads the first time you call a function that does a spawn. &amp;nbsp;To get a more realistic timing, add these lines to the&amp;nbsp;&lt;EM&gt;beginning&lt;/EM&gt;&amp;nbsp;of &lt;STRONG&gt;main().&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;cilk_spawn fib_s(1);
cilk_sync;
&lt;/PRE&gt;

&lt;P&gt;&lt;SPAN style="font-size: 13.008px;"&gt;Time it if you want to measure the overhead. &amp;nbsp;I'm pretty sure that if you do this, the time spent in the call to fib(39) will go way down.&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-size: 13.008px;"&gt;-Pablo&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 07 Mar 2017 18:55:06 GMT</pubDate>
    <dc:creator>Pablo_H_Intel</dc:creator>
    <dc:date>2017-03-07T18:55:06Z</dc:date>
    <item>
      <title>Cilk Fibonancci doesn't work properly</title>
      <link>https://community.intel.com/t5/Software-Archive/Cilk-Fibonancci-doesn-t-work-properly/m-p/1113108#M73066</link>
      <description>&lt;P&gt;I get the Fibonancci example from a web site but the output doesn't make any sense as serial code takes 2.25 sec while the parallel code takes 4.5 sec.&lt;BR /&gt;
	I'm using visual studio 2013, and Intel parallel studio&lt;BR /&gt;
	this is the code:&lt;/P&gt;

&lt;P&gt;#include &amp;lt;stdio.h&amp;gt;&lt;BR /&gt;
	#include &amp;lt;stdlib.h&amp;gt;&lt;BR /&gt;
	#include &amp;lt;time.h&amp;gt;&lt;BR /&gt;
	#include &amp;lt;cilk/cilk.h&amp;gt;&lt;BR /&gt;
	#include &amp;lt;cilk/cilk_api.h&amp;gt;&lt;/P&gt;

&lt;P&gt;/*Cilk_SPAWN*/&lt;BR /&gt;
	int fib(int n)&lt;BR /&gt;
	{&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; &amp;nbsp;if (n &amp;lt; 2)&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;return n;&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; &amp;nbsp;int x = cilk_spawn fib(n - 1);&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; &amp;nbsp;int y = fib(n - 2);&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; &amp;nbsp;cilk_sync;&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; &amp;nbsp;return x + y;&lt;BR /&gt;
	}&lt;/P&gt;

&lt;P&gt;/*Serial Function*/&lt;BR /&gt;
	int fib_s(int n)&lt;BR /&gt;
	{&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; &amp;nbsp;if (n &amp;lt; 2)&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;return n;&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; &amp;nbsp;int x = fib_s(n - 1);&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; &amp;nbsp;int y = fib_s(n - 2);&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; &amp;nbsp;return x + y;&lt;BR /&gt;
	}&lt;/P&gt;

&lt;P&gt;&lt;BR /&gt;
	int main(int argc, char *argv[])&lt;BR /&gt;
	{&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; &amp;nbsp;/*CILK SPAWN*/&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; &amp;nbsp;// Fibonacci number to be calculated. &amp;nbsp;39 is big enough to take a reasonable amount of time&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; &amp;nbsp;int n = 39;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;int result ;&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; &amp;nbsp;// Time how long it takes to calculate the nth Fibonacci number Serially first&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; &amp;nbsp;clock_t start = clock();&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; &amp;nbsp;result = fib_s(n);&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; &amp;nbsp;clock_t end = clock();&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; &amp;nbsp;double dur = (double)(end - start) / CLOCKS_PER_SEC;&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; &amp;nbsp;// Display our results&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; &amp;nbsp;printf("SERIAL &amp;nbsp;%.3f sec == \n\n", dur);&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;// Time how long it takes to calculate the nth Fibonacci number Parallel&amp;nbsp;&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; &amp;nbsp;start = clock();&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; &amp;nbsp;result = fib(n);&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; &amp;nbsp;end = clock();&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; &amp;nbsp;// Display our results&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; &amp;nbsp;dur = (double)(end - start) / CLOCKS_PER_SEC;&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; &amp;nbsp;printf("PARALLEL &amp;nbsp;%.3f sec == \n\n", dur);&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; &amp;nbsp;return 0;&lt;BR /&gt;
	}&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2017 15:49:31 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/Cilk-Fibonancci-doesn-t-work-properly/m-p/1113108#M73066</guid>
      <dc:creator>Khaled_A_</dc:creator>
      <dc:date>2017-03-07T15:49:31Z</dc:date>
    </item>
    <item>
      <title>That is surprising. What</title>
      <link>https://community.intel.com/t5/Software-Archive/Cilk-Fibonancci-doesn-t-work-properly/m-p/1113109#M73067</link>
      <description>&lt;P&gt;That &lt;EM&gt;is&lt;/EM&gt;&amp;nbsp;surprising. What hardware and operating system are you using? Have you done anything to set the number of workers, such as setting CILK_NWORKERS? &amp;nbsp;Are there any other CPU-intensive programs running at the same time?&lt;/P&gt;

&lt;P&gt;Please try the test again with the environment CILK_NWORKERS set to 1 and CILK_NWORKERS set to 2 and list the results here.&lt;/P&gt;

&lt;P&gt;-Pablo&lt;/P&gt;

&lt;P&gt;P.S. fib is not a great test program, but you should definitely be getting speedup.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2017 16:30:06 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/Cilk-Fibonancci-doesn-t-work-properly/m-p/1113109#M73067</guid>
      <dc:creator>Pablo_H_Intel</dc:creator>
      <dc:date>2017-03-07T16:30:06Z</dc:date>
    </item>
    <item>
      <title>In terms of total time spent</title>
      <link>https://community.intel.com/t5/Software-Archive/Cilk-Fibonancci-doesn-t-work-properly/m-p/1113110#M73068</link>
      <description>&lt;P&gt;In terms of total time spent by all logical processors, as measured by clock(), it's not surprising that you see an increase, particularly on such a short job.&amp;nbsp;&amp;nbsp; Besides setting CILK_NWORKERS, as Pablo advised, you should be checking elapsed time.&amp;nbsp; Assuming you have HyperThreading on, you should see minimum elapsed time somewhere between nworkers set to number of cores and number of logical processors minus 1 (almost certainly with fewer than default number of workers).&lt;/P&gt;

&lt;P&gt;I thought (but could be wrong) that tasks suitable for cilk_for() might show the most scaling with nworkers, but of course you give up the advantages seen with processor affinity in threading models which support it.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2017 17:13:42 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/Cilk-Fibonancci-doesn-t-work-properly/m-p/1113110#M73068</guid>
      <dc:creator>TimP</dc:creator>
      <dc:date>2017-03-07T17:13:42Z</dc:date>
    </item>
    <item>
      <title>On my 2-core laptop, elapsed</title>
      <link>https://community.intel.com/t5/Software-Archive/Cilk-Fibonancci-doesn-t-work-properly/m-p/1113111#M73069</link>
      <description>&lt;P&gt;On my 2-core laptop, elapsed times for {1,2,3,4} workers are {6.4,3.9,3.0,2.6} sec.&amp;nbsp; Your serial code is much faster.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2017 18:05:31 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/Cilk-Fibonancci-doesn-t-work-properly/m-p/1113111#M73069</guid>
      <dc:creator>TimP</dc:creator>
      <dc:date>2017-03-07T18:05:31Z</dc:date>
    </item>
    <item>
      <title>I forgot to mention something</title>
      <link>https://community.intel.com/t5/Software-Archive/Cilk-Fibonancci-doesn-t-work-properly/m-p/1113112#M73070</link>
      <description>&lt;P&gt;I forgot to mention something. &amp;nbsp;For small jobs, the Cilk startup overhead dominates the total time. &amp;nbsp;The Cilk runtime starts up its worker threads the first time you call a function that does a spawn. &amp;nbsp;To get a more realistic timing, add these lines to the&amp;nbsp;&lt;EM&gt;beginning&lt;/EM&gt;&amp;nbsp;of &lt;STRONG&gt;main().&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;cilk_spawn fib_s(1);
cilk_sync;
&lt;/PRE&gt;

&lt;P&gt;&lt;SPAN style="font-size: 13.008px;"&gt;Time it if you want to measure the overhead. &amp;nbsp;I'm pretty sure that if you do this, the time spent in the call to fib(39) will go way down.&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-size: 13.008px;"&gt;-Pablo&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2017 18:55:06 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/Cilk-Fibonancci-doesn-t-work-properly/m-p/1113112#M73070</guid>
      <dc:creator>Pablo_H_Intel</dc:creator>
      <dc:date>2017-03-07T18:55:06Z</dc:date>
    </item>
    <item>
      <title>It's really not surprising</title>
      <link>https://community.intel.com/t5/Software-Archive/Cilk-Fibonancci-doesn-t-work-properly/m-p/1113113#M73071</link>
      <description>&lt;P&gt;It's really not surprising that your serial code is faster than the Cilk code. &amp;nbsp;Fib is the posterchild for programs that don't do enough in their spawned functions. What you're really measuring is the overhead imposed by Cilk.&lt;/P&gt;

&lt;P&gt;See Jim Sukha's article&amp;nbsp;&lt;A href="https://software.intel.com/en-us/articles/why-is-my-cilk-plus-program-not-showing-speedup-part-1"&gt;Why is Cilk™ Plus not speeding up my program? (Part 1)&lt;/A&gt;. Entry #1 is "Parallel regions with insufficient work"&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2017 19:29:05 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/Cilk-Fibonancci-doesn-t-work-properly/m-p/1113113#M73071</guid>
      <dc:creator>Barry_T_Intel</dc:creator>
      <dc:date>2017-03-07T19:29:05Z</dc:date>
    </item>
    <item>
      <title>Yes, it looks like there is</title>
      <link>https://community.intel.com/t5/Software-Archive/Cilk-Fibonancci-doesn-t-work-properly/m-p/1113114#M73072</link>
      <description>&lt;P&gt;Yes, it looks like there is only small amount of actual work as Barry said.&lt;/P&gt;

&lt;P&gt;This is not the first time we see this question, and there are some suggestions in the following post if we want to see any performance gain from Fibonacci code.&lt;/P&gt;

&lt;P&gt;&lt;A href="https://software.intel.com/en-us/forums/intel-cilk-plus/topic/559858" target="_blank"&gt;https://software.intel.com/en-us/forums/intel-cilk-plus/topic/559858&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Mar 2017 00:46:53 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/Cilk-Fibonancci-doesn-t-work-properly/m-p/1113114#M73072</guid>
      <dc:creator>Hansang_B_Intel</dc:creator>
      <dc:date>2017-03-08T00:46:53Z</dc:date>
    </item>
    <item>
      <title>Thank you all for helping me </title>
      <link>https://community.intel.com/t5/Software-Archive/Cilk-Fibonancci-doesn-t-work-properly/m-p/1113115#M73073</link>
      <description>&lt;P&gt;Thank you all for helping me&amp;nbsp;&lt;BR /&gt;
	&lt;BR /&gt;
	first to&amp;nbsp;&lt;A href="https://software.intel.com/en-us/user/452777" style="font-size: 11px; background-color: rgb(238, 238, 238);"&gt;Pablo Halpern&lt;/A&gt;&lt;BR /&gt;
	My CPU is Intel core i7-4720HQ, i'm running windows 8.1 (64 bit ).&lt;BR /&gt;
	I tried with {1,2,4,6, and 8} workers and the time result is {16.061,8.438,5.769,4.882, and 4.311} sec&lt;BR /&gt;
	Moreover i tried to add the 2 lines you mentioned but the overhead time almost 0 at 16 and 8 workers.&lt;BR /&gt;
	please see the image&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&lt;A href="https://drive.google.com/open?id=0BwocMhGn9e4FVGgtdWc4cEdXQXM"&gt;https://drive.google.com/open?id=0BwocMhGn9e4FVGgtdWc4cEdXQXM&lt;/A&gt;&lt;BR /&gt;
	&lt;BR /&gt;
	second &lt;A href="https://software.intel.com/en-us/user/452777" style="font-size: 11px; background-color: rgb(238, 238, 238);"&gt;Pablo Halpern&lt;/A&gt;,&amp;nbsp;&lt;A href="https://software.intel.com/en-us/user/483654" style="font-size: 11px; background-color: rgb(238, 238, 238);"&gt;Barry Tannenbaum,&amp;nbsp;&lt;/A&gt;&lt;A href="https://software.intel.com/en-us/user/941857" style="font-size: 11px; background-color: rgb(238, 238, 238);"&gt;Hansang B&lt;/A&gt;, and&amp;nbsp;&lt;A href="https://software.intel.com/en-us/user/336903" style="font-size: 11px; background-color: rgb(238, 238, 238);"&gt;Tim P&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;I saw a tutorial for someone in which he use the same code. And there is an improvement in time that i can't achieve with my i7 CPU&amp;nbsp;&lt;BR /&gt;
	Please if you have enough time to see his result at time 4:26 in the link&lt;BR /&gt;
	&lt;A href="https://www.youtube.com/watch?v=JnUEOvitBN8&amp;amp;index=2&amp;amp;list=PLNMIeqLiUa7ZseuQFj3tI6dCtVG71JUgU"&gt;https://www.youtube.com/watch?v=JnUEOvitBN8&amp;amp;index=2&amp;amp;list=PLNMIeqLiUa7ZseuQFj3tI6dCtVG71JUgU&lt;/A&gt;&lt;BR /&gt;
	&lt;SPAN style="font-size: 1em;"&gt;I wonder if any one of you mention a good example to just see the power of cilk.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;&lt;BR /&gt;
	&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Mar 2017 20:08:57 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/Cilk-Fibonancci-doesn-t-work-properly/m-p/1113115#M73073</guid>
      <dc:creator>Khaled_A_</dc:creator>
      <dc:date>2017-03-08T20:08:57Z</dc:date>
    </item>
    <item>
      <title>The Fibonacci example is</title>
      <link>https://community.intel.com/t5/Software-Archive/Cilk-Fibonancci-doesn-t-work-properly/m-p/1113116#M73074</link>
      <description>&lt;P&gt;The Fibonacci example is intended to illustrate how to perform&amp;nbsp;recursive parallelism. This example is NOT intended to&amp;nbsp;illustrate how to best perform the Fibonacci series calculation using parallel programming.&lt;/P&gt;

&lt;P&gt;The intension of the example is for you to examine your own problem+solution and determine if it can be reformulated into a recursive expression (with inner most recursion level having sufficient work to be beneficial to parallelization). The example has a secondary benefit in illustrating cases where parallelization is not sufficiently efficient (which is a valuable learning experience).&lt;/P&gt;

&lt;P&gt;Jim Dempsey&lt;/P&gt;</description>
      <pubDate>Sat, 25 Mar 2017 16:14:30 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/Cilk-Fibonancci-doesn-t-work-properly/m-p/1113116#M73074</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2017-03-25T16:14:30Z</dc:date>
    </item>
  </channel>
</rss>

