Feature: set default OpenMP parallel number to 1
Background
For those ABACUS freshmen, when they just use mpirun -np $NPROCS abacus to run abacus, they tend to forget about the OpenMP parallel setting OMP_NUM_THREADS, for which in VASP is 1 and often only 1, but sometimes in ABACUS will be $NPROC and lead to low performance.
Describe the solution you'd like
Set default OMP_NUM_THREADS=1 in ABACUS itself will be a user-friendly option, for users will usually use MPI first.
Task list only for developers
- [X] Notice possible changes of behavior
- [ ] Explain the changes of codes in core modules of ESolver, HSolver, ElecState, Hamilt, Operator or Psi
Notice Possible Changes of Behavior (Reminder only for developers)
No response
Notice any changes of core modules (Reminder only for developers)
No response
Notice Possible Changes of Core Modules (Reminder only for developers)
No response
Additional Context
No response
Task list for Issue attackers (only for developers)
- [ ] Review and understand the proposed feature and its importance.
- [ ] Research on the existing solutions and relevant research articles/resources.
- [ ] Discuss with the team to evaluate the feasibility of implementing the feature.
- [ ] Create a design document outlining the proposed solution and implementation details.
- [ ] Get feedback from the team on the design document.
- [ ] Develop the feature following the agreed design.
- [ ] Write unit tests and integration tests for the feature.
- [ ] Update the documentation to include the new feature.
- [ ] Perform code review and address any issues.
- [ ] Merge the feature into the main branch.
- [ ] Monitor for any issues or bugs reported by users after the feature is released.
- [ ] Address any issues or bugs reported by users and continuously improve the feature.
@mohanchen and @dyzheng, Are you agree with that?
I agree with that, in many environment, OpenMP parallel will lead to pool performance, the default setting of threads should not be more than 1.
@QuantumMisaka
FYI: https://github.com/deepmodeling/abacus-develop/blob/3d2f3061a26e7bb53db4735607a2950fca3ae2c4/source/module_base/parallel_global.cpp#L181-L218
@QuantumMisaka
FYI:
https://github.com/deepmodeling/abacus-develop/blob/3d2f3061a26e7bb53db4735607a2950fca3ae2c4/source/module_base/parallel_global.cpp#L181-L218
Simply remove line 182-184 will not have any change on OpenMP behavior (It seems the only change is the OpenMP threads in the warning message), which is weird and need check.
@QuantumMisaka any update?
Hi @QuantumMisaka , apart from the environment variable "OMP_NUM_THREADS", according to
[https://www.openmp.org/wp-content/uploads/OpenMP-4.0-C.pdf]
there are two other ways that can affect the number of threads used by openmp. The first one is to explicitly specify the number of threads in an openmp directive (like #pragma omp parallel num_threads(4)), and the second is to use the function "omp_set_num_threads()" (requires #include <omp.h>).
The precedence follows directive > function > environment variable, i.e., the one specified in the directive has the highest priority, which will override the rest; if not specified in the directive, the one set by "omp_set_num_threads()" will affect all subsequent openmp code; if neither the directive nor the function is called, openmp will use the environment variable. Finally, if the environment variable is not set, different system environment might make their own assumptions, which is our current situation.
I think we might try to call omp_set_num_threads(...) at the very beginning of the code.
@QuantumMisaka, any update?