Skip to content

Commit d365b25

Browse files
committed
fix bug
1 parent 630dcfd commit d365b25

File tree

4 files changed

+13
-42
lines changed

4 files changed

+13
-42
lines changed

source/module_base/parallel_comm.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include "parallel_global.h"
55

66
MPI_Comm POOL_WORLD;
7-
MPI_Comm INTER_POOL = MPI_COMM_NULL; // communicator among different pools
7+
MPI_Comm INTER_POOL; // communicator among different pools
88
MPI_Comm STO_WORLD;
99
MPI_Comm PARAPW_WORLD;
1010
MPI_Comm GRID_WORLD; // mohan add 2012-01-13

source/module_base/parallel_global.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ void Parallel_Global::divide_pools(const int& NPROC,
328328
// and MY_STOGROUP will be the same as well.
329329
if(BNDPAR > 1 && NPROC %(BNDPAR * KPAR) != 0)
330330
{
331-
std::cout << "Error: When " << BNDPAR << " > 1, number of processes (" << NPROC << ") must be divisible by the number of groups ("
331+
std::cout << "Error: When BNDPAR = " << BNDPAR << " > 1, number of processes (" << NPROC << ") must be divisible by the number of groups ("
332332
<< BNDPAR * KPAR << ")." << std::endl;
333333
exit(1);
334334
}
@@ -351,6 +351,10 @@ void Parallel_Global::divide_pools(const int& NPROC,
351351
{
352352
MPI_Comm_dup(kpar_group.inter_comm, &INTER_POOL);
353353
}
354+
else
355+
{
356+
INTER_POOL = MPI_COMM_NULL;
357+
}
354358

355359
if(BNDPAR > 1)
356360
{

source/module_base/test_parallel/parallel_global_test.cpp

Lines changed: 6 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "mpi.h"
55

66
#include "gtest/gtest.h"
7+
#include "gmock/gmock.h"
78
#include <complex>
89
#include <cstring>
910
#include <string>
@@ -165,8 +166,8 @@ TEST_F(ParaGlobal, InitPools)
165166
mpi.kpar = 3;
166167
mpi.nstogroup = 3;
167168
my_rank = 5;
168-
169-
Parallel_Global::init_pools(nproc,
169+
testing::internal::CaptureStdout();
170+
EXPECT_EXIT(Parallel_Global::init_pools(nproc,
170171
my_rank,
171172
mpi.nstogroup,
172173
mpi.kpar,
@@ -175,45 +176,11 @@ TEST_F(ParaGlobal, InitPools)
175176
mpi.my_stogroup,
176177
mpi.nproc_in_pool,
177178
mpi.rank_in_pool,
178-
mpi.my_pool);
179-
EXPECT_EQ(mpi.nproc_in_stogroup, 4);
180-
EXPECT_EQ(mpi.my_stogroup, 1);
181-
EXPECT_EQ(mpi.rank_in_stogroup, 1);
182-
EXPECT_EQ(mpi.my_pool, 0);
183-
EXPECT_EQ(mpi.rank_in_pool, 1);
184-
EXPECT_EQ(mpi.nproc_in_pool, 2);
185-
EXPECT_EQ(MPI_COMM_WORLD != STO_WORLD, true);
186-
EXPECT_EQ(STO_WORLD != POOL_WORLD, true);
187-
EXPECT_EQ(MPI_COMM_WORLD != PARAPW_WORLD, true);
179+
mpi.my_pool), ::testing::ExitedWithCode(1), "");
180+
std::string output = testing::internal::GetCapturedStdout();
181+
EXPECT_THAT(output, testing::HasSubstr("Error:"));
188182
}
189183

190-
TEST_F(ParaGlobal, DividePools)
191-
{
192-
nproc = 12;
193-
mpi.kpar = 3;
194-
mpi.nstogroup = 3;
195-
this->my_rank = 5;
196-
197-
Parallel_Global::divide_pools(nproc,
198-
this->my_rank,
199-
mpi.nstogroup,
200-
mpi.kpar,
201-
mpi.nproc_in_stogroup,
202-
mpi.rank_in_stogroup,
203-
mpi.my_stogroup,
204-
mpi.nproc_in_pool,
205-
mpi.rank_in_pool,
206-
mpi.my_pool);
207-
EXPECT_EQ(mpi.nproc_in_stogroup, 4);
208-
EXPECT_EQ(mpi.my_stogroup, 1);
209-
EXPECT_EQ(mpi.rank_in_stogroup, 1);
210-
EXPECT_EQ(mpi.my_pool, 0);
211-
EXPECT_EQ(mpi.rank_in_pool, 1);
212-
EXPECT_EQ(mpi.nproc_in_pool, 2);
213-
EXPECT_EQ(MPI_COMM_WORLD != STO_WORLD, true);
214-
EXPECT_EQ(STO_WORLD != POOL_WORLD, true);
215-
EXPECT_EQ(MPI_COMM_WORLD != PARAPW_WORLD, true);
216-
}
217184

218185
TEST_F(ParaGlobal, DivideMPIPools)
219186
{

source/module_elecstate/test_mpi/charge_mpi_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ TEST_F(ChargeMpiTest, reduce_diff_pools1)
6666
if (GlobalV::NPROC >= 2 && GlobalV::NPROC % 2 == 0)
6767
{
6868
GlobalV::KPAR = 2;
69-
Parallel_Global::divide_pools(GlobalV::NPROC,
69+
Parallel_Global::init_pools(GlobalV::NPROC,
7070
GlobalV::MY_RANK,
7171
PARAM.input.bndpar,
7272
GlobalV::KPAR,

0 commit comments

Comments
 (0)