<?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 Making parallel calls to rand in Software Archive</title>
    <link>https://community.intel.com/t5/Software-Archive/Parallel-Search-With-Cilk-Plus/m-p/1005512#M31965</link>
    <description>&lt;P&gt;Making parallel calls to rand() is generally not going to get good performance because there will be contention (and probably a race) on the shared state within rand().&lt;/P&gt;

&lt;P&gt;One solution is to use the deterministic parallel random-number generator that is implemented in Cilkpub. &amp;nbsp;You can download that code from the Cilk Plus community website:&lt;BR /&gt;
	&lt;BR /&gt;
	&lt;A href="http://www.cilkplus.org/sites/default/files/contributions/cilkpub_v104.tar.gz" target="_blank"&gt;http://www.cilkplus.org/sites/default/files/contributions/cilkpub_v104.tar.gz&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;With that, the code looks something like:&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;#include &amp;lt;cilkpub/dotmix.h&amp;gt;


...

cilkpub::DotMix rng(seed);   // Seed RNG
cilk_for(int i = 0; i &amp;lt; n; ++i) {
    currentPoint&lt;I&gt; = rng.get() % 3;
}
&lt;/I&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;BR /&gt;
	That being said, I'd first consider Arch's suggestion of investigating whether there are serial optimizations you can make to your program first. &amp;nbsp;I don't know the details of the problem you are trying to solve, but it sounds like hashing would be the better approach than linear search...&lt;BR /&gt;
	&lt;BR /&gt;
	Cheers,&lt;BR /&gt;
	&lt;BR /&gt;
	Jim&lt;/P&gt;</description>
    <pubDate>Fri, 02 May 2014 13:05:47 GMT</pubDate>
    <dc:creator>Jim_S_Intel</dc:creator>
    <dc:date>2014-05-02T13:05:47Z</dc:date>
    <item>
      <title>Parallel Search With Cilk Plus</title>
      <link>https://community.intel.com/t5/Software-Archive/Parallel-Search-With-Cilk-Plus/m-p/1005509#M31962</link>
      <description>&lt;P&gt;Hi everyone , I have a program that generating random number if it does not exist in ( allocated custom size) array &amp;nbsp;then add array. But if custom size is very big &amp;nbsp; ( 1 million ) &amp;nbsp;after a period search is very slowing down. I did learn &amp;nbsp;cilk_for and reducers.I want to paralleize but I could not decide what &lt;STRONG&gt;reducer is suitable for array.&lt;/STRONG&gt;&amp;nbsp;Is there someone who can help me ?&amp;nbsp;&lt;/P&gt;

&lt;P&gt;(Sorry for my english if you do not understand my problem you can write my e-mail&amp;nbsp; &amp;nbsp;" 03011241@st.meliksah.edu.tr " ) &amp;nbsp;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 May 2014 15:08:52 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/Parallel-Search-With-Cilk-Plus/m-p/1005509#M31962</guid>
      <dc:creator>Ömer_Faruk_Kalkan</dc:creator>
      <dc:date>2014-05-01T15:08:52Z</dc:date>
    </item>
    <item>
      <title>Before trying to parallelize</title>
      <link>https://community.intel.com/t5/Software-Archive/Parallel-Search-With-Cilk-Plus/m-p/1005510#M31963</link>
      <description>&lt;P&gt;Before trying to parallelize the code, I'd like to understand if all practical serial improvements have been made. &amp;nbsp;For example, I'm wondering if &lt;A href="http://en.wikipedia.org/wiki/Open_addressing"&gt;open-addressing hashing&lt;/A&gt; might be used. &amp;nbsp;That could decrease the search time from O(N) to O(1) in the average case.&lt;/P&gt;</description>
      <pubDate>Thu, 01 May 2014 16:24:46 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/Parallel-Search-With-Cilk-Plus/m-p/1005510#M31963</guid>
      <dc:creator>ARCH_R_Intel</dc:creator>
      <dc:date>2014-05-01T16:24:46Z</dc:date>
    </item>
    <item>
      <title>I did not use any hash</title>
      <link>https://community.intel.com/t5/Software-Archive/Parallel-Search-With-Cilk-Plus/m-p/1005511#M31964</link>
      <description>&lt;P&gt;I did not use any hash function. linear search is being done with....&lt;/P&gt;

&lt;P&gt;I have a question also ..This code snippet is entry of &amp;nbsp;search program.&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;    srand (time (NULL)); 

    char * first;
    first = ( char * ) malloc (14348907);
    char * currentPoint = first;

    for (int i = 0; i &amp;lt; 14348907; i++)
    {
        *currentPoint =rand () % 3;     //  it is simple assign  but assignment process will be complex
        currentPoint++;
    }
&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp; I want to &amp;nbsp;use reducer for currentPoint and parallize this loop ...&lt;/P&gt;</description>
      <pubDate>Fri, 02 May 2014 09:32:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/Parallel-Search-With-Cilk-Plus/m-p/1005511#M31964</guid>
      <dc:creator>Ömer_Faruk_Kalkan</dc:creator>
      <dc:date>2014-05-02T09:32:00Z</dc:date>
    </item>
    <item>
      <title>Making parallel calls to rand</title>
      <link>https://community.intel.com/t5/Software-Archive/Parallel-Search-With-Cilk-Plus/m-p/1005512#M31965</link>
      <description>&lt;P&gt;Making parallel calls to rand() is generally not going to get good performance because there will be contention (and probably a race) on the shared state within rand().&lt;/P&gt;

&lt;P&gt;One solution is to use the deterministic parallel random-number generator that is implemented in Cilkpub. &amp;nbsp;You can download that code from the Cilk Plus community website:&lt;BR /&gt;
	&lt;BR /&gt;
	&lt;A href="http://www.cilkplus.org/sites/default/files/contributions/cilkpub_v104.tar.gz" target="_blank"&gt;http://www.cilkplus.org/sites/default/files/contributions/cilkpub_v104.tar.gz&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;With that, the code looks something like:&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;#include &amp;lt;cilkpub/dotmix.h&amp;gt;


...

cilkpub::DotMix rng(seed);   // Seed RNG
cilk_for(int i = 0; i &amp;lt; n; ++i) {
    currentPoint&lt;I&gt; = rng.get() % 3;
}
&lt;/I&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;BR /&gt;
	That being said, I'd first consider Arch's suggestion of investigating whether there are serial optimizations you can make to your program first. &amp;nbsp;I don't know the details of the problem you are trying to solve, but it sounds like hashing would be the better approach than linear search...&lt;BR /&gt;
	&lt;BR /&gt;
	Cheers,&lt;BR /&gt;
	&lt;BR /&gt;
	Jim&lt;/P&gt;</description>
      <pubDate>Fri, 02 May 2014 13:05:47 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/Parallel-Search-With-Cilk-Plus/m-p/1005512#M31965</guid>
      <dc:creator>Jim_S_Intel</dc:creator>
      <dc:date>2014-05-02T13:05:47Z</dc:date>
    </item>
    <item>
      <title>Thank you for suggestions...I</title>
      <link>https://community.intel.com/t5/Software-Archive/Parallel-Search-With-Cilk-Plus/m-p/1005513#M31966</link>
      <description>&lt;P&gt;Thank you for suggestions...I decided to make hash function.And I will implement Jim`s sugesstion.(&amp;nbsp;&lt;SPAN style="font-size: 12px; line-height: 18px;"&gt;deterministic parallel random-number generator&amp;nbsp;&lt;/SPAN&gt;&amp;nbsp;)&lt;/P&gt;

&lt;P&gt;I briefly tell you what do my program . Generator is creating guess 0 , 1 or 2 as random 15 steps. (&amp;nbsp;I will produce with an algorithm in next ) . Later ,&amp;nbsp;merging to be juxtaposed&amp;nbsp;which produced it like this "011012212012211" . After , it is adding in array if the result is true.&lt;/P&gt;

&lt;P&gt;Now in this step I am converting &amp;nbsp;to decimal&amp;nbsp;which is a 15-digit number at the base 3&amp;nbsp;like this&amp;nbsp;011012212012211 =&amp;nbsp;&lt;STRONG&gt;2.241.103&amp;nbsp;&lt;/STRONG&gt;. When search the element (&lt;SPAN style="font-weight: 700;"&gt;2.241.103&amp;nbsp;&lt;/SPAN&gt;)&amp;nbsp;if that element is empty, the result will be true.&amp;nbsp;So this converting provides &lt;STRONG&gt;O(n) to O(1)&lt;/STRONG&gt;. But&amp;nbsp;too many iterations are still experiencing slowdowns.Here we can do to parallel conversion stage.&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;    long number = 0;
    int j = 14; // j will be the power of the 3 in loop

    for (int i = 0; i &amp;lt; 15; i++, j--)
    {
        number += (*currentPoint) * (pow (3 , j)); // convert to number-based 10
        currentPoint++;
    }&lt;/PRE&gt;

&lt;P&gt;This section parallels how should it be ?&lt;/P&gt;

&lt;P&gt;Thanks...&lt;/P&gt;</description>
      <pubDate>Fri, 02 May 2014 17:40:52 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/Parallel-Search-With-Cilk-Plus/m-p/1005513#M31966</guid>
      <dc:creator>Ömer_Faruk_Kalkan</dc:creator>
      <dc:date>2014-05-02T17:40:52Z</dc:date>
    </item>
    <item>
      <title>Variables j and currentPoint</title>
      <link>https://community.intel.com/t5/Software-Archive/Parallel-Search-With-Cilk-Plus/m-p/1005514#M31967</link>
      <description>&lt;P&gt;Variables j and currentPoint are what compiler people call "induction variables", because their value in each iteration depends on their value in the previous iteration. &amp;nbsp;Parallelization requires removing induction variables, typically by calculating their values directly as a function of the loop index variable. &amp;nbsp;In your example, j is 14-i and currentPoint is the original currentPoint+i. &amp;nbsp;If you need their values after the loop, add an explicit calculation after the loop that computes their values. &amp;nbsp;Here is what the code looks like after induction variables are replaced with direct calculations:&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;long number = 0;
int j = 14; // j will be the power of the 3 in loop

for (int i = 0; i &amp;lt; 15; i++, j--)
{
    number += (*(currentPoint+i)) * (pow (3 , j-i)); // convert to number-based 10
}
j -= 15;
currentPoint += 15;&lt;/PRE&gt;

&lt;P&gt;Then the for can be replaced by cilk_for and number declared as a cilk::reducer_opadd&amp;lt;long&amp;gt;.&lt;/P&gt;</description>
      <pubDate>Fri, 02 May 2014 19:18:44 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/Parallel-Search-With-Cilk-Plus/m-p/1005514#M31967</guid>
      <dc:creator>ARCH_R_Intel</dc:creator>
      <dc:date>2014-05-02T19:18:44Z</dc:date>
    </item>
    <item>
      <title>I try your code but results</title>
      <link>https://community.intel.com/t5/Software-Archive/Parallel-Search-With-Cilk-Plus/m-p/1005515#M31968</link>
      <description>&lt;P&gt;I try your code but results are not true, I`ve changed like this and&amp;nbsp;began to work properly...&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;
  cilk::reducer_opadd&amp;lt;long&amp;gt;number (0);       
.
.
.

 cilk_for (int i = 14; i &amp;gt;= 0; i--)
        {
            number += (*(currentPoint+(14-i))) * (pow (3 , i));// this code convert to number-based 10
        }

        currentPoint += 15;
        number.set_value (0); // needed for the next iteration
.
.
.&lt;/PRE&gt;

&lt;P&gt;I can now generate and search quickly . thanks :)&lt;/P&gt;</description>
      <pubDate>Sat, 03 May 2014 11:38:28 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/Parallel-Search-With-Cilk-Plus/m-p/1005515#M31968</guid>
      <dc:creator>Ömer_Faruk_Kalkan</dc:creator>
      <dc:date>2014-05-03T11:38:28Z</dc:date>
    </item>
  </channel>
</rss>

