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

Code runs slower when openmp is used #28

Open
JereKnuutinen opened this issue Apr 2, 2024 · 5 comments
Open

Code runs slower when openmp is used #28

JereKnuutinen opened this issue Apr 2, 2024 · 5 comments

Comments

@JereKnuutinen
Copy link

JereKnuutinen commented Apr 2, 2024

For some reason, the code gets slower when OpenMP is used together with the release build compared to case when I just comment target_link_libraries(example PUBLIC OpenMP::OpenMP_CXX) in my cmakelist. Is there some reason for this?

@ddemidov
Copy link
Owner

ddemidov commented Apr 6, 2024

There is probably too little work to hide openmp overhead. The only place in the library OMP is used is this:

mba/mba/mba.hpp

Line 366 in 9091b67

#pragma omp parallel
, so you could comment it out if that makes it faster in your case.

@JereKnuutinen
Copy link
Author

Is there need for commenting since I think that compilers are suppose to ignore pragmas they do not understand?

@ddemidov
Copy link
Owner

ddemidov commented Jun 6, 2024

I thought you want to keep using openmp in your outside project, but remove it from the mba code

@JereKnuutinen
Copy link
Author

JereKnuutinen commented Jun 10, 2024

I also noticed that the MBA does not give always same result if OpenMP is used in compilation. How that can be possible? If I do not use openMP or If I use older commits where openMP is not utilized this does not happen.

@ddemidov
Copy link
Owner

The only reason I can think of is that when using openmp the order of summation is unpredictable here:

mba/mba/mba.hpp

Lines 414 to 419 in 3b296b2

for(ptrdiff_t i = 0; i < m; ++i) {
#pragma omp atomic
delta[i] += t_delta[i];
#pragma omp atomic
omega[i] += t_omega[i];
}

This could produce slightly different results with floating point arithmetic.

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

2 participants