Skip to content

Commit

Permalink
exchange some pointers into vectors (#3965)
Browse files Browse the repository at this point in the history
* Update berryphase.cpp

* Update berryphase.cpp

* Update read_wfc_pw.cpp

* Update to_wannier90_pw.cpp
  • Loading branch information
Zjhjunhao committed Apr 13, 2024
1 parent 93b3276 commit cc21a8d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 17 deletions.
11 changes: 4 additions & 7 deletions source/module_io/berryphase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,10 +395,10 @@ void berryphase::Berry_Phase(int nbands,
const K_Vectors& kv)
{
std::complex<double> cave = 0.0;
double *phik = new double[total_string];
std::vector<double> phik(total_string);
double phik_ave = 0.0;
std::complex<double> *cphik = new std::complex<double>[total_string];
double *wistring = new double[total_string];
std::vector<std::complex<double>> cphik(total_string);
std::vector<double> wistring(total_string);


// electron polarization
Expand Down Expand Up @@ -453,10 +453,7 @@ void berryphase::Berry_Phase(int nbands,
}



delete[] phik;
delete[] cphik;
delete[] wistring;



//GlobalV::ofs_running << "Berry_Phase end " << std::endl;
Expand Down
12 changes: 6 additions & 6 deletions source/module_io/read_wfc_pw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,14 @@ bool ModuleIO::read_wfc_pw(const std::string& filename,
}
MPI_Allreduce(MPI_IN_PLACE, &ip, 1, MPI_INT, MPI_MAX, MPI_COMM_WORLD);
MPI_Bcast(&size, 1, MPI_INT, ip, MPI_COMM_WORLD);
char* swap = new char[size + 1];
std::vector<char> swap(size + 1);
if (error)
{
strcpy(swap, msg.c_str());
strcpy(swap.data(), msg.c_str());
}
MPI_Bcast(swap, size + 1, MPI_CHAR, ip, MPI_COMM_WORLD);
msg = static_cast<std::string>(swap);
delete[] swap;
MPI_Bcast(swap.data(), size + 1, MPI_CHAR, ip, MPI_COMM_WORLD);
msg = static_cast<std::string>(swap.data());


MPI_Bcast(&error, 1, MPI_C_BOOL, ip, MPI_COMM_WORLD);
#endif
Expand Down Expand Up @@ -362,4 +362,4 @@ bool ModuleIO::read_wfc_pw(const std::string& filename,

ModuleBase::timer::tick("ModuleIO", "read_wfc_pw");
return true;
}
}
7 changes: 3 additions & 4 deletions source/module_io/to_wannier90_pw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ void toWannier90_PW::out_unk(

#ifdef __MPI
// which_ip: found iz belongs to which ip.
int* which_ip = new int[wfcpw->nz];
ModuleBase::GlobalFunc::ZEROS(which_ip, wfcpw->nz);
std::vector<int> which_ip(wfcpw->nz);
ModuleBase::GlobalFunc::ZEROS(which_ip.data(), wfcpw->nz);

for (int ip = 0; ip < GlobalV::NPROC_IN_POOL; ip++)
{
Expand Down Expand Up @@ -338,7 +338,6 @@ void toWannier90_PW::out_unk(
}
MPI_Barrier(MPI_COMM_WORLD);

delete[] which_ip;
delete[] porter;
delete[] zpiece;

Expand Down Expand Up @@ -1046,4 +1045,4 @@ void toWannier90_PW::unkdotW_A(
Parallel_Reduce::reduce_all(Amn.c, Amn.size);
#endif

}
}

0 comments on commit cc21a8d

Please sign in to comment.