diff --git a/source/source_esolver/esolver_dp.cpp b/source/source_esolver/esolver_dp.cpp index 879193e668b..baced2bbeac 100644 --- a/source/source_esolver/esolver_dp.cpp +++ b/source/source_esolver/esolver_dp.cpp @@ -71,18 +71,17 @@ void ESolver_DP::runner(UnitCell& ucell, const int istep) cell[8] = ucell.latvec.e33 * ucell.lat0_angstrom; std::vector 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) { - 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 f, v; @@ -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; @@ -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