Skip to content

Commit 3203ec6

Browse files
Add number of threads output in stdout (#5281)
* leave a space for use GlobalV::THREAD_PRE_PROC * use extern omp_number var * remove redundant ';' * bug fix and print modification * using GlobalV::NTHREADS_PER_PROC - avoiding usage of extern `omp_number` in *parallel_global.cpp* - add error message for bad OMP setting * change nthreads variables to PARAM.globalv.nthread_per_proc * [pre-commit.ci lite] apply automatic fixes * Update parallel_global.cpp fix removal of #include ”parallel_global.h“ * change usage of nthreads to extern omp_number in parallel_global.h temporally change it to check error in CI * Use WARNING_QUIT instead of exit(1) * usage and init of PARAM.globalv.nthread_per_proc * Update CMakeLists.txt * Update CMakeLists.txt * fall back WARNING_QUIT to exit(1) with error message * change function name to involve omp info * remove redundant binary * remove space --------- Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
1 parent efb83c8 commit 3203ec6

File tree

14 files changed

+40
-17
lines changed

14 files changed

+40
-17
lines changed

source/main.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,14 @@ int main(int argc, char** argv)
2727
*/
2828
int nproc = 1;
2929
int my_rank = 0;
30-
Parallel_Global::read_mpi_parameters(argc, argv, nproc, my_rank);
30+
int nthread_per_proc = 1;
31+
Parallel_Global::read_pal_param(argc, argv, nproc, nthread_per_proc, my_rank);
3132
#ifdef _OPENMP
3233
// ref: https://www.fftw.org/fftw3_doc/Usage-of-Multi_002dthreaded-FFTW.html
3334
fftw_init_threads();
3435
fftw_plan_with_nthreads(omp_get_max_threads());
3536
#endif
36-
PARAM.set_rank_nproc(my_rank, nproc);
37+
PARAM.set_pal_param(my_rank, nproc, nthread_per_proc);
3738

3839
/*
3940
main program for doing electronic structure calculations.

source/module_base/parallel_global.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#include "module_base/global_function.h"
1515
#include "module_base/parallel_common.h"
1616
#include "module_base/parallel_reduce.h"
17+
#include "module_parameter/parameter.h"
18+
// #include "module_base/tool_quit.h"
1719
#include "version.h"
1820

1921
#include <iostream>
@@ -85,7 +87,12 @@ void Parallel_Global::split_grid_world(const int diag_np, const int& nproc, cons
8587
return;
8688
}
8789

88-
void Parallel_Global::read_mpi_parameters(int argc, char** argv, int& NPROC, int& MY_RANK)
90+
// changed from read_mpi_parameters in 2024-1018
91+
void Parallel_Global::read_pal_param(int argc,
92+
char** argv,
93+
int& NPROC,
94+
int& NTHREAD_PER_PROC,
95+
int& MY_RANK)
8996
{
9097
#ifdef __MPI
9198
#ifdef _OPENMP
@@ -150,6 +157,10 @@ void Parallel_Global::read_mpi_parameters(int argc, char** argv, int& NPROC, int
150157
// the user may take their own risk by set the OMP_NUM_THREADS env var.
151158
if (std::getenv("OMP_NUM_THREADS") == nullptr)
152159
{
160+
// usage of WARNING_QUIT need module_base/tool_quit.cpp
161+
// lead to undefined error in unit_test building
162+
// ModuleBase::WARNING_QUIT( "Parallel_Global::read_pal_param","OMP_NUM_THREADS setting is invalid. Please set it to a proper value.");
163+
std::cerr << "ERROR: OMP_NUM_THREADS setting is invalid. Please set it to a proper value." << std::endl;
153164
exit(1);
154165
}
155166
}
@@ -162,6 +173,8 @@ void Parallel_Global::read_mpi_parameters(int argc, char** argv, int& NPROC, int
162173
<< "Local thread limit: " << max_thread_num << std::endl;
163174
}
164175

176+
NTHREAD_PER_PROC = current_thread_num;
177+
165178
if (MY_RANK == 0)
166179
{
167180
#ifdef VERSION
@@ -192,7 +205,7 @@ void Parallel_Global::read_mpi_parameters(int argc, char** argv, int& NPROC, int
192205
<< std::endl
193206
<< " Commit: " << commit << std::endl
194207
<< std::endl;
195-
time_t time_now = time(NULL);
208+
time_t time_now = time(nullptr);
196209
std::cout << " " << ctime(&time_now);
197210
}
198211

source/module_base/parallel_global.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ extern int omp_number;
1818
//---------------------------
1919
// call at the very first.
2020
//---------------------------
21-
void read_mpi_parameters(int argc, char** argv, int& NPROC, int& MY_RANK);
21+
22+
// changed from read_mpi_parameters in 2024-1018
23+
void read_pal_param(int argc, char** argv, int& NPROC, int& NTHREAD_PER_PROC, int& MY_RANK);
2224
#ifdef __MPI
2325
void myProd(std::complex<double>* in, std::complex<double>* inout, int* len, MPI_Datatype* dptr);
2426
#endif

source/module_cell/module_symmetry/run_symmetry.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ int main(int argc, char **argv)
1414
std::cout << "Hello, this is the 'symmetry' module of ABACUS." << std::endl;
1515

1616
std::cout << "The module does symmetry analysis for an input geometry." << std::endl;
17-
Parallel_Global::read_mpi_parameters(argc,argv);
17+
Parallel_Global::read_pal_param(argc,argv);
1818
//std::cout << "Right now, the module is still empty, soon we will have more tests." << std::endl;
1919

2020
calculate();

source/module_io/print_info.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "module_base/global_variable.h"
44
#include "module_parameter/parameter.h"
55

6+
67
namespace ModuleIO
78
{
89

@@ -70,7 +71,8 @@ void setup_parameters(UnitCell& ucell, K_Vectors& kv)
7071

7172
std::cout << " " << std::setw(8) << "SPIN"
7273
<< std::setw(16) << "KPOINTS"
73-
<< std::setw(12) << "PROCESSORS";
74+
<< std::setw(12) << "PROCESSORS"
75+
<< std::setw(12) << "THREADS";
7476

7577
const bool orbinfo = (PARAM.inp.basis_type=="lcao" || PARAM.inp.basis_type=="lcao_in_pw"
7678
|| (PARAM.inp.basis_type=="pw" && PARAM.inp.init_wfc.substr(0, 3) == "nao"));
@@ -88,7 +90,8 @@ void setup_parameters(UnitCell& ucell, K_Vectors& kv)
8890
std::cout << std::setw(16) << kv.get_nkstot();
8991
}
9092

91-
std::cout << std::setw(12) << GlobalV::NPROC;
93+
std::cout << std::setw(12) << GlobalV::NPROC
94+
<< std::setw(12) << PARAM.globalv.nthread_per_proc * GlobalV::NPROC;
9295
if (orbinfo) { std::cout << std::setw(12) << PARAM.globalv.nlocal; }
9396

9497
std::cout << std::endl;

source/module_parameter/parameter.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
Parameter PARAM;
44

5-
void Parameter::set_rank_nproc(const int& myrank, const int& nproc)
5+
// changed from set_rank_nproc in 2024-1018
6+
void Parameter::set_pal_param(const int& myrank, const int& nproc, const int& nthread_per_proc)
67
{
78
sys.myrank = myrank;
89
sys.nproc = nproc;
10+
sys.nthread_per_proc = nthread_per_proc;
911
}
1012

1113
void Parameter::set_start_time(const std::time_t& start_time)

source/module_parameter/parameter.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ class Parameter
2727
// We can only read the value of globalv parameters, but cannot modify it.
2828
const System_para& globalv = sys;
2929

30-
// Set the rank & nproc
31-
void set_rank_nproc(const int& myrank, const int& nproc);
30+
// Set the rank & nproc & nthreads_per_proc
31+
// changed from set_rank_nproc in 2024-1018
32+
void set_pal_param(const int& myrank, const int& nproc, const int& nthread_per_proc);
3233
// Set the start time
3334
void set_start_time(const std::time_t& start_time);
3435

source/module_parameter/system_parameter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ struct System_para
1010
// ---------------------------------------------------------------
1111
int myrank = 0;
1212
int nproc = 1;
13+
int nthread_per_proc = 1;
1314
int mypool = 0;
1415
int npool = 1;
1516
int nproc_in_pool = 1;

tools/SIAB/SimulatedAnnealing/backup_old_version/1_Source/src_parallel/parallel_global.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ void Parallel_Global::myProd(complex<double> *in,complex<double> *inout,int *len
2727
}
2828
#endif
2929

30-
void Parallel_Global::read_mpi_parameters(int argc,char **argv)
30+
void Parallel_Global::read_pal_param(int argc,char **argv)
3131
{
3232
#if defined __MPI
3333
//for test

tools/SIAB/SimulatedAnnealing/backup_old_version/1_Source/src_parallel/parallel_global.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ extern MPI_Comm POOL_WORLD;
1818

1919
namespace Parallel_Global
2020
{
21-
void read_mpi_parameters(int argc, char **argv);
21+
void read_pal_param(int argc, char **argv);
2222

2323
#ifdef __MPI
2424
void myProd(complex<double> *in,complex<double> *inout,int *len,MPI_Datatype *dptr);

0 commit comments

Comments
 (0)