Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OPENMP for loop with reduction #38

Open
arocketguy opened this issue Mar 3, 2021 · 0 comments
Open

OPENMP for loop with reduction #38

arocketguy opened this issue Mar 3, 2021 · 0 comments

Comments

@arocketguy
Copy link

I am trying to get an openmp for loop with reduction to compile and run. Based on the documentation and examples I would have thought something like:

#pragma omp parallel for reduction(+:y) ADOLC_OPENMP
for ( i = 0 ; i < n ; i++ ) {

 y += x[i]*x[i];

 y+= cos(x[i]);

}

would work, but the g++ compiler complains:
error: user defined reduction not found for ‘y’

so it's not figuring out how to reduce y...

playing around with things:

#pragma omp ADOLC_OPENMP parallel for reduction(+:y)
for ( i = 0 ; i < n ; i++ ) {

 y += x[i]*x[i];

 y+= cos(x[i]);

}

does compile and run (correctly it seems), but is only using a single processor.

If I just ignore the reduction (yes, it will be wrong) and go back to the original syntax:

#pragma omp parallel for ADOLC_OPENMP
for ( i = 0 ; i < n ; i++ ) {

 y += x[i]*x[i];

 y+= cos(x[i]);

}

will compile (no error: user defined reduction not found for ‘y’ ), and it does use all the threads given it...but of course it gives the incorrect answer.

Is ADOL-C forcing the reduction down to 1 thread? And am I employing the syntax correctly?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant