Skip to content

Commit 772ca9e

Browse files
authored
Test: Fix tests to work without MPI (#5631)
1 parent e500584 commit 772ca9e

File tree

6 files changed

+40
-11
lines changed

6 files changed

+40
-11
lines changed

source/module_hsolver/test/CMakeLists.txt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ remove_definitions(-DUSE_PAW)
44
remove_definitions(-D__EXX)
55

66
if (ENABLE_MPI)
7+
AddTest(
8+
TARGET hsolver_parak2d_test
9+
LIBS parameter ${math_libs} base device MPI::MPI_CXX
10+
SOURCES parallel_k2d_test.cpp ../parallel_k2d.cpp ../../module_cell/parallel_kpoints.cpp ../../module_basis/module_ao/parallel_2d.cpp
11+
)
712
AddTest(
813
TARGET HSolver_bpcg
914
LIBS parameter ${math_libs} base psi device container
@@ -147,11 +152,7 @@ install(FILES PEXSI-DM-GammaOnly-Si2.dat DESTINATION ${CMAKE_CURRENT_BINARY_DIR}
147152
install(FILES diago_pexsi_parallel_test.sh DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
148153
install(FILES parallel_k2d_test.sh DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
149154

150-
AddTest(
151-
TARGET hsolver_parak2d_test
152-
LIBS parameter ${math_libs} base device MPI::MPI_CXX
153-
SOURCES parallel_k2d_test.cpp ../parallel_k2d.cpp ../../module_cell/parallel_kpoints.cpp ../../module_basis/module_ao/parallel_2d.cpp
154-
)
155+
155156

156157
find_program(BASH bash)
157158
if (ENABLE_MPI)

source/module_hsolver/test/diago_lapack_test.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Author: Zhang Xiaoyang
22
// A modified version of diago_lcao_test.cpp
3-
#define private public
3+
// #define private public
44
#include "module_parameter/parameter.h"
5-
#undef private
5+
// #undef private
66
// Remove some useless functions and dependencies. Serialized the full code
77
// and refactored some function.
88

@@ -187,8 +187,10 @@ class DiagoLapackPrepare
187187

188188
void set_env()
189189
{
190-
PARAM.sys.nlocal = nlocal;
191-
PARAM.input.nbands = nbands;
190+
// PARAM.sys.nlocal = nlocal;
191+
PARAM.set_sys_nlocal(nlocal);
192+
// PARAM.input.nbands = nbands;
193+
PARAM.set_input_nbands(nbands);
192194
}
193195

194196
void diago()

source/module_lr/AX/test/AX_test.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include <gtest/gtest.h>
2+
#ifdef __MPI
23
#include "mpi.h"
4+
#endif
35
#include "../AX.h"
46

57
#include "module_lr/utils/lr_util.h"
@@ -206,9 +208,13 @@ TEST_F(AXTest, ComplexParallel)
206208
int main(int argc, char** argv)
207209
{
208210
srand(time(nullptr)); // for random number generator
211+
#ifdef __MPI
209212
MPI_Init(&argc, &argv);
213+
#endif
210214
testing::InitGoogleTest(&argc, argv);
211215
int result = RUN_ALL_TESTS();
216+
#ifdef __MPI
212217
MPI_Finalize();
218+
#endif
213219
return result;
214220
}

source/module_lr/dm_trans/test/dm_trans_test.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#include <gtest/gtest.h>
2-
#include "mpi.h"
2+
#include <fstream>
33
#include "../dm_trans.h"
44
#ifdef __MPI
5+
#include "mpi.h"
56
#include "module_lr/utils/lr_util.h"
67
#endif
78
struct matsize
@@ -226,9 +227,13 @@ TEST_F(DMTransTest, ComplexParallel)
226227
int main(int argc, char** argv)
227228
{
228229
srand(time(NULL)); // for random number generator
230+
#ifdef __MPI
229231
MPI_Init(&argc, &argv);
232+
#endif
230233
testing::InitGoogleTest(&argc, argv);
231234
int result = RUN_ALL_TESTS();
235+
#ifdef __MPI
232236
MPI_Finalize();
237+
#endif
233238
return result;
234239
}

source/module_parameter/parameter.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,14 @@ void Parameter::set_pal_param(const int& myrank, const int& nproc, const int& nt
1313
void Parameter::set_start_time(const std::time_t& start_time)
1414
{
1515
sys.start_time = start_time;
16-
}
16+
}
17+
18+
void Parameter::set_input_nbands(const int& nbands)
19+
{
20+
input.nbands = nbands;
21+
}
22+
23+
void Parameter::set_sys_nlocal(const int& nlocal)
24+
{
25+
sys.nlocal = nlocal;
26+
}

source/module_parameter/parameter.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ class Parameter
3333
// Set the start time
3434
void set_start_time(const std::time_t& start_time);
3535

36+
// set input.nbands
37+
void set_input_nbands(const int& nbands);
38+
// set sys.nlocal
39+
void set_sys_nlocal(const int& nlocal);
40+
3641
private:
3742
// Only ReadInput and CalAtomInfo can modify the value of Parameter.
3843
// Do not add extra friend class here!!!

0 commit comments

Comments
 (0)