refactor handling of pair/only flag for GPU and KOKKOS
This commit is contained in:
@ -136,7 +136,6 @@ FixGPU::FixGPU(LAMMPS *lmp, int narg, char **arg) :
|
||||
double binsize = 0.0;
|
||||
char *opencl_args = nullptr;
|
||||
int block_pair = -1;
|
||||
int pair_only_flag = 0;
|
||||
int ocl_platform = -1;
|
||||
char *device_type_flags = nullptr;
|
||||
|
||||
@ -194,7 +193,7 @@ FixGPU::FixGPU(LAMMPS *lmp, int narg, char **arg) :
|
||||
iarg += 2;
|
||||
} else if (strcmp(arg[iarg],"pair/only") == 0) {
|
||||
if (iarg+2 > narg) error->all(FLERR,"Illegal package gpu command");
|
||||
pair_only_flag = utils::logical(FLERR,arg[iarg+1],false,lmp);
|
||||
lmp->pair_only_flag = utils::logical(FLERR,arg[iarg+1],false,lmp);
|
||||
iarg += 2;
|
||||
} else if (strcmp(arg[iarg],"ocl_args") == 0) {
|
||||
if (iarg+2 > narg) error->all(FLERR,"Illegal package gpu command");
|
||||
@ -224,16 +223,6 @@ FixGPU::FixGPU(LAMMPS *lmp, int narg, char **arg) :
|
||||
if (force->newton_pair == 1 && _particle_split < 1)
|
||||
error->all(FLERR,"Cannot use newton pair on for split less than 1 for now");
|
||||
|
||||
if (pair_only_flag) {
|
||||
lmp->suffixp = lmp->suffix;
|
||||
lmp->suffix = nullptr;
|
||||
} else {
|
||||
if (lmp->suffixp) {
|
||||
lmp->suffix = lmp->suffixp;
|
||||
lmp->suffixp = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
// pass params to GPU library
|
||||
// change binsize default (0.0) to -1.0 used by GPU lib
|
||||
|
||||
|
||||
@ -374,7 +374,6 @@ void KokkosLMP::finalize()
|
||||
|
||||
void KokkosLMP::accelerator(int narg, char **arg)
|
||||
{
|
||||
int pair_only_flag = 0;
|
||||
int iarg = 0;
|
||||
while (iarg < narg) {
|
||||
if (strcmp(arg[iarg],"neigh") == 0) {
|
||||
@ -493,7 +492,7 @@ void KokkosLMP::accelerator(int narg, char **arg)
|
||||
iarg += 2;
|
||||
} else if (strcmp(arg[iarg],"pair/only") == 0) {
|
||||
if (iarg+2 > narg) error->all(FLERR,"Illegal package kokkos command");
|
||||
pair_only_flag = utils::logical(FLERR,arg[iarg+1],false,lmp);
|
||||
lmp->pair_only_flag = utils::logical(FLERR,arg[iarg+1],false,lmp);
|
||||
iarg += 2;
|
||||
} else if (strcmp(arg[iarg],"neigh/thread") == 0) {
|
||||
if (iarg+2 > narg) error->all(FLERR,"Illegal package kokkos command");
|
||||
@ -509,24 +508,12 @@ void KokkosLMP::accelerator(int narg, char **arg)
|
||||
|
||||
#ifdef LMP_KOKKOS_GPU
|
||||
|
||||
if (pair_only_flag) {
|
||||
lmp->suffixp = lmp->suffix;
|
||||
lmp->suffix = utils::strdup("kk/host");
|
||||
} else {
|
||||
// restore settings to regular suffix use, if previously, pair/only was used
|
||||
if (lmp->suffixp) {
|
||||
delete[] lmp->suffix;
|
||||
lmp->suffix = lmp->suffixp;
|
||||
lmp->suffixp = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
int nmpi = 0;
|
||||
MPI_Comm_size(world,&nmpi);
|
||||
|
||||
// if "gpu/aware off" or "pair/only on", and "comm device", change to "comm no"
|
||||
|
||||
if ((!gpu_aware_flag && nmpi > 1) || pair_only_flag) {
|
||||
if ((!gpu_aware_flag && nmpi > 1) || lmp->pair_only_flag) {
|
||||
if (exchange_comm_classic == 0 && exchange_comm_on_host == 0) {
|
||||
exchange_comm_classic = 1;
|
||||
exchange_comm_changed = 1;
|
||||
@ -555,7 +542,7 @@ void KokkosLMP::accelerator(int narg, char **arg)
|
||||
|
||||
// if "gpu/aware on" and "pair/only off", and comm flags were changed previously, change them back
|
||||
|
||||
if (gpu_aware_flag && !pair_only_flag) {
|
||||
if (gpu_aware_flag && !lmp->pair_only_flag) {
|
||||
if (exchange_comm_changed) {
|
||||
exchange_comm_classic = 0;
|
||||
exchange_comm_changed = 0;
|
||||
|
||||
@ -237,22 +237,13 @@ 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 or 3 for suffix1/2/p added
|
||||
special case: if suffixp exists only try suffixp, not suffix
|
||||
return sflag = 0 for no suffix added, 1 or 2 for suffix1/2 added
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
Pair *Force::new_pair(const std::string &style, int trysuffix, int &sflag)
|
||||
{
|
||||
if (trysuffix && lmp->suffix_enable) {
|
||||
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) {
|
||||
if (lmp->suffix) {
|
||||
sflag = 1;
|
||||
std::string estyle = style + "/" + lmp->suffix;
|
||||
if (pair_map->find(estyle) != pair_map->end()) {
|
||||
@ -347,6 +338,24 @@ void Force::create_bond(const std::string &style, int trysuffix)
|
||||
bond_style = store_style(style, sflag);
|
||||
}
|
||||
|
||||
// helper function to reduce redundant code.
|
||||
|
||||
static const char *pair_only_suffix(const char *suffix, int flag)
|
||||
{
|
||||
const char *mysuffix;
|
||||
if (flag) {
|
||||
#ifdef LMP_KOKKOS_GPU
|
||||
if strmatch(suffix,"^kk") mysuffix = "kk/host";
|
||||
else mysuffix = nullptr;
|
||||
#else
|
||||
mysuffix = nullptr;
|
||||
#endif
|
||||
} else {
|
||||
mysuffix = suffix;
|
||||
}
|
||||
return mysuffix;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
generate a bond class, fist with suffix appended
|
||||
------------------------------------------------------------------------- */
|
||||
@ -354,9 +363,10 @@ void Force::create_bond(const std::string &style, int trysuffix)
|
||||
Bond *Force::new_bond(const std::string &style, int trysuffix, int &sflag)
|
||||
{
|
||||
if (trysuffix && lmp->suffix_enable) {
|
||||
if (lmp->suffix) {
|
||||
auto mysuffix = pair_only_suffix(lmp->suffix, lmp->pair_only_flag);
|
||||
if (mysuffix) {
|
||||
sflag = 1;
|
||||
std::string estyle = style + "/" + lmp->suffix;
|
||||
std::string estyle = style + "/" + mysuffix;
|
||||
if (bond_map->find(estyle) != bond_map->end()) {
|
||||
BondCreator &bond_creator = (*bond_map)[estyle];
|
||||
return bond_creator(lmp);
|
||||
@ -422,9 +432,10 @@ void Force::create_angle(const std::string &style, int trysuffix)
|
||||
Angle *Force::new_angle(const std::string &style, int trysuffix, int &sflag)
|
||||
{
|
||||
if (trysuffix && lmp->suffix_enable) {
|
||||
if (lmp->suffix) {
|
||||
auto mysuffix = pair_only_suffix(lmp->suffix, lmp->pair_only_flag);
|
||||
if (mysuffix) {
|
||||
sflag = 1;
|
||||
std::string estyle = style + "/" + lmp->suffix;
|
||||
std::string estyle = style + "/" + mysuffix;
|
||||
if (angle_map->find(estyle) != angle_map->end()) {
|
||||
AngleCreator &angle_creator = (*angle_map)[estyle];
|
||||
return angle_creator(lmp);
|
||||
@ -490,9 +501,10 @@ void Force::create_dihedral(const std::string &style, int trysuffix)
|
||||
Dihedral *Force::new_dihedral(const std::string &style, int trysuffix, int &sflag)
|
||||
{
|
||||
if (trysuffix && lmp->suffix_enable) {
|
||||
if (lmp->suffix) {
|
||||
auto mysuffix = pair_only_suffix(lmp->suffix, lmp->pair_only_flag);
|
||||
if (mysuffix) {
|
||||
sflag = 1;
|
||||
std::string estyle = style + "/" + lmp->suffix;
|
||||
std::string estyle = style + "/" + mysuffix;
|
||||
if (dihedral_map->find(estyle) != dihedral_map->end()) {
|
||||
DihedralCreator &dihedral_creator = (*dihedral_map)[estyle];
|
||||
return dihedral_creator(lmp);
|
||||
@ -558,9 +570,10 @@ void Force::create_improper(const std::string &style, int trysuffix)
|
||||
Improper *Force::new_improper(const std::string &style, int trysuffix, int &sflag)
|
||||
{
|
||||
if (trysuffix && lmp->suffix_enable) {
|
||||
if (lmp->suffix) {
|
||||
auto mysuffix = pair_only_suffix(lmp->suffix, lmp->pair_only_flag);
|
||||
if (mysuffix) {
|
||||
sflag = 1;
|
||||
std::string estyle = style + "/" + lmp->suffix;
|
||||
std::string estyle = style + "/" + mysuffix;
|
||||
if (improper_map->find(estyle) != improper_map->end()) {
|
||||
ImproperCreator &improper_creator = (*improper_map)[estyle];
|
||||
return improper_creator(lmp);
|
||||
@ -626,9 +639,10 @@ void Force::create_kspace(const std::string &style, int trysuffix)
|
||||
KSpace *Force::new_kspace(const std::string &style, int trysuffix, int &sflag)
|
||||
{
|
||||
if (trysuffix && lmp->suffix_enable) {
|
||||
if (lmp->suffix) {
|
||||
auto mysuffix = pair_only_suffix(lmp->suffix, lmp->pair_only_flag);
|
||||
if (mysuffix) {
|
||||
sflag = 1;
|
||||
std::string estyle = style + "/" + lmp->suffix;
|
||||
std::string estyle = style + "/" + mysuffix;
|
||||
if (kspace_map->find(estyle) != kspace_map->end()) {
|
||||
KSpaceCreator &kspace_creator = (*kspace_map)[estyle];
|
||||
return kspace_creator(lmp);
|
||||
@ -676,19 +690,18 @@ 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/3, append suffix or suffix2 or suffixp to style
|
||||
if sflag = 1/2, append suffix or suffix2 to style
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
char *Force::store_style(const std::string &style, int sflag)
|
||||
{
|
||||
std::string estyle = style;
|
||||
auto mystyle = pair_only_suffix(lmp->suffix, lmp->pair_only_flag);
|
||||
|
||||
if (sflag == 1)
|
||||
estyle += std::string("/") + lmp->suffix;
|
||||
if ((sflag == 1) && mystyle)
|
||||
estyle += std::string("/") + mystyle;
|
||||
else if (sflag == 2)
|
||||
estyle += std::string("/") + lmp->suffix2;
|
||||
else if (sflag == 3)
|
||||
estyle += std::string("/") + lmp->suffixp;
|
||||
return utils::strdup(estyle);
|
||||
}
|
||||
|
||||
|
||||
@ -1775,10 +1775,7 @@ void Input::pair_style()
|
||||
int match = 0;
|
||||
if (style == force->pair_style) match = 1;
|
||||
if (!match && lmp->suffix_enable) {
|
||||
if (lmp->suffixp)
|
||||
if (style + "/" + lmp->suffixp == force->pair_style) match = 1;
|
||||
|
||||
if (lmp->suffix && !lmp->suffixp)
|
||||
if (lmp->suffix)
|
||||
if (style + "/" + lmp->suffix == force->pair_style) match = 1;
|
||||
|
||||
if (lmp->suffix2)
|
||||
|
||||
@ -200,8 +200,9 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) :
|
||||
int helpflag = 0;
|
||||
int nonbufflag = 0;
|
||||
|
||||
suffix = suffix2 = suffixp = nullptr;
|
||||
suffix = suffix2 = nullptr;
|
||||
suffix_enable = 0;
|
||||
pair_only_flag = 0;
|
||||
if (arg) exename = arg[0];
|
||||
else exename = nullptr;
|
||||
packargs = nullptr;
|
||||
@ -777,7 +778,6 @@ LAMMPS::~LAMMPS()
|
||||
delete kokkos;
|
||||
delete[] suffix;
|
||||
delete[] suffix2;
|
||||
delete[] suffixp;
|
||||
|
||||
// free the MPI comm created by -mpicolor cmdline arg processed in constructor
|
||||
// it was passed to universe as if original universe world
|
||||
@ -871,7 +871,6 @@ void LAMMPS::post_create()
|
||||
// invoke any command-line package commands
|
||||
|
||||
if (num_package) {
|
||||
if (suffixp) suffix=suffixp;
|
||||
std::string str;
|
||||
for (int i = 0; i < num_package; i++) {
|
||||
str = "package";
|
||||
@ -887,16 +886,13 @@ void LAMMPS::post_create()
|
||||
}
|
||||
input->one(str);
|
||||
}
|
||||
if (suffixp) suffix=nullptr;
|
||||
}
|
||||
|
||||
// either suffix or suffixp will be set if suffix_enable = 1
|
||||
// check that KOKKOS package classes were instantiated
|
||||
// check that GPU, INTEL, OPENMP fixes were compiled with LAMMPS
|
||||
// do not re-issue package command if already issued
|
||||
|
||||
if (suffix_enable) {
|
||||
if (suffixp) suffix = suffixp;
|
||||
|
||||
if (strcmp(suffix,"gpu") == 0 && !modify->check_package("GPU"))
|
||||
error->all(FLERR,"Using suffix gpu without GPU package installed");
|
||||
@ -923,7 +919,6 @@ void LAMMPS::post_create()
|
||||
if (strcmp(suffix2,"omp") == 0 && !(package_issued & Suffix::OMP))
|
||||
input->one("package omp 0");
|
||||
}
|
||||
if (suffixp) suffix = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -58,8 +58,9 @@ class LAMMPS {
|
||||
double initclock; // wall clock at instantiation
|
||||
int skiprunflag; // 1 inserts timer command to skip run and minimize loops
|
||||
|
||||
char *suffix, *suffix2, *suffixp; // suffixes to add to input script style names
|
||||
char *suffix, *suffix2; // suffixes to add to input script style names
|
||||
int suffix_enable; // 1 if suffixes are enabled, 0 if disabled
|
||||
int pair_only_flag; // 1 if only force field pair styles are accelerated, 0 if all
|
||||
char *exename; // pointer to argv[0]
|
||||
|
||||
char ***packargs; // arguments for cmdline package commands
|
||||
|
||||
Reference in New Issue
Block a user