mba icon indicating copy to clipboard operation
mba copied to clipboard

Code runs slower when openmp is used

Open JereKnuutinen opened this issue 10 months ago • 5 comments

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?

JereKnuutinen avatar Apr 02 '24 06:04 JereKnuutinen

There is probably too little work to hide openmp overhead. The only place in the library OMP is used is this: https://github.com/ddemidov/mba/blob/9091b6702d7c6e8e4d50bd777c6d466052839c2c/mba/mba.hpp#L366, so you could comment it out if that makes it faster in your case.

ddemidov avatar Apr 06 '24 16:04 ddemidov

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

JereKnuutinen avatar Jun 06 '24 16:06 JereKnuutinen

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

ddemidov avatar Jun 06 '24 16:06 ddemidov

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.

JereKnuutinen avatar Jun 10 '24 06:06 JereKnuutinen

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

https://github.com/ddemidov/mba/blob/3b296b212315b947f6094704f7c69fba5c1ed2e3/mba/mba.hpp#L414-L419

This could produce slightly different results with floating point arithmetic.

ddemidov avatar Jun 16 '24 19:06 ddemidov