Skip to content

Commit 5d635e7

Browse files
committed
using GlobalV::NTHREADS_PER_PROC
- avoiding usage of extern `omp_number` in *parallel_global.cpp* - add error message for bad OMP setting
1 parent 9e38d6f commit 5d635e7

File tree

4 files changed

+7
-5
lines changed

4 files changed

+7
-5
lines changed

source/module_base/global_variable.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace GlobalV
1717
//----------------------------------------------------------
1818

1919
int NPROC = 1; ///< global number of process
20-
int THREAD_PER_PROC = 1; ///< global number of thread per process
20+
int NTHREAD_PER_PROC = 1; ///< global number of thread per process
2121
int KPAR = 1; ///< global number of pools
2222
int KPAR_LCAO = 1; ///< global number of pools for LCAO diagonalization only
2323
int MY_RANK = 0; ///< global index of process

source/module_base/global_variable.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace GlobalV
1717
// EXPLAIN : Parallel information
1818
// GLOBAL VARIABLES :
1919
// NAME : NPROC( global number of process )
20-
// NAME : THREAD_PER_PROC ( global number of threads per process )
20+
// NAME : NTHREAD_PER_PROC ( global number of threads per process )
2121
// NAME : KPAR( global number of pools )
2222
// NAME : MY_RANK( global index of process )
2323
// NAME : MY_POOL( global index of pool (count in pool))
@@ -32,7 +32,7 @@ namespace GlobalV
3232
// NAME : KPAR_LCAO ( global number of pools for LCAO diagonalization only)
3333
//========================================================================
3434
extern int NPROC;
35-
extern int THREAD_PER_PROC;
35+
extern int NTHREAD_PER_PROC;
3636
extern int KPAR;
3737
extern int MY_RANK;
3838
extern int MY_POOL;

source/module_base/parallel_global.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ void Parallel_Global::read_mpi_parameters(int argc, char** argv, int& NPROC, int
139139
#endif
140140
mpi_number = process_num;
141141
omp_number = current_thread_num;
142+
GlobalV::NTHREAD_PER_PROC = current_thread_num;
142143
if (current_thread_num * process_num > max_thread_num && local_rank == 0)
143144
{
144145
std::stringstream mess;
@@ -150,6 +151,8 @@ void Parallel_Global::read_mpi_parameters(int argc, char** argv, int& NPROC, int
150151
// the user may take their own risk by set the OMP_NUM_THREADS env var.
151152
if (std::getenv("OMP_NUM_THREADS") == nullptr)
152153
{
154+
// print error message
155+
std::cerr << "Error: OMP_NUM_THREADS setting is invalid. Please set it to a proper value." << std::endl;
153156
exit(1);
154157
}
155158
}

source/module_io/print_info.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
#include "module_base/global_variable.h"
44
#include "module_parameter/parameter.h"
5-
#include "module_base/parallel_global.h"
65

76

87
namespace ModuleIO
@@ -92,7 +91,7 @@ void setup_parameters(UnitCell& ucell, K_Vectors& kv)
9291
}
9392

9493
std::cout << std::setw(12) << GlobalV::NPROC
95-
<< std::setw(12) << Parallel_Global::omp_number * GlobalV::NPROC;
94+
<< std::setw(12) << GlobalV::NTHREAD_PER_PROC * GlobalV::NPROC;
9695
if (orbinfo) { std::cout << std::setw(12) << PARAM.globalv.nlocal; }
9796

9897
std::cout << std::endl;

0 commit comments

Comments
 (0)