OpenACC: Complex loop carried dependence of '*(*(b))' prevents parallelization

3.2k views Asked by At

I am using OpenACC with dynamic array allocation. Here is how I allocate:

float **a;
float **b;
float **c;
float **seq;
a=(float**)malloc(SIZE*sizeof(float*));
b=(float**)malloc(SIZE*sizeof(float*));
c=(float**)malloc(SIZE*sizeof(float*));
seq=(float**)malloc(SIZE*sizeof(float*));
for(i=0; i<SIZE; i++){
        a[i]=(float*)malloc(SIZE*sizeof(float));
        b[i]=(float*)malloc(SIZE*sizeof(float));
        c[i]=(float*)malloc(SIZE*sizeof(float));
        seq[i]=(float*)malloc(SIZE*sizeof(float));
}

and here is how I am paralleling the matrix add:

#pragma acc kernels copyin(a[0:SIZE][0:SIZE],b[0:SIZE][0:SIZE]) copy(c[0:SIZE][0:SIZE])
        for (i = 0; i < SIZE; ++i) {
                for (j = 0; j < SIZE; ++j) {
                        c[i][j] = a[i][j] + b[i][j];
                }
        }

When I compile this code with pgcc it detect dependency on float** pointers over loop iterations and generates all scalar kernel (1 block 1 thread-per-block) which performs poorly as expected:

 40, Complex loop carried dependence of '*(*(b))' prevents parallelization
     Complex loop carried dependence of '*(*(a))' prevents parallelization
     Complex loop carried dependence of '*(*(c))' prevents parallelization
     Accelerator scalar kernel generated
     CC 1.0 : 11 registers; 40 shared, 4 constant, 0 local memory bytes
     CC 2.0 : 22 registers; 0 shared, 56 constant, 0 local memory bytes

The loop is obviously parallel and I think this can be detected by compiler too. I am curious how to explain it to pgcc?

Thanks in advance.

1

There are 1 answers

4
lashgar On BEST ANSWER

I think I found the answer. The key is to use independent clause:

    #pragma acc data copyin(a[0:SIZE][0:SIZE],b[0:SIZE][0:SIZE]) copy(c[0:SIZE][0:SIZE])
    {
             # pragma acc region 
             {
                    #pragma acc loop independent vector(16)
                    for (i = 0; i < SIZE; ++i) {
                            #pragma acc loop independent vector(16)
                            for (j = 0; j < SIZE; ++j) {
                                   c[i][j] = a[i][j] + b[i][j];
                            }
                    }
             }
    }