Skip to content

Commit fb40dbc

Browse files
committed
feature: finish google test
1 parent b426c1f commit fb40dbc

20 files changed

+625
-255
lines changed

source/module_pw/pw_basis.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,15 @@ class PW_Basis
5555
public:
5656
//reciprocal-space
5757
// only on first proc.
58-
int *startnsz_per; // startnsz_per[ip]: starting is * nz stick in the ip^th proc.
59-
int *nstnz_per; // nz * nst(number of sticks) on each core.
58+
int *startnsz_per;//useless // startnsz_per[ip]: starting is * nz stick in the ip^th proc.
59+
int *nstnz_per;//useless // nz * nst(number of sticks) on each core.
6060
int *nst_per;// nst on each core
6161
// on all proc.
6262
int *ig2isz; // map ig to (is, iz).
6363
int *istot2bigixy; // istot2bigixy[is]: iy + ix * bigny of is^th stick among all sticks.
64-
int *ixy2istot; // ixy2istot[ix + iy * nx]: is of stick on (ix, iy) among all sticks.
64+
int *ixy2istot; //useless // ixy2istot[ix + iy * nx]: is of stick on (ix, iy) among all sticks.
6565
int *is2ixy; // is2ixy[is]: ix + iy * bignx of is^th stick among sticks on current proc.
66-
int *ixy2ip; // ixy2ip[ix + iy * nx]: ip of proc which contains stick on (ix, iy).
66+
int *ixy2ip; // useless// ixy2ip[ix + iy * nx]: ip of proc which contains stick on (ix, iy).
6767
int nst; //num. of sticks in current proc.
6868
int nstnz; // nst * nz
6969
int nstot; //num. of sticks in total.

source/module_pw/test/Makefile

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#==========================
55
CPLUSPLUS = mpiicpc
66
CUDA_COMPILE = nvcc
7-
OBJ_DIR = pw_obj
7+
OBJ_DIR = obj
88
NP = 12
99
#==========================
1010
# Objects
@@ -32,9 +32,13 @@ pw_basis_k.o\
3232
pw_operation.o\
3333
pw_transform_k.o
3434

35-
DOUBLEFILE=test1-2.o\
35+
DOUBLEFILE=test1-1-1.o\
36+
test1-1-2.o\
37+
test1-2.o\
3638
test1-3.o\
3739
test1-4.o\
40+
test2-1-1.o\
41+
test2-1-2.o\
3842
test2-2.o\
3943
test2-3.o
4044

@@ -57,14 +61,14 @@ TESTFILE0 = ${DOUBLEFILE}
5761
# CPLUSPLUS = icpc
5862

5963
#Only MPI
60-
HONG = -D__MPI -D__NORMAL
64+
# HONG = -D__MPI -D__NORMAL
6165

6266
#MPI + Mix Precision
6367
# HONG = -D__MPI -D__MIX_PRECISION -D__NORMAL
6468
# TESTFILE0 = ${DOUBLEFILE} ${FLOATFILE}
6569

6670
#Cuda
67-
#HONG = -D__MPI -D__CUDA -D__NORMAL
71+
HONG = -D__MPI -D__CUDA -D__NORMAL
6872

6973
#Cuda & Mix Precision
7074
#HONG = -D__MPI -D__CUDA -D__MIX_PRECISION -D__NORMAL
@@ -113,17 +117,17 @@ OPTS = -I${FFTW_INCLUDE_DIR} ${HONG} -Ofast -std=c++11 -simd -m64 -qopenmp -Wall
113117
#==========================
114118
pw :
115119
@ make init
116-
@ make -j $(NP) utest.exe
120+
@ make -j $(NP) pw_test.exe
117121

118122
init :
119123
@ if [ ! -d $(OBJ_DIR) ]; then mkdir $(OBJ_DIR); fi
120124

121-
utest.exe: ${PW_OBJS} ${TESTFILE}
122-
${CPLUSPLUS} ${OPTS} ${TESTFILE} utest.cpp test_tool.cpp ${PW_OBJS} ${LIBS} -o utest.exe ${GTESTOPTS}
125+
pw_test.exe: ${PW_OBJS} ${TESTFILE} pw_test.cpp test_tool.cpp
126+
${CPLUSPLUS} ${OPTS} ${TESTFILE} pw_test.cpp test_tool.cpp ${PW_OBJS} ${LIBS} -o pw_test.exe ${GTESTOPTS}
123127
${OBJ_DIR}/%.o:%.cpp
124128
${CPLUSPLUS} ${OPTS} -c ${HONG} $< -o $@ ${GTESTOPTS}
125129

126130
.PHONY:clean
127131
clean:
128132
@ if [ -d $(OBJ_DIR) ]; then rm -rf $(OBJ_DIR); fi
129-
@ if [ -e utest.exe ]; then rm -f utest.exe; fi
133+
@ if [ -e pw_test.exe ]; then rm -f pw_test.exe; fi

source/module_pw/test/Makefile.gnu

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#==========================
55
CPLUSPLUS = mpicxx
66
CUDA_COMPILE = nvcc
7-
OBJ_DIR = pw_obj
7+
OBJ_DIR = obj
88
NP = 12
99
#==========================
1010
# Objects
@@ -32,9 +32,13 @@ pw_basis_k.o\
3232
pw_operation.o\
3333
pw_transform_k.o
3434

35-
DOUBLEFILE=test1-2.o\
35+
DOUBLEFILE=test1-1-1.o\
36+
test1-1-2.o\
37+
test1-2.o\
3638
test1-3.o\
3739
test1-4.o\
40+
test2-1-1.o\
41+
test2-1-2.o\
3842
test2-2.o\
3943
test2-3.o
4044

@@ -57,11 +61,11 @@ TESTFILE0 = ${DOUBLEFILE}
5761
# CPLUSPLUS = g++
5862

5963
#Only MPI
60-
HONG = -D__MPI -D__NORMAL
64+
# HONG = -D__MPI -D__NORMAL
6165

6266
#MPI + Mix Precision
63-
# HONG = -D__MPI -D__MIX_PRECISION -D__NORMAL
64-
# TESTFILE0 = ${DOUBLEFILE} ${FLOATFILE}
67+
HONG = -D__MPI -D__MIX_PRECISION -D__NORMAL
68+
TESTFILE0 = ${DOUBLEFILE} ${FLOATFILE}
6569

6670
#Cuda
6771
#HONG = -D__MPI -D__CUDA -D__NORMAL
@@ -81,8 +85,8 @@ TESTFILE=$(patsubst %.o, ${OBJ_DIR}/%.o, ${TESTFILE0})
8185
FFTW_DIR = /home/qianrui/gnucompile/g_fftw-3.3.8-mpi
8286
FFTW_LIB_DIR = ${FFTW_DIR}/lib
8387
FFTW_INCLUDE_DIR = ${FFTW_DIR}/include
84-
# FFTW_LIB = -L${FFTW_LIB_DIR} -lfftw3 -lfftw3f -Wl,-rpath=${FFTW_LIB_DIR}
85-
FFTW_LIB = -L${FFTW_LIB_DIR} -lfftw3 -Wl,-rpath=${FFTW_LIB_DIR}
88+
FFTW_LIB = -L${FFTW_LIB_DIR} -lfftw3 -lfftw3f -Wl,-rpath=${FFTW_LIB_DIR}
89+
# FFTW_LIB = -L${FFTW_LIB_DIR} -lfftw3 -Wl,-rpath=${FFTW_LIB_DIR}
8690

8791

8892

@@ -109,17 +113,17 @@ OPTS = -I${FFTW_INCLUDE_DIR} ${HONG} -Ofast -std=c++11 -Wall -g
109113
#==========================
110114
pw :
111115
@ make init
112-
@ make -j $(NP) utest.exe
116+
@ make -j $(NP) pw_test.exe
113117

114118
init :
115119
@ if [ ! -d $(OBJ_DIR) ]; then mkdir $(OBJ_DIR); fi
116120

117-
utest.exe: ${PW_OBJS} ${TESTFILE}
118-
${CPLUSPLUS} ${OPTS} ${TESTFILE} utest.cpp test_tool.cpp ${PW_OBJS} ${LIBS} -o utest.exe ${GTESTOPTS}
121+
pw_test.exe: ${PW_OBJS} ${TESTFILE}
122+
${CPLUSPLUS} ${OPTS} ${TESTFILE} pw_test.cpp test_tool.cpp ${PW_OBJS} ${LIBS} -o pw_test.exe ${GTESTOPTS}
119123
${OBJ_DIR}/%.o:%.cpp
120124
${CPLUSPLUS} ${OPTS} -c ${HONG} $< -o $@ ${GTESTOPTS}
121125

122126
.PHONY:clean
123127
clean:
124128
@ if [ -d $(OBJ_DIR) ]; then rm -rf $(OBJ_DIR); fi
125-
@ if [ -e utest.exe ]; then rm -f utest.exe; fi
129+
@ if [ -e pw_test.exe ]; then rm -f pw_test.exe; fi

source/module_pw/test/Makefile.intel

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#==========================
55
CPLUSPLUS = mpiicpc
66
CUDA_COMPILE = nvcc
7-
OBJ_DIR = pw_obj
7+
OBJ_DIR = obj
88
NP = 12
99
#==========================
1010
# Objects
@@ -32,9 +32,13 @@ pw_basis_k.o\
3232
pw_operation.o\
3333
pw_transform_k.o
3434

35-
DOUBLEFILE=test1-2.o\
35+
DOUBLEFILE=test1-1-1.o\
36+
test1-1-2.o\
37+
test1-2.o\
3638
test1-3.o\
3739
test1-4.o\
40+
test2-1-1.o\
41+
test2-1-2.o\
3842
test2-2.o\
3943
test2-3.o
4044

@@ -57,14 +61,14 @@ TESTFILE0 = ${DOUBLEFILE}
5761
# CPLUSPLUS = icpc
5862

5963
#Only MPI
60-
HONG = -D__MPI -D__NORMAL
64+
# HONG = -D__MPI -D__NORMAL
6165

6266
#MPI + Mix Precision
6367
# HONG = -D__MPI -D__MIX_PRECISION -D__NORMAL
6468
# TESTFILE0 = ${DOUBLEFILE} ${FLOATFILE}
6569

6670
#Cuda
67-
#HONG = -D__MPI -D__CUDA -D__NORMAL
71+
HONG = -D__MPI -D__CUDA -D__NORMAL
6872

6973
#Cuda & Mix Precision
7074
#HONG = -D__MPI -D__CUDA -D__MIX_PRECISION -D__NORMAL
@@ -113,17 +117,17 @@ OPTS = -I${FFTW_INCLUDE_DIR} ${HONG} -Ofast -std=c++11 -simd -m64 -qopenmp -Wall
113117
#==========================
114118
pw :
115119
@ make init
116-
@ make -j $(NP) utest.exe
120+
@ make -j $(NP) pw_test.exe
117121

118122
init :
119123
@ if [ ! -d $(OBJ_DIR) ]; then mkdir $(OBJ_DIR); fi
120124

121-
utest.exe: ${PW_OBJS} ${TESTFILE}
122-
${CPLUSPLUS} ${OPTS} ${TESTFILE} utest.cpp test_tool.cpp ${PW_OBJS} ${LIBS} -o utest.exe ${GTESTOPTS}
125+
pw_test.exe: ${PW_OBJS} ${TESTFILE} pw_test.cpp test_tool.cpp
126+
${CPLUSPLUS} ${OPTS} ${TESTFILE} pw_test.cpp test_tool.cpp ${PW_OBJS} ${LIBS} -o pw_test.exe ${GTESTOPTS}
123127
${OBJ_DIR}/%.o:%.cpp
124128
${CPLUSPLUS} ${OPTS} -c ${HONG} $< -o $@ ${GTESTOPTS}
125129

126130
.PHONY:clean
127131
clean:
128132
@ if [ -d $(OBJ_DIR) ]; then rm -rf $(OBJ_DIR); fi
129-
@ if [ -e utest.exe ]; then rm -f utest.exe; fi
133+
@ if [ -e pw_test.exe ]; then rm -f pw_test.exe; fi

source/module_pw/test/utest.cpp renamed to source/module_pw/test/pw_test.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include "mpi.h"
44
#endif
55
#include "fftw3.h"
6-
#include "utest.h"
6+
#include "pw_test.h"
77
using namespace std;
88

99
int nproc_in_pool, rank_in_pool;
@@ -32,15 +32,16 @@ class TestEnv : public testing::Environment
3232

3333
int main(int argc, char **argv)
3434
{
35-
int nproc, myrank;
36-
int npool, mypool;
35+
36+
int npool;
3737
npool = 1;
3838
#ifdef __MPI
39+
int nproc, myrank,mypool;
3940
setupmpi(argc,argv,nproc, myrank);
4041
divide_pools(nproc, myrank, nproc_in_pool, npool, mypool, rank_in_pool);
4142
#else
42-
nproc = nproc_in_pool = npool = 1;
43-
myrank = mypool = rank_in_pool = 0;
43+
nproc_in_pool = npool = 1;
44+
rank_in_pool = 0;
4445
#endif
4546
int result = 0;
4647
testing::AddGlobalTestEnvironment(new TestEnv);
File renamed without changes.
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
#include "../pw_basis.h"
2+
#ifdef __MPI
3+
#include "test_tool.h"
4+
#include "../../src_parallel/parallel_global.h"
5+
#include "mpi.h"
6+
#endif
7+
#include "../../module_base/global_function.h"
8+
#include "../../module_base/constants.h"
9+
#include "pw_test.h"
10+
extern int nproc_in_pool,rank_in_pool;
11+
using namespace std;
12+
13+
TEST_F(PWTEST,test1_1_1)
14+
{
15+
cout<<"dividemthd 1, gamma_only: off, check gcar,gdirect,gg,istot2bigixy,ig2isz"<<endl;
16+
//--------------------------------------------------
17+
ModuleBase::Matrix3 latvec(20,1,0,0,1,0,0,0,5);
18+
bool gamma_only = false;
19+
double wfcecut = 70;
20+
double lat0 = 1;
21+
int distribution_type = 1;
22+
//--------------------------------------------------
23+
24+
ModulePW::PW_Basis pwtest;
25+
26+
pwtest.initgrids(lat0, latvec, wfcecut,nproc_in_pool, rank_in_pool);
27+
pwtest.initparameters(gamma_only, wfcecut, distribution_type);
28+
pwtest.distribute_r();
29+
pwtest.distribute_g();
30+
pwtest.collect_local_pw();
31+
ModuleBase::Matrix3 GT,G,GGT;
32+
GT = latvec.Inverse();
33+
G = GT.Transpose();
34+
GGT = G * GT;
35+
double tpiba2 = ModuleBase::TWO_PI * ModuleBase::TWO_PI / lat0 / lat0;
36+
double ggecut = wfcecut / tpiba2;
37+
38+
//ref
39+
const int totnpw_ref = 1051;
40+
const int totnst_ref = 123;
41+
const int nx_ref = 54;
42+
const int ny_ref = 3;
43+
const int nz_ref = 15;
44+
45+
46+
//results
47+
int tot_npw = 0;
48+
#ifdef __MPI
49+
MPI_Allreduce(&pwtest.npw, &tot_npw, 1, MPI_INT, MPI_SUM, POOL_WORLD);
50+
#else
51+
tot_npw = pwtest.npw;
52+
#endif
53+
ASSERT_EQ(pwtest.nx, nx_ref);
54+
ASSERT_EQ(pwtest.ny, ny_ref);
55+
ASSERT_EQ(pwtest.bigny, ny_ref);
56+
ASSERT_EQ(pwtest.nz, nz_ref);
57+
ASSERT_EQ(tot_npw, totnpw_ref);
58+
ASSERT_EQ(pwtest.nstot,totnst_ref);
59+
ASSERT_EQ(pwtest.bignxyz, nx_ref*ny_ref*nz_ref);
60+
61+
62+
int *tmpx = new int[pwtest.nx*pwtest.ny*pwtest.nz];
63+
int *tmpy = new int[pwtest.nx*pwtest.ny*pwtest.nz];
64+
int *tmpz = new int[pwtest.nx*pwtest.ny*pwtest.nz];
65+
ModuleBase::GlobalFunc::ZEROS(tmpx,pwtest.nx*pwtest.ny*pwtest.nz);
66+
ModuleBase::GlobalFunc::ZEROS(tmpy,pwtest.nx*pwtest.ny*pwtest.nz);
67+
ModuleBase::GlobalFunc::ZEROS(tmpz,pwtest.nx*pwtest.ny*pwtest.nz);
68+
69+
int * startnst = new int [nproc_in_pool];
70+
startnst[0] = 0;
71+
for(int ip = 1 ; ip < nproc_in_pool; ++ip)
72+
{
73+
startnst[ip] = startnst[ip-1] + pwtest.nst_per[ip-1];
74+
}
75+
76+
for(int ig = 0 ; ig < pwtest.npw; ++ig)
77+
{
78+
int istot = pwtest.ig2isz[ig] / pwtest.nz + startnst[rank_in_pool];
79+
// int is = pwtest.ig2isz[ig] / pwtest.nz;
80+
int iz = pwtest.ig2isz[ig] % pwtest.nz;
81+
int iy = pwtest.istot2bigixy[istot] % pwtest.ny;
82+
int ix = pwtest.istot2bigixy[istot] / pwtest.ny;
83+
// int iy = pwtest.is2ixy[is] % pwtest.ny;
84+
// int ix = pwtest.is2ixy[is] / pwtest.ny;
85+
86+
tmpx[iz+(iy+ix*pwtest.ny)*pwtest.nz] = int(pwtest.gdirect[ig].x);
87+
tmpy[iz+(iy+ix*pwtest.ny)*pwtest.nz] = int(pwtest.gdirect[ig].y);
88+
tmpz[iz+(iy+ix*pwtest.ny)*pwtest.nz] = int(pwtest.gdirect[ig].z);
89+
}
90+
#ifdef __MPI
91+
MPI_Allreduce(MPI_IN_PLACE,tmpx,pwtest.bignxyz,MPI_INT,MPI_SUM,POOL_WORLD);
92+
MPI_Allreduce(MPI_IN_PLACE,tmpy,pwtest.bignxyz,MPI_INT,MPI_SUM,POOL_WORLD);
93+
MPI_Allreduce(MPI_IN_PLACE,tmpz,pwtest.bignxyz,MPI_INT,MPI_SUM,POOL_WORLD);
94+
#endif
95+
if(rank_in_pool==0)
96+
{
97+
for(int iz = 0 ; iz < pwtest.nz; ++iz)
98+
{
99+
for(int iy = 0 ; iy < pwtest.ny ; ++iy)
100+
{
101+
for(int ix = 0 ; ix < pwtest.nx ; ++ix)
102+
{
103+
ModuleBase::Vector3<double> f;
104+
f.x = ix;
105+
f.y = iy;
106+
f.z = iz;
107+
if(iz >= int(pwtest.nz/2) +1) f.z -= pwtest.nz;
108+
if(iy >= int(pwtest.ny/2) +1) f.y -= pwtest.ny;
109+
if(ix >= int(pwtest.nx/2) +1) f.x -= pwtest.nx;
110+
double modulus = f * (GGT * f);
111+
if (modulus <= ggecut)
112+
{
113+
EXPECT_EQ(tmpx[iz + iy*pwtest.nz + ix*pwtest.ny*pwtest.nz], int(f.x));
114+
EXPECT_EQ(tmpy[iz + iy*pwtest.nz + ix*pwtest.ny*pwtest.nz], int(f.y));
115+
EXPECT_EQ(tmpz[iz + iy*pwtest.nz + ix*pwtest.ny*pwtest.nz], int(f.z));
116+
}
117+
118+
}
119+
}
120+
}
121+
}
122+
for(int ig = 0 ;ig < pwtest.npw ; ++ig)
123+
{
124+
ModuleBase::Vector3<double> f;
125+
f.x = pwtest.gdirect[ig].x;
126+
f.y = pwtest.gdirect[ig].y;
127+
f.z = pwtest.gdirect[ig].z;
128+
ModuleBase::Vector3<double> gcar;
129+
gcar = f * G;
130+
double modulus = f*GGT*f;
131+
EXPECT_NEAR(gcar.x,pwtest.gcar[ig].x,1e-6);
132+
EXPECT_NEAR(gcar.y,pwtest.gcar[ig].y,1e-6);
133+
EXPECT_NEAR(gcar.z,pwtest.gcar[ig].z,1e-6);
134+
EXPECT_NEAR(modulus,pwtest.gg[ig],1e-6);
135+
}
136+
delete [] startnst;
137+
delete [] tmpx;
138+
delete [] tmpy;
139+
delete [] tmpz;
140+
}

0 commit comments

Comments
 (0)