<?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 Thanks all. Your comments is in Software Archive</title>
    <link>https://community.intel.com/t5/Software-Archive/recursive-function-in-Cilk/m-p/1082057#M61992</link>
    <description>&lt;P&gt;Thanks all. Your comments is really helpful to me.&amp;nbsp;&lt;/P&gt;

&lt;P&gt;Amos&lt;/P&gt;</description>
    <pubDate>Wed, 02 Mar 2016 17:40:45 GMT</pubDate>
    <dc:creator>Amos_W_</dc:creator>
    <dc:date>2016-03-02T17:40:45Z</dc:date>
    <item>
      <title>recursive function in Cilk</title>
      <link>https://community.intel.com/t5/Software-Archive/recursive-function-in-Cilk/m-p/1082054#M61989</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I just write a simple Cilk code to test how deep recursive function call Cilk can reach. &amp;nbsp;When I set up recursive level over 100,000, Cilk application has segmentation fault. &amp;nbsp;How do I extend recursive level to go deeper? &amp;nbsp;Or, how big the stacksize there is as default?&lt;/P&gt;

&lt;P&gt;--&lt;/P&gt;

&lt;P&gt;Result:&lt;BR /&gt;
	[amos@Machine Pi]$ ./cilk-icc 100&lt;BR /&gt;
	Cilk took 0.000000 sec&lt;BR /&gt;
	Steps = 100.000000;Pi = 3.141601&lt;BR /&gt;
	[amos@&lt;SPAN style="font-size: 14.634px; line-height: 21.951px;"&gt;Machine&lt;/SPAN&gt; Pi]$ ./cilk-icc 1000&lt;BR /&gt;
	Cilk took 0.290000 sec&lt;BR /&gt;
	Steps = 1000.000000;Pi = 3.141593&lt;BR /&gt;
	[amos@&lt;SPAN style="font-size: 14.634px; line-height: 21.951px;"&gt;Machine&lt;/SPAN&gt; Pi]$ ./cilk-icc 10000&lt;BR /&gt;
	Cilk took 0.370000 sec&lt;BR /&gt;
	Steps = 10000.000000;Pi = 3.141593&lt;BR /&gt;
	[amos@&lt;SPAN style="font-size: 14.634px; line-height: 21.951px;"&gt;Machine&lt;/SPAN&gt; Pi]$ ./cilk-icc 100000&lt;BR /&gt;
	Segmentation fault (core dumped)&lt;/P&gt;

&lt;P&gt;--&lt;/P&gt;

&lt;P&gt;Code:&lt;BR /&gt;
	#include &amp;lt;stdio.h&amp;gt;&lt;BR /&gt;
	#include &amp;lt;stdlib.h&amp;gt;&lt;BR /&gt;
	#include &amp;lt;unistd.h&amp;gt;&lt;BR /&gt;
	#include &amp;lt;cilk/cilk.h&amp;gt;&lt;BR /&gt;
	#include &amp;lt;time.h&amp;gt;&lt;/P&gt;

&lt;P&gt;static double num_steps;&lt;BR /&gt;
	double step, pi;&lt;BR /&gt;
	double pi_calculate( double counter, double sum );&lt;/P&gt;

&lt;P&gt;static void _usage(FILE *f, int error) {&lt;BR /&gt;
	&amp;nbsp; fprintf(f, "Usage: ./cilk NUMBER\n");&lt;BR /&gt;
	&amp;nbsp; fflush(f);&lt;BR /&gt;
	}&lt;/P&gt;

&lt;P&gt;int main(int argc, char *argv[])&lt;BR /&gt;
	{&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; int i,j;&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; double x, sum=0;&lt;/P&gt;

&lt;P&gt;&amp;nbsp; &amp;nbsp; argc -= optind;&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; argv += optind;&lt;/P&gt;

&lt;P&gt;&amp;nbsp; &amp;nbsp; switch (argc) {&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; case 0:&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; fprintf(stderr, "\nMissing pi number.\n"); // fall through&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; default:&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; _usage(stderr, 0);&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; case 1:&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; num_steps = atof(argv[0]);&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; break;&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; }&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; step = 1.0/ (double)num_steps;&lt;/P&gt;

&lt;P&gt;&amp;nbsp; &amp;nbsp; clock_t start = clock();&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; sum = pi_calculate( 0, 0 );&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; clock_t end = clock();&lt;/P&gt;

&lt;P&gt;&amp;nbsp; &amp;nbsp; double duration = (double)(end - start) / CLOCKS_PER_SEC;&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; printf("Cilk took %f sec\n", duration);&lt;/P&gt;

&lt;P&gt;&amp;nbsp; &amp;nbsp; pi = step*sum;&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; printf( "Steps = %f;Pi = %f\n", num_steps, pi );&lt;/P&gt;

&lt;P&gt;&amp;nbsp; &amp;nbsp; return 0;&lt;BR /&gt;
	}&lt;/P&gt;

&lt;P&gt;double pi_calculate( double counter, double sum )&lt;BR /&gt;
	{&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; double x, result=0, result_2=0;&lt;/P&gt;

&lt;P&gt;//printf("counter =%f/%f\n", counter, num_steps);&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; if( counter &amp;lt; num_steps ) {&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; x = (counter + 0.5) * step;&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; result = sum + 4.0/(1.0+x*x);&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; result_2 = cilk_spawn pi_calculate( counter+1, result );&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; cilk_sync;&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return result_2;&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; }&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; else return sum;&lt;BR /&gt;
	}&lt;/P&gt;

&lt;P&gt;--&lt;/P&gt;

&lt;P&gt;Amos&lt;/P&gt;</description>
      <pubDate>Sun, 21 Feb 2016 16:58:58 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/recursive-function-in-Cilk/m-p/1082054#M61989</guid>
      <dc:creator>Amos_W_</dc:creator>
      <dc:date>2016-02-21T16:58:58Z</dc:date>
    </item>
    <item>
      <title>The stack size should be same</title>
      <link>https://community.intel.com/t5/Software-Archive/recursive-function-in-Cilk/m-p/1082055#M61990</link>
      <description>&lt;P&gt;The stack size should be same as for a C/C++ app. And on Windows, at least (I don't recall if we could get the information on Mac and/or LInux) if you change the stack size via linker directives, we'll should obey those too.&lt;/P&gt;

&lt;P&gt;However, you're also hitting the spawn depth limit. The worker's deque is hard coded to 1024 entries, so you can't spawn infinitely either. This is a balance between how deep is reasonable and memory usage, since every worker will contain a deque.&lt;/P&gt;

&lt;P&gt;Of course, you're welcome to build your own runtime and specify a custom deque size. Look in global_state.cpp for function&amp;nbsp;cilkg_init_global_state(), and then look for the initialization of g-&amp;gt;ltqsize with the comment /* FIXME */ :o)&lt;/P&gt;</description>
      <pubDate>Mon, 22 Feb 2016 16:38:31 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/recursive-function-in-Cilk/m-p/1082055#M61990</guid>
      <dc:creator>Barry_T_Intel</dc:creator>
      <dc:date>2016-02-22T16:38:31Z</dc:date>
    </item>
    <item>
      <title>It is counter productive to</title>
      <link>https://community.intel.com/t5/Software-Archive/recursive-function-in-Cilk/m-p/1082056#M61991</link>
      <description>&lt;P&gt;It is counter productive to recurse-spawn to create a number of tasks that exceed&amp;nbsp;more than a few times the number of available logical processors. When the workload per recursion level is equal, then 1x the number of available logical processors. Unequal loads may experience a benefit with a larger multiplier. When you reach the desired number of tasks, then you can continue recursions without spawn.&lt;/P&gt;

&lt;P&gt;Jim Dempsey&lt;/P&gt;</description>
      <pubDate>Mon, 29 Feb 2016 13:44:54 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/recursive-function-in-Cilk/m-p/1082056#M61991</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2016-02-29T13:44:54Z</dc:date>
    </item>
    <item>
      <title>Thanks all. Your comments is</title>
      <link>https://community.intel.com/t5/Software-Archive/recursive-function-in-Cilk/m-p/1082057#M61992</link>
      <description>&lt;P&gt;Thanks all. Your comments is really helpful to me.&amp;nbsp;&lt;/P&gt;

&lt;P&gt;Amos&lt;/P&gt;</description>
      <pubDate>Wed, 02 Mar 2016 17:40:45 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/recursive-function-in-Cilk/m-p/1082057#M61992</guid>
      <dc:creator>Amos_W_</dc:creator>
      <dc:date>2016-03-02T17:40:45Z</dc:date>
    </item>
  </channel>
</rss>

