ddemidov / mba

Scattered data interpolation with multilevel B-Splines
MIT License
74 stars 23 forks source link

Code runs slower when openmp is used #28

Open JereKnuutinen opened 7 months ago

JereKnuutinen commented 7 months ago

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 commented 7 months ago

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.

JereKnuutinen commented 5 months ago

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

ddemidov commented 5 months ago

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

JereKnuutinen commented 5 months ago

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 commented 5 months ago

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.