Juan David
Juan David

Reputation: 25

How to use OpenACC for computing the Mandelbrot set?

I'm trying to learn to use OpenACC and to begin with I'm implementing it in a simple code for computing the Mandelbrot set but I receive errors when compiling my code.

I found this

OpenACC must have routine information error

and thought it would be easy to use in my code but it didn't seem to work.

These are the routines I want to use OpenACC on, and what I tried

#pragma acc parallel loop copyout(color)

for (int i=0;i<=n0x;i++)
{

Cx=Re_start+dx*i;

  #pragma acc loop

    for (int h=0;h<=n0y;h++)
    {

    Cy=Im_start+dy*h;
    Zx1=0.;
    Zy1=0.;

    #pragma acc loop

        for(int k=0;k<=n;k++ && mod<=4.)
        { 


        Zx=Zx1*Zx1-Zy1*Zy1+Cx;
        Zy=2*Zx1*Zy1+Cy;
        Zx1=Zx;
        Zy1=Zy; 

        mod=(Zx*Zx+Zy*Zy);

            if(mod<=4.)
            {

            if(k==n) 
            color[i][h]=-1; 


            color[i][h]=k+1;

            }

        }  

    }

}

I receive the error (I'm compiling using pgc++ -acc splot.cpp -Minfo=accel)

PGCC-S-0155-Compiler failed to translate accelerator region (see -Minfo messages): Unknown variable reference (splot.cpp: 48)
main:
     48, Generating copyout(color[:][:])
         Generating Tesla code
         52, #pragma acc loop gang /* blockIdx.x */
         59, #pragma acc loop seq
         68, #pragma acc loop vector(128) /* threadIdx.x */
     52, Accelerator restriction: scalar variable live-out from loop: color
     59, Loop is parallelizable
         Accelerator restriction: scalar variable live-out from loop: color
     68, Loop is parallelizable
         Accelerator restriction: scalar variable live-out from loop: color
PGCC-F-0704-Compilation aborted due to previous errors. (splot.cpp)
PGCC/x86-64 Linux 19.4-0: compilation aborted

What do I need to modify to be able to compile and run my code properly?

Upvotes: 0

Views: 204

Answers (1)

Mat Colgrove
Mat Colgrove

Reputation: 5646

The problem is the "&& mod<=4.0" in " for(int k=0;k<=n;k++ && mod<=4.)". Compound expressions in for loops is a known PGI limitation and not currently available in device code generation.

Removing the "&& mod<=4.0" will work around the problem.

I can file an issue report, though I'm unclear why this bit of code is there since it seems extraneous. Can you explain the intent?

Upvotes: 1

Related Questions