Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 64 additions & 12 deletions tests/testIons.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ int main(int argc, char** argv)
// read species info from pseudopotential file
std::string file_path = argv[1];
std::string filename(file_path + "/pseudo.C_ONCV_PBE_SG15");
std::cout << "Potential = " << filename << std::endl;
if (myrank == 0) std::cout << "Potential = " << filename << std::endl;

sp.read_1species(filename);
sp.set_dim_nl(h[0]);
Expand Down Expand Up @@ -80,25 +80,77 @@ int main(int argc, char** argv)

ions.setup();

std::vector<Ion*>& new_local_ions(ions.local_ions());
// verify sum of local ions adds up to total number of ions
{
std::vector<Ion*>& new_local_ions(ions.local_ions());

int nlocal = new_local_ions.size();
std::cout << "PE " << myrank << ", nlocal = " << nlocal << std::endl;

int ntotal = 0;
MPI_Allreduce(&nlocal, &ntotal, 1, MPI_INT, MPI_SUM, comm);
if (ntotal != na)
{
std::cout << "ntotal = " << ntotal << std::endl;
return 1;
}
}
MPI_Barrier(MPI_COMM_WORLD);

int nlocal = new_local_ions.size();
std::cout << "PE " << myrank << ", nlocal = " << nlocal << std::endl;
// verify some functionalities of class Ions
{
std::vector<double> positions;
std::vector<short> anumbers;
ions.getPositions(positions);
ions.getAtomicNumbers(anumbers);
if (myrank == 0)
{
int i = 0;
for (auto& position : positions)
{
std::cout << position;
if (i % 3 == 2)
std::cout << std::endl;
else
std::cout << " ";
i++;
}
}
MPI_Barrier(MPI_COMM_WORLD);

// swap x and z
for (size_t i = 0; i < positions.size() - 2; i++)
{
double x = positions[i];
double z = positions[i + 2];
positions[i] = z;
positions[i + 2] = x;
}

ions.setPositions(positions, anumbers);
}

int ntotal = 0;
MPI_Allreduce(&nlocal, &ntotal, 1, MPI_INT, MPI_SUM, comm);
MPI_Barrier(MPI_COMM_WORLD);
{
std::vector<Ion*>& new_local_ions(ions.local_ions());

int nlocal = new_local_ions.size();
std::cout << "PE " << myrank << ", nlocal = " << nlocal << std::endl;

int ntotal = 0;
MPI_Allreduce(&nlocal, &ntotal, 1, MPI_INT, MPI_SUM, comm);
if (ntotal != na)
{
std::cout << "ntotal = " << ntotal << std::endl;
return 1;
}
}
mpirc = MPI_Finalize();
if (mpirc != MPI_SUCCESS)
{
std::cerr << "MPI Finalize failed!!!" << std::endl;
return 1;
}

if (ntotal != na)
{
std::cout << "ntotal = " << ntotal << std::endl;
return 1;
}

return 0;
}