2

I'm trying to paralelize some code with OpenACC.

        #pragma acc parallel loop reduction (+:matriz())
        for(auto i = 0; i <= (width-siz); i += siz)
            for(auto j = 0; j <= (width-siz); j += siz)
                for(auto k = 0; k <= (width-siz); k += siz)
                    for(auto l = 0; l <= (width-siz); l += siz)
                        matriz[i][j][k][l] = matriz[i][j][k+1][l] + matriz[i][j][k][l+1];

matriz is declared like this:

vector<vector<vector<vector<short>>>> matriz;

I compile with this command:

pgc++ -std=c++11 -acc -ta=multicore,tesla -Minfo=accel  boxcount4d.cpp -o boxcount4d

And I get this error:


"boxcount4d.cpp", line 304: error: expected a ")"
          #pragma acc parallel loop reduction (+:matriz())
                                                       ^

1 error detected in the compilation of "boxcount4d.cpp".

I don't know if it is just a syntax error or if I have to use this library https://docs.nvidia.com/cuda/thrust/index.html because I couln't use STL vectors with OpenACC

1 Answers1

1

It's a syntax error due to the extra "()". Correct syntax would be:

#pragma acc parallel loop reduction (+:matriz)

Though why are you using a reduction here? It's not needed since you're not trying parallelize the k and l loops.

I couln't use STL vectors with OpenACC

You can use vectors in device code, though vectors are not thread safe so you need to be careful to only use the access operator, "[]". Also it's recommended to compile with CUDA unified memory ("-ta=multicore,tesla:managed") since manually trying to copy vectors can be difficult.

Mat Colgrove
  • 5,441
  • 1
  • 10
  • 11