Skip to content

Commit f402ff6

Browse files
committed
< add >
add serial version
1 parent 4c0c6f6 commit f402ff6

File tree

16 files changed

+189
-77
lines changed

16 files changed

+189
-77
lines changed

source/module_pw/pw_gatherscatter.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace ModulePW
1414
//in[] will be changed
1515
//
1616
template<typename T>
17-
void PW_Basis:: gatherp_scatters(complex<T> *in, complex<T> *out)
17+
void PW_Basis:: gatherp_scatters(std::complex<T> *in, std::complex<T> *out)
1818
{
1919
ModuleBase::timer::tick("PW_Basis", "gatherp_scatters");
2020

@@ -74,7 +74,7 @@ void PW_Basis:: gatherp_scatters(complex<T> *in, complex<T> *out)
7474
//in[] will be changed
7575
//
7676
template<typename T>
77-
void PW_Basis:: gathers_scatterp(complex<T> *in, complex<T> *out)
77+
void PW_Basis:: gathers_scatterp(std::complex<T> *in, std::complex<T> *out)
7878
{
7979
ModuleBase::timer::tick("PW_Basis", "gatherp_scatterp");
8080

source/module_pw/unittest/Makefile

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
#==========================
33
# Compiler information
44
#==========================
5-
CPLUSPLUS = icpc
6-
CPLUSPLUS_MPI = mpiicpc
5+
CPLUSPULS = mpiicpc
76
CUDA_COMPILE = nvcc
87
OBJ_DIR = pw_obj
98
BIN_DIR = testbin
@@ -43,14 +42,16 @@ test_t2.exe
4342

4443
FLOATFILE=testf2.exe\
4544
testf3.exe
46-
45+
TESTFILE0 = ${DOUBLEFILE}
4746

4847
#==========================
4948
# Options
5049
#==========================
50+
#No MPI
51+
# HONG = -D__NORMAL
52+
5153
#Only MPI
5254
HONG = -D__MPI -D__NORMAL
53-
TESTFILE0 = ${DOUBLEFILE}
5455

5556
#Mix Precision
5657
# HONG = -D__MPI -D__MIX_PRECISION -D__NORMAL
@@ -61,6 +62,7 @@ TESTFILE0 = ${DOUBLEFILE}
6162

6263
#Cuda & Mix Precision
6364
#HONG = -D__MPI -D__CUDA -D__MIX_PRECISION -D__NORMAL
65+
# TESTFILE0 = ${DOUBLEFILE} ${FLOATFILE}
6466

6567

6668
PW_OBJS=$(patsubst %.o, ${OBJ_DIR}/%.o, ${PW_OBJS_0})
@@ -107,9 +109,9 @@ init :
107109
@ if [ ! -d $(OBJ_DIR)/README ]; then echo "This directory contains all of the .o files" > $(OBJ_DIR)/README; fi
108110

109111
${BIN_DIR}/%.exe: %.cpp
110-
${CPLUSPLUS_MPI} ${OPTS} $< test_tool.cpp ${PW_OBJS} ${LIBS} -o $@
112+
${CPLUSPULS} ${OPTS} $< test_tool.cpp ${PW_OBJS} ${LIBS} -o $@
111113
${OBJ_DIR}/%.o:%.cpp
112-
${CPLUSPLUS_MPI} ${OPTS} -c ${HONG} $< -o $@
114+
${CPLUSPULS} ${OPTS} -c ${HONG} $< -o $@
113115

114116
.PHONY:clean
115117
clean:

source/module_pw/unittest/Makefile.gnu

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
#==========================
33
# Compiler information
44
#==========================
5-
CPLUSPLUS = g++
6-
CPLUSPLUS_MPI = mpicxx
5+
CPLUSPLUS = mpicxx
76
CUDA_COMPILE = nvcc
87
OBJ_DIR = pw_obj
98
BIN_DIR = testbin
@@ -43,23 +42,27 @@ test_t2.exe
4342

4443
FLOATFILE=testf2.exe\
4544
testf3.exe
45+
TESTFILE0 = ${DOUBLEFILE}
4646

4747
#==========================
4848
# Options
4949
#==========================
50+
#No MPI
51+
# HONG = -D__NORMAL
52+
5053
#Only MPI
51-
# HONG = -D__MPI -D__NORMAL
52-
# TESTFILE0 = ${DOUBLEFILE}
54+
HONG = -D__MPI -D__NORMAL
5355

5456
#Mix Precision
55-
HONG = -D__MPI -D__MIX_PRECISION -D__NORMAL
56-
TESTFILE0 = ${DOUBLEFILE} ${FLOATFILE}
57+
# HONG = -D__MPI -D__MIX_PRECISION -D__NORMAL
58+
# TESTFILE0 = ${DOUBLEFILE} ${FLOATFILE}
5759

5860
#Cuda
5961
#HONG = -D__MPI -D__CUDA -D__NORMAL
6062

6163
#Cuda & Mix Precision
6264
#HONG = -D__MPI -D__CUDA -D__MIX_PRECISION -D__NORMAL
65+
# TESTFILE0 = ${DOUBLEFILE} ${FLOATFILE}
6366

6467

6568
PW_OBJS=$(patsubst %.o, ${OBJ_DIR}/%.o, ${PW_OBJS_0})
@@ -102,9 +105,9 @@ init :
102105
@ if [ ! -d $(OBJ_DIR)/README ]; then echo "This directory contains all of the .o files" > $(OBJ_DIR)/README; fi
103106

104107
${BIN_DIR}/%.exe: %.cpp
105-
${CPLUSPLUS_MPI} ${OPTS} $< test_tool.cpp ${PW_OBJS} ${LIBS} -o $@
108+
${CPLUSPLUS} ${OPTS} $< test_tool.cpp ${PW_OBJS} ${LIBS} -o $@
106109
${OBJ_DIR}/%.o:%.cpp
107-
${CPLUSPLUS_MPI} ${OPTS} -c ${HONG} $< -o $@
110+
${CPLUSPLUS} ${OPTS} -c ${HONG} $< -o $@
108111

109112
.PHONY:clean
110113
clean:

source/module_pw/unittest/Makefile.intel

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
#==========================
33
# Compiler information
44
#==========================
5-
CPLUSPLUS = icpc
6-
CPLUSPLUS_MPI = mpiicpc
5+
CPLUSPULS = mpiicpc
76
CUDA_COMPILE = nvcc
87
OBJ_DIR = pw_obj
98
BIN_DIR = testbin
@@ -43,14 +42,16 @@ test_t2.exe
4342

4443
FLOATFILE=testf2.exe\
4544
testf3.exe
46-
45+
TESTFILE0 = ${DOUBLEFILE}
4746

4847
#==========================
4948
# Options
5049
#==========================
50+
#No MPI
51+
# HONG = -D__NORMAL
52+
5153
#Only MPI
5254
HONG = -D__MPI -D__NORMAL
53-
TESTFILE0 = ${DOUBLEFILE}
5455

5556
#Mix Precision
5657
# HONG = -D__MPI -D__MIX_PRECISION -D__NORMAL
@@ -61,6 +62,7 @@ TESTFILE0 = ${DOUBLEFILE}
6162

6263
#Cuda & Mix Precision
6364
#HONG = -D__MPI -D__CUDA -D__MIX_PRECISION -D__NORMAL
65+
# TESTFILE0 = ${DOUBLEFILE} ${FLOATFILE}
6466

6567

6668
PW_OBJS=$(patsubst %.o, ${OBJ_DIR}/%.o, ${PW_OBJS_0})
@@ -107,9 +109,9 @@ init :
107109
@ if [ ! -d $(OBJ_DIR)/README ]; then echo "This directory contains all of the .o files" > $(OBJ_DIR)/README; fi
108110

109111
${BIN_DIR}/%.exe: %.cpp
110-
${CPLUSPLUS_MPI} ${OPTS} $< test_tool.cpp ${PW_OBJS} ${LIBS} -o $@
112+
${CPLUSPULS} ${OPTS} $< test_tool.cpp ${PW_OBJS} ${LIBS} -o $@
111113
${OBJ_DIR}/%.o:%.cpp
112-
${CPLUSPLUS_MPI} ${OPTS} -c ${HONG} $< -o $@
114+
${CPLUSPULS} ${OPTS} -c ${HONG} $< -o $@
113115

114116
.PHONY:clean
115117
clean:

source/module_pw/unittest/test1.cpp

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#include "../pw_basis.h"
22
#include "../../src_parallel/parallel_global.h"
3+
#ifdef __MPI
34
#include "test_tool.h"
5+
#include "mpi.h"
6+
#endif
47
#include "../../module_base/timer.h"
58
#include "../../module_base/global_function.h"
69

@@ -13,8 +16,13 @@ int main(int argc,char **argv)
1316
int nproc, myrank;
1417
int nproc_in_pool, npool, mypool, rank_in_pool;
1518
npool = 1;
19+
#ifdef __MPI
1620
setupmpi(argc,argv,nproc, myrank);
1721
divide_pools(nproc, myrank, nproc_in_pool, npool, mypool, rank_in_pool);
22+
#else
23+
nproc = nproc_in_pool = npool = 1;
24+
myrank = mypool = rank_in_pool = 0;
25+
#endif
1826

1927
ModuleBase::timer::start();
2028

@@ -25,14 +33,19 @@ int main(int argc,char **argv)
2533
pwtest.initparameters(gamma_only, ecut, nproc, rank_in_pool, distribution_type);
2634
pwtest.distribute_r();
2735
pwtest.distribute_g();
28-
MPI_Barrier(POOL_WORLD);
2936

3037
int tot_npw = 0;
3138
int nxy = pwtest.nx * pwtest.ny;
39+
#ifdef __MPI
3240
MPI_Reduce(&pwtest.npw, &tot_npw, 1, MPI_INT, MPI_SUM, 0, POOL_WORLD);
41+
#else
42+
tot_npw = pwtest.npw;
43+
#endif
3344
for (int ip = 0; ip < nproc; ip++)
3445
{
46+
#ifdef __MPI
3547
MPI_Barrier(POOL_WORLD);
48+
#endif
3649
if (rank_in_pool == ip)
3750
{
3851
std::cout<<"ip: "<<ip<<'\n';
@@ -58,11 +71,15 @@ int main(int argc,char **argv)
5871
std::cout << "\n";
5972
}
6073
}
74+
#ifdef __MPI
6175
MPI_Barrier(POOL_WORLD);
76+
#endif
6277
pwtest.collect_local_pw();
6378
for (int ip = 0; ip < nproc; ip++)
6479
{
80+
#ifdef __MPI
6581
MPI_Barrier(POOL_WORLD);
82+
#endif
6683
if (rank_in_pool == ip)
6784
{
6885
std::cout<<"ip: "<<ip<<'\n';
@@ -80,23 +97,5 @@ int main(int argc,char **argv)
8097
}
8198
if(rank_in_pool==0) ModuleBase::timer::finish(GlobalV::ofs_running, true);
8299

83-
// if (rank_in_pool == 0)
84-
// {
85-
// std::cout << "tot_npw " << tot_npw << "\n";
86-
// double* gg_global = new double[tot_npw];
87-
// ModuleBase::Vector3<double> *gdirect_global = new ModuleBase::Vector3<double>[tot_npw];
88-
// ModuleBase::Vector3<double> *gcar_global = new ModuleBase::Vector3<double>[tot_npw];
89-
// pwtest.collect_tot_pw(gg_global, gdirect_global, gcar_global);
90-
// std::cout<<"gg_global gdirect_global gcar_global\n";
91-
// for (int ig = 0; ig < tot_npw; ++ig)
92-
// {
93-
// std::cout << gg_global[ig] << std::setw(4) << gdirect_global[ig] << std::setw(4) << gcar_global[ig];
94-
// std::cout << "\n";
95-
// }
96-
// std::cout<<"done"<<"\n";
97-
// delete[] gg_global;
98-
// delete[] gdirect_global;
99-
// delete[] gcar_global;
100-
// }
101100
return 0;
102101
}

source/module_pw/unittest/test2-1.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#include "../pw_basis.h"
22
#include "../../src_parallel/parallel_global.h"
3+
#ifdef __MPI
34
#include "test_tool.h"
5+
#include "mpi.h"
6+
#endif
47
#include "../../module_base/timer.h"
58
#include "../../module_base/global_function.h"
69

@@ -13,8 +16,13 @@ int main(int argc,char **argv)
1316
int nproc, myrank;
1417
int nproc_in_pool, npool, mypool, rank_in_pool;
1518
npool = 1;
19+
#ifdef __MPI
1620
setupmpi(argc,argv,nproc, myrank);
1721
divide_pools(nproc, myrank, nproc_in_pool, npool, mypool, rank_in_pool);
22+
#else
23+
nproc = nproc_in_pool = npool = 1;
24+
myrank = mypool = rank_in_pool = 0;
25+
#endif
1826

1927
ModuleBase::timer::start();
2028

@@ -25,14 +33,16 @@ int main(int argc,char **argv)
2533
pwtest.initparameters(gamma_only, ecut, nproc, rank_in_pool, distribution_type);
2634
pwtest.distribute_r();
2735
pwtest.distribute_g();
28-
MPI_Barrier(POOL_WORLD);
29-
3036
int tot_npw = 0;
3137
int nxy = pwtest.nx * pwtest.ny;
38+
#ifdef __MPI
3239
MPI_Reduce(&pwtest.npw, &tot_npw, 1, MPI_INT, MPI_SUM, 0, POOL_WORLD);
40+
#endif
3341
for (int ip = 0; ip < nproc; ip++)
3442
{
43+
#ifdef __MPI
3544
MPI_Barrier(POOL_WORLD);
45+
#endif
3646
if (rank_in_pool == ip)
3747
{
3848
std::cout<<"ip: "<<ip<<'\n';
@@ -58,11 +68,15 @@ int main(int argc,char **argv)
5868
std::cout << "\n";
5969
}
6070
}
71+
#ifdef __MPI
6172
MPI_Barrier(POOL_WORLD);
73+
#endif
6274
pwtest.collect_local_pw();
6375
for (int ip = 0; ip < nproc; ip++)
6476
{
77+
#ifdef __MPI
6578
MPI_Barrier(POOL_WORLD);
79+
#endif
6680
if (rank_in_pool == ip)
6781
{
6882
std::cout<<"ip: "<<ip<<'\n';

source/module_pw/unittest/test2-2.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
// TEST for FFT
33
//---------------------------------------------
44
#include "../pw_basis.h"
5+
#ifdef __MPI
56
#include "test_tool.h"
7+
#include "mpi.h"
8+
#endif
69
#include "../../module_base/constants.h"
710
#include "../../module_base/global_function.h"
811
#include <iostream>
912
#include <iomanip>
10-
#include "mpi.h"
1113
#include "../../module_base/timer.h"
1214

1315
using namespace std;
@@ -31,8 +33,13 @@ int main(int argc,char **argv)
3133
//--------------------------------------------------
3234

3335
//setup mpi
36+
#ifdef __MPI
3437
setupmpi(argc,argv,nproc, myrank);
3538
divide_pools(nproc, myrank, nproc_in_pool, npool, mypool, rank_in_pool);
39+
#else
40+
nproc = nproc_in_pool = npool = 1;
41+
myrank = mypool = rank_in_pool = 0;
42+
#endif
3643
//cout<<nproc<<" d "<<myrank<<" d "<<nproc_in_pool<<" "<<npool<<" "<<mypool<<" "<<rank_in_pool<<endl;
3744
ModuleBase::timer::start();
3845

@@ -115,7 +122,9 @@ int main(int argc,char **argv)
115122
complex<double> * rhor = new complex<double> [nrxx];
116123
pwtest.recip2real(rhog,rhor);
117124
if(myrank == 0) cout << "new pw module\n";
125+
#ifdef __MPI
118126
MPI_Barrier(MPI_COMM_WORLD);
127+
#endif
119128
for(int ixy = 0 ; ixy < nx * ny ; ixy+=5)
120129
{
121130
for(int ip = 0 ; ip < nproc ; ++ip)
@@ -127,7 +136,9 @@ int main(int argc,char **argv)
127136
cout<<setprecision(5)<<setiosflags(ios::left)<<setw(30)<<rhor[ixy*nplane+iz];
128137
}
129138
}
130-
MPI_Barrier(MPI_COMM_WORLD);
139+
#ifdef __MPI
140+
MPI_Barrier(MPI_COMM_WORLD);
141+
#endif
131142
}
132143
}
133144

@@ -155,8 +166,9 @@ int main(int argc,char **argv)
155166
cout<<endl;
156167
}
157168

158-
159-
MPI_Barrier(MPI_COMM_WORLD);
169+
#ifdef __MPI
170+
MPI_Barrier(MPI_COMM_WORLD);
171+
#endif
160172
if(rank_in_pool==0) ModuleBase::timer::finish(GlobalV::ofs_running, true);
161173

162174
delete [] rhog;

0 commit comments

Comments
 (0)