Skip to content

Commit

Permalink
Fix: nosmt OMP Threads Default (AMReX-Codes#3647)
Browse files Browse the repository at this point in the history
## Summary

Fix that `OMP_NUM_THREADS` was ignored in non-verbose runs.

## Additional background

Follow-up to AMReX-Codes#3607

## Checklist

The proposed changes:
- [x] fix a bug or incorrect behavior in AMReX
- [ ] add new capabilities to AMReX
- [ ] changes answers in the test suite to more than roundoff level
- [ ] are likely to significantly affect the results of downstream AMReX
users
- [ ] include documentation in the code and/or rst files, if appropriate
  • Loading branch information
ax3l authored Nov 29, 2023
1 parent 44c5c7a commit 0cd1385
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions Src/Base/AMReX_OpenMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,13 @@ namespace amrex::OpenMP
// default or OMP_NUM_THREADS environment variable
} else if (omp_threads == "nosmt") {
char const *env_omp_num_threads = std::getenv("OMP_NUM_THREADS");
if (env_omp_num_threads != nullptr && amrex::system::verbose > 1) {
if (env_omp_num_threads == nullptr) {
omp_set_num_threads(numUniquePhysicalCores());
}
else if (amrex::system::verbose > 1) {
amrex::Print() << "amrex.omp_threads was set to nosmt,"
<< "but OMP_NUM_THREADS was set. Will keep "
<< "OMP_NUM_THREADS=" << env_omp_num_threads << ".\n";
} else {
omp_set_num_threads(numUniquePhysicalCores());
}
} else {
std::optional<int> num_omp_threads = to_int(omp_threads);
Expand Down

0 comments on commit 0cd1385

Please sign in to comment.