Skip to content

Commit

Permalink
Merge pull request #4139 from akohlmey/eam-warning-bugfix
Browse files Browse the repository at this point in the history
Later than last minute bugfix in EAM density warning for OPENMP package
  • Loading branch information
akohlmey committed Apr 17, 2024
2 parents cf0dc2a + 1b88adf commit 6836bca
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 40 deletions.
22 changes: 3 additions & 19 deletions src/INTEL/pair_eam_intel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@ void PairEAMIntel::eval(const int offload, const int vflag,
const int istride = fc.rhor_istride();
const int jstride = fc.rhor_jstride();
const int fstride = fc.frho_stride();
int beyond_rhomax = 0;
{
#if defined(__MIC__) && defined(_LMP_INTEL_OFFLOAD)
*timer_compute = MIC_Wtime();
Expand Down Expand Up @@ -453,10 +452,7 @@ void PairEAMIntel::eval(const int offload, const int vflag,
if (EFLAG) {
flt_t phi = ((frho_spline_e[ioff].a*p + frho_spline_e[ioff].b)*p +
frho_spline_e[ioff].c)*p + frho_spline_e[ioff].d;
if (rho[i] > frhomax) {
phi += fp_f[i] * (rho[i]-frhomax);
beyond_rhomax = 1;
}
if (rho[i] > frhomax) phi += fp_f[i] * (rho[i]-frhomax);
if (!ONETYPE) {
const int ptr_off=itype*ntypes + itype;
oscale = scale_f[ptr_off];
Expand Down Expand Up @@ -568,12 +564,10 @@ void PairEAMIntel::eval(const int offload, const int vflag,
} else
rhoip = rhojp;
const flt_t z2p = (z2r_spline_t[joff].a*p +
z2r_spline_t[joff].b)*p +
z2r_spline_t[joff].c;
z2r_spline_t[joff].b)*p + z2r_spline_t[joff].c;
const flt_t z2 = ((z2r_spline_t[joff].d*p +
z2r_spline_t[joff].e)*p +
z2r_spline_t[joff].f)*p +
z2r_spline_t[joff].g;
z2r_spline_t[joff].f)*p + z2r_spline_t[joff].g;

const flt_t recip = (flt_t)1.0/r;
const flt_t phi = z2*recip;
Expand Down Expand Up @@ -656,16 +650,6 @@ void PairEAMIntel::eval(const int offload, const int vflag,
else
fix->stop_watch(TIME_HOST_PAIR);

if (EFLAG && (!exceeded_rhomax)) {
MPI_Allreduce(&beyond_rhomax, &exceeded_rhomax, 1, MPI_INT, MPI_SUM, world);
if (exceeded_rhomax) {
if (comm->me == 0)
error->warning(FLERR,
"A per-atom density exceeded rhomax of EAM potential table - "
"a linear extrapolation to the energy was made");
}
}

if (EFLAG || vflag)
fix->add_result_array(f_start, ev_global, offload, eatom, 0, vflag);
else
Expand Down
40 changes: 20 additions & 20 deletions src/OPENMP/pair_eam_omp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ void PairEAMOMP::compute(int eflag, int vflag)
const int nall = atom->nlocal + atom->nghost;
const int nthreads = comm->nthreads;
const int inum = list->inum;
int beyond_rhomax = 0;

// grow energy and fp arrays if necessary
// need to be atom->nmax in length
Expand All @@ -61,7 +62,7 @@ void PairEAMOMP::compute(int eflag, int vflag)
}

#if defined(_OPENMP)
#pragma omp parallel LMP_DEFAULT_NONE LMP_SHARED(eflag,vflag)
#pragma omp parallel LMP_DEFAULT_NONE LMP_SHARED(eflag,vflag) reduction(+:beyond_rhomax)
#endif
{
int ifrom, ito, tid;
Expand All @@ -78,32 +79,41 @@ void PairEAMOMP::compute(int eflag, int vflag)

if (evflag) {
if (eflag) {
if (force->newton_pair) eval<1,1,1>(ifrom, ito, thr);
else eval<1,1,0>(ifrom, ito, thr);
if (force->newton_pair) eval<1,1,1>(ifrom, ito, &beyond_rhomax, thr);
else eval<1,1,0>(ifrom, ito, &beyond_rhomax, thr);
} else {
if (force->newton_pair) eval<1,0,1>(ifrom, ito, thr);
else eval<1,0,0>(ifrom, ito, thr);
if (force->newton_pair) eval<1,0,1>(ifrom, ito, &beyond_rhomax, thr);
else eval<1,0,0>(ifrom, ito, &beyond_rhomax, thr);
}
} else {
if (force->newton_pair) eval<0,0,1>(ifrom, ito, thr);
else eval<0,0,0>(ifrom, ito, thr);
if (force->newton_pair) eval<0,0,1>(ifrom, ito, &beyond_rhomax, thr);
else eval<0,0,0>(ifrom, ito, &beyond_rhomax, thr);
}

thr->timer(Timer::PAIR);
reduce_thr(this, eflag, vflag, thr);
} // end of omp parallel region

if (eflag && (!exceeded_rhomax)) {
MPI_Allreduce(&beyond_rhomax, &exceeded_rhomax, 1, MPI_INT, MPI_SUM, world);
if (exceeded_rhomax) {
if (comm->me == 0)
error->warning(FLERR,
"A per-atom density exceeded rhomax of EAM potential table - "
"a linear extrapolation to the energy was made");
}
}
}

template <int EVFLAG, int EFLAG, int NEWTON_PAIR>
void PairEAMOMP::eval(int iifrom, int iito, ThrData * const thr)
void PairEAMOMP::eval(int iifrom, int iito, int *beyond_rhomax, ThrData * const thr)
{
int i,j,ii,jj,m,jnum,itype,jtype;
double xtmp,ytmp,ztmp,delx,dely,delz,evdwl,fpair;
double rsq,r,p,rhoip,rhojp,z2,z2p,recip,phip,psip,phi;
double *coeff;
int *ilist,*jlist,*numneigh,**firstneigh;

int beyond_rhomax = 0;
evdwl = 0.0;

const auto * _noalias const x = (dbl3_t *) atom->x[0];
Expand Down Expand Up @@ -207,7 +217,7 @@ void PairEAMOMP::eval(int iifrom, int iito, ThrData * const thr)
phi = ((coeff[3]*p + coeff[4])*p + coeff[5])*p + coeff[6];
if (rho[i] > rhomax) {
phi += fp[i] * (rho[i]-rhomax);
beyond_rhomax = 1;
*beyond_rhomax = 1;
}
e_tally_thr(this, i, i, nlocal, NEWTON_PAIR, scale[type[i]][type[i]]*phi, 0.0, thr);
}
Expand Down Expand Up @@ -303,16 +313,6 @@ void PairEAMOMP::eval(int iifrom, int iito, ThrData * const thr)
f[i].y += fytmp;
f[i].z += fztmp;
}

if (EFLAG && (!exceeded_rhomax)) {
MPI_Allreduce(&beyond_rhomax, &exceeded_rhomax, 1, MPI_INT, MPI_SUM, world);
if (exceeded_rhomax) {
if (comm->me == 0)
error->warning(FLERR,
"A per-atom density exceeded rhomax of EAM potential table - "
"a linear extrapolation to the energy was made");
}
}
}

/* ---------------------------------------------------------------------- */
Expand Down
2 changes: 1 addition & 1 deletion src/OPENMP/pair_eam_omp.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class PairEAMOMP : public PairEAM, public ThrOMP {

private:
template <int EVFLAG, int EFLAG, int NEWTON_PAIR>
void eval(int iifrom, int iito, ThrData *const thr);
void eval(int iifrom, int iito, int *beyond_rhomax, ThrData *const thr);
};

} // namespace LAMMPS_NS
Expand Down

0 comments on commit 6836bca

Please sign in to comment.