11#include " module_base/element_name.h"
22#include " module_io/cube_io.h"
3+ #include < vector>
34
45void ModuleIO::write_cube (
56#ifdef __MPI
@@ -126,8 +127,8 @@ void ModuleIO::write_cube(
126127 {
127128 // / for cube file
128129 int nxyz = nx * ny * nz;
129- double * data_cube = new double [ nxyz] ;
130- ModuleBase::GlobalFunc::ZEROS (data_cube, nxyz);
130+ std::vector< double > data_cube ( nxyz) ;
131+ ModuleBase::GlobalFunc::ZEROS (data_cube. data () , nxyz);
131132 // / for cube file
132133
133134 // num_z: how many planes on processor 'ip'
@@ -149,8 +150,8 @@ void ModuleIO::write_cube(
149150 }
150151
151152 // which_ip: found iz belongs to which ip.
152- int * which_ip = new int [nz] ;
153- ModuleBase::GlobalFunc::ZEROS (which_ip, nz);
153+ std::vector< int > which_ip (nz) ;
154+ ModuleBase::GlobalFunc::ZEROS (which_ip. data () , nz);
154155 for (int iz=0 ; iz<nz; iz++)
155156 {
156157 for (int ip=0 ; ip<GlobalV::NPROC_IN_POOL; ip++)
@@ -172,14 +173,14 @@ void ModuleIO::write_cube(
172173
173174 int count=0 ;
174175 int nxy = nx * ny;
175- double * zpiece = new double [ nxy] ;
176+ std::vector< double > zpiece ( nxy) ;
176177
177178 // save the rho one z by one z.
178179 for (int iz=0 ; iz<nz; iz++)
179180 {
180181 // std::cout << "\n iz=" << iz << std::endl;
181182 // tag must be different for different iz.
182- ModuleBase::GlobalFunc::ZEROS (zpiece, nxy);
183+ ModuleBase::GlobalFunc::ZEROS (zpiece. data () , nxy);
183184 int tag = iz;
184185 MPI_Status ierror;
185186
@@ -205,14 +206,14 @@ void ModuleIO::write_cube(
205206 zpiece[ir] = data[ir*nplane+iz-startz_current];
206207 // GlobalV::ofs_running << "\n get zpiece[" << ir << "]=" << zpiece[ir] << " ir*rhopw->nplane+iz=" << ir*rhopw->nplane+iz;
207208 }
208- MPI_Send (zpiece, nxy, MPI_DOUBLE, 0 , tag, POOL_WORLD);
209+ MPI_Send (zpiece. data () , nxy, MPI_DOUBLE, 0 , tag, POOL_WORLD);
209210 }
210211
211212 // case 2: > first part rho: processor 0 receive the rho
212213 // from other processors
213214 else if (GlobalV::RANK_IN_POOL==0 )
214215 {
215- MPI_Recv (zpiece, nxy, MPI_DOUBLE, which_ip[iz], tag, POOL_WORLD, &ierror);
216+ MPI_Recv (zpiece. data () , nxy, MPI_DOUBLE, which_ip[iz], tag, POOL_WORLD, &ierror);
216217 // GlobalV::ofs_running << "\n Receieve First number = " << zpiece[0];
217218 }
218219
@@ -226,8 +227,6 @@ void ModuleIO::write_cube(
226227 // / for cube file
227228 }
228229 }// end iz
229- delete[] zpiece;
230- delete[] which_ip;
231230 delete[] num_z;
232231 delete[] start_z;
233232 // for cube file
@@ -246,7 +245,6 @@ void ModuleIO::write_cube(
246245 }
247246 }
248247 }
249- delete[] data_cube;
250248 // / for cube file
251249 }
252250 MPI_Barrier (MPI_COMM_WORLD);
0 commit comments