From 96fa85f61c96b041cd81126db1a61cb4ae4236d8 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 17 Dec 2020 22:39:36 -0500 Subject: [PATCH] alternate implementation of pair/only option (for KOKKOS and GPU) --- src/GPU/fix_gpu.cpp | 12 ++++++++++++ src/KOKKOS/kokkos.cpp | 16 ++++++++++++++++ src/force.cpp | 16 +++++++++++++--- src/input.cpp | 5 ++++- src/lammps.cpp | 3 ++- src/lammps.h | 2 +- 6 files changed, 48 insertions(+), 6 deletions(-) diff --git a/src/GPU/fix_gpu.cpp b/src/GPU/fix_gpu.cpp index 5774d1ea50..1f5ad59e09 100644 --- a/src/GPU/fix_gpu.cpp +++ b/src/GPU/fix_gpu.cpp @@ -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 diff --git a/src/KOKKOS/kokkos.cpp b/src/KOKKOS/kokkos.cpp index 64455fef4f..d702fbc1be 100644 --- a/src/KOKKOS/kokkos.cpp +++ b/src/KOKKOS/kokkos.cpp @@ -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; + } } /* ---------------------------------------------------------------------- diff --git a/src/force.cpp b/src/force.cpp index d271d1207e..1f03206f31 100644 --- a/src/force.cpp +++ b/src/force.cpp @@ -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()); diff --git a/src/input.cpp b/src/input.cpp index abdc3775ce..457cf74b1a 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -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) diff --git a/src/lammps.cpp b/src/lammps.cpp index 102d2f18cf..69baec5557 100644 --- a/src/lammps.cpp +++ b/src/lammps.cpp @@ -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 diff --git a/src/lammps.h b/src/lammps.h index 0d9442ffb9..49d55d4e37 100644 --- a/src/lammps.h +++ b/src/lammps.h @@ -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