Skip to content
Open
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
46 changes: 26 additions & 20 deletions source/source_esolver/esolver_dp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,17 @@ void ESolver_DP::runner(UnitCell& ucell, const int istep)
cell[8] = ucell.latvec.e33 * ucell.lat0_angstrom;

std::vector<double> coord(3 * ucell.nat, 0.0);
int iat = 0;
for (int it = 0; it < ucell.ntype; ++it)
#ifdef _OPENMP
#pragma omp parallel for default(none) shared(ucell, coord)
#endif
for (int iat = 0; iat < ucell.nat; ++iat)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend default(none) because it requires explicit variable scoping and avoids hidden parallel errors.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the recommendation!😊

{
for (int ia = 0; ia < ucell.atoms[it].na; ++ia)
{
coord[3 * iat] = ucell.atoms[it].tau[ia].x * ucell.lat0_angstrom;
coord[3 * iat + 1] = ucell.atoms[it].tau[ia].y * ucell.lat0_angstrom;
coord[3 * iat + 2] = ucell.atoms[it].tau[ia].z * ucell.lat0_angstrom;
iat++;
}
int it = ucell.iat2it[iat];
int ia = ucell.iat2ia[iat];
coord[3 * iat] = ucell.atoms[it].tau[ia].x * ucell.lat0_angstrom;
coord[3 * iat + 1] = ucell.atoms[it].tau[ia].y * ucell.lat0_angstrom;
coord[3 * iat + 2] = ucell.atoms[it].tau[ia].z * ucell.lat0_angstrom;
}
assert(ucell.nat == iat);

#ifdef __DPMD
std::vector<double> f, v;
Expand All @@ -101,6 +100,9 @@ void ESolver_DP::runner(UnitCell& ucell, const int istep)
GlobalV::ofs_running << " #TOTAL ENERGY# " << std::setprecision(11) << dp_potential * ModuleBase::Ry_to_eV << " eV"
<< std::endl;

#ifdef _OPENMP
#pragma omp parallel for default(none) shared(ucell, f, fact_f)
#endif
for (int i = 0; i < ucell.nat; ++i)
{
dp_force(i, 0) = f[3 * i] * fact_f;
Expand Down Expand Up @@ -186,20 +188,24 @@ void ESolver_DP::type_map(const UnitCell& ucell)
}
std::cout << "\n -----------------------------------------------------------------" << std::endl;

int iat = 0;
// validate labels exist in DP model type map
for (int it = 0; it < ucell.ntype; ++it)
{
for (int ia = 0; ia < ucell.atoms[it].na; ++ia)
if (label.find(ucell.atoms[it].label) == label.end())
{
if (label.find(ucell.atoms[it].label) == label.end())
{
ModuleBase::WARNING_QUIT("ESolver_DP",
"The label " + ucell.atoms[it].label + " is not found in the type map.");
}
atype[iat] = label[ucell.atoms[it].label];
iat++;
ModuleBase::WARNING_QUIT("ESolver_DP",
"The label " + ucell.atoms[it].label + " is not found in the type map.");
}
}
assert(ucell.nat == iat);

// assign atype for each atom
#ifdef _OPENMP
#pragma omp parallel for default(none) shared(ucell, label)
#endif
for (int iat = 0; iat < ucell.nat; ++iat)
{
int it = ucell.iat2it[iat];
atype[iat] = label[ucell.atoms[it].label];
}
}
#endif
Loading