Skip to content

Commit 2905405

Browse files
committed
Gtest: add valgrind test for test_gnu.sh
add test for nst_per and npw_per scope: test1-1-1.cpp,test1-1-2.cpp,test2-1-1.cpp,test2-1-2.cpp
1 parent fa4ae7a commit 2905405

File tree

9 files changed

+280
-21
lines changed

9 files changed

+280
-21
lines changed

source/module_pw/pw_distributeg_method1.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ void PW_Basis::distribution_method1()
5959
// std::cout << '\n';
6060
// }
6161
// ------------------------------------------------------------
62+
ModuleBase::GlobalFunc::ZEROS(this->nst_per, poolnproc);
6263
#ifdef __MPI
6364
// Parallel line
6465

@@ -78,7 +79,6 @@ void PW_Basis::distribution_method1()
7879
this->nstnz_per = new int[this->poolnproc]; // nz * nst(number of sticks) on each core.
7980
this->startnsz_per = new int[this->poolnproc];
8081
ModuleBase::GlobalFunc::ZEROS(npw_per, poolnproc);
81-
ModuleBase::GlobalFunc::ZEROS(this->nst_per, poolnproc);
8282
ModuleBase::GlobalFunc::ZEROS(this->nstnz_per, poolnproc);
8383
ModuleBase::GlobalFunc::ZEROS(startnsz_per, poolnproc);
8484

@@ -124,6 +124,7 @@ void PW_Basis::distribution_method1()
124124
this->nstnz_per[0] = this->nst * this->nz;
125125
this->startnsz_per = new int[1];
126126
this->startnsz_per[0] = 0;
127+
this->nst_per[0] = this->nst;
127128

128129
this->ixy2istot = new int[nxy];
129130
this->istot2bigixy = new int[this->nstot];

source/module_pw/test/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,14 @@ GTESTOPTS = -I${GTEST_DIR}/include -L${GTEST_DIR}/lib -lgtest -lpthread
6767
# CPLUSPLUS = icpc
6868

6969
#Only MPI
70-
# HONG = -D__MPI -D__NORMAL
70+
HONG = -D__MPI -D__NORMAL
7171

7272
#MPI + Mix Precision
7373
# HONG = -D__MPI -D__MIX_PRECISION -D__NORMAL
7474
# TESTFILE0 = ${DOUBLEFILE} ${FLOATFILE}
7575

7676
#Cuda
77-
HONG = -D__MPI -D__CUDA -D__NORMAL
77+
# HONG = -D__MPI -D__CUDA -D__NORMAL
7878

7979
#Cuda & Mix Precision
8080
#HONG = -D__MPI -D__CUDA -D__MIX_PRECISION -D__NORMAL

source/module_pw/test/Makefile.intel

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,14 @@ GTESTOPTS = -I${GTEST_DIR}/include -L${GTEST_DIR}/lib -lgtest -lpthread
6767
# CPLUSPLUS = icpc
6868

6969
#Only MPI
70-
# HONG = -D__MPI -D__NORMAL
70+
HONG = -D__MPI -D__NORMAL
7171

7272
#MPI + Mix Precision
7373
# HONG = -D__MPI -D__MIX_PRECISION -D__NORMAL
7474
# TESTFILE0 = ${DOUBLEFILE} ${FLOATFILE}
7575

7676
#Cuda
77-
HONG = -D__MPI -D__CUDA -D__NORMAL
77+
# HONG = -D__MPI -D__CUDA -D__NORMAL
7878

7979
#Cuda & Mix Precision
8080
#HONG = -D__MPI -D__CUDA -D__MIX_PRECISION -D__NORMAL

source/module_pw/test/test1-1-1.cpp

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,62 @@ TEST_F(PWTEST,test1_1_1)
4141
const int nx_ref = 54;
4242
const int ny_ref = 3;
4343
const int nz_ref = 15;
44-
44+
45+
//some results for different number of processors
46+
int npw_per_ref[12][12]={
47+
{1051},
48+
{525,526},
49+
{351,351,349},
50+
{263,263,263,262},
51+
{210,211,211,211,208},
52+
{177,177,174,174,175,174},
53+
{152,152,149,149,149,150,150},
54+
{131,131,131,131,131,132,132,132},
55+
{118,118,118,118,118,115,115,115,116},
56+
{106,107,107,104,104,104,104,107,104,104},
57+
{98,95,95,95,95,95,95,98,95,95,95},
58+
{88,88,88,88,89,89,86,86,86,86,88,89}
59+
};
60+
int nst_per_ref[12][12]={
61+
{123},
62+
{61,62},
63+
{41,41,41},
64+
{31,31,31,30},
65+
{24,25,25,25,24},
66+
{21,21,20,20,21,20},
67+
{18,18,17,17,17,18,18},
68+
{15,15,15,15,15,16,16,16},
69+
{14,14,14,14,14,13,13,13,14},
70+
{12,13,13,12,12,12,12,13,12,12},
71+
{12,11,11,11,11,11,11,12,11,11,11},
72+
{10,10,10,10,11,11,10,10,10,10,10,11}
73+
};
74+
int *npw_per;
75+
if(rank_in_pool == 0)
76+
{
77+
npw_per = new int [nproc_in_pool];
78+
}
79+
#ifdef __MPI
80+
MPI_Gather(&pwtest.npw,1,MPI_INT,npw_per,1,MPI_INT,0,POOL_WORLD);
81+
#else
82+
if(rank_in_pool == 0) npw_per[0] = pwtest.npw;
83+
#endif
84+
if(rank_in_pool == 0)
85+
{
86+
if(nproc_in_pool <= 12)
87+
{
88+
for(int ip = 0 ; ip < nproc_in_pool ; ++ip)
89+
{
90+
ASSERT_EQ(npw_per_ref[nproc_in_pool-1][ip], npw_per[ip]);
91+
ASSERT_EQ(nst_per_ref[nproc_in_pool-1][ip], pwtest.nst_per[ip]);
92+
}
93+
}
94+
else
95+
{
96+
cout<<"Please use mpi processors no more than 12."<<endl;
97+
}
98+
delete []npw_per;
99+
}
45100

46101
//results
47102
int tot_npw = 0;

source/module_pw/test/test1-1-2.cpp

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,61 @@ TEST_F(PWTEST,test1_1_2)
4242
const int bigny_ref = 27;
4343
const int ny_ref = 14;
4444
const int nz_ref = 54;
45+
//some results for different number of processors
46+
int npw_per_ref[12][12]={
47+
{5012},
48+
{2506,2506},
49+
{1672,1670,1670},
50+
{1253,1253,1251,1255},
51+
{1002,1002,1002,1003,1003},
52+
{835,837,835,836,835,834},
53+
{716,717,716,716,716,716,715},
54+
{627,627,628,626,626,627,625,626},
55+
{556,559,555,555,555,557,559,559,557},
56+
{502,502,501,499,498,502,502,503,503,500},
57+
{457,457,454,458,458,454,456,455,452,455,456},
58+
{419,419,419,418,417,418,416,416,416,420,416,418}
59+
};
60+
int nst_per_ref[12][12]={
61+
{176},
62+
{88,88},
63+
{59,59,58},
64+
{44,44,44,44},
65+
{35,35,35,36,35},
66+
{29,30,30,29,29,29},
67+
{25,25,25,25,26,25,25},
68+
{22,22,22,22,22,22,22,22},
69+
{20,19,19,19,19,20,20,20,20},
70+
{17,17,18,18,17,17,18,18,18,18},
71+
{16,16,16,16,16,16,16,16,16,16,16},
72+
{15,15,15,15,15,15,14,14,14,15,14,15}
73+
};
74+
int *npw_per;
75+
if(rank_in_pool == 0)
76+
{
77+
npw_per = new int [nproc_in_pool];
78+
}
79+
#ifdef __MPI
80+
MPI_Gather(&pwtest.npw,1,MPI_INT,npw_per,1,MPI_INT,0,POOL_WORLD);
81+
#else
82+
if(rank_in_pool == 0) npw_per[0] = pwtest.npw;
83+
#endif
84+
if(rank_in_pool == 0)
85+
{
86+
if(nproc_in_pool <= 12)
87+
{
88+
for(int ip = 0 ; ip < nproc_in_pool ; ++ip)
89+
{
90+
ASSERT_EQ(npw_per_ref[nproc_in_pool-1][ip], npw_per[ip]);
91+
ASSERT_EQ(nst_per_ref[nproc_in_pool-1][ip], pwtest.nst_per[ip]);
92+
}
93+
}
94+
else
95+
{
96+
cout<<"Please use mpi processors no more than 12."<<endl;
97+
}
98+
delete []npw_per;
99+
}
45100

46101

47102
//results

source/module_pw/test/test2-1-1.cpp

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,61 @@ TEST_F(PWTEST,test2_1_1)
4141
const int nx_ref = 54;
4242
const int ny_ref = 3;
4343
const int nz_ref = 15;
44+
//some results for different number of processors
45+
int npw_per_ref[12][12]={
46+
{911},
47+
{468,443},
48+
{332,256,323},
49+
{248,220,204,239},
50+
{191,195,143,187,195},
51+
{156,176,136,120,176,147},
52+
{140,152,130,98,119,149,123},
53+
{116,132,122,98,82,122,140,99},
54+
{111,115,117,97,71,88,106,110,96},
55+
{102,102,108,90,72,71,83,99,99,85},
56+
{89,91,101,89,79,53,77,82,90,88,72},
57+
{82,74,92,84,70,66,52,68,84,92,80,67}
58+
};
59+
int nst_per_ref[12][12]={
60+
{95},
61+
{48,47},
62+
{32,32,31},
63+
{24,24,24,23},
64+
{19,19,19,19,19},
65+
{16,16,16,16,16,15},
66+
{14,14,14,14,13,13,13},
67+
{12,12,12,12,12,12,12,11},
68+
{11,11,11,11,11,10,10,10,10},
69+
{10,10,10,10,10,9,9,9,9,9},
70+
{9,9,9,9,9,9,9,8,8,8,8},
71+
{8,8,8,8,8,8,8,8,8,8,8,7}
72+
};
73+
int *npw_per;
74+
if(rank_in_pool == 0)
75+
{
76+
npw_per = new int [nproc_in_pool];
77+
}
78+
#ifdef __MPI
79+
MPI_Gather(&pwtest.npw,1,MPI_INT,npw_per,1,MPI_INT,0,POOL_WORLD);
80+
#else
81+
if(rank_in_pool == 0) npw_per[0] = pwtest.npw;
82+
#endif
83+
if(rank_in_pool == 0)
84+
{
85+
if(nproc_in_pool <= 12)
86+
{
87+
for(int ip = 0 ; ip < nproc_in_pool ; ++ip)
88+
{
89+
ASSERT_EQ(npw_per_ref[nproc_in_pool-1][ip], npw_per[ip]);
90+
ASSERT_EQ(nst_per_ref[nproc_in_pool-1][ip], pwtest.nst_per[ip]);
91+
}
92+
}
93+
else
94+
{
95+
cout<<"Please use mpi processors no more than 12."<<endl;
96+
}
97+
delete []npw_per;
98+
}
4499

45100

46101
//results

source/module_pw/test/test2-1-2.cpp

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,61 @@ TEST_F(PWTEST,test2_1_2)
4242
const int bigny_ref = 36;
4343
const int ny_ref = 19;
4444
const int nz_ref = 50;
45+
//some results for different number of processors
46+
int npw_per_ref[12][12]={
47+
{2931},
48+
{1548,1383},
49+
{1133,744,1054},
50+
{870,678,586,797},
51+
{699,617,397,559,659},
52+
{598,535,415,329,521,533},
53+
{501,457,421,267,371,431,483},
54+
{458,412,384,294,230,356,406,391},
55+
{418,364,364,304,181,267,319,367,347},
56+
{374,340,328,286,234,165,277,291,329,307},
57+
{328,314,298,276,234,160,200,240,310,296,275},
58+
{303,295,291,257,233,183,151,204,236,262,254,262}
59+
};
60+
int nst_per_ref[12][12]={
61+
{175},
62+
{88,87},
63+
{59,58,58},
64+
{44,44,44,43},
65+
{35,35,35,35,35},
66+
{30,29,29,29,29,29},
67+
{25,25,25,25,25,25,25},
68+
{22,22,22,22,22,22,22,21},
69+
{20,20,20,20,19,19,19,19,19},
70+
{18,18,18,18,18,17,17,17,17,17},
71+
{16,16,16,16,16,16,16,16,16,16,15},
72+
{15,15,15,15,15,15,15,14,14,14,14,14}
73+
};
74+
int *npw_per;
75+
if(rank_in_pool == 0)
76+
{
77+
npw_per = new int [nproc_in_pool];
78+
}
79+
#ifdef __MPI
80+
MPI_Gather(&pwtest.npw,1,MPI_INT,npw_per,1,MPI_INT,0,POOL_WORLD);
81+
#else
82+
if(rank_in_pool == 0) npw_per[0] = pwtest.npw;
83+
#endif
84+
if(rank_in_pool == 0)
85+
{
86+
if(nproc_in_pool <= 12)
87+
{
88+
for(int ip = 0 ; ip < nproc_in_pool ; ++ip)
89+
{
90+
ASSERT_EQ(npw_per_ref[nproc_in_pool-1][ip], npw_per[ip]);
91+
ASSERT_EQ(nst_per_ref[nproc_in_pool-1][ip], pwtest.nst_per[ip]);
92+
}
93+
}
94+
else
95+
{
96+
cout<<"Please use mpi processors no more than 12."<<endl;
97+
}
98+
delete []npw_per;
99+
}
45100

46101

47102
//results

source/module_pw/test/test_gnu.sh

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@ GTEST_DIR=/home/qianrui/gnucompile/g_gtest
44
FFTW_DIR=/home/qianrui/gnucompile/g_fftw-3.3.8-mpi
55

66
GTESTOPTS="-I$GTEST_DIR/include -L$GTEST_DIR/lib -lgtest -lpthread"
7-
7+
headn=`grep -n "FFTW package needed" Makefile.gnu |cut -d ':' -f1`
8+
((headn-=2))
9+
filen=`wc -l Makefile.gnu |cut -d ' ' -f1`
10+
tailn=`grep -n "PW_OBJS=" Makefile.gnu |cut -d ':' -f1`
11+
((tailn=filen-tailn+2))
812
make clean > /dev/null 2>&1
913
mv Makefile Makefile.bak
1014
for((i=0;i<4;++i))
1115
do
12-
head -n 50 Makefile.gnu > Makefile
16+
head -n $headn Makefile.gnu > Makefile
1317
if ((i==0)) ;then
1418
cat >>Makefile<<EOF
1519
HONG = -D__NORMAL
@@ -38,22 +42,45 @@ FFTW_LIB_DIR = \${FFTW_DIR}/lib
3842
FFTW_INCLUDE_DIR = \${FFTW_DIR}/include
3943
FFTW_LIB = -L\${FFTW_LIB_DIR} -lfftw3 -lfftw3f -Wl,-rpath=\${FFTW_LIB_DIR}
4044
EOF
41-
tail -n 36 Makefile.gnu >>Makefile
45+
tail -n $tailn Makefile.gnu >>Makefile
4246
make > /dev/null 2>&1
4347

44-
if ((i==0||i==1)) ;then
48+
if ((i==0)) ;then
4549
./pw_test.exe
50+
elif ((i==1)) ;then
51+
./pw_test.exe
52+
echo "valgrind test:(1 processors)"
53+
valgrind ./pw_test.exe >_tmp.txt 2>&1
54+
cat _tmp.txt|grep "ERROR SUMMARY"
4655
else
56+
echo "1 processor:"
4757
./pw_test.exe
4858
sleep 1
49-
echo "====================="
50-
mpirun -np 2 ./pw_test.exe |grep PASSED
59+
echo "2 processors:"
60+
mpirun -np 2 ./pw_test.exe >_tmp.txt 2>&1
61+
cat _tmp.txt|grep PASSED
62+
cat _tmp.txt|grep FAILED
5163
sleep 1
52-
echo "====================="
53-
mpirun -np 8 ./pw_test.exe |grep PASSED
64+
echo "8 processors:"
65+
mpirun -np 8 ./pw_test.exe >_tmp.txt 2>&1
66+
cat _tmp.txt|grep PASSED
67+
cat _tmp.txt|grep FAILED
68+
fi
69+
#for mix compile
70+
if ((i==3)) ;then
71+
echo "valgrind test:(1 processors)"
72+
valgrind ./pw_test.exe >_tmp.txt 2>&1
73+
cat _tmp.txt|grep "ERROR SUMMARY";
74+
echo "valgrind test:(2 processors)"
75+
mpirun -np 2 valgrind ./pw_test.exe >_tmp.txt 2>&1
76+
cat _tmp.txt|grep "ERROR SUMMARY";
77+
echo "valgrind test:(8 processors)"
78+
mpirun -np 8 valgrind ./pw_test.exe >_tmp.txt 2>&1
79+
cat _tmp.txt|grep "ERROR SUMMARY";
5480
fi
5581
make clean > /dev/null 2>&1
5682
done
5783
mv Makefile.bak Makefile
84+
test -e _tmp.txt && rm -f _tmp.txt
5885

5986
exit 0

0 commit comments

Comments
 (0)