Skip to content

Commit 41d38a0

Browse files
authored
Merge pull request #509 from Qianruipku/planewave
use valgrind to test the memory problems
2 parents 968d123 + e76c1a4 commit 41d38a0

File tree

4 files changed

+20
-13
lines changed

4 files changed

+20
-13
lines changed

source/module_pw/pw_gatherscatter.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ void PW_Basis:: gatherp_scatters(complex<double> *in, complex<double> *out)
2323
return;
2424
}
2525
#ifdef __MPI
26-
std::complex<double> * tmp;
26+
std::complex<double> * tmp = NULL;
2727
if(this->poolrank == 0) tmp = new std::complex<double> [this->nz * this->nstot];
2828

2929
//gather planes of different processors
@@ -40,7 +40,7 @@ void PW_Basis:: gatherp_scatters(complex<double> *in, complex<double> *out)
4040
MPI_Scatterv(tmp, this->nstnz_per, this->startnsz_per,mpicomplex,out,
4141
this->nstnz,mpicomplex,0, POOL_WORLD);
4242

43-
if(this->poolrank == 0) delete[] tmp;
43+
if(tmp!=NULL) delete[] tmp;
4444
#endif
4545
return;
4646
}
@@ -107,7 +107,7 @@ void PW_Basis:: gathers_scatterp(complex<double> *in, complex<double> *out)
107107
}
108108
#ifdef __MPI
109109
if(this->poolnproc == 1) return;
110-
std::complex<double> * tmp;
110+
std::complex<double> * tmp = NULL;
111111
if(this->poolrank == 0) tmp = new std::complex<double> [this->nz * this->nstot];
112112

113113
//scatter sticks to different processors
@@ -121,7 +121,7 @@ void PW_Basis:: gathers_scatterp(complex<double> *in, complex<double> *out)
121121
MPI_Scatterv(&tmp[istot*this->nz], this->numz,this->startz, mpicomplex, &out[ixy*this->nplane],
122122
this->nplane,mpicomplex,0,POOL_WORLD);
123123
}
124-
if(this->poolrank == 0) delete[] tmp;
124+
if(tmp!=NULL) delete[] tmp;
125125
#endif
126126
return;
127127
}

source/module_pw/unittest/Makefile.gnu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ FFTW_LIB = -L${FFTW_LIB_DIR} -lfftw3 -Wl,-rpath=${FFTW_LIB_DIR}
6969
# CUDA_LIB = -L${CUDA_LIB_DIR} -lcufft -lcublas -lcudart
7070

7171
LIBS = ${FFTW_LIB} ${CUDA_LIB}
72-
OPTS = -I${FFTW_INCLUDE_DIR} ${HONG} -Ofast -march=native -std=c++11 -Wall -g
72+
OPTS = -I${FFTW_INCLUDE_DIR} ${HONG} -Ofast -std=c++11 -Wall -g
7373
#==========================
7474
# MAKING OPTIONS
7575
#==========================

source/module_pw/unittest/test2.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ int main(int argc,char **argv)
5555
GT = latvec.Inverse();
5656
G = GT.Transpose();
5757
GGT = G * GT;
58-
58+
complex<double> *tmp = NULL;
5959
if(myrank == 0)
6060
{
61-
complex<double> *tmp = new complex<double> [nx*ny*nz];
61+
tmp = new complex<double> [nx*ny*nz];
6262
for(int ix = 0 ; ix < nx ; ++ix)
6363
{
6464
for(int iy = 0 ; iy < ny ; ++iy)
@@ -80,7 +80,8 @@ int main(int argc,char **argv)
8080
}
8181
}
8282
fftw_plan pp = fftw_plan_dft_3d(nx,ny,nz,(fftw_complex *) tmp, (fftw_complex *) tmp, FFTW_BACKWARD, FFTW_ESTIMATE);
83-
fftw_execute(pp);
83+
fftw_execute(pp);
84+
fftw_destroy_plan(pp);
8485

8586
//output
8687
cout << "reference\n";
@@ -153,6 +154,9 @@ int main(int argc,char **argv)
153154
}
154155

155156

156-
MPI_Barrier(MPI_COMM_WORLD);
157+
MPI_Barrier(MPI_COMM_WORLD);
158+
delete [] rhog;
159+
delete [] rhor;
160+
if(tmp!=NULL) delete []tmp;
157161
return 0;
158162
}

source/module_pw/unittest/test3.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ int main(int argc,char **argv)
5555
GT = latvec.Inverse();
5656
G = GT.Transpose();
5757
GGT = G * GT;
58-
58+
complex<double> *tmp = NULL;
5959
if(myrank == 0)
6060
{
61-
complex<double> *tmp = new complex<double> [nx*ny*nz];
61+
tmp = new complex<double> [nx*ny*nz];
6262
for(int ix = 0 ; ix < nx ; ++ix)
6363
{
6464
for(int iy = 0 ; iy < ny ; ++iy)
@@ -81,7 +81,8 @@ int main(int argc,char **argv)
8181
}
8282
}
8383
fftw_plan pp = fftw_plan_dft_3d(nx,ny,nz,(fftw_complex *) tmp, (fftw_complex *) tmp, FFTW_BACKWARD, FFTW_ESTIMATE);
84-
fftw_execute(pp);
84+
fftw_execute(pp);
85+
fftw_destroy_plan(pp);
8586

8687
//output
8788
cout << "reference\n";
@@ -152,6 +153,8 @@ int main(int argc,char **argv)
152153
}
153154

154155
MPI_Barrier(MPI_COMM_WORLD);
155-
156+
delete [] rhog;
157+
delete [] rhor;
158+
if(tmp!=NULL) delete []tmp;
156159
return 0;
157160
}

0 commit comments

Comments
 (0)