AnsweredAssumed Answered

How do I parallelize the following sequential code?

Question asked by shreedhar_pawar on Apr 2, 2013

I wanted to to make the following kernel code parallel,

  In the code below size of a is n, b and c is 8*n and of d is some value less than n(eg : 3*n/4)

 

j=0;

for(i=0;i<n;i++)

  {

     if (a[b[i]]!=a[c[i]])

        {

             d[j]=b[i];

              j++;

       }

}

 

Since the number of elements of a and d aren't the same I am facing a problem to give i=get_global_id(0), since by doing this, in some elements of d there would be nothing placed if the 'if'' condition violates...! So how do I make parallel..?

If not this then, is it possible to delete the "no value" positions of d in the kernel if I store the positions where the values are placed in d in a different array..?

Outcomes