<?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 Another way to do private in Software Archive</title>
    <link>https://community.intel.com/t5/Software-Archive/Cilk-Plus-s-equivalent-to-firstprivate-threadprivate-in-OpenMP/m-p/740645#M273</link>
    <description>&lt;P&gt;Another way to do private variables in a cilk_for loop is simply to declare them inside the loop body. &amp;nbsp;Then they are allocated on the stack inside the lambda function created out of the loop body and automatically private. &amp;nbsp;The equivalent of a FIRSTPRIVATE variable would be something like&lt;/P&gt;
&lt;P&gt;[cpp]&lt;/P&gt;
&lt;P&gt;myclass init_value;&lt;/P&gt;
&lt;P&gt;cilk_for(int i = 0; i &amp;lt; trip_count; i++)&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; myclass private_value(init_value);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; work(private_value);&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;[/cpp]&lt;/P&gt;
&lt;P&gt;Since init_value is never modified during the paralllel code, using it to initialize private_value is not a race.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; - Barry&lt;/P&gt;</description>
    <pubDate>Fri, 12 Apr 2013 13:36:00 GMT</pubDate>
    <dc:creator>Barry_T_Intel</dc:creator>
    <dc:date>2013-04-12T13:36:00Z</dc:date>
    <item>
      <title>Cilk Plus's equivalent to firstprivate, threadprivate in OpenMP?</title>
      <link>https://community.intel.com/t5/Software-Archive/Cilk-Plus-s-equivalent-to-firstprivate-threadprivate-in-OpenMP/m-p/740641#M269</link>
      <description>The support of reduction variables in Cilk Plus is outstanding, comparing to OpenMP. However, I was unable to find equivalents to OpenMP's private, firstprivate, threadprivate.For example,&lt;DIV&gt;&lt;SPAN style="font-family: Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;

&lt;DIV&gt;&lt;PRE&gt;[cpp]#pragma omp parallel for firstprivate(accessor)
  for (int i = 0; i &amp;lt; trip_count; ++i)
  {
    work(accessor.GetWorkData(i));
  }[/cpp]&lt;/PRE&gt; &lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;

The above code has 'accessor', which is a simple struct with only POD types.&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;In OpenMP, it is very easy to allocate this 'accessor' per thread, by using &lt;B&gt;firstprivate&lt;/B&gt;, or &lt;B&gt;threadprivate&lt;/B&gt;.

What would be an optimal approach in Cilk Plus?&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;Of course, I can write the code that allocates thread-private accessors by using thread id returned by __cilkrts_get_worker_number(), while avoiding false sharing.&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;I also think I might able to write a class based on reducer and hyperobject.&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;However, I just want to find a better and elegant solution proposed by Cilk Plus.&lt;/DIV&gt;</description>
      <pubDate>Thu, 06 Oct 2011 02:39:17 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/Cilk-Plus-s-equivalent-to-firstprivate-threadprivate-in-OpenMP/m-p/740641#M269</guid>
      <dc:creator>Minjang_Kim</dc:creator>
      <dc:date>2011-10-06T02:39:17Z</dc:date>
    </item>
    <item>
      <title>Cilk Plus's equivalent to firstprivate, threadprivate in OpenMP</title>
      <link>https://community.intel.com/t5/Software-Archive/Cilk-Plus-s-equivalent-to-firstprivate-threadprivate-in-OpenMP/m-p/740642#M270</link>
      <description>What you're looking for is a holder -- a different kind of hyperobject that works a little like firstprivate, lastprivate, and/or threadprivate. By default, a holder works like threadprivate:&lt;BR /&gt;&lt;PRE&gt;[cpp]#include &lt;CILK&gt;&lt;BR /&gt;&lt;BR /&gt;cilk::holder&lt;ACCESSORTYPE&gt; accessor_holder;
cilk_for (int = 0; i &amp;lt; trip_count; ++i)
{
    work(accessor_holder()); // separate view for each iteration&lt;BR /&gt;}
[/cpp]&lt;/ACCESSORTYPE&gt;&lt;/CILK&gt;&lt;/PRE&gt; Note that you need to put an empty pair of parenthesis after the holder name to cause it to yield its value. (A new syntax for holders and reducers is in the works that will make them look like pointers rather than like function objects.)&lt;BR /&gt;&lt;BR /&gt;To get the effect of firstprivate, assign the holder a specific value at the start of each iteration:&lt;BR /&gt;&lt;PRE&gt;[cpp]cilk::holder&lt;ACCESSORTYPE&gt; accessor_holder(accessor); // Initial value&lt;BR /&gt;cilk_for (int = 0; i &amp;lt; trip_count; ++i)&lt;BR /&gt;{&lt;BR /&gt;    accessor_holder() = accessor; // Initialized to value of accessor at each iteration&lt;BR /&gt;    work(accessor_holder());&lt;BR /&gt;}
[/cpp]&lt;/ACCESSORTYPE&gt;&lt;/PRE&gt; To get the effect of lastprivate, specify the "keep_last" policy for the holder. This policy causes the holder to retain its "last" value (i.e., the last value that would be set if the program were run serially) at the end of the parallel region:&lt;BR /&gt;&lt;PRE&gt;[cpp]cilk::holder&lt;ACCESSORTYPE&gt; accessor_holder;&lt;BR /&gt;cilk_for (int = 0; i &amp;lt; trip_count; ++i)
{
    accessor_holder() = work();  // Modify a different view in each iteration&lt;BR /&gt;}
accessor = accessor_holder(); // get value of "last" view[/cpp]&lt;/ACCESSORTYPE&gt;&lt;/PRE&gt;Holders can do a lot more than this, however. Arch Robison wrote an excellent &lt;A title="Left versus Right Holders in Intel Cilk Plus" href="http://software.intel.com/en-us/articles/left-holders-versus-right-holders/?wapkw=%28holder%29"&gt;blog entry&lt;/A&gt; about holders (including how to create your own holder), although it was written before holders were added as a standard component in the Cilk Plus library. Documentation for holders is available in the&lt;A title="Intel C++ Compiler XE 12.1 User and Reference Guides" href="http://software.intel.com/sites/products/documentation/hpc/composerxe/en-us/2011Update/cpp/win/index.htm"&gt;Intel C++ Compiler XE 12.1 User and Reference Guides&lt;/A&gt; under "Key Features|Intel Cilk Plus|Holders".&lt;BR /&gt;&lt;BR /&gt;At present, holders are available only in C++. A syntax for using holder in C is still under development.&lt;BR /&gt;&lt;BR /&gt;Let us know how they work for you.&lt;BR /&gt;&lt;BR /&gt;-Pablo</description>
      <pubDate>Fri, 07 Oct 2011 18:51:37 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/Cilk-Plus-s-equivalent-to-firstprivate-threadprivate-in-OpenMP/m-p/740642#M270</guid>
      <dc:creator>Pablo_H_Intel</dc:creator>
      <dc:date>2011-10-07T18:51:37Z</dc:date>
    </item>
    <item>
      <title>Cilk Plus's equivalent to firstprivate, threadprivate in OpenMP</title>
      <link>https://community.intel.com/t5/Software-Archive/Cilk-Plus-s-equivalent-to-firstprivate-threadprivate-in-OpenMP/m-p/740643#M271</link>
      <description>Thanks Pablo, it works as what I wanted to do!&lt;SPAN style="white-space: pre;"&gt;	&lt;/SPAN&gt;&lt;DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 07 Oct 2011 19:53:14 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/Cilk-Plus-s-equivalent-to-firstprivate-threadprivate-in-OpenMP/m-p/740643#M271</guid>
      <dc:creator>Minjang_Kim</dc:creator>
      <dc:date>2011-10-07T19:53:14Z</dc:date>
    </item>
    <item>
      <title>Hi,</title>
      <link>https://community.intel.com/t5/Software-Archive/Cilk-Plus-s-equivalent-to-firstprivate-threadprivate-in-OpenMP/m-p/740644#M272</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I am getting the following error when I tried to do this.&lt;/P&gt;
&lt;P&gt;error: missing template arguments before ‘accessor_holder&lt;/P&gt;</description>
      <pubDate>Thu, 11 Apr 2013 22:15:13 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/Cilk-Plus-s-equivalent-to-firstprivate-threadprivate-in-OpenMP/m-p/740644#M272</guid>
      <dc:creator>Sushek_Shekar</dc:creator>
      <dc:date>2013-04-11T22:15:13Z</dc:date>
    </item>
    <item>
      <title>Another way to do private</title>
      <link>https://community.intel.com/t5/Software-Archive/Cilk-Plus-s-equivalent-to-firstprivate-threadprivate-in-OpenMP/m-p/740645#M273</link>
      <description>&lt;P&gt;Another way to do private variables in a cilk_for loop is simply to declare them inside the loop body. &amp;nbsp;Then they are allocated on the stack inside the lambda function created out of the loop body and automatically private. &amp;nbsp;The equivalent of a FIRSTPRIVATE variable would be something like&lt;/P&gt;
&lt;P&gt;[cpp]&lt;/P&gt;
&lt;P&gt;myclass init_value;&lt;/P&gt;
&lt;P&gt;cilk_for(int i = 0; i &amp;lt; trip_count; i++)&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; myclass private_value(init_value);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; work(private_value);&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;[/cpp]&lt;/P&gt;
&lt;P&gt;Since init_value is never modified during the paralllel code, using it to initialize private_value is not a race.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; - Barry&lt;/P&gt;</description>
      <pubDate>Fri, 12 Apr 2013 13:36:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/Cilk-Plus-s-equivalent-to-firstprivate-threadprivate-in-OpenMP/m-p/740645#M273</guid>
      <dc:creator>Barry_T_Intel</dc:creator>
      <dc:date>2013-04-12T13:36:00Z</dc:date>
    </item>
    <item>
      <title>When I last tried it,</title>
      <link>https://community.intel.com/t5/Software-Archive/Cilk-Plus-s-equivalent-to-firstprivate-threadprivate-in-OpenMP/m-p/740646#M274</link>
      <description>&lt;P&gt;When I last tried it, compiling with icc didn't give a warning about the shared induction variable implied by&lt;/P&gt;
&lt;P&gt;cilk_for(i=0; ...&lt;/P&gt;
&lt;P&gt;while a warning was issued by icpc.&lt;/P&gt;
&lt;P&gt;It's definitely important to compile in C99 or C++ mode so as to have a private induction variable, so as not to limit scaling to larger numbers of workers.&lt;/P&gt;</description>
      <pubDate>Fri, 12 Apr 2013 14:23:59 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/Cilk-Plus-s-equivalent-to-firstprivate-threadprivate-in-OpenMP/m-p/740646#M274</guid>
      <dc:creator>TimP</dc:creator>
      <dc:date>2013-04-12T14:23:59Z</dc:date>
    </item>
    <item>
      <title>Cilkscreen (or Amplifier)</title>
      <link>https://community.intel.com/t5/Software-Archive/Cilk-Plus-s-equivalent-to-firstprivate-threadprivate-in-OpenMP/m-p/740647#M275</link>
      <description>&lt;P&gt;Cilkscreen (or Amplifier) should tell you about this, as well as any other races in your code. &amp;nbsp;Anyone who writes parallel code should run a race detection religiously. &amp;nbsp;If you haven't checked for races recently, you probably have them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; - Barry&lt;/P&gt;</description>
      <pubDate>Fri, 12 Apr 2013 15:54:40 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/Cilk-Plus-s-equivalent-to-firstprivate-threadprivate-in-OpenMP/m-p/740647#M275</guid>
      <dc:creator>Barry_T_Intel</dc:creator>
      <dc:date>2013-04-12T15:54:40Z</dc:date>
    </item>
    <item>
      <title>It might be worth noting that</title>
      <link>https://community.intel.com/t5/Software-Archive/Cilk-Plus-s-equivalent-to-firstprivate-threadprivate-in-OpenMP/m-p/740648#M276</link>
      <description>&lt;P&gt;It might be worth noting that the code environment used in these forum posts sometimes has an ugly habit of swallowing text between "&amp;lt;" and "&amp;gt;" arguments.&amp;nbsp;&amp;nbsp; Notice that the name of&amp;nbsp;the include file in #include &amp;lt; ... &amp;gt;&amp;nbsp; has disappeared.&amp;nbsp; Are you missing the object type in your declaration of a holder?&lt;/P&gt;
&lt;P&gt;cilk::holder&amp;lt;ObjectType&amp;gt; accessor_holder(accessor);&lt;/P&gt;
&lt;P&gt;Anyway, I have also attached a simple but complete test program that uses a holder, that may be of some use to you.&lt;BR /&gt;Cheers,&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Fri, 12 Apr 2013 18:34:41 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/Cilk-Plus-s-equivalent-to-firstprivate-threadprivate-in-OpenMP/m-p/740648#M276</guid>
      <dc:creator>Jim_S_Intel</dc:creator>
      <dc:date>2013-04-12T18:34:41Z</dc:date>
    </item>
  </channel>
</rss>

