alternate implementation of pair/only option (for KOKKOS and GPU)

This commit is contained in:
Axel Kohlmeyer
2020-12-17 22:39:36 -05:00
parent 79833f9b83
commit 96fa85f61c
6 changed files with 48 additions and 6 deletions

View File

@ -120,6 +120,7 @@ FixGPU::FixGPU(LAMMPS *lmp, int narg, char **arg) :
double binsize = 0.0;
char *opencl_flags = nullptr;
int block_pair = -1;
int pair_only_flag = 0;
int iarg = 4;
while (iarg < narg) {
@ -169,6 +170,12 @@ FixGPU::FixGPU(LAMMPS *lmp, int narg, char **arg) :
if (iarg+2 > narg) error->all(FLERR,"Illegal package gpu command");
block_pair = utils::inumeric(FLERR,arg[iarg+1],false,lmp);
iarg += 2;
} else if (strcmp(arg[iarg],"pair/only") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Illegal package gpu command");
if (strcmp(arg[iarg+1],"off") == 0) pair_only_flag = 0;
else if (strcmp(arg[iarg+1],"on") == 0) pair_only_flag = 1;
else error->all(FLERR,"Illegal package gpu command");
iarg += 2;
} else error->all(FLERR,"Illegal package gpu command");
}
@ -186,6 +193,11 @@ FixGPU::FixGPU(LAMMPS *lmp, int narg, char **arg) :
if (force->newton_pair || force->newton_bond) force->newton = 1;
else force->newton = 0;
if (pair_only_flag) {
lmp->suffixp = lmp->suffix;
lmp->suffix = nullptr;
}
// pass params to GPU library
// change binsize default (0.0) to -1.0 used by GPU lib

View File

@ -301,6 +301,7 @@ KokkosLMP::~KokkosLMP()
void KokkosLMP::accelerator(int narg, char **arg)
{
int pair_only_flag = 0;
int iarg = 0;
while (iarg < narg) {
if (strcmp(arg[iarg],"neigh") == 0) {
@ -390,6 +391,12 @@ void KokkosLMP::accelerator(int narg, char **arg)
else if (strcmp(arg[iarg+1],"on") == 0) gpu_aware_flag = 1;
else error->all(FLERR,"Illegal package kokkos command");
iarg += 2;
} else if (strcmp(arg[iarg],"pair/only") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Illegal package kokkos command");
if (strcmp(arg[iarg+1],"off") == 0) pair_only_flag = 0;
else if (strcmp(arg[iarg+1],"on") == 0) pair_only_flag = 1;
else error->all(FLERR,"Illegal package kokkos command");
iarg += 2;
} else if (strcmp(arg[iarg],"neigh/thread") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Illegal package kokkos command");
if (strcmp(arg[iarg+1],"off") == 0) neigh_thread = 0;
@ -452,6 +459,15 @@ void KokkosLMP::accelerator(int narg, char **arg)
neighbor->binsize_user = binsize;
if (binsize <= 0.0) neighbor->binsizeflag = 0;
else neighbor->binsizeflag = 1;
if (pair_only_flag) {
lmp->suffixp = lmp->suffix;
lmp->suffix = new char[7];
strcpy(lmp->suffix,"kk/host");
exchange_comm_classic = forward_comm_classic = reverse_comm_classic = 1;
exchange_comm_on_host = forward_comm_on_host = reverse_comm_on_host = 0;
}
}
/* ----------------------------------------------------------------------

View File

@ -245,13 +245,22 @@ void Force::create_pair(const std::string &style, int trysuffix)
/* ----------------------------------------------------------------------
generate a pair class
if trysuffix = 1, try first with suffix1/2 appended
return sflag = 0 for no suffix added, 1 or 2 for suffix1/2 added
return sflag = 0 for no suffix added, 1 or 2 or 3 for suffix1/2/p added
special case: if suffixp exists only try suffixp, not suffix
------------------------------------------------------------------------- */
Pair *Force::new_pair(const std::string &style, int trysuffix, int &sflag)
{
if (trysuffix && lmp->suffix_enable) {
if (lmp->suffix) {
if (lmp->suffixp) {
sflag = 3;
std::string estyle = style + "/" + lmp->suffixp;
if (pair_map->find(estyle) != pair_map->end()) {
PairCreator &pair_creator = (*pair_map)[estyle];
return pair_creator(lmp);
}
}
if (lmp->suffix && !lmp->suffixp) {
sflag = 1;
std::string estyle = style + "/" + lmp->suffix;
if (pair_map->find(estyle) != pair_map->end()) {
@ -727,7 +736,7 @@ KSpace *Force::kspace_match(const std::string &word, int exact)
/* ----------------------------------------------------------------------
store style name in str allocated here
if sflag = 0, no suffix
if sflag = 1/2, append suffix or suffix2 to style
if sflag = 1/2/3, append suffix or suffix2 or suffixp to style
------------------------------------------------------------------------- */
void Force::store_style(char *&str, const std::string &style, int sflag)
@ -736,6 +745,7 @@ void Force::store_style(char *&str, const std::string &style, int sflag)
if (sflag == 1) estyle += std::string("/") + lmp->suffix;
else if (sflag == 2) estyle += std::string("/") + lmp->suffix2;
else if (sflag == 3) estyle += std::string("/") + lmp->suffixp;
str = new char[estyle.size()+1];
strcpy(str,estyle.c_str());

View File

@ -1715,7 +1715,10 @@ void Input::pair_style()
int match = 0;
if (style == force->pair_style) match = 1;
if (!match && lmp->suffix_enable) {
if (lmp->suffix)
if (lmp->suffixp)
if (style + "/" + lmp->suffixp == force->pair_style) match = 1;
if (lmp->suffix && !lmp->suffixp)
if (style + "/" + lmp->suffix == force->pair_style) match = 1;
if (lmp->suffix2)

View File

@ -173,7 +173,7 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) :
int citeflag = 1;
int helpflag = 0;
suffix = suffix2 = nullptr;
suffix = suffix2 = suffixp = nullptr;
suffix_enable = 0;
if (arg) exename = arg[0];
else exename = nullptr;
@ -714,6 +714,7 @@ LAMMPS::~LAMMPS()
delete kokkos;
delete [] suffix;
delete [] suffix2;
delete [] suffixp;
// free the MPI comm created by -mpi command-line arg processed in constructor
// it was passed to universe as if original universe world

View File

@ -51,7 +51,7 @@ class LAMMPS {
double initclock; // wall clock at instantiation
char *suffix,*suffix2; // suffixes to add to input script style names
char *suffix,*suffix2,*suffixp;// suffixes to add to input script style names
int suffix_enable; // 1 if suffixes are enabled, 0 if disabled
char *exename; // pointer to argv[0]
char ***packargs; // arguments for cmdline package commands