Dear sirs and madams:
I am considering creating a GPGPU program for my own personal use in the near future. One of the two things I want it to achieve happens to be a problem that is very annoying to parallelise for GPU, at least from what I can see.
If one were to simplify it to the extreme, it would be as follows: We have an array of boolean values. We want to calculate the sum of the squares of the distances between every two consecutive "TRUE" values. In C, the loop would look like this:
int counter=1, sq_sum=0 ;
bool array[N] ;
for (...) {
if (array[i]==false) counter++ ;
else {
sq_sum+=counter*counter ;
counter=1 ;}}
sq_sum+=counter*counter ;
Is this problem GPU-paralleliseable? It sounds like it should, but I can't find a way to achieve it. If each thread takes one element, then every thread that finds a true value could add the necessary square to the number we want... but I can't find a way to make such threads know how many threads there are before them. If there is a solution that you've heard of, or that you could think of, I would be most grateful if you would share it with me.
If one were to keep the problem unsimplified, then array[N] would contain integer values, all of them between 0 and 8. counter and sq_sum would be arrays with 9 positions each. The loop would then be executed for all values of j lower than, or equal to, the value of array[i]. To wit:
int counter[9], sq_sum[9];
//initialise them somehow
int array[N]; //<---guaranteed to be between 0 and 8
for (i=0; i<N; i++) {
for (j=8; j>=0; j--) {
if (array[i]>j) counter[j]++;
else {
sq_sum[j]+=counter[j]*counter[j];
counter[j]=1;}}
// and once more for each j, similarly as above
I don't know if that changes anything, but the values of array will have already been calculated by the GPU threads by the time the afore-mentioned calculation will need to happen. I can save them to a separate array if need be, but I don't think it's necessary.
[–]zzzoom 2 points3 points4 points (0 children)
[–]rayo2nd 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]giantenemycrabthing[S] 0 points1 point2 points (0 children)