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?

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.