4

I want to use C++ and vectors. I had C code with C arrays created like this:

double* data = (double*)malloc(sizeof(double) * n);
double* result = (double*)malloc(sizeof(double) * n);

#pragma omp target data map(tofrom: data[0:n],result[0:n])
//loop

Now I use C++ vector and I get:

example.cpp:31:41: error: expected variable name or an array item
    #pragma omp target data map(tofrom: data[0:n],result[0:n])

Here they say OpenMP4 introduced user-defined reductions. But have it any analogs for data maps?

Community
  • 1
  • 1
DuckQueen
  • 772
  • 10
  • 62
  • 134

1 Answers1

4

You could always get the pointers of the underlying storage of std::vector and then use them in the same way as in your C code.

double* data = vec_data.data();
double* result = vec_res.data();
int n = vec_data.size();

#pragma omp target data map(tofrom:data[0:n],result[0:n])
//loop
kangshiyin
  • 9,681
  • 1
  • 17
  • 29