-
Notifications
You must be signed in to change notification settings - Fork 96
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
Add number of OpenMP threads to dump file #2868
Conversation
clang-tidy review says "All clean, LGTM! 👍" |
On 2/20/24 10:01, David Dickinson wrote:
***@***.**** commented on this pull request.
It's a long time since I've worked with BOUT++ internals, but could the
|ifdef| be replaced by a check of |options["use_openmp"]|?
I thought the omp_get_max_threads() function would only be definied if
we use openmp, thus it might work with an if constexpr, but I am not
sure whether that would be C++17? bout::build::use_openmp should be a
constexpr, and thus usable in a if constexpr ...
|
Yes sorry, immediately after posting the comment I realised it was a silly suggestion so deleted it. |
clang-tidy review says "All clean, LGTM! 👍" |
Sorry, I was confused why I couldn't see it on the web. Looking at: https://en.cppreference.com/w/cpp/language/if it seems that would be possible if that was within a function, but does not seem to be possible in normal function. We could add |
This could be generally useful 👍 Does it make sense to actually |
There is one case where it may be set to 0 without openmp, but in other cases it is 1. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-tidy made some suggestions
clang-tidy review says "All clean, LGTM! 👍" |
Co-authored-by: Peter Hill <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lovely, thanks @dschwoerer ! Always nice to remove some #ifdef
s
clang-tidy review says "All clean, LGTM! 👍" |
I'm on the fence about this. In some sense, without OpenMP we have no threads -- there's definitely a measurable difference between 1 thread and no OpenMP, but I guess we do also store whether or not OpenMP is enabled, so we can use that in post-processing if necessary. |
I vote for |
The OpenMP builds are failing because we're missing #include "bout/build_defines.hxx" in |
Otherwise the header does not expose the correct definitions and macros, leading to potential bugs.
clang-tidy review says "All clean, LGTM! 👍" |
clang-tidy review says "All clean, LGTM! 👍" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-tidy made some suggestions
include/bout/openmpwrap.hxx
Outdated
inline int constexpr omp_get_num_threads() { return 1; } | ||
inline int constexpr omp_get_thread_num() { return 0; } | ||
#else | ||
#error OpenMP used but BOUT++ thinks it is disabled |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: OpenMP used but BOUT++ thinks it is disabled [clang-diagnostic-error]
#error OpenMP used but BOUT++ thinks it is disabled
^
clang-tidy review says "All clean, LGTM! 👍" |
The cuda builds are worrying me. They seem to have openmp enabled, but BOUT_USE_OPENMP is disabled. That means that all the thread-safety feature we can enable are not enabled. That might work most of the time (I have not tried) but can lead to race conditions, data corruption (two threads using the same data block) and crashes (random and annoying, but still better then simply wrong results). I have added a check now, which is why the cuda build fails. One solution would be to just enable openmp for BOUT++ for cuda. The other builds with openmp are failing in the test for |
Verbose CUDA build here: https://github.com/boutproject/BOUT-dev/actions/runs/8002349081/job/21855360746 |
Also, I noticed |
So something adds |
It might be coming from RAJA or UMPIRE, it doesn't appear to be turned on after we detect CUDA: https://github.com/boutproject/BOUT-dev/actions/runs/8002552988/job/21856012784#step:4:64 |
OpenMP is enabled any way, but if bout is not aware of using openmp, it might misbehave.
clang-tidy review says "All clean, LGTM! 👍" |
BOUT_OMP is split in BOUT_OMP_SAFE for cases where we want to ensure that bout++ behaves correctly in an openmp parallel environement. BOUT_OMP_PERF on the other hand enables using openmp for parallel regions. BOUT_OMP_SAFE is enabled whenever openmp is detected, while BOUT_OMP_PERF is a user option.
clang-tidy review says "All clean, LGTM! 👍" |
Thanks for fixing this @dschwoerer, but it feels a bit like overkill now, as you say just to add one flag to the output! It sort of sidesteps the issue of why the CUDA build is getting OpenMP turned on when we haven't requested it. @ggeorgakoudis Is this coming from the RAJA dependency? Should we actually be forcing OpenMP on in BOUT++ if RAJA is built with OpenMP? Just because a dependency uses OpenMP doesn't necessarily mean we need to enable it in BOUT++ to ensure thread safety -- that depends on whether we're passing callbacks that include thread unsafe code. |
@ZedThree No, I haven't made any changes to the build system so I do not explicitly set openmp flags in compilation. It may be picked up by including RAJA (since its spack installation in the CI container includes the openmp variant), although I haven't found the exact spot in the cmake file hierarchy where this happens (let me know if you spot it). We can enable openmp in the CUDA CI configuration (https://github.com/boutproject/BOUT-dev/actions/runs/8002552988/job/21856012784#step:4:15) to avoid BOUT++ thinking it builds without openmp when RAJA pulls that in. Makes sense? |
I did not mean overkill, I just meant feature creep. I think there was a bug that hasn't been noticed before and this fixes it.
Why would this be limited to callbacks? I think BOUT++ should always try to be on the safe side. Otherwise we could go back to commit 62f3d2c and ignore all of the other changes ... however I think it is not so bad, compared to getting sometimes wrong results because some memory block is double used and contains the wrong data. |
Much nicer than having to parse the log to get the number of threads for e.g. plotting ...