From 7ba8d96ddb2d464b7610051a23084af921f6f9ad Mon Sep 17 00:00:00 2001 From: sjplimp Date: Fri, 27 Mar 2015 13:37:06 +0000 Subject: [PATCH 01/22] git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@13302 f3b2605a-c512-4ea7-a41b-209d697bcdaa --- doc/fix_balance.html | 2 +- doc/fix_balance.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/fix_balance.html b/doc/fix_balance.html index 22543741c9..3d84dede62 100644 --- a/doc/fix_balance.html +++ b/doc/fix_balance.html @@ -203,7 +203,7 @@ tallied. If the counts do not match the target value for the plane, the position of the cut is adjusted based on the local density. The low and high bounds are adjusted on each iteration, using new count information, so that they become closer together over time. Thus as -the recustion progresses, the count of particles on either side of the +the recursion progresses, the count of particles on either side of the plane gets closer to the target value.

The density-dependent part of this algorithm is often an advantage diff --git a/doc/fix_balance.txt b/doc/fix_balance.txt index 6c214a2041..7b6f523048 100644 --- a/doc/fix_balance.txt +++ b/doc/fix_balance.txt @@ -191,7 +191,7 @@ tallied. If the counts do not match the target value for the plane, the position of the cut is adjusted based on the local density. The low and high bounds are adjusted on each iteration, using new count information, so that they become closer together over time. Thus as -the recustion progresses, the count of particles on either side of the +the recursion progresses, the count of particles on either side of the plane gets closer to the target value. The density-dependent part of this algorithm is often an advantage From d72fcf5acca3b8dd94017e4986e4fe42abc91d4c Mon Sep 17 00:00:00 2001 From: sjplimp Date: Fri, 27 Mar 2015 13:41:29 +0000 Subject: [PATCH 02/22] git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@13303 f3b2605a-c512-4ea7-a41b-209d697bcdaa --- src/CLASS2/pair_lj_class2.cpp | 24 +++++++------- src/CLASS2/pair_lj_class2.h | 6 ++-- src/CLASS2/pair_lj_class2_coul_cut.cpp | 30 +++++++++-------- src/CLASS2/pair_lj_class2_coul_cut.h | 8 ++--- src/CLASS2/pair_lj_class2_coul_long.cpp | 26 ++++++++------- src/CLASS2/pair_lj_class2_coul_long.h | 8 ++--- src/KOKKOS/pair_kokkos.h | 4 +-- src/KSPACE/pair_buck_coul_long.cpp | 28 ++++++++-------- src/KSPACE/pair_buck_coul_long.h | 2 +- src/KSPACE/pair_coul_long.cpp | 12 ++++--- src/KSPACE/pair_coul_long.h | 4 +-- src/KSPACE/pair_lj_charmm_coul_long.cpp | 36 ++++++++++++--------- src/KSPACE/pair_lj_charmm_coul_long.h | 8 ++--- src/MOLECULE/pair_lj_charmm_coul_charmm.cpp | 4 ++- src/MOLECULE/pair_lj_charmm_coul_charmm.h | 8 ++--- src/pair_buck_coul_cut.cpp | 2 +- src/pair_buck_coul_cut.h | 2 +- src/pair_lj_cut_coul_dsf.cpp | 26 ++++++++------- src/pair_lj_cut_coul_dsf.h | 6 ++-- src/pair_lj_expand.cpp | 4 ++- src/pair_lj_expand.h | 6 ++-- src/pair_lj_gromacs.cpp | 4 ++- src/pair_lj_gromacs.h | 4 +-- src/pair_lj_gromacs_coul_gromacs.cpp | 4 ++- src/pair_lj_gromacs_coul_gromacs.h | 6 ++-- 25 files changed, 148 insertions(+), 124 deletions(-) diff --git a/src/CLASS2/pair_lj_class2.cpp b/src/CLASS2/pair_lj_class2.cpp index 90f5881ffd..9ae9613a74 100644 --- a/src/CLASS2/pair_lj_class2.cpp +++ b/src/CLASS2/pair_lj_class2.cpp @@ -37,18 +37,20 @@ PairLJClass2::PairLJClass2(LAMMPS *lmp) : Pair(lmp) PairLJClass2::~PairLJClass2() { - if (allocated) { - memory->destroy(setflag); - memory->destroy(cutsq); + if (!copymode) { + if (allocated) { + memory->destroy(setflag); + memory->destroy(cutsq); - memory->destroy(cut); - memory->destroy(epsilon); - memory->destroy(sigma); - memory->destroy(lj1); - memory->destroy(lj2); - memory->destroy(lj3); - memory->destroy(lj4); - memory->destroy(offset); + memory->destroy(cut); + memory->destroy(epsilon); + memory->destroy(sigma); + memory->destroy(lj1); + memory->destroy(lj2); + memory->destroy(lj3); + memory->destroy(lj4); + memory->destroy(offset); + } } } diff --git a/src/CLASS2/pair_lj_class2.h b/src/CLASS2/pair_lj_class2.h index b6b604cbca..4a89ce2a3f 100644 --- a/src/CLASS2/pair_lj_class2.h +++ b/src/CLASS2/pair_lj_class2.h @@ -29,9 +29,9 @@ class PairLJClass2 : public Pair { PairLJClass2(class LAMMPS *); virtual ~PairLJClass2(); virtual void compute(int, int); - void settings(int, char **); + virtual void settings(int, char **); void coeff(int, char **); - double init_one(int, int); + virtual double init_one(int, int); void write_restart(FILE *); void read_restart(FILE *); void write_restart_settings(FILE *); @@ -46,7 +46,7 @@ class PairLJClass2 : public Pair { double **epsilon,**sigma; double **lj1,**lj2,**lj3,**lj4,**offset; - void allocate(); + virtual void allocate(); }; } diff --git a/src/CLASS2/pair_lj_class2_coul_cut.cpp b/src/CLASS2/pair_lj_class2_coul_cut.cpp index 7f851fd239..23f4d36141 100644 --- a/src/CLASS2/pair_lj_class2_coul_cut.cpp +++ b/src/CLASS2/pair_lj_class2_coul_cut.cpp @@ -38,21 +38,23 @@ PairLJClass2CoulCut::PairLJClass2CoulCut(LAMMPS *lmp) : Pair(lmp) PairLJClass2CoulCut::~PairLJClass2CoulCut() { - if (allocated) { - memory->destroy(setflag); - memory->destroy(cutsq); + if (!copymode) { + if (allocated) { + memory->destroy(setflag); + memory->destroy(cutsq); - memory->destroy(cut_lj); - memory->destroy(cut_ljsq); - memory->destroy(cut_coul); - memory->destroy(cut_coulsq); - memory->destroy(epsilon); - memory->destroy(sigma); - memory->destroy(lj1); - memory->destroy(lj2); - memory->destroy(lj3); - memory->destroy(lj4); - memory->destroy(offset); + memory->destroy(cut_lj); + memory->destroy(cut_ljsq); + memory->destroy(cut_coul); + memory->destroy(cut_coulsq); + memory->destroy(epsilon); + memory->destroy(sigma); + memory->destroy(lj1); + memory->destroy(lj2); + memory->destroy(lj3); + memory->destroy(lj4); + memory->destroy(offset); + } } } diff --git a/src/CLASS2/pair_lj_class2_coul_cut.h b/src/CLASS2/pair_lj_class2_coul_cut.h index cea218f759..9b9c654ec6 100644 --- a/src/CLASS2/pair_lj_class2_coul_cut.h +++ b/src/CLASS2/pair_lj_class2_coul_cut.h @@ -29,10 +29,10 @@ class PairLJClass2CoulCut : public Pair { PairLJClass2CoulCut(class LAMMPS *); virtual ~PairLJClass2CoulCut(); virtual void compute(int, int); - void settings(int, char **); + virtual void settings(int, char **); void coeff(int, char **); - void init_style(); - double init_one(int, int); + virtual void init_style(); + virtual double init_one(int, int); void write_restart(FILE *); void read_restart(FILE *); void write_restart_settings(FILE *); @@ -48,7 +48,7 @@ class PairLJClass2CoulCut : public Pair { double **epsilon,**sigma; double **lj1,**lj2,**lj3,**lj4,**offset; - void allocate(); + virtual void allocate(); }; } diff --git a/src/CLASS2/pair_lj_class2_coul_long.cpp b/src/CLASS2/pair_lj_class2_coul_long.cpp index 2460515b98..7801e1687f 100644 --- a/src/CLASS2/pair_lj_class2_coul_long.cpp +++ b/src/CLASS2/pair_lj_class2_coul_long.cpp @@ -50,19 +50,21 @@ PairLJClass2CoulLong::PairLJClass2CoulLong(LAMMPS *lmp) : Pair(lmp) PairLJClass2CoulLong::~PairLJClass2CoulLong() { - if (allocated) { - memory->destroy(setflag); - memory->destroy(cutsq); + if (!copymode) { + if (allocated) { + memory->destroy(setflag); + memory->destroy(cutsq); - memory->destroy(cut_lj); - memory->destroy(cut_ljsq); - memory->destroy(epsilon); - memory->destroy(sigma); - memory->destroy(lj1); - memory->destroy(lj2); - memory->destroy(lj3); - memory->destroy(lj4); - memory->destroy(offset); + memory->destroy(cut_lj); + memory->destroy(cut_ljsq); + memory->destroy(epsilon); + memory->destroy(sigma); + memory->destroy(lj1); + memory->destroy(lj2); + memory->destroy(lj3); + memory->destroy(lj4); + memory->destroy(offset); + } } } diff --git a/src/CLASS2/pair_lj_class2_coul_long.h b/src/CLASS2/pair_lj_class2_coul_long.h index 829c4f23e0..202aaaaa43 100644 --- a/src/CLASS2/pair_lj_class2_coul_long.h +++ b/src/CLASS2/pair_lj_class2_coul_long.h @@ -29,10 +29,10 @@ class PairLJClass2CoulLong : public Pair { PairLJClass2CoulLong(class LAMMPS *); virtual ~PairLJClass2CoulLong(); virtual void compute(int, int); - void settings(int, char **); + virtual void settings(int, char **); void coeff(int, char **); - void init_style(); - double init_one(int, int); + virtual void init_style(); + virtual double init_one(int, int); void write_restart(FILE *); void read_restart(FILE *); void write_restart_settings(FILE *); @@ -50,7 +50,7 @@ class PairLJClass2CoulLong : public Pair { double **lj1,**lj2,**lj3,**lj4,**offset; double g_ewald; - void allocate(); + virtual void allocate(); }; } diff --git a/src/KOKKOS/pair_kokkos.h b/src/KOKKOS/pair_kokkos.h index 288f338c17..f3bef77b86 100644 --- a/src/KOKKOS/pair_kokkos.h +++ b/src/KOKKOS/pair_kokkos.h @@ -621,7 +621,7 @@ EV_FLOAT pair_compute_neighlist (PairStyle* fpair, typename Kokkos::Impl::enable EV_FLOAT ev; (void) fpair; (void) list; - printf("ERROR: calling pair_compute with invalid neighbor list style: requested %i available %i",NEIGHFLAG,PairStyle::EnabledNeighFlags); + printf("ERROR: calling pair_compute with invalid neighbor list style: requested %i available %i \n",NEIGHFLAG,PairStyle::EnabledNeighFlags); return ev; } @@ -630,7 +630,7 @@ EV_FLOAT pair_compute_fullcluster (PairStyle* fpair, typename Kokkos::Impl::enab EV_FLOAT ev; (void) fpair; (void) list; - printf("ERROR: calling pair_compute with invalid neighbor list style: requested %i available %i",FULLCLUSTER,PairStyle::EnabledNeighFlags); + printf("ERROR: calling pair_compute with invalid neighbor list style: requested %i available %i \n",FULLCLUSTER,PairStyle::EnabledNeighFlags); return ev; } diff --git a/src/KSPACE/pair_buck_coul_long.cpp b/src/KSPACE/pair_buck_coul_long.cpp index 7db7211908..08d3ebf3d7 100644 --- a/src/KSPACE/pair_buck_coul_long.cpp +++ b/src/KSPACE/pair_buck_coul_long.cpp @@ -50,21 +50,23 @@ PairBuckCoulLong::PairBuckCoulLong(LAMMPS *lmp) : Pair(lmp) PairBuckCoulLong::~PairBuckCoulLong() { - if (allocated) { - memory->destroy(setflag); - memory->destroy(cutsq); + if (!copymode) { + if (allocated) { + memory->destroy(setflag); + memory->destroy(cutsq); - memory->destroy(cut_lj); - memory->destroy(cut_ljsq); - memory->destroy(a); - memory->destroy(rho); - memory->destroy(c); - memory->destroy(rhoinv); - memory->destroy(buck1); - memory->destroy(buck2); - memory->destroy(offset); + memory->destroy(cut_lj); + memory->destroy(cut_ljsq); + memory->destroy(a); + memory->destroy(rho); + memory->destroy(c); + memory->destroy(rhoinv); + memory->destroy(buck1); + memory->destroy(buck2); + memory->destroy(offset); + } + if (ftable) free_tables(); } - if (ftable) free_tables(); } /* ---------------------------------------------------------------------- */ diff --git a/src/KSPACE/pair_buck_coul_long.h b/src/KSPACE/pair_buck_coul_long.h index 48bd707941..c19c2d8a5a 100644 --- a/src/KSPACE/pair_buck_coul_long.h +++ b/src/KSPACE/pair_buck_coul_long.h @@ -52,7 +52,7 @@ class PairBuckCoulLong : public Pair { double *cut_respa; double g_ewald; - void allocate(); + virtual void allocate(); }; } diff --git a/src/KSPACE/pair_coul_long.cpp b/src/KSPACE/pair_coul_long.cpp index 84c4854deb..8d9347be7b 100644 --- a/src/KSPACE/pair_coul_long.cpp +++ b/src/KSPACE/pair_coul_long.cpp @@ -55,13 +55,15 @@ PairCoulLong::PairCoulLong(LAMMPS *lmp) : Pair(lmp) PairCoulLong::~PairCoulLong() { - if (allocated) { - memory->destroy(setflag); - memory->destroy(cutsq); + if (!copymode) { + if (allocated) { + memory->destroy(setflag); + memory->destroy(cutsq); - memory->destroy(scale); + memory->destroy(scale); + } + if (ftable) free_tables(); } - if (ftable) free_tables(); } /* ---------------------------------------------------------------------- */ diff --git a/src/KSPACE/pair_coul_long.h b/src/KSPACE/pair_coul_long.h index 0629dfedaa..a231127381 100644 --- a/src/KSPACE/pair_coul_long.h +++ b/src/KSPACE/pair_coul_long.h @@ -32,7 +32,7 @@ class PairCoulLong : public Pair { virtual void settings(int, char **); void coeff(int, char **); virtual void init_style(); - double init_one(int, int); + virtual double init_one(int, int); void write_restart(FILE *); void read_restart(FILE *); virtual void write_restart_settings(FILE *); @@ -46,7 +46,7 @@ class PairCoulLong : public Pair { double g_ewald; double **scale; - void allocate(); + virtual void allocate(); }; } diff --git a/src/KSPACE/pair_lj_charmm_coul_long.cpp b/src/KSPACE/pair_lj_charmm_coul_long.cpp index a92d175cc2..1fbacdee77 100644 --- a/src/KSPACE/pair_lj_charmm_coul_long.cpp +++ b/src/KSPACE/pair_lj_charmm_coul_long.cpp @@ -59,24 +59,27 @@ PairLJCharmmCoulLong::PairLJCharmmCoulLong(LAMMPS *lmp) : Pair(lmp) PairLJCharmmCoulLong::~PairLJCharmmCoulLong() { - if (allocated) { - memory->destroy(setflag); - memory->destroy(cutsq); + if (!copymode) { + if (allocated) { + memory->destroy(setflag); + memory->destroy(cutsq); - memory->destroy(epsilon); - memory->destroy(sigma); - memory->destroy(eps14); - memory->destroy(sigma14); - memory->destroy(lj1); - memory->destroy(lj2); - memory->destroy(lj3); - memory->destroy(lj4); - memory->destroy(lj14_1); - memory->destroy(lj14_2); - memory->destroy(lj14_3); - memory->destroy(lj14_4); + memory->destroy(epsilon); + memory->destroy(sigma); + memory->destroy(eps14); + memory->destroy(sigma14); + memory->destroy(lj1); + memory->destroy(lj2); + memory->destroy(lj3); + memory->destroy(lj4); + memory->destroy(lj14_1); + memory->destroy(lj14_2); + memory->destroy(lj14_3); + memory->destroy(lj14_4); + memory->destroy(offset); + } + if (ftable) free_tables(); } - if (ftable) free_tables(); } /* ---------------------------------------------------------------------- */ @@ -643,6 +646,7 @@ void PairLJCharmmCoulLong::allocate() memory->create(lj14_2,n+1,n+1,"pair:lj14_2"); memory->create(lj14_3,n+1,n+1,"pair:lj14_3"); memory->create(lj14_4,n+1,n+1,"pair:lj14_4"); + memory->create(offset,n+1,n+1,"pair:offset"); } /* ---------------------------------------------------------------------- diff --git a/src/KSPACE/pair_lj_charmm_coul_long.h b/src/KSPACE/pair_lj_charmm_coul_long.h index 09cf57fffd..8e2c049088 100644 --- a/src/KSPACE/pair_lj_charmm_coul_long.h +++ b/src/KSPACE/pair_lj_charmm_coul_long.h @@ -30,11 +30,11 @@ class PairLJCharmmCoulLong : public Pair { virtual ~PairLJCharmmCoulLong(); virtual void compute(int, int); - void settings(int, char **); + virtual void settings(int, char **); void coeff(int, char **); - void init_style(); + virtual void init_style(); void init_list(int, class NeighList *); - double init_one(int, int); + virtual double init_one(int, int); void write_restart(FILE *); void read_restart(FILE *); void write_restart_settings(FILE *); @@ -61,7 +61,7 @@ class PairLJCharmmCoulLong : public Pair { double *cut_respa; double g_ewald; - void allocate(); + virtual void allocate(); }; } diff --git a/src/MOLECULE/pair_lj_charmm_coul_charmm.cpp b/src/MOLECULE/pair_lj_charmm_coul_charmm.cpp index 430b805f0f..89f4350335 100644 --- a/src/MOLECULE/pair_lj_charmm_coul_charmm.cpp +++ b/src/MOLECULE/pair_lj_charmm_coul_charmm.cpp @@ -43,7 +43,8 @@ PairLJCharmmCoulCharmm::PairLJCharmmCoulCharmm(LAMMPS *lmp) : Pair(lmp) PairLJCharmmCoulCharmm::~PairLJCharmmCoulCharmm() { - if (allocated) { + if (!copymode) { + if (allocated) { memory->destroy(setflag); memory->destroy(cutsq); @@ -59,6 +60,7 @@ PairLJCharmmCoulCharmm::~PairLJCharmmCoulCharmm() memory->destroy(lj14_2); memory->destroy(lj14_3); memory->destroy(lj14_4); + } } } diff --git a/src/MOLECULE/pair_lj_charmm_coul_charmm.h b/src/MOLECULE/pair_lj_charmm_coul_charmm.h index 3f59953b93..1c4ef00fc5 100644 --- a/src/MOLECULE/pair_lj_charmm_coul_charmm.h +++ b/src/MOLECULE/pair_lj_charmm_coul_charmm.h @@ -29,10 +29,10 @@ class PairLJCharmmCoulCharmm : public Pair { PairLJCharmmCoulCharmm(class LAMMPS *); virtual ~PairLJCharmmCoulCharmm(); virtual void compute(int, int); - void settings(int, char **); + virtual void settings(int, char **); void coeff(int, char **); - void init_style(); - double init_one(int, int); + virtual void init_style(); + virtual double init_one(int, int); void write_restart(FILE *); void read_restart(FILE *); void write_restart_settings(FILE *); @@ -51,7 +51,7 @@ class PairLJCharmmCoulCharmm : public Pair { double **lj1,**lj2,**lj3,**lj4; double **lj14_1,**lj14_2,**lj14_3,**lj14_4; - void allocate(); + virtual void allocate(); }; } diff --git a/src/pair_buck_coul_cut.cpp b/src/pair_buck_coul_cut.cpp index 0faf6a6f42..1021bd1e4d 100644 --- a/src/pair_buck_coul_cut.cpp +++ b/src/pair_buck_coul_cut.cpp @@ -42,7 +42,7 @@ PairBuckCoulCut::PairBuckCoulCut(LAMMPS *lmp) : Pair(lmp) PairBuckCoulCut::~PairBuckCoulCut() { - if (allocated) { + if (!copymode) { memory->destroy(setflag); memory->destroy(cutsq); diff --git a/src/pair_buck_coul_cut.h b/src/pair_buck_coul_cut.h index cefcc0a701..b400ca3152 100644 --- a/src/pair_buck_coul_cut.h +++ b/src/pair_buck_coul_cut.h @@ -48,7 +48,7 @@ class PairBuckCoulCut : public Pair { double **a,**rho,**c; double **rhoinv,**buck1,**buck2,**offset; - void allocate(); + virtual void allocate(); }; } diff --git a/src/pair_lj_cut_coul_dsf.cpp b/src/pair_lj_cut_coul_dsf.cpp index 4d3cbd9a45..0cebb4a845 100644 --- a/src/pair_lj_cut_coul_dsf.cpp +++ b/src/pair_lj_cut_coul_dsf.cpp @@ -52,19 +52,21 @@ PairLJCutCoulDSF::PairLJCutCoulDSF(LAMMPS *lmp) : Pair(lmp) PairLJCutCoulDSF::~PairLJCutCoulDSF() { - if (allocated) { - memory->destroy(setflag); - memory->destroy(cutsq); + if (!copymode) { + if (allocated) { + memory->destroy(setflag); + memory->destroy(cutsq); - memory->destroy(cut_lj); - memory->destroy(cut_ljsq); - memory->destroy(epsilon); - memory->destroy(sigma); - memory->destroy(lj1); - memory->destroy(lj2); - memory->destroy(lj3); - memory->destroy(lj4); - memory->destroy(offset); + memory->destroy(cut_lj); + memory->destroy(cut_ljsq); + memory->destroy(epsilon); + memory->destroy(sigma); + memory->destroy(lj1); + memory->destroy(lj2); + memory->destroy(lj3); + memory->destroy(lj4); + memory->destroy(offset); + } } } diff --git a/src/pair_lj_cut_coul_dsf.h b/src/pair_lj_cut_coul_dsf.h index 7cbc2ad4ff..5a0a6b553d 100644 --- a/src/pair_lj_cut_coul_dsf.h +++ b/src/pair_lj_cut_coul_dsf.h @@ -31,8 +31,8 @@ class PairLJCutCoulDSF : public Pair { void compute(int, int); void settings(int, char **); void coeff(int, char **); - void init_style(); - double init_one(int, int); + virtual void init_style(); + virtual double init_one(int, int); void write_restart(FILE *); void read_restart(FILE *); void write_restart_settings(FILE *); @@ -50,7 +50,7 @@ class PairLJCutCoulDSF : public Pair { double alpha; double f_shift,e_shift; - void allocate(); + virtual void allocate(); }; } diff --git a/src/pair_lj_expand.cpp b/src/pair_lj_expand.cpp index 02e148fe4e..0085a4acd5 100644 --- a/src/pair_lj_expand.cpp +++ b/src/pair_lj_expand.cpp @@ -38,7 +38,8 @@ PairLJExpand::PairLJExpand(LAMMPS *lmp) : Pair(lmp) PairLJExpand::~PairLJExpand() { - if (allocated) { + if (!copymode) { + if (allocated) { memory->destroy(setflag); memory->destroy(cutsq); @@ -51,6 +52,7 @@ PairLJExpand::~PairLJExpand() memory->destroy(lj3); memory->destroy(lj4); memory->destroy(offset); + } } } diff --git a/src/pair_lj_expand.h b/src/pair_lj_expand.h index 05ef3d26e9..3a32716003 100644 --- a/src/pair_lj_expand.h +++ b/src/pair_lj_expand.h @@ -30,9 +30,9 @@ class PairLJExpand : public Pair { virtual ~PairLJExpand(); virtual void compute(int, int); - void settings(int, char **); + virtual void settings(int, char **); void coeff(int, char **); - double init_one(int, int); + virtual double init_one(int, int); void write_restart(FILE *); void read_restart(FILE *); void write_restart_settings(FILE *); @@ -48,7 +48,7 @@ class PairLJExpand : public Pair { double **epsilon,**sigma,**shift; double **lj1,**lj2,**lj3,**lj4,**offset; - void allocate(); + virtual void allocate(); }; } diff --git a/src/pair_lj_gromacs.cpp b/src/pair_lj_gromacs.cpp index 5b4bb35089..d81be7e83d 100644 --- a/src/pair_lj_gromacs.cpp +++ b/src/pair_lj_gromacs.cpp @@ -41,7 +41,8 @@ PairLJGromacs::PairLJGromacs(LAMMPS *lmp) : Pair(lmp) PairLJGromacs::~PairLJGromacs() { - if (allocated) { + if (!copymode) { + if (allocated) { memory->destroy(setflag); memory->destroy(cutsq); @@ -59,6 +60,7 @@ PairLJGromacs::~PairLJGromacs() memory->destroy(ljsw3); memory->destroy(ljsw4); memory->destroy(ljsw5); + } } } diff --git a/src/pair_lj_gromacs.h b/src/pair_lj_gromacs.h index f02db18c03..c58de220f8 100644 --- a/src/pair_lj_gromacs.h +++ b/src/pair_lj_gromacs.h @@ -31,7 +31,7 @@ class PairLJGromacs : public Pair { virtual void compute(int, int); virtual void settings(int, char **); void coeff(int, char **); - double init_one(int, int); + virtual double init_one(int, int); void write_restart(FILE *); void read_restart(FILE *); virtual void write_restart_settings(FILE *); @@ -47,7 +47,7 @@ class PairLJGromacs : public Pair { double **lj1,**lj2,**lj3,**lj4; double **ljsw1,**ljsw2,**ljsw3,**ljsw4,**ljsw5; - void allocate(); + virtual void allocate(); }; } diff --git a/src/pair_lj_gromacs_coul_gromacs.cpp b/src/pair_lj_gromacs_coul_gromacs.cpp index 5a78c4e140..bd9bb56c7e 100644 --- a/src/pair_lj_gromacs_coul_gromacs.cpp +++ b/src/pair_lj_gromacs_coul_gromacs.cpp @@ -41,7 +41,8 @@ PairLJGromacsCoulGromacs::PairLJGromacsCoulGromacs(LAMMPS *lmp) : Pair(lmp) PairLJGromacsCoulGromacs::~PairLJGromacsCoulGromacs() { - if (allocated) { + if (!copymode) { + if (allocated) { memory->destroy(setflag); memory->destroy(cutsq); @@ -56,6 +57,7 @@ PairLJGromacsCoulGromacs::~PairLJGromacsCoulGromacs() memory->destroy(ljsw3); memory->destroy(ljsw4); memory->destroy(ljsw5); + } } } diff --git a/src/pair_lj_gromacs_coul_gromacs.h b/src/pair_lj_gromacs_coul_gromacs.h index 378a51a98c..85b3051b25 100644 --- a/src/pair_lj_gromacs_coul_gromacs.h +++ b/src/pair_lj_gromacs_coul_gromacs.h @@ -31,8 +31,8 @@ class PairLJGromacsCoulGromacs : public Pair { virtual void compute(int, int); virtual void settings(int, char **); void coeff(int, char **); - void init_style(); - double init_one(int, int); + virtual void init_style(); + virtual double init_one(int, int); void write_restart(FILE *); void read_restart(FILE *); virtual void write_restart_settings(FILE *); @@ -49,7 +49,7 @@ class PairLJGromacsCoulGromacs : public Pair { double **ljsw1,**ljsw2,**ljsw3,**ljsw4,**ljsw5; double coulsw1,coulsw2,coulsw3,coulsw4,coulsw5; - void allocate(); + virtual void allocate(); }; } From 185b8197d5cc32d28bfe80c7d2ccd87db49dddf0 Mon Sep 17 00:00:00 2001 From: sjplimp Date: Fri, 27 Mar 2015 13:48:30 +0000 Subject: [PATCH 03/22] git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@13304 f3b2605a-c512-4ea7-a41b-209d697bcdaa --- src/KOKKOS/Install.sh | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/src/KOKKOS/Install.sh b/src/KOKKOS/Install.sh index 91dd935da6..c28f68280e 100644 --- a/src/KOKKOS/Install.sh +++ b/src/KOKKOS/Install.sh @@ -81,23 +81,53 @@ action neigh_list_kokkos.cpp action neigh_list_kokkos.h action neighbor_kokkos.cpp action neighbor_kokkos.h +action pair_buck_coul_cut_kokkos.cpp +action pair_buck_coul_cut_kokkos.h +action pair_buck_coul_long_kokkos.cpp +action pair_buck_coul_long_kokkos.h action pair_buck_kokkos.cpp action pair_buck_kokkos.h action pair_coul_cut_kokkos.cpp action pair_coul_cut_kokkos.h +action pair_coul_debye_kokkos.cpp +action pair_coul_debye_kokkos.h action pair_coul_dsf_kokkos.cpp action pair_coul_dsf_kokkos.h +action pair_coul_long_kokkos.cpp +action pair_coul_long_kokkos.h action pair_coul_wolf_kokkos.cpp action pair_coul_wolf_kokkos.h action pair_eam_kokkos.cpp pair_eam.cpp action pair_eam_kokkos.h pair_eam.h action pair_kokkos.h +action pair_lj_charmm_coul_charmm_implicit_kokkos.cpp pair_lj_charmm_coul_charmm_implicit.cpp +action pair_lj_charmm_coul_charmm_implicit_kokkos.h pair_lj_charmm_coul_charmm_implicit.h +action pair_lj_charmm_coul_charmm_kokkos.cpp pair_lj_charmm_coul_charmm.cpp +action pair_lj_charmm_coul_charmm_kokkos.h pair_lj_charmm_coul_charmm.h +action pair_lj_charmm_coul_long_kokkos.cpp pair_lj_charmm_coul_long.cpp +action pair_lj_charmm_coul_long_kokkos.h pair_lj_charmm_coul_long.h +action pair_lj_class2_coul_cut_kokkos.cpp pair_lj_class2_coul_cut.cpp +action pair_lj_class2_coul_cut_kokkos.h pair_lj_class2_coul_cut.h +action pair_lj_class2_coul_long_kokkos.cpp pair_lj_class2_coul_long.cpp +action pair_lj_class2_coul_long_kokkos.h pair_lj_class2_coul_long.h +action pair_lj_class2_kokkos.cpp pair_lj_class2.cpp +action pair_lj_class2_kokkos.h pair_lj_class2.h action pair_lj_cut_coul_cut_kokkos.cpp action pair_lj_cut_coul_cut_kokkos.h -action pair_lj_cut_coul_long_kokkos.cpp pair_lj_cut_coul_long.cpp -action pair_lj_cut_coul_long_kokkos.h pair_lj_cut_coul_long.h +action pair_lj_cut_coul_debye_kokkos.cpp +action pair_lj_cut_coul_debye_kokkos.h +action pair_lj_cut_coul_dsf_kokkos.cpp +action pair_lj_cut_coul_dsf_kokkos.h +action pair_lj_cut_coul_long_kokkos.cpp pair_lj_cut_coul_long.cpp pair_lj_cut_coul_long_kokkos.cpp pair_lj_cut_co.cpp +action pair_lj_cut_coul_long_kokkos.h pair_lj_cut_coul_long.h pair_lj_cut_coul_long_kokkos.h pair_lj_cut_co.h action pair_lj_cut_kokkos.cpp action pair_lj_cut_kokkos.h +action pair_lj_expand_kokkos.cpp +action pair_lj_expand_kokkos.h +action pair_lj_gromacs_coul_gromacs_kokkos.cp +action pair_lj_gromacs_coul_gromacs_kokkos.h +action pair_lj_gromacs_kokkos.cpp +action pair_lj_gromacs_kokkos.h action pair_table_kokkos.cpp action pair_table_kokkos.h action verlet_kokkos.cpp From f1acd4762f16f736916e0b7de991af54cda69cb5 Mon Sep 17 00:00:00 2001 From: sjplimp Date: Fri, 27 Mar 2015 13:48:47 +0000 Subject: [PATCH 04/22] git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@13305 f3b2605a-c512-4ea7-a41b-209d697bcdaa --- src/KOKKOS/pair_buck_coul_cut_kokkos.cpp | 373 ++++++++++++ src/KOKKOS/pair_buck_coul_cut_kokkos.h | 134 +++++ src/KOKKOS/pair_buck_coul_long_kokkos.cpp | 517 +++++++++++++++++ src/KOKKOS/pair_buck_coul_long_kokkos.h | 150 +++++ src/KOKKOS/pair_coul_debye_kokkos.cpp | 313 ++++++++++ src/KOKKOS/pair_coul_debye_kokkos.h | 135 +++++ src/KOKKOS/pair_coul_long_kokkos.cpp | 456 +++++++++++++++ src/KOKKOS/pair_coul_long_kokkos.h | 154 +++++ ..._lj_charmm_coul_charmm_implicit_kokkos.cpp | 513 +++++++++++++++++ ...ir_lj_charmm_coul_charmm_implicit_kokkos.h | 151 +++++ .../pair_lj_charmm_coul_charmm_kokkos.cpp | 515 +++++++++++++++++ .../pair_lj_charmm_coul_charmm_kokkos.h | 151 +++++ .../pair_lj_charmm_coul_long_kokkos.cpp | 534 ++++++++++++++++++ src/KOKKOS/pair_lj_charmm_coul_long_kokkos.h | 151 +++++ src/KOKKOS/pair_lj_class2_coul_cut_kokkos.cpp | 354 ++++++++++++ src/KOKKOS/pair_lj_class2_coul_cut_kokkos.h | 131 +++++ .../pair_lj_class2_coul_long_kokkos.cpp | 503 +++++++++++++++++ src/KOKKOS/pair_lj_class2_coul_long_kokkos.h | 147 +++++ src/KOKKOS/pair_lj_class2_kokkos.cpp | 281 +++++++++ src/KOKKOS/pair_lj_class2_kokkos.h | 125 ++++ src/KOKKOS/pair_lj_cut_coul_debye_kokkos.cpp | 375 ++++++++++++ src/KOKKOS/pair_lj_cut_coul_debye_kokkos.h | 131 +++++ src/KOKKOS/pair_lj_cut_coul_dsf_kokkos.cpp | 366 ++++++++++++ src/KOKKOS/pair_lj_cut_coul_dsf_kokkos.h | 130 +++++ src/KOKKOS/pair_lj_expand_kokkos.cpp | 285 ++++++++++ src/KOKKOS/pair_lj_expand_kokkos.h | 125 ++++ .../pair_lj_gromacs_coul_gromacs_kokkos.cpp | 501 ++++++++++++++++ .../pair_lj_gromacs_coul_gromacs_kokkos.h | 151 +++++ src/KOKKOS/pair_lj_gromacs_kokkos.cpp | 333 +++++++++++ src/KOKKOS/pair_lj_gromacs_kokkos.h | 153 +++++ 30 files changed, 8338 insertions(+) create mode 100644 src/KOKKOS/pair_buck_coul_cut_kokkos.cpp create mode 100644 src/KOKKOS/pair_buck_coul_cut_kokkos.h create mode 100644 src/KOKKOS/pair_buck_coul_long_kokkos.cpp create mode 100644 src/KOKKOS/pair_buck_coul_long_kokkos.h create mode 100644 src/KOKKOS/pair_coul_debye_kokkos.cpp create mode 100644 src/KOKKOS/pair_coul_debye_kokkos.h create mode 100644 src/KOKKOS/pair_coul_long_kokkos.cpp create mode 100644 src/KOKKOS/pair_coul_long_kokkos.h create mode 100644 src/KOKKOS/pair_lj_charmm_coul_charmm_implicit_kokkos.cpp create mode 100644 src/KOKKOS/pair_lj_charmm_coul_charmm_implicit_kokkos.h create mode 100644 src/KOKKOS/pair_lj_charmm_coul_charmm_kokkos.cpp create mode 100644 src/KOKKOS/pair_lj_charmm_coul_charmm_kokkos.h create mode 100644 src/KOKKOS/pair_lj_charmm_coul_long_kokkos.cpp create mode 100644 src/KOKKOS/pair_lj_charmm_coul_long_kokkos.h create mode 100644 src/KOKKOS/pair_lj_class2_coul_cut_kokkos.cpp create mode 100644 src/KOKKOS/pair_lj_class2_coul_cut_kokkos.h create mode 100644 src/KOKKOS/pair_lj_class2_coul_long_kokkos.cpp create mode 100644 src/KOKKOS/pair_lj_class2_coul_long_kokkos.h create mode 100644 src/KOKKOS/pair_lj_class2_kokkos.cpp create mode 100644 src/KOKKOS/pair_lj_class2_kokkos.h create mode 100644 src/KOKKOS/pair_lj_cut_coul_debye_kokkos.cpp create mode 100644 src/KOKKOS/pair_lj_cut_coul_debye_kokkos.h create mode 100644 src/KOKKOS/pair_lj_cut_coul_dsf_kokkos.cpp create mode 100644 src/KOKKOS/pair_lj_cut_coul_dsf_kokkos.h create mode 100644 src/KOKKOS/pair_lj_expand_kokkos.cpp create mode 100644 src/KOKKOS/pair_lj_expand_kokkos.h create mode 100644 src/KOKKOS/pair_lj_gromacs_coul_gromacs_kokkos.cpp create mode 100644 src/KOKKOS/pair_lj_gromacs_coul_gromacs_kokkos.h create mode 100644 src/KOKKOS/pair_lj_gromacs_kokkos.cpp create mode 100644 src/KOKKOS/pair_lj_gromacs_kokkos.h diff --git a/src/KOKKOS/pair_buck_coul_cut_kokkos.cpp b/src/KOKKOS/pair_buck_coul_cut_kokkos.cpp new file mode 100644 index 0000000000..7ffdf903f3 --- /dev/null +++ b/src/KOKKOS/pair_buck_coul_cut_kokkos.cpp @@ -0,0 +1,373 @@ +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + http://lammps.sandia.gov, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +/* ---------------------------------------------------------------------- + Contributing author: Ray Shan (SNL) +------------------------------------------------------------------------- */ + +#include "math.h" +#include "stdio.h" +#include "stdlib.h" +#include "string.h" +#include "pair_buck_coul_cut_kokkos.h" +#include "kokkos.h" +#include "atom_kokkos.h" +#include "comm.h" +#include "force.h" +#include "neighbor.h" +#include "neigh_list.h" +#include "neigh_request.h" +#include "update.h" +#include "integrate.h" +#include "respa.h" +#include "math_const.h" +#include "memory.h" +#include "error.h" +#include "atom_masks.h" + +using namespace LAMMPS_NS; +using namespace MathConst; + +#define KOKKOS_CUDA_MAX_THREADS 256 +#define KOKKOS_CUDA_MIN_BLOCKS 8 + +/* ---------------------------------------------------------------------- */ + +template +PairBuckCoulCutKokkos::PairBuckCoulCutKokkos(LAMMPS *lmp):PairBuckCoulCut(lmp) +{ + respa_enable = 0; + + atomKK = (AtomKokkos *) atom; + execution_space = ExecutionSpaceFromDevice::space; + datamask_read = X_MASK | F_MASK | TYPE_MASK | Q_MASK | ENERGY_MASK | VIRIAL_MASK; + datamask_modify = F_MASK | ENERGY_MASK | VIRIAL_MASK; + cutsq = NULL; + cut_ljsq = NULL; + cut_coulsq = NULL; + +} + +/* ---------------------------------------------------------------------- */ + +template +PairBuckCoulCutKokkos::~PairBuckCoulCutKokkos() +{ + + if (!copymode) { + memory->destroy_kokkos(k_eatom,eatom); + memory->destroy_kokkos(k_vatom,vatom); + k_cutsq = DAT::tdual_ffloat_2d(); + k_cut_ljsq = DAT::tdual_ffloat_2d(); + k_cut_coulsq = DAT::tdual_ffloat_2d(); + memory->sfree(cutsq); + memory->sfree(cut_ljsq); + memory->sfree(cut_coulsq); + eatom = NULL; + vatom = NULL; + cutsq = NULL; + cut_ljsq = NULL; + cut_coulsq = NULL; + } + +} + +/* ---------------------------------------------------------------------- */ + +template +void PairBuckCoulCutKokkos::compute(int eflag_in, int vflag_in) +{ + eflag = eflag_in; + vflag = vflag_in; + + if (neighflag == FULL || neighflag == FULLCLUSTER) no_virial_fdotr_compute = 1; + + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = vflag_fdotr = 0; + + // reallocate per-atom arrays if necessary + + if (eflag_atom) { + memory->destroy_kokkos(k_eatom,eatom); + memory->create_kokkos(k_eatom,eatom,maxeatom,"pair:eatom"); + d_eatom = k_eatom.view(); + } + if (vflag_atom) { + memory->destroy_kokkos(k_vatom,vatom); + memory->create_kokkos(k_vatom,vatom,maxvatom,6,"pair:vatom"); + d_vatom = k_vatom.view(); + } + + atomKK->sync(execution_space,datamask_read); + k_cutsq.template sync(); + k_cut_ljsq.template sync(); + k_cut_coulsq.template sync(); + k_params.template sync(); + if (eflag || vflag) atomKK->modified(execution_space,datamask_modify); + else atomKK->modified(execution_space,F_MASK); + + x = atomKK->k_x.view(); + c_x = atomKK->k_x.view(); + f = atomKK->k_f.view(); + q = atomKK->k_q.view(); + type = atomKK->k_type.view(); + nlocal = atom->nlocal; + nall = atom->nlocal + atom->nghost; + qqrd2e = force->qqrd2e; + newton_pair = force->newton_pair; + special_lj[0] = force->special_lj[0]; + special_lj[1] = force->special_lj[1]; + special_lj[2] = force->special_lj[2]; + special_lj[3] = force->special_lj[3]; + special_coul[0] = force->special_coul[0]; + special_coul[1] = force->special_coul[1]; + special_coul[2] = force->special_coul[2]; + special_coul[3] = force->special_coul[3]; + + // loop over neighbors of my atoms + + copymode = 1; + + EV_FLOAT ev = pair_compute,void > + (this,(NeighListKokkos*)list); + + DeviceType::fence(); + + if (eflag) { + eng_vdwl += ev.evdwl; + eng_coul += ev.ecoul; + } + if (vflag_global) { + virial[0] += ev.v[0]; + virial[1] += ev.v[1]; + virial[2] += ev.v[2]; + virial[3] += ev.v[3]; + virial[4] += ev.v[4]; + virial[5] += ev.v[5]; + } + + if (vflag_fdotr) virial_fdotr_compute(); + + if (eflag_atom) { + k_eatom.template modify(); + k_eatom.template sync(); + } + + if (vflag_atom) { + k_vatom.template modify(); + k_vatom.template sync(); + } + + copymode = 0; +} + +/* ---------------------------------------------------------------------- + compute Buckingham pair force between atoms i and j + ---------------------------------------------------------------------- */ +template +template +KOKKOS_INLINE_FUNCTION +F_FLOAT PairBuckCoulCutKokkos:: +compute_fpair(const F_FLOAT& rsq, const int& i, const int&j, const int& itype, const int& jtype) const { + const F_FLOAT r2inv = 1.0/rsq; + const F_FLOAT r6inv = r2inv*r2inv*r2inv; + const F_FLOAT r = sqrt(rsq); + const F_FLOAT rexp = exp(-r*(STACKPARAMS?m_params[itype][jtype].rhoinv:params(itype,jtype).rhoinv)); + + const F_FLOAT forcebuck = + (STACKPARAMS?m_params[itype][jtype].buck1:params(itype,jtype).buck1)*r*rexp - + (STACKPARAMS?m_params[itype][jtype].buck2:params(itype,jtype).buck2)*r6inv; + + return forcebuck*r2inv; +} + +/* ---------------------------------------------------------------------- + compute Buckingham pair potential energy between atoms i and j + ---------------------------------------------------------------------- */ +template +template +KOKKOS_INLINE_FUNCTION +F_FLOAT PairBuckCoulCutKokkos:: +compute_evdwl(const F_FLOAT& rsq, const int& i, const int&j, const int& itype, const int& jtype) const { + const F_FLOAT r2inv = 1.0/rsq; + const F_FLOAT r6inv = r2inv*r2inv*r2inv; + const F_FLOAT r = sqrt(rsq); + const F_FLOAT rexp = exp(-r*(STACKPARAMS?m_params[itype][jtype].rhoinv:params(itype,jtype).rhoinv)); + + return (STACKPARAMS?m_params[itype][jtype].a:params(itype,jtype).a)*rexp - + (STACKPARAMS?m_params[itype][jtype].c:params(itype,jtype).c)*r6inv - + (STACKPARAMS?m_params[itype][jtype].offset:params(itype,jtype).offset); +} + +/* ---------------------------------------------------------------------- + compute coulomb pair force between atoms i and j + ---------------------------------------------------------------------- */ +template +template +KOKKOS_INLINE_FUNCTION +F_FLOAT PairBuckCoulCutKokkos:: +compute_fcoul(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype, const F_FLOAT& factor_coul, const F_FLOAT& qtmp) const { + const F_FLOAT r2inv = 1.0/rsq; + const F_FLOAT rinv = sqrt(r2inv); + F_FLOAT forcecoul; + + forcecoul = qqrd2e*qtmp*q(j) *rinv; + + return factor_coul*forcecoul*r2inv; +} + +/* ---------------------------------------------------------------------- + compute coulomb pair potential energy between atoms i and j + ---------------------------------------------------------------------- */ +template +template +KOKKOS_INLINE_FUNCTION +F_FLOAT PairBuckCoulCutKokkos:: +compute_ecoul(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype, const F_FLOAT& factor_coul, const F_FLOAT& qtmp) const { + const F_FLOAT r2inv = 1.0/rsq; + const F_FLOAT rinv = sqrt(r2inv); + + return factor_coul*qqrd2e*qtmp*q(j)*rinv; + +} + +/* ---------------------------------------------------------------------- + allocate all arrays +------------------------------------------------------------------------- */ + +template +void PairBuckCoulCutKokkos::allocate() +{ + PairBuckCoulCut::allocate(); + + int n = atom->ntypes; + memory->destroy(cutsq); + memory->create_kokkos(k_cutsq,cutsq,n+1,n+1,"pair:cutsq"); + d_cutsq = k_cutsq.template view(); + memory->destroy(cut_ljsq); + memory->create_kokkos(k_cut_ljsq,cut_ljsq,n+1,n+1,"pair:cut_ljsq"); + d_cut_ljsq = k_cut_ljsq.template view(); + memory->destroy(cut_coulsq); + memory->create_kokkos(k_cut_coulsq,cut_coulsq,n+1,n+1,"pair:cut_coulsq"); + d_cut_coulsq = k_cut_coulsq.template view(); + k_params = Kokkos::DualView("PairBuckCoulCut::params",n+1,n+1); + params = k_params.d_view; +} + +/* ---------------------------------------------------------------------- + global settings +------------------------------------------------------------------------- */ + +template +void PairBuckCoulCutKokkos::settings(int narg, char **arg) +{ + if (narg > 2) error->all(FLERR,"Illegal pair_style command"); + + PairBuckCoulCut::settings(1,arg); +} + +/* ---------------------------------------------------------------------- + init specific to this pair style +------------------------------------------------------------------------- */ + +template +void PairBuckCoulCutKokkos::init_style() +{ + PairBuckCoulCut::init_style(); + + // error if rRESPA with inner levels + + if (update->whichflag == 1 && strstr(update->integrate_style,"respa")) { + int respa = 0; + if (((Respa *) update->integrate)->level_inner >= 0) respa = 1; + if (((Respa *) update->integrate)->level_middle >= 0) respa = 2; + if (respa) + error->all(FLERR,"Cannot use Kokkos pair style with rRESPA inner/middle"); + } + + // irequest = neigh request made by parent class + + neighflag = lmp->kokkos->neighflag; + int irequest = neighbor->nrequest - 1; + + neighbor->requests[irequest]-> + kokkos_host = Kokkos::Impl::is_same::value && + !Kokkos::Impl::is_same::value; + neighbor->requests[irequest]-> + kokkos_device = Kokkos::Impl::is_same::value; + + if (neighflag == FULL) { + neighbor->requests[irequest]->full = 1; + neighbor->requests[irequest]->half = 0; + neighbor->requests[irequest]->full_cluster = 0; + } else if (neighflag == HALF || neighflag == HALFTHREAD) { + neighbor->requests[irequest]->full = 0; + neighbor->requests[irequest]->half = 1; + neighbor->requests[irequest]->full_cluster = 0; + } else if (neighflag == N2) { + neighbor->requests[irequest]->full_cluster = 0; + neighbor->requests[irequest]->full = 0; + neighbor->requests[irequest]->half = 0; + } else if (neighflag == FULLCLUSTER) { + neighbor->requests[irequest]->full = 1; + neighbor->requests[irequest]->half = 0; + neighbor->requests[irequest]->full_cluster = 1; + } else { + error->all(FLERR,"Cannot use chosen neighbor list style with buck/coul/cut/kk"); + } +} + +/* ---------------------------------------------------------------------- + init for one type pair i,j and corresponding j,i +------------------------------------------------------------------------- */ + +template +double PairBuckCoulCutKokkos::init_one(int i, int j) +{ + double cutone = PairBuckCoulCut::init_one(i,j); + double cut_ljsqm = cut_ljsq[i][j]; + double cut_coulsqm = cut_coulsq[i][j]; + + k_params.h_view(i,j).a = a[i][j]; + k_params.h_view(i,j).c = c[i][j]; + k_params.h_view(i,j).rhoinv = rhoinv[i][j]; + k_params.h_view(i,j).buck1 = buck1[i][j]; + k_params.h_view(i,j).buck2 = buck2[i][j]; + k_params.h_view(i,j).offset = offset[i][j]; + k_params.h_view(i,j).cut_ljsq = cut_ljsqm; + k_params.h_view(i,j).cut_coulsq = cut_coulsqm; + + k_params.h_view(j,i) = k_params.h_view(i,j); + if(i(); + k_cut_ljsq.h_view(i,j) = cut_ljsqm; + k_cut_ljsq.template modify(); + k_cut_coulsq.h_view(i,j) = cut_coulsqm; + k_cut_coulsq.template modify(); + k_params.template modify(); + + return cutone; +} + +template class PairBuckCoulCutKokkos; +#ifdef KOKKOS_HAVE_CUDA +template class PairBuckCoulCutKokkos; +#endif diff --git a/src/KOKKOS/pair_buck_coul_cut_kokkos.h b/src/KOKKOS/pair_buck_coul_cut_kokkos.h new file mode 100644 index 0000000000..709098493b --- /dev/null +++ b/src/KOKKOS/pair_buck_coul_cut_kokkos.h @@ -0,0 +1,134 @@ +/* -*- c++ -*- ---------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + http://lammps.sandia.gov, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +#ifdef PAIR_CLASS + +PairStyle(buck/coul/cut/kk,PairBuckCoulCutKokkos) +PairStyle(buck/coul/cut/kk/device,PairBuckCoulCutKokkos) +PairStyle(buck/coul/cut/kk/host,PairBuckCoulCutKokkos) + +#else + +#ifndef LMP_PAIR_BUCK_COUL_CUT_KOKKOS_H +#define LMP_PAIR_BUCK_COUL_CUT_KOKKOS_H + +#include "pair_kokkos.h" +#include "pair_buck_coul_cut.h" +#include "neigh_list_kokkos.h" + +namespace LAMMPS_NS { + +template +class PairBuckCoulCutKokkos : public PairBuckCoulCut { + public: + enum {EnabledNeighFlags=FULL|HALFTHREAD|HALF}; + enum {COUL_FLAG=1}; + typedef DeviceType device_type; + PairBuckCoulCutKokkos(class LAMMPS *); + ~PairBuckCoulCutKokkos(); + + void compute(int, int); + + void settings(int, char **); + void init_style(); + double init_one(int, int); + + struct params_buck_coul{ + params_buck_coul(){cut_ljsq=0;cut_coulsq=0;a=0;c=0;rhoinv=0;buck1=0;buck2=0;offset=0;}; + params_buck_coul(int i){cut_ljsq=0;cut_coulsq=0;a=0;c=0;rhoinv=0;buck1=0;buck2=0;offset=0;}; + F_FLOAT cut_ljsq,cut_coulsq,a,c,rhoinv,buck1,buck2,offset; + }; + + protected: + void cleanup_copy() {} + + template + KOKKOS_INLINE_FUNCTION + F_FLOAT compute_fpair(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype) const; + + template + KOKKOS_INLINE_FUNCTION + F_FLOAT compute_evdwl(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype) const; + + template + KOKKOS_INLINE_FUNCTION + F_FLOAT compute_fcoul(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype, const F_FLOAT& factor_coul, const F_FLOAT& qtmp) const; + + template + KOKKOS_INLINE_FUNCTION + F_FLOAT compute_ecoul(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype, const F_FLOAT& factor_coul, const F_FLOAT& qtmp) const; + + Kokkos::DualView k_params; + typename Kokkos::DualView::t_dev_const params; + // hardwired to space for 15 atom types + params_buck_coul m_params[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; + + F_FLOAT m_cutsq[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; + F_FLOAT m_cut_ljsq[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; + F_FLOAT m_cut_coulsq[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; + typename ArrayTypes::t_x_array_randomread x; + typename ArrayTypes::t_x_array c_x; + typename ArrayTypes::t_f_array f; + typename ArrayTypes::t_int_1d_randomread type; + typename ArrayTypes::t_float_1d_randomread q; + + DAT::tdual_efloat_1d k_eatom; + DAT::tdual_virial_array k_vatom; + typename ArrayTypes::t_efloat_1d d_eatom; + typename ArrayTypes::t_virial_array d_vatom; + + int newton_pair; + + typename ArrayTypes::tdual_ffloat_2d k_cutsq; + typename ArrayTypes::t_ffloat_2d d_cutsq; + typename ArrayTypes::tdual_ffloat_2d k_cut_ljsq; + typename ArrayTypes::t_ffloat_2d d_cut_ljsq; + typename ArrayTypes::tdual_ffloat_2d k_cut_coulsq; + typename ArrayTypes::t_ffloat_2d d_cut_coulsq; + + class AtomKokkos *atomKK; + int neighflag; + int nlocal,nall,eflag,vflag; + + double special_lj[4], special_coul[4]; + double qqrd2e; + + void allocate(); + + friend class PairComputeFunctor; + friend class PairComputeFunctor; + friend class PairComputeFunctor; + friend class PairComputeFunctor; + friend class PairComputeFunctor; + friend class PairComputeFunctor; + friend EV_FLOAT pair_compute_neighlist(PairBuckCoulCutKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairBuckCoulCutKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairBuckCoulCutKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute(PairBuckCoulCutKokkos*, + NeighListKokkos*); + +}; + +} + +#endif +#endif + +/* ERROR/WARNING messages: + +*/ diff --git a/src/KOKKOS/pair_buck_coul_long_kokkos.cpp b/src/KOKKOS/pair_buck_coul_long_kokkos.cpp new file mode 100644 index 0000000000..1f733ab3d7 --- /dev/null +++ b/src/KOKKOS/pair_buck_coul_long_kokkos.cpp @@ -0,0 +1,517 @@ +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + http://lammps.sandia.gov, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +/* ---------------------------------------------------------------------- + Contributing author: Ray Shan (SNL) +------------------------------------------------------------------------- */ + +#include "math.h" +#include "stdio.h" +#include "stdlib.h" +#include "string.h" +#include "pair_buck_coul_long_kokkos.h" +#include "kokkos.h" +#include "atom_kokkos.h" +#include "comm.h" +#include "force.h" +#include "neighbor.h" +#include "neigh_list.h" +#include "neigh_request.h" +#include "update.h" +#include "integrate.h" +#include "respa.h" +#include "math_const.h" +#include "memory.h" +#include "error.h" +#include "atom_masks.h" + +using namespace LAMMPS_NS; +using namespace MathConst; + +#define KOKKOS_CUDA_MAX_THREADS 256 +#define KOKKOS_CUDA_MIN_BLOCKS 8 + + +#define EWALD_F 1.12837917 +#define EWALD_P 0.3275911 +#define A1 0.254829592 +#define A2 -0.284496736 +#define A3 1.421413741 +#define A4 -1.453152027 +#define A5 1.061405429 + +/* ---------------------------------------------------------------------- */ + +template +PairBuckCoulLongKokkos::PairBuckCoulLongKokkos(LAMMPS *lmp):PairBuckCoulLong(lmp) +{ + respa_enable = 0; + + atomKK = (AtomKokkos *) atom; + execution_space = ExecutionSpaceFromDevice::space; + datamask_read = X_MASK | F_MASK | TYPE_MASK | Q_MASK | ENERGY_MASK | VIRIAL_MASK; + datamask_modify = F_MASK | ENERGY_MASK | VIRIAL_MASK; + cutsq = NULL; + cut_ljsq = NULL; + cut_coulsq = 0.0; + +} + +/* ---------------------------------------------------------------------- */ + +template +PairBuckCoulLongKokkos::~PairBuckCoulLongKokkos() +{ + if (!copymode) { + memory->destroy_kokkos(k_eatom,eatom); + memory->destroy_kokkos(k_vatom,vatom); + k_cutsq = DAT::tdual_ffloat_2d(); + k_cut_ljsq = DAT::tdual_ffloat_2d(); + k_cut_coulsq = DAT::tdual_ffloat_2d(); + memory->sfree(cutsq); + memory->sfree(cut_ljsq); + //memory->sfree(cut_coulsq); + eatom = NULL; + vatom = NULL; + cutsq = NULL; + cut_ljsq = NULL; + //cut_coulsq = NULL; + } +} + +/* ---------------------------------------------------------------------- */ + +template +void PairBuckCoulLongKokkos::cleanup_copy() { + allocated = 0; + cutsq = NULL; + cut_ljsq = NULL; + eatom = NULL; + vatom = NULL; + ftable = NULL; +} + +/* ---------------------------------------------------------------------- */ + +template +void PairBuckCoulLongKokkos::compute(int eflag_in, int vflag_in) +{ + eflag = eflag_in; + vflag = vflag_in; + + if (neighflag == FULL || neighflag == FULLCLUSTER) no_virial_fdotr_compute = 1; + + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = vflag_fdotr = 0; + + atomKK->sync(execution_space,datamask_read); + k_cutsq.template sync(); + k_cut_ljsq.template sync(); + k_cut_coulsq.template sync(); + k_params.template sync(); + if (eflag || vflag) atomKK->modified(execution_space,datamask_modify); + else atomKK->modified(execution_space,F_MASK); + + x = atomKK->k_x.view(); + c_x = atomKK->k_x.view(); + f = atomKK->k_f.view(); + q = atomKK->k_q.view(); + type = atomKK->k_type.view(); + nlocal = atom->nlocal; + nall = atom->nlocal + atom->nghost; + qqrd2e = force->qqrd2e; + newton_pair = force->newton_pair; + special_lj[0] = force->special_lj[0]; + special_lj[1] = force->special_lj[1]; + special_lj[2] = force->special_lj[2]; + special_lj[3] = force->special_lj[3]; + special_coul[0] = force->special_coul[0]; + special_coul[1] = force->special_coul[1]; + special_coul[2] = force->special_coul[2]; + special_coul[3] = force->special_coul[3]; + + // loop over neighbors of my atoms + + copymode = 1; + + EV_FLOAT ev; + if(ncoultablebits) + ev = pair_compute,CoulLongTable<1> > + (this,(NeighListKokkos*)list); + else + ev = pair_compute,CoulLongTable<0> > + (this,(NeighListKokkos*)list); + + + DeviceType::fence(); + + if (eflag) { + eng_vdwl += ev.evdwl; + eng_coul += ev.ecoul; + } + if (vflag_global) { + virial[0] += ev.v[0]; + virial[1] += ev.v[1]; + virial[2] += ev.v[2]; + virial[3] += ev.v[3]; + virial[4] += ev.v[4]; + virial[5] += ev.v[5]; + } + + if (vflag_fdotr) pair_virial_fdotr_compute(this); + + copymode = 0; +} + +/* ---------------------------------------------------------------------- + compute Buckingham pair force between atoms i and j + ---------------------------------------------------------------------- */ +template +template +KOKKOS_INLINE_FUNCTION +F_FLOAT PairBuckCoulLongKokkos:: +compute_fpair(const F_FLOAT& rsq, const int& i, const int&j, const int& itype, const int& jtype) const { + const F_FLOAT r2inv = 1.0/rsq; + const F_FLOAT r6inv = r2inv*r2inv*r2inv; + const F_FLOAT r = sqrt(rsq); + const F_FLOAT rexp = exp(-r*(STACKPARAMS?m_params[itype][jtype].rhoinv:params(itype,jtype).rhoinv)); + + const F_FLOAT forcebuck = + (STACKPARAMS?m_params[itype][jtype].buck1:params(itype,jtype).buck1)*r*rexp - + (STACKPARAMS?m_params[itype][jtype].buck2:params(itype,jtype).buck2)*r6inv; + + return forcebuck*r2inv; +} + +/* ---------------------------------------------------------------------- + compute Buckingham pair potential energy between atoms i and j + ---------------------------------------------------------------------- */ +template +template +KOKKOS_INLINE_FUNCTION +F_FLOAT PairBuckCoulLongKokkos:: +compute_evdwl(const F_FLOAT& rsq, const int& i, const int&j, const int& itype, const int& jtype) const { + const F_FLOAT r2inv = 1.0/rsq; + const F_FLOAT r6inv = r2inv*r2inv*r2inv; + const F_FLOAT r = sqrt(rsq); + const F_FLOAT rexp = exp(-r*(STACKPARAMS?m_params[itype][jtype].rhoinv:params(itype,jtype).rhoinv)); + + return (STACKPARAMS?m_params[itype][jtype].a:params(itype,jtype).a)*rexp - + (STACKPARAMS?m_params[itype][jtype].c:params(itype,jtype).c)*r6inv - + (STACKPARAMS?m_params[itype][jtype].offset:params(itype,jtype).offset); +} + +/* ---------------------------------------------------------------------- + compute coulomb pair force between atoms i and j + ---------------------------------------------------------------------- */ + +template +template +KOKKOS_INLINE_FUNCTION +F_FLOAT PairBuckCoulLongKokkos:: +compute_fcoul(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype, const F_FLOAT& factor_coul, const F_FLOAT& qtmp) const { + if(Specialisation::DoTable && rsq > tabinnersq) { + union_int_float_t rsq_lookup; + rsq_lookup.f = rsq; + const int itable = (rsq_lookup.i & ncoulmask) >> ncoulshiftbits; + const F_FLOAT fraction = (rsq_lookup.f - d_rtable[itable]) * d_drtable[itable]; + const F_FLOAT table = d_ftable[itable] + fraction*d_dftable[itable]; + F_FLOAT forcecoul = qtmp*q[j] * table; + if (factor_coul < 1.0) { + const F_FLOAT table = d_ctable[itable] + fraction*d_dctable[itable]; + const F_FLOAT prefactor = qtmp*q[j] * table; + forcecoul -= (1.0-factor_coul)*prefactor; + } + return forcecoul/rsq; + } else { + const F_FLOAT r = sqrt(rsq); + const F_FLOAT grij = g_ewald * r; + const F_FLOAT expm2 = exp(-grij*grij); + const F_FLOAT t = 1.0 / (1.0 + EWALD_P*grij); + const F_FLOAT rinv = 1.0/r; + const F_FLOAT erfc = t * (A1+t*(A2+t*(A3+t*(A4+t*A5)))) * expm2; + const F_FLOAT prefactor = qqrd2e * qtmp*q[j]*rinv; + F_FLOAT forcecoul = prefactor * (erfc + EWALD_F*grij*expm2); + if (factor_coul < 1.0) forcecoul -= (1.0-factor_coul)*prefactor; + + return forcecoul*rinv*rinv; + } +} + +/* ---------------------------------------------------------------------- + compute coulomb pair potential energy between atoms i and j + ---------------------------------------------------------------------- */ + +template +template +KOKKOS_INLINE_FUNCTION +F_FLOAT PairBuckCoulLongKokkos:: +compute_ecoul(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype, const F_FLOAT& factor_coul, const F_FLOAT& qtmp) const { + if(Specialisation::DoTable) { + union_int_float_t rsq_lookup; + rsq_lookup.f = rsq; + const int itable = (rsq_lookup.i & ncoulmask) >> ncoulshiftbits; + const F_FLOAT fraction = (rsq_lookup.f - d_rtable[itable]) * d_drtable[itable]; + const F_FLOAT table = d_etable[itable] + fraction*d_detable[itable]; + F_FLOAT ecoul = qtmp*q[j] * table; + if (factor_coul < 1.0) { + const F_FLOAT table = d_ctable[itable] + fraction*d_dctable[itable]; + const F_FLOAT prefactor = qtmp*q[j] * table; + ecoul -= (1.0-factor_coul)*prefactor; + } + return ecoul; + } else { + const F_FLOAT r = sqrt(rsq); + const F_FLOAT grij = g_ewald * r; + const F_FLOAT expm2 = exp(-grij*grij); + const F_FLOAT t = 1.0 / (1.0 + EWALD_P*grij); + const F_FLOAT erfc = t * (A1+t*(A2+t*(A3+t*(A4+t*A5)))) * expm2; + const F_FLOAT prefactor = qqrd2e * qtmp*q[j]/r; + F_FLOAT ecoul = prefactor * erfc; + if (factor_coul < 1.0) ecoul -= (1.0-factor_coul)*prefactor; + return ecoul; + } +} + +/* ---------------------------------------------------------------------- + allocate all arrays +------------------------------------------------------------------------- */ + +template +void PairBuckCoulLongKokkos::allocate() +{ + PairBuckCoulLong::allocate(); + + int n = atom->ntypes; + + memory->destroy(cutsq); + memory->create_kokkos(k_cutsq,cutsq,n+1,n+1,"pair:cutsq"); + d_cutsq = k_cutsq.template view(); + + memory->destroy(cut_ljsq); + memory->create_kokkos(k_cut_ljsq,cut_ljsq,n+1,n+1,"pair:cut_ljsq"); + d_cut_ljsq = k_cut_ljsq.template view(); + + memory->create_kokkos(k_cut_coulsq,n+1,n+1,"pair:cut_coulsq"); + d_cut_coulsq = k_cut_coulsq.template view(); + + k_params = Kokkos::DualView("PairBuckCoulLong::params",n+1,n+1); + params = k_params.d_view; +} + +template +void PairBuckCoulLongKokkos::init_tables(double cut_coul, double *cut_respa) +{ + Pair::init_tables(cut_coul,cut_respa); + + typedef typename ArrayTypes::t_ffloat_1d table_type; + typedef typename ArrayTypes::t_ffloat_1d host_table_type; + + int ntable = 1; + for (int i = 0; i < ncoultablebits; i++) ntable *= 2; + + + // Copy rtable and drtable + { + host_table_type h_table("HostTable",ntable); + table_type d_table("DeviceTable",ntable); + for(int i = 0; i < ntable; i++) { + h_table(i) = rtable[i]; + } + Kokkos::deep_copy(d_table,h_table); + d_rtable = d_table; + } + + { + host_table_type h_table("HostTable",ntable); + table_type d_table("DeviceTable",ntable); + for(int i = 0; i < ntable; i++) { + h_table(i) = drtable[i]; + } + Kokkos::deep_copy(d_table,h_table); + d_drtable = d_table; + } + + { + host_table_type h_table("HostTable",ntable); + table_type d_table("DeviceTable",ntable); + + // Copy ftable and dftable + for(int i = 0; i < ntable; i++) { + h_table(i) = ftable[i]; + } + Kokkos::deep_copy(d_table,h_table); + d_ftable = d_table; + } + + { + host_table_type h_table("HostTable",ntable); + table_type d_table("DeviceTable",ntable); + + for(int i = 0; i < ntable; i++) { + h_table(i) = dftable[i]; + } + Kokkos::deep_copy(d_table,h_table); + d_dftable = d_table; + } + + { + host_table_type h_table("HostTable",ntable); + table_type d_table("DeviceTable",ntable); + + // Copy ctable and dctable + for(int i = 0; i < ntable; i++) { + h_table(i) = ctable[i]; + } + Kokkos::deep_copy(d_table,h_table); + d_ctable = d_table; + } + + { + host_table_type h_table("HostTable",ntable); + table_type d_table("DeviceTable",ntable); + + for(int i = 0; i < ntable; i++) { + h_table(i) = dctable[i]; + } + Kokkos::deep_copy(d_table,h_table); + d_dctable = d_table; + } + + { + host_table_type h_table("HostTable",ntable); + table_type d_table("DeviceTable",ntable); + + // Copy etable and detable + for(int i = 0; i < ntable; i++) { + h_table(i) = etable[i]; + } + Kokkos::deep_copy(d_table,h_table); + d_etable = d_table; + } + + { + host_table_type h_table("HostTable",ntable); + table_type d_table("DeviceTable",ntable); + + for(int i = 0; i < ntable; i++) { + h_table(i) = detable[i]; + } + Kokkos::deep_copy(d_table,h_table); + d_detable = d_table; + } +} + + +/* ---------------------------------------------------------------------- + global settings +------------------------------------------------------------------------- */ + +template +void PairBuckCoulLongKokkos::settings(int narg, char **arg) +{ + if (narg > 2) error->all(FLERR,"Illegal pair_style command"); + + PairBuckCoulLong::settings(narg,arg); +} + +/* ---------------------------------------------------------------------- + init specific to this pair style +------------------------------------------------------------------------- */ + +template +void PairBuckCoulLongKokkos::init_style() +{ + PairBuckCoulLong::init_style(); + + // error if rRESPA with inner levels + + if (update->whichflag == 1 && strstr(update->integrate_style,"respa")) { + int respa = 0; + if (((Respa *) update->integrate)->level_inner >= 0) respa = 1; + if (((Respa *) update->integrate)->level_middle >= 0) respa = 2; + if (respa) + error->all(FLERR,"Cannot use Kokkos pair style with rRESPA inner/middle"); + } + + // irequest = neigh request made by parent class + + neighflag = lmp->kokkos->neighflag; + int irequest = neighbor->nrequest - 1; + + neighbor->requests[irequest]-> + kokkos_host = Kokkos::Impl::is_same::value && + !Kokkos::Impl::is_same::value; + neighbor->requests[irequest]-> + kokkos_device = Kokkos::Impl::is_same::value; + + if (neighflag == FULL) { + neighbor->requests[irequest]->full = 1; + neighbor->requests[irequest]->half = 0; + neighbor->requests[irequest]->full_cluster = 0; + } else if (neighflag == HALF || neighflag == HALFTHREAD) { + neighbor->requests[irequest]->full = 0; + neighbor->requests[irequest]->half = 1; + neighbor->requests[irequest]->full_cluster = 0; + } else { + error->all(FLERR,"Cannot use chosen neighbor list style with buck/coul/long/kk"); + } +} + +/* ---------------------------------------------------------------------- + init for one type pair i,j and corresponding j,i +------------------------------------------------------------------------- */ + +template +double PairBuckCoulLongKokkos::init_one(int i, int j) +{ + double cutone = PairBuckCoulLong::init_one(i,j); + double cut_ljsqm = cut_ljsq[i][j]; + double cut_coulsqm = cut_coulsq; + + k_params.h_view(i,j).a = a[i][j]; + k_params.h_view(i,j).c = c[i][j]; + k_params.h_view(i,j).rhoinv = rhoinv[i][j]; + k_params.h_view(i,j).buck1 = buck1[i][j]; + k_params.h_view(i,j).buck2 = buck2[i][j]; + k_params.h_view(i,j).offset = offset[i][j]; + k_params.h_view(i,j).cut_ljsq = cut_ljsqm; + k_params.h_view(i,j).cut_coulsq = cut_coulsqm; + + k_params.h_view(j,i) = k_params.h_view(i,j); + if(i(); + k_cut_ljsq.h_view(i,j) = cut_ljsqm; + k_cut_ljsq.template modify(); + k_cut_coulsq.h_view(i,j) = cut_coulsqm; + k_cut_coulsq.template modify(); + k_params.template modify(); + + return cutone; + +} + + +template class PairBuckCoulLongKokkos; +#ifdef KOKKOS_HAVE_CUDA +template class PairBuckCoulLongKokkos; +#endif diff --git a/src/KOKKOS/pair_buck_coul_long_kokkos.h b/src/KOKKOS/pair_buck_coul_long_kokkos.h new file mode 100644 index 0000000000..b4a0c96ff6 --- /dev/null +++ b/src/KOKKOS/pair_buck_coul_long_kokkos.h @@ -0,0 +1,150 @@ +/* -*- c++ -*- ---------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + http://lammps.sandia.gov, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +#ifdef PAIR_CLASS + +PairStyle(buck/coul/long/kk,PairBuckCoulLongKokkos) +PairStyle(buck/coul/long/kk/device,PairBuckCoulLongKokkos) +PairStyle(buck/coul/long/kk/host,PairBuckCoulLongKokkos) + +#else + +#ifndef LMP_PAIR_BUCK_COUL_LONG_KOKKOS_H +#define LMP_PAIR_BUCK_COUL_LONG_KOKKOS_H + +#include "pair_kokkos.h" +#include "pair_buck_coul_long.h" +#include "neigh_list_kokkos.h" + +namespace LAMMPS_NS { + +template +class PairBuckCoulLongKokkos : public PairBuckCoulLong { + public: + enum {EnabledNeighFlags=FULL|HALFTHREAD|HALF}; + enum {COUL_FLAG=1}; + typedef DeviceType device_type; + PairBuckCoulLongKokkos(class LAMMPS *); + ~PairBuckCoulLongKokkos(); + + void compute(int, int); + + void settings(int, char **); + void init_tables(double cut_coul, double *cut_respa); + void init_style(); + double init_one(int, int); + + struct params_buck_coul{ + params_buck_coul(){cut_ljsq=0;cut_coulsq=0;a=0;c=0;rhoinv=0;buck1=0;buck2=0;offset=0;}; + params_buck_coul(int i){cut_ljsq=0;cut_coulsq=0;a=0;c=0;rhoinv=0;buck1=0;buck2=0;offset=0;}; + F_FLOAT cut_ljsq,cut_coulsq,a,c,rhoinv,buck1,buck2,offset; + }; + + protected: + void cleanup_copy(); + + template + KOKKOS_INLINE_FUNCTION + F_FLOAT compute_fpair(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype) const; + + template + KOKKOS_INLINE_FUNCTION + F_FLOAT compute_fcoul(const F_FLOAT& rsq, const int& i, const int&j, const int& itype, + const int& jtype, const F_FLOAT& factor_coul, const F_FLOAT& qtmp) const; + + template + KOKKOS_INLINE_FUNCTION + F_FLOAT compute_evdwl(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype) const; + + template + KOKKOS_INLINE_FUNCTION + F_FLOAT compute_ecoul(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype, const F_FLOAT& factor_coul, const F_FLOAT& qtmp) const; + + Kokkos::DualView k_params; + typename Kokkos::DualView::t_dev_const params; + // hardwired to space for 15 atom types + params_buck_coul m_params[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; + + F_FLOAT m_cutsq[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; + F_FLOAT m_cut_ljsq[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; + F_FLOAT m_cut_coulsq[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; + typename ArrayTypes::t_x_array_randomread x; + typename ArrayTypes::t_x_array c_x; + typename ArrayTypes::t_f_array f; + typename ArrayTypes::t_int_1d_randomread type; + typename ArrayTypes::t_float_1d_randomread q; + + DAT::tdual_efloat_1d k_eatom; + DAT::tdual_virial_array k_vatom; + typename ArrayTypes::t_efloat_1d d_eatom; + typename ArrayTypes::t_virial_array d_vatom; + + int newton_pair; + + typename ArrayTypes::tdual_ffloat_2d k_cutsq; + typename ArrayTypes::t_ffloat_2d d_cutsq; + typename ArrayTypes::tdual_ffloat_2d k_cut_ljsq; + typename ArrayTypes::t_ffloat_2d d_cut_ljsq; + typename ArrayTypes::tdual_ffloat_2d k_cut_coulsq; + typename ArrayTypes::t_ffloat_2d d_cut_coulsq; + + typename ArrayTypes::t_ffloat_1d_randomread + d_rtable, d_drtable, d_ftable, d_dftable, + d_ctable, d_dctable, d_etable, d_detable; + class AtomKokkos *atomKK; + int neighflag; + int nlocal,nall,eflag,vflag; + + double special_lj[4], special_coul[4]; + double qqrd2e; + + void allocate(); + + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend EV_FLOAT pair_compute_neighlist >(PairBuckCoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist >(PairBuckCoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist >(PairBuckCoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute >(PairBuckCoulLongKokkos*, + NeighListKokkos*); + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend EV_FLOAT pair_compute_neighlist >(PairBuckCoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist >(PairBuckCoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist >(PairBuckCoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute >(PairBuckCoulLongKokkos*, + NeighListKokkos*); + friend void pair_virial_fdotr_compute(PairBuckCoulLongKokkos*); + +}; + +} + +#endif +#endif + +/* ERROR/WARNING messages: + +*/ diff --git a/src/KOKKOS/pair_coul_debye_kokkos.cpp b/src/KOKKOS/pair_coul_debye_kokkos.cpp new file mode 100644 index 0000000000..50fb7f8162 --- /dev/null +++ b/src/KOKKOS/pair_coul_debye_kokkos.cpp @@ -0,0 +1,313 @@ +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + http://lammps.sandia.gov, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +/* ---------------------------------------------------------------------- + Contributing author: Ray Shan (SNL) +------------------------------------------------------------------------- */ + +#include "math.h" +#include "stdio.h" +#include "stdlib.h" +#include "string.h" +#include "pair_coul_debye_kokkos.h" +#include "kokkos.h" +#include "atom_kokkos.h" +#include "comm.h" +#include "force.h" +#include "neighbor.h" +#include "neigh_list.h" +#include "neigh_request.h" +#include "update.h" +#include "integrate.h" +#include "respa.h" +#include "math_const.h" +#include "memory.h" +#include "error.h" +#include "atom_masks.h" + +using namespace LAMMPS_NS; +using namespace MathConst; + +#define KOKKOS_CUDA_MAX_THREADS 256 +#define KOKKOS_CUDA_MIN_BLOCKS 8 + +/* ---------------------------------------------------------------------- */ + +template +PairCoulDebyeKokkos::PairCoulDebyeKokkos(LAMMPS *lmp):PairCoulDebye(lmp) +{ + respa_enable = 0; + + atomKK = (AtomKokkos *) atom; + execution_space = ExecutionSpaceFromDevice::space; + datamask_read = X_MASK | F_MASK | TYPE_MASK | Q_MASK | ENERGY_MASK | VIRIAL_MASK; + datamask_modify = F_MASK | ENERGY_MASK | VIRIAL_MASK; + cutsq = NULL; + +} + +/* ---------------------------------------------------------------------- */ + +template +PairCoulDebyeKokkos::~PairCoulDebyeKokkos() +{ + if (!copymode) { + memory->destroy_kokkos(k_cutsq, cutsq); + } +} + +/* ---------------------------------------------------------------------- */ + +template +void PairCoulDebyeKokkos::cleanup_copy() { + // WHY needed: this prevents parent copy from deallocating any arrays + allocated = 0; + cutsq = NULL; + eatom = NULL; + vatom = NULL; +} + +/* ---------------------------------------------------------------------- */ + +template +void PairCoulDebyeKokkos::compute(int eflag_in, int vflag_in) +{ + eflag = eflag_in; + vflag = vflag_in; + + if (neighflag == FULL || neighflag == FULLCLUSTER) no_virial_fdotr_compute = 1; + + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = vflag_fdotr = 0; + + atomKK->sync(execution_space,datamask_read); + k_cutsq.template sync(); + k_cut_ljsq.template sync(); + k_cut_coulsq.template sync(); + k_params.template sync(); + if (eflag || vflag) atomKK->modified(execution_space,datamask_modify); + else atomKK->modified(execution_space,F_MASK); + + x = atomKK->k_x.view(); + c_x = atomKK->k_x.view(); + f = atomKK->k_f.view(); + q = atomKK->k_q.view(); + type = atomKK->k_type.view(); + nlocal = atom->nlocal; + nall = atom->nlocal + atom->nghost; + special_lj[0] = force->special_lj[0]; + special_lj[1] = force->special_lj[1]; + special_lj[2] = force->special_lj[2]; + special_lj[3] = force->special_lj[3]; + special_coul[0] = force->special_coul[0]; + special_coul[1] = force->special_coul[1]; + special_coul[2] = force->special_coul[2]; + special_coul[3] = force->special_coul[3]; + qqrd2e = force->qqrd2e; + newton_pair = force->newton_pair; + + // loop over neighbors of my atoms + + copymode = 1; + + EV_FLOAT ev = pair_compute,void > + (this,(NeighListKokkos*)list); + + DeviceType::fence(); + + if (eflag) { + eng_vdwl += ev.evdwl; + eng_coul += ev.ecoul; + } + if (vflag_global) { + virial[0] += ev.v[0]; + virial[1] += ev.v[1]; + virial[2] += ev.v[2]; + virial[3] += ev.v[3]; + virial[4] += ev.v[4]; + virial[5] += ev.v[5]; + } + + if (vflag_fdotr) virial_fdotr_compute(); + + copymode = 0; +} + +/* ---------------------------------------------------------------------- + compute coulomb pair force between atoms i and j + ---------------------------------------------------------------------- */ +template +template +KOKKOS_INLINE_FUNCTION +F_FLOAT PairCoulDebyeKokkos:: +compute_fcoul(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype, const F_FLOAT& factor_coul, const F_FLOAT& qtmp) const { + + const F_FLOAT r2inv = 1.0/rsq; + const F_FLOAT rinv = sqrt(r2inv); + const F_FLOAT r = 1.0/rinv; + const F_FLOAT screening = exp(-kappa*r); + F_FLOAT forcecoul; + + forcecoul = qqrd2e * qtmp * q(j) * screening * (kappa + rinv) * + (STACKPARAMS?m_params[itype][jtype].scale:params(itype,jtype).scale); + + return factor_coul*forcecoul*r2inv; + +} + +/* ---------------------------------------------------------------------- + compute coulomb pair potential energy between atoms i and j + ---------------------------------------------------------------------- */ +template +template +KOKKOS_INLINE_FUNCTION +F_FLOAT PairCoulDebyeKokkos:: +compute_ecoul(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype, const F_FLOAT& factor_coul, const F_FLOAT& qtmp) const { + + const F_FLOAT r2inv = 1.0/rsq; + const F_FLOAT rinv = sqrt(r2inv); + const F_FLOAT r = 1.0/rinv; + const F_FLOAT screening = exp(-kappa*r); + + return factor_coul * qqrd2e * qtmp * q(j) * rinv * screening * + (STACKPARAMS?m_params[itype][jtype].scale:params(itype,jtype).scale); + +} + +/* ---------------------------------------------------------------------- + allocate all arrays +------------------------------------------------------------------------- */ + +template +void PairCoulDebyeKokkos::allocate() +{ + PairCoulDebye::allocate(); + + int n = atom->ntypes; + memory->destroy(cutsq); + memory->create_kokkos(k_cutsq,cutsq,n+1,n+1,"pair:cutsq"); + d_cutsq = k_cutsq.template view(); + k_params = Kokkos::DualView("PairCoulDebye::params",n+1,n+1); + params = k_params.d_view; +} + +/* ---------------------------------------------------------------------- + global settings +------------------------------------------------------------------------- */ + +template +void PairCoulDebyeKokkos::settings(int narg, char **arg) +{ + if (narg > 2) error->all(FLERR,"Illegal pair_style command"); + + kappa = force->numeric(FLERR,arg[0]); + cut_global = force->numeric(FLERR,arg[1]); + + // reset cutoffs that have been explicitly set + + if (allocated) { + int i,j; + for (i = 1; i <= atom->ntypes; i++) + for (j = i+1; j <= atom->ntypes; j++) + if (setflag[i][j]) cut[i][j] = cut_global; + } + +} + +/* ---------------------------------------------------------------------- + init specific to this pair style +------------------------------------------------------------------------- */ + +template +void PairCoulDebyeKokkos::init_style() +{ + PairCoulDebye::init_style(); + + // error if rRESPA with inner levels + + if (update->whichflag == 1 && strstr(update->integrate_style,"respa")) { + int respa = 0; + if (((Respa *) update->integrate)->level_inner >= 0) respa = 1; + if (((Respa *) update->integrate)->level_middle >= 0) respa = 2; + if (respa) + error->all(FLERR,"Cannot use Kokkos pair style with rRESPA inner/middle"); + } + + // irequest = neigh request made by parent class + + neighflag = lmp->kokkos->neighflag; + int irequest = neighbor->nrequest - 1; + + neighbor->requests[irequest]-> + kokkos_host = Kokkos::Impl::is_same::value && + !Kokkos::Impl::is_same::value; + neighbor->requests[irequest]-> + kokkos_device = Kokkos::Impl::is_same::value; + + if (neighflag == FULL) { + neighbor->requests[irequest]->full = 1; + neighbor->requests[irequest]->half = 0; + neighbor->requests[irequest]->full_cluster = 0; + } else if (neighflag == HALF || neighflag == HALFTHREAD) { + neighbor->requests[irequest]->full = 0; + neighbor->requests[irequest]->half = 1; + neighbor->requests[irequest]->full_cluster = 0; + } else if (neighflag == N2) { + neighbor->requests[irequest]->full = 0; + neighbor->requests[irequest]->half = 0; + neighbor->requests[irequest]->full_cluster = 0; + } else if (neighflag == FULLCLUSTER) { + neighbor->requests[irequest]->full_cluster = 1; + neighbor->requests[irequest]->full = 1; + neighbor->requests[irequest]->half = 0; + } else { + error->all(FLERR,"Cannot use chosen neighbor list style with coul/debye/kk"); + } +} + +/* ---------------------------------------------------------------------- + init for one type pair i,j and corresponding j,i +------------------------------------------------------------------------- */ + +template +double PairCoulDebyeKokkos::init_one(int i, int j) +{ + double cutone = PairCoulDebye::init_one(i,j); + + k_params.h_view(i,j).scale = scale[i][j]; + k_params.h_view(i,j).cutsq = cutone*cutone; + k_params.h_view(j,i) = k_params.h_view(i,j); + + if(i(); + //k_cut_ljsq.h_view(i,j) = cutone*cutone; + k_cut_ljsq.template modify(); + //k_cut_coulsq.h_view(i,j) = cutone*cutone; + k_cut_coulsq.template modify(); + k_params.template modify(); + + return cutone; +} + +template class PairCoulDebyeKokkos; +#ifdef KOKKOS_HAVE_CUDA +template class PairCoulDebyeKokkos; +#endif diff --git a/src/KOKKOS/pair_coul_debye_kokkos.h b/src/KOKKOS/pair_coul_debye_kokkos.h new file mode 100644 index 0000000000..b5d77c0e38 --- /dev/null +++ b/src/KOKKOS/pair_coul_debye_kokkos.h @@ -0,0 +1,135 @@ +/* -*- c++ -*- ---------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + http://lammps.sandia.gov, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +#ifdef PAIR_CLASS + +PairStyle(coul/debye/kk,PairCoulDebyeKokkos) +PairStyle(coul/debye/kk/device,PairCoulDebyeKokkos) +PairStyle(coul/debye/kk/host,PairCoulDebyeKokkos) + +#else + +#ifndef LMP_PAIR_COUL_DEBYE_KOKKOS_H +#define LMP_PAIR_COUL_DEBYE_KOKKOS_H + +#include "pair_kokkos.h" +#include "pair_coul_debye.h" +#include "neigh_list_kokkos.h" + +namespace LAMMPS_NS { + +template +class PairCoulDebyeKokkos : public PairCoulDebye { + public: + enum {EnabledNeighFlags=FULL|HALFTHREAD|HALF}; + enum {COUL_FLAG=1}; + typedef DeviceType device_type; + PairCoulDebyeKokkos(class LAMMPS *); + ~PairCoulDebyeKokkos(); + + void compute(int, int); + + void settings(int, char **); + void init_style(); + double init_one(int, int); + + struct params_coul{ + params_coul(){cutsq=0,scale=0;}; + params_coul(int i){cutsq=0,scale=0;}; + F_FLOAT cutsq, scale; + }; + + protected: + void cleanup_copy(); + + template + KOKKOS_INLINE_FUNCTION + F_FLOAT compute_fpair(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype) const { + return 0.0; + } + + template + KOKKOS_INLINE_FUNCTION + F_FLOAT compute_fcoul(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype, const F_FLOAT& factor_coul, const F_FLOAT& qtmp) const; + + template + KOKKOS_INLINE_FUNCTION + F_FLOAT compute_evdwl(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype) const { + return 0.0; + } + + template + KOKKOS_INLINE_FUNCTION + F_FLOAT compute_ecoul(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype, const F_FLOAT& factor_coul, const F_FLOAT& qtmp) const; + + Kokkos::DualView k_params; + typename Kokkos::DualView::t_dev_const params; + // hardwired to space for 15 atom types + params_coul m_params[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; + + F_FLOAT m_cutsq[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; + F_FLOAT m_cut_ljsq[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; + F_FLOAT m_cut_coulsq[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; + typename ArrayTypes::t_x_array_randomread x; + typename ArrayTypes::t_x_array c_x; + typename ArrayTypes::t_f_array f; + typename ArrayTypes::t_int_1d_randomread type; + typename ArrayTypes::t_float_1d_randomread q; + typename ArrayTypes::t_efloat_1d d_eatom; + typename ArrayTypes::t_virial_array d_vatom; + + int newton_pair; + + typename ArrayTypes::tdual_ffloat_2d k_cutsq; + typename ArrayTypes::t_ffloat_2d d_cutsq; + typename ArrayTypes::tdual_ffloat_2d k_cut_ljsq; + typename ArrayTypes::t_ffloat_2d d_cut_ljsq; + typename ArrayTypes::tdual_ffloat_2d k_cut_coulsq; + typename ArrayTypes::t_ffloat_2d d_cut_coulsq; + + class AtomKokkos *atomKK; + int neighflag; + int nlocal,nall,eflag,vflag; + + double special_coul[4]; + double special_lj[4]; + double qqrd2e; + + void allocate(); + friend class PairComputeFunctor; + friend class PairComputeFunctor; + friend class PairComputeFunctor; + friend class PairComputeFunctor; + friend class PairComputeFunctor; + friend class PairComputeFunctor; + friend EV_FLOAT pair_compute_neighlist(PairCoulDebyeKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairCoulDebyeKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairCoulDebyeKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute(PairCoulDebyeKokkos*, + NeighListKokkos*); + +}; + +} + +#endif +#endif + +/* ERROR/WARNING messages: + +*/ diff --git a/src/KOKKOS/pair_coul_long_kokkos.cpp b/src/KOKKOS/pair_coul_long_kokkos.cpp new file mode 100644 index 0000000000..50cddc2c16 --- /dev/null +++ b/src/KOKKOS/pair_coul_long_kokkos.cpp @@ -0,0 +1,456 @@ +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + http://lammps.sandia.gov, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +/* ---------------------------------------------------------------------- + Contributing author: Ray Shan (SNL) +------------------------------------------------------------------------- */ + +#include "math.h" +#include "stdio.h" +#include "stdlib.h" +#include "string.h" +#include "pair_coul_long_kokkos.h" +#include "kokkos.h" +#include "atom_kokkos.h" +#include "comm.h" +#include "force.h" +#include "neighbor.h" +#include "neigh_list.h" +#include "neigh_request.h" +#include "update.h" +#include "integrate.h" +#include "respa.h" +#include "math_const.h" +#include "memory.h" +#include "error.h" +#include "atom_masks.h" + +using namespace LAMMPS_NS; +using namespace MathConst; + +#define KOKKOS_CUDA_MAX_THREADS 256 +#define KOKKOS_CUDA_MIN_BLOCKS 8 + + +#define EWALD_F 1.12837917 +#define EWALD_P 0.3275911 +#define A1 0.254829592 +#define A2 -0.284496736 +#define A3 1.421413741 +#define A4 -1.453152027 +#define A5 1.061405429 + +/* ---------------------------------------------------------------------- */ + +template +PairCoulLongKokkos::PairCoulLongKokkos(LAMMPS *lmp):PairCoulLong(lmp) +{ + respa_enable = 0; + + atomKK = (AtomKokkos *) atom; + execution_space = ExecutionSpaceFromDevice::space; + datamask_read = X_MASK | F_MASK | TYPE_MASK | Q_MASK | ENERGY_MASK | VIRIAL_MASK; + datamask_modify = F_MASK | ENERGY_MASK | VIRIAL_MASK; + cutsq = NULL; + cut_coulsq = 0.0; + +} + +/* ---------------------------------------------------------------------- */ + +template +PairCoulLongKokkos::~PairCoulLongKokkos() +{ + if (!copymode) { + memory->destroy_kokkos(k_eatom,eatom); + memory->destroy_kokkos(k_vatom,vatom); + k_cutsq = DAT::tdual_ffloat_2d(); + k_cut_coulsq = DAT::tdual_ffloat_2d(); + memory->sfree(cutsq); + eatom = NULL; + vatom = NULL; + cutsq = NULL; + } +} + +/* ---------------------------------------------------------------------- */ + +template +void PairCoulLongKokkos::cleanup_copy() { + allocated = 0; + cutsq = NULL; + eatom = NULL; + vatom = NULL; + ftable = NULL; +} + +/* ---------------------------------------------------------------------- */ + +template +void PairCoulLongKokkos::compute(int eflag_in, int vflag_in) +{ + eflag = eflag_in; + vflag = vflag_in; + + if (neighflag == FULL || neighflag == FULLCLUSTER) no_virial_fdotr_compute = 1; + + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = vflag_fdotr = 0; + + atomKK->sync(execution_space,datamask_read); + k_cutsq.template sync(); + k_cut_coulsq.template sync(); + k_params.template sync(); + if (eflag || vflag) atomKK->modified(execution_space,datamask_modify); + else atomKK->modified(execution_space,F_MASK); + + x = atomKK->k_x.view(); + c_x = atomKK->k_x.view(); + f = atomKK->k_f.view(); + q = atomKK->k_q.view(); + type = atomKK->k_type.view(); + nlocal = atom->nlocal; + nall = atom->nlocal + atom->nghost; + qqrd2e = force->qqrd2e; + newton_pair = force->newton_pair; + special_lj[0] = force->special_lj[0]; + special_lj[1] = force->special_lj[1]; + special_lj[2] = force->special_lj[2]; + special_lj[3] = force->special_lj[3]; + special_coul[0] = force->special_coul[0]; + special_coul[1] = force->special_coul[1]; + special_coul[2] = force->special_coul[2]; + special_coul[3] = force->special_coul[3]; + + // loop over neighbors of my atoms + + copymode = 1; + + EV_FLOAT ev; + if(ncoultablebits) + ev = pair_compute,CoulLongTable<1> > + (this,(NeighListKokkos*)list); + else + ev = pair_compute,CoulLongTable<0> > + (this,(NeighListKokkos*)list); + + + DeviceType::fence(); + + if (eflag) { + eng_vdwl += ev.evdwl; + eng_coul += ev.ecoul; + } + if (vflag_global) { + virial[0] += ev.v[0]; + virial[1] += ev.v[1]; + virial[2] += ev.v[2]; + virial[3] += ev.v[3]; + virial[4] += ev.v[4]; + virial[5] += ev.v[5]; + } + + if (vflag_fdotr) pair_virial_fdotr_compute(this); + + copymode = 0; +} + +/* ---------------------------------------------------------------------- + compute coulomb pair force between atoms i and j + ---------------------------------------------------------------------- */ + +template +template +KOKKOS_INLINE_FUNCTION +F_FLOAT PairCoulLongKokkos:: +compute_fcoul(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype, const F_FLOAT& factor_coul, const F_FLOAT& qtmp) const { + if(Specialisation::DoTable && rsq > tabinnersq) { + union_int_float_t rsq_lookup; + rsq_lookup.f = rsq; + const int itable = (rsq_lookup.i & ncoulmask) >> ncoulshiftbits; + const F_FLOAT fraction = (rsq_lookup.f - d_rtable[itable]) * d_drtable[itable]; + const F_FLOAT table = d_ftable[itable] + fraction*d_dftable[itable]; + F_FLOAT forcecoul = qtmp*q[j] * table; + if (factor_coul < 1.0) { + const F_FLOAT table = d_ctable[itable] + fraction*d_dctable[itable]; + const F_FLOAT prefactor = qtmp*q[j] * table; + forcecoul -= (1.0-factor_coul)*prefactor; + } + return forcecoul/rsq; + } else { + const F_FLOAT r = sqrt(rsq); + const F_FLOAT grij = g_ewald * r; + const F_FLOAT expm2 = exp(-grij*grij); + const F_FLOAT t = 1.0 / (1.0 + EWALD_P*grij); + const F_FLOAT rinv = 1.0/r; + const F_FLOAT erfc = t * (A1+t*(A2+t*(A3+t*(A4+t*A5)))) * expm2; + const F_FLOAT prefactor = qqrd2e * qtmp*q[j]*rinv; + F_FLOAT forcecoul = prefactor * (erfc + EWALD_F*grij*expm2); + if (factor_coul < 1.0) forcecoul -= (1.0-factor_coul)*prefactor; + + return forcecoul*rinv*rinv; + } +} + +/* ---------------------------------------------------------------------- + compute coulomb pair potential energy between atoms i and j + ---------------------------------------------------------------------- */ + +template +template +KOKKOS_INLINE_FUNCTION +F_FLOAT PairCoulLongKokkos:: +compute_ecoul(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype, const F_FLOAT& factor_coul, const F_FLOAT& qtmp) const { + if(Specialisation::DoTable) { + union_int_float_t rsq_lookup; + rsq_lookup.f = rsq; + const int itable = (rsq_lookup.i & ncoulmask) >> ncoulshiftbits; + const F_FLOAT fraction = (rsq_lookup.f - d_rtable[itable]) * d_drtable[itable]; + const F_FLOAT table = d_etable[itable] + fraction*d_detable[itable]; + F_FLOAT ecoul = qtmp*q[j] * table; + if (factor_coul < 1.0) { + const F_FLOAT table = d_ctable[itable] + fraction*d_dctable[itable]; + const F_FLOAT prefactor = qtmp*q[j] * table; + ecoul -= (1.0-factor_coul)*prefactor; + } + return ecoul; + } else { + const F_FLOAT r = sqrt(rsq); + const F_FLOAT grij = g_ewald * r; + const F_FLOAT expm2 = exp(-grij*grij); + const F_FLOAT t = 1.0 / (1.0 + EWALD_P*grij); + const F_FLOAT erfc = t * (A1+t*(A2+t*(A3+t*(A4+t*A5)))) * expm2; + const F_FLOAT prefactor = qqrd2e * qtmp*q[j]/r; + F_FLOAT ecoul = prefactor * erfc; + if (factor_coul < 1.0) ecoul -= (1.0-factor_coul)*prefactor; + return ecoul; + } +} + +/* ---------------------------------------------------------------------- + allocate all arrays +------------------------------------------------------------------------- */ + +template +void PairCoulLongKokkos::allocate() +{ + PairCoulLong::allocate(); + + int n = atom->ntypes; + + memory->destroy(cutsq); + memory->create_kokkos(k_cutsq,cutsq,n+1,n+1,"pair:cutsq"); + d_cutsq = k_cutsq.template view(); + + memory->create_kokkos(k_cut_coulsq,n+1,n+1,"pair:cut_coulsq"); + d_cut_coulsq = k_cut_coulsq.template view(); + + k_params = Kokkos::DualView("PairCoulLong::params",n+1,n+1); + params = k_params.d_view; +} + +template +void PairCoulLongKokkos::init_tables(double cut_coul, double *cut_respa) +{ + Pair::init_tables(cut_coul,cut_respa); + + typedef typename ArrayTypes::t_ffloat_1d table_type; + typedef typename ArrayTypes::t_ffloat_1d host_table_type; + + int ntable = 1; + for (int i = 0; i < ncoultablebits; i++) ntable *= 2; + + + // Copy rtable and drtable + { + host_table_type h_table("HostTable",ntable); + table_type d_table("DeviceTable",ntable); + for(int i = 0; i < ntable; i++) { + h_table(i) = rtable[i]; + } + Kokkos::deep_copy(d_table,h_table); + d_rtable = d_table; + } + + { + host_table_type h_table("HostTable",ntable); + table_type d_table("DeviceTable",ntable); + for(int i = 0; i < ntable; i++) { + h_table(i) = drtable[i]; + } + Kokkos::deep_copy(d_table,h_table); + d_drtable = d_table; + } + + { + host_table_type h_table("HostTable",ntable); + table_type d_table("DeviceTable",ntable); + + // Copy ftable and dftable + for(int i = 0; i < ntable; i++) { + h_table(i) = ftable[i]; + } + Kokkos::deep_copy(d_table,h_table); + d_ftable = d_table; + } + + { + host_table_type h_table("HostTable",ntable); + table_type d_table("DeviceTable",ntable); + + for(int i = 0; i < ntable; i++) { + h_table(i) = dftable[i]; + } + Kokkos::deep_copy(d_table,h_table); + d_dftable = d_table; + } + + { + host_table_type h_table("HostTable",ntable); + table_type d_table("DeviceTable",ntable); + + // Copy ctable and dctable + for(int i = 0; i < ntable; i++) { + h_table(i) = ctable[i]; + } + Kokkos::deep_copy(d_table,h_table); + d_ctable = d_table; + } + + { + host_table_type h_table("HostTable",ntable); + table_type d_table("DeviceTable",ntable); + + for(int i = 0; i < ntable; i++) { + h_table(i) = dctable[i]; + } + Kokkos::deep_copy(d_table,h_table); + d_dctable = d_table; + } + + { + host_table_type h_table("HostTable",ntable); + table_type d_table("DeviceTable",ntable); + + // Copy etable and detable + for(int i = 0; i < ntable; i++) { + h_table(i) = etable[i]; + } + Kokkos::deep_copy(d_table,h_table); + d_etable = d_table; + } + + { + host_table_type h_table("HostTable",ntable); + table_type d_table("DeviceTable",ntable); + + for(int i = 0; i < ntable; i++) { + h_table(i) = detable[i]; + } + Kokkos::deep_copy(d_table,h_table); + d_detable = d_table; + } +} + + +/* ---------------------------------------------------------------------- + global settings +------------------------------------------------------------------------- */ + +template +void PairCoulLongKokkos::settings(int narg, char **arg) +{ + if (narg > 2) error->all(FLERR,"Illegal pair_style command"); + + PairCoulLong::settings(narg,arg); +} + +/* ---------------------------------------------------------------------- + init specific to this pair style +------------------------------------------------------------------------- */ + +template +void PairCoulLongKokkos::init_style() +{ + PairCoulLong::init_style(); + + // error if rRESPA with inner levels + + if (update->whichflag == 1 && strstr(update->integrate_style,"respa")) { + int respa = 0; + if (((Respa *) update->integrate)->level_inner >= 0) respa = 1; + if (((Respa *) update->integrate)->level_middle >= 0) respa = 2; + if (respa) + error->all(FLERR,"Cannot use Kokkos pair style with rRESPA inner/middle"); + } + + // irequest = neigh request made by parent class + + neighflag = lmp->kokkos->neighflag; + int irequest = neighbor->nrequest - 1; + + neighbor->requests[irequest]-> + kokkos_host = Kokkos::Impl::is_same::value && + !Kokkos::Impl::is_same::value; + neighbor->requests[irequest]-> + kokkos_device = Kokkos::Impl::is_same::value; + + if (neighflag == FULL) { + neighbor->requests[irequest]->full = 1; + neighbor->requests[irequest]->half = 0; + neighbor->requests[irequest]->full_cluster = 0; + } else if (neighflag == HALF || neighflag == HALFTHREAD) { + neighbor->requests[irequest]->full = 0; + neighbor->requests[irequest]->half = 1; + neighbor->requests[irequest]->full_cluster = 0; + } else { + error->all(FLERR,"Cannot use chosen neighbor list style with buck/coul/long/kk"); + } +} + +/* ---------------------------------------------------------------------- + init for one type pair i,j and corresponding j,i +------------------------------------------------------------------------- */ + +template +double PairCoulLongKokkos::init_one(int i, int j) +{ + double cutone = PairCoulLong::init_one(i,j); + double cut_coulsqm = cut_coulsq; + + k_params.h_view(i,j).cut_coulsq = cut_coulsqm; + + k_params.h_view(j,i) = k_params.h_view(i,j); + if(i(); + k_cut_coulsq.h_view(i,j) = cut_coulsqm; + k_cut_coulsq.template modify(); + k_params.template modify(); + + return cutone; + +} + + +template class PairCoulLongKokkos; +#ifdef KOKKOS_HAVE_CUDA +template class PairCoulLongKokkos; +#endif diff --git a/src/KOKKOS/pair_coul_long_kokkos.h b/src/KOKKOS/pair_coul_long_kokkos.h new file mode 100644 index 0000000000..8325c200f5 --- /dev/null +++ b/src/KOKKOS/pair_coul_long_kokkos.h @@ -0,0 +1,154 @@ +/* -*- c++ -*- ---------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + http://lammps.sandia.gov, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +#ifdef PAIR_CLASS + +PairStyle(coul/long/kk,PairCoulLongKokkos) +PairStyle(coul/long/kk/device,PairCoulLongKokkos) +PairStyle(coul/long/kk/host,PairCoulLongKokkos) + +#else + +#ifndef LMP_PAIR_COUL_LONG_KOKKOS_H +#define LMP_PAIR_COUL_LONG_KOKKOS_H + +#include "pair_kokkos.h" +#include "pair_coul_long.h" +#include "neigh_list_kokkos.h" + +namespace LAMMPS_NS { + +template +class PairCoulLongKokkos : public PairCoulLong { + public: + enum {EnabledNeighFlags=FULL|HALFTHREAD|HALF}; + enum {COUL_FLAG=1}; + typedef DeviceType device_type; + PairCoulLongKokkos(class LAMMPS *); + ~PairCoulLongKokkos(); + + void compute(int, int); + + void settings(int, char **); + void init_tables(double cut_coul, double *cut_respa); + void init_style(); + double init_one(int, int); + + struct params_coul{ + params_coul(){cut_coulsq=0;}; + params_coul(int i){cut_coulsq=0;}; + F_FLOAT cut_coulsq; + }; + + protected: + void cleanup_copy(); + + template + KOKKOS_INLINE_FUNCTION + F_FLOAT compute_fpair(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype) const { + return 0.0; + } + + template + KOKKOS_INLINE_FUNCTION + F_FLOAT compute_fcoul(const F_FLOAT& rsq, const int& i, const int&j, const int& itype, + const int& jtype, const F_FLOAT& factor_coul, const F_FLOAT& qtmp) const; + + template + KOKKOS_INLINE_FUNCTION + F_FLOAT compute_evdwl(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype) const { + return 0.0; + } + + template + KOKKOS_INLINE_FUNCTION + F_FLOAT compute_ecoul(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype, const F_FLOAT& factor_coul, const F_FLOAT& qtmp) const; + + Kokkos::DualView k_params; + typename Kokkos::DualView::t_dev_const params; + // hardwired to space for 15 atom types + params_coul m_params[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; + + F_FLOAT m_cutsq[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; + F_FLOAT m_cut_ljsq[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; + F_FLOAT m_cut_coulsq[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; + typename ArrayTypes::t_x_array_randomread x; + typename ArrayTypes::t_x_array c_x; + typename ArrayTypes::t_f_array f; + typename ArrayTypes::t_int_1d_randomread type; + typename ArrayTypes::t_float_1d_randomread q; + + DAT::tdual_efloat_1d k_eatom; + DAT::tdual_virial_array k_vatom; + typename ArrayTypes::t_efloat_1d d_eatom; + typename ArrayTypes::t_virial_array d_vatom; + + int newton_pair; + + typename ArrayTypes::tdual_ffloat_2d k_cutsq; + typename ArrayTypes::t_ffloat_2d d_cutsq; + typename ArrayTypes::tdual_ffloat_2d k_cut_ljsq; + typename ArrayTypes::t_ffloat_2d d_cut_ljsq; + typename ArrayTypes::tdual_ffloat_2d k_cut_coulsq; + typename ArrayTypes::t_ffloat_2d d_cut_coulsq; + + typename ArrayTypes::t_ffloat_1d_randomread + d_rtable, d_drtable, d_ftable, d_dftable, + d_ctable, d_dctable, d_etable, d_detable; + class AtomKokkos *atomKK; + int neighflag; + int nlocal,nall,eflag,vflag; + + double special_lj[4], special_coul[4]; + double qqrd2e; + + void allocate(); + + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend EV_FLOAT pair_compute_neighlist >(PairCoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist >(PairCoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist >(PairCoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute >(PairCoulLongKokkos*, + NeighListKokkos*); + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend EV_FLOAT pair_compute_neighlist >(PairCoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist >(PairCoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist >(PairCoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute >(PairCoulLongKokkos*, + NeighListKokkos*); + friend void pair_virial_fdotr_compute(PairCoulLongKokkos*); + +}; + +} + +#endif +#endif + +/* ERROR/WARNING messages: + +*/ diff --git a/src/KOKKOS/pair_lj_charmm_coul_charmm_implicit_kokkos.cpp b/src/KOKKOS/pair_lj_charmm_coul_charmm_implicit_kokkos.cpp new file mode 100644 index 0000000000..8a0d35b1a5 --- /dev/null +++ b/src/KOKKOS/pair_lj_charmm_coul_charmm_implicit_kokkos.cpp @@ -0,0 +1,513 @@ +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + http://lammps.sandia.gov, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +/* ---------------------------------------------------------------------- + Contributing author: Ray Shan (SNL) +------------------------------------------------------------------------- */ + +#include "math.h" +#include "stdio.h" +#include "stdlib.h" +#include "string.h" +#include "pair_lj_charmm_coul_charmm_implicit_kokkos.h" +#include "kokkos.h" +#include "atom_kokkos.h" +#include "comm.h" +#include "force.h" +#include "neighbor.h" +#include "neigh_list.h" +#include "neigh_request.h" +#include "update.h" +#include "integrate.h" +#include "respa.h" +#include "math_const.h" +#include "memory.h" +#include "error.h" +#include "atom_masks.h" + +using namespace LAMMPS_NS; +using namespace MathConst; + +#define KOKKOS_CUDA_MAX_THREADS 256 +#define KOKKOS_CUDA_MIN_BLOCKS 8 + + +#define EWALD_F 1.12837917 +#define EWALD_P 0.3275911 +#define A1 0.254829592 +#define A2 -0.284496736 +#define A3 1.421413741 +#define A4 -1.453152027 +#define A5 1.061405429 + +/* ---------------------------------------------------------------------- */ + +template +PairLJCharmmCoulCharmmImplicitKokkos::PairLJCharmmCoulCharmmImplicitKokkos(LAMMPS *lmp):PairLJCharmmCoulCharmmImplicit(lmp) +{ + respa_enable = 0; + + atomKK = (AtomKokkos *) atom; + execution_space = ExecutionSpaceFromDevice::space; + datamask_read = X_MASK | F_MASK | TYPE_MASK | Q_MASK | ENERGY_MASK | VIRIAL_MASK; + datamask_modify = F_MASK | ENERGY_MASK | VIRIAL_MASK; + cutsq = NULL; + cut_ljsq = 0.0; + cut_coulsq = 0.0; + +} + +/* ---------------------------------------------------------------------- */ + +template +PairLJCharmmCoulCharmmImplicitKokkos::~PairLJCharmmCoulCharmmImplicitKokkos() +{ + if (!copymode) { + memory->destroy_kokkos(k_eatom,eatom); + memory->destroy_kokkos(k_vatom,vatom); + k_cutsq = DAT::tdual_ffloat_2d(); + k_cut_ljsq = DAT::tdual_ffloat_2d(); + k_cut_coulsq = DAT::tdual_ffloat_2d(); + memory->sfree(cutsq); + //memory->sfree(cut_ljsq); + //memory->sfree(cut_coulsq); + eatom = NULL; + vatom = NULL; + cutsq = NULL; + cut_ljsq = 0.0; + cut_coulsq = 0.0; + } +} + +/* ---------------------------------------------------------------------- */ + +template +void PairLJCharmmCoulCharmmImplicitKokkos::cleanup_copy() { + // WHY needed: this prevents parent copy from deallocating any arrays + allocated = 0; + cutsq = NULL; + cut_ljsq = 0.0; + eatom = NULL; + vatom = NULL; + ftable = NULL; +} + +/* ---------------------------------------------------------------------- */ + +template +void PairLJCharmmCoulCharmmImplicitKokkos::compute(int eflag_in, int vflag_in) +{ + eflag = eflag_in; + vflag = vflag_in; + + if (neighflag == FULL || neighflag == FULLCLUSTER) no_virial_fdotr_compute = 1; + + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = vflag_fdotr = 0; + + atomKK->sync(execution_space,datamask_read); + k_cutsq.template sync(); + k_cut_ljsq.template sync(); + k_cut_coulsq.template sync(); + k_params.template sync(); + if (eflag || vflag) atomKK->modified(execution_space,datamask_modify); + else atomKK->modified(execution_space,F_MASK); + + x = atomKK->k_x.view(); + c_x = atomKK->k_x.view(); + f = atomKK->k_f.view(); + q = atomKK->k_q.view(); + type = atomKK->k_type.view(); + nlocal = atom->nlocal; + nall = atom->nlocal + atom->nghost; + special_lj[0] = force->special_lj[0]; + special_lj[1] = force->special_lj[1]; + special_lj[2] = force->special_lj[2]; + special_lj[3] = force->special_lj[3]; + special_coul[0] = force->special_coul[0]; + special_coul[1] = force->special_coul[1]; + special_coul[2] = force->special_coul[2]; + special_coul[3] = force->special_coul[3]; + qqrd2e = force->qqrd2e; + newton_pair = force->newton_pair; + + // loop over neighbors of my atoms + + copymode = 1; + + EV_FLOAT ev; + if(ncoultablebits) + ev = pair_compute,CoulLongTable<1> > + (this,(NeighListKokkos*)list); + else + ev = pair_compute,CoulLongTable<0> > + (this,(NeighListKokkos*)list); + + + DeviceType::fence(); + + if (eflag) { + eng_vdwl += ev.evdwl; + eng_coul += ev.ecoul; + } + if (vflag_global) { + virial[0] += ev.v[0]; + virial[1] += ev.v[1]; + virial[2] += ev.v[2]; + virial[3] += ev.v[3]; + virial[4] += ev.v[4]; + virial[5] += ev.v[5]; + } + + if (vflag_fdotr) pair_virial_fdotr_compute(this); + + copymode = 0; +} + +/* ---------------------------------------------------------------------- + compute LJ CHARMM pair force between atoms i and j + ---------------------------------------------------------------------- */ +template +template +KOKKOS_INLINE_FUNCTION +F_FLOAT PairLJCharmmCoulCharmmImplicitKokkos:: +compute_fpair(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype) const { + const F_FLOAT r2inv = 1.0/rsq; + const F_FLOAT r6inv = r2inv*r2inv*r2inv; + F_FLOAT forcelj, switch1, switch2, englj; + + forcelj = r6inv * + ((STACKPARAMS?m_params[itype][jtype].lj1:params(itype,jtype).lj1)*r6inv - + (STACKPARAMS?m_params[itype][jtype].lj2:params(itype,jtype).lj2)); + + if (rsq > cut_lj_innersq) { + switch1 = (cut_ljsq-rsq) * (cut_ljsq-rsq) * + (cut_ljsq + 2.0*rsq - 3.0*cut_lj_innersq) / denom_lj; + switch2 = 12.0*rsq * (cut_ljsq-rsq) * (rsq-cut_lj_innersq) / denom_lj; + englj = r6inv * + ((STACKPARAMS?m_params[itype][jtype].lj3:params(itype,jtype).lj3)*r6inv - + (STACKPARAMS?m_params[itype][jtype].lj4:params(itype,jtype).lj4)); + forcelj = forcelj*switch1 + englj*switch2; + } + + return forcelj*r2inv; +} + +/* ---------------------------------------------------------------------- + compute LJ CHARMM pair potential energy between atoms i and j + ---------------------------------------------------------------------- */ +template +template +KOKKOS_INLINE_FUNCTION +F_FLOAT PairLJCharmmCoulCharmmImplicitKokkos:: +compute_evdwl(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype) const { + const F_FLOAT r2inv = 1.0/rsq; + const F_FLOAT r6inv = r2inv*r2inv*r2inv; + F_FLOAT englj, switch1; + + englj = r6inv * + ((STACKPARAMS?m_params[itype][jtype].lj3:params(itype,jtype).lj3)*r6inv - + (STACKPARAMS?m_params[itype][jtype].lj4:params(itype,jtype).lj4)); + + if (rsq > cut_lj_innersq) { + switch1 = (cut_ljsq-rsq) * (cut_ljsq-rsq) * + (cut_ljsq + 2.0*rsq - 3.0*cut_lj_innersq) / denom_lj; + englj *= switch1; + } + + return englj; + +} + +/* ---------------------------------------------------------------------- + compute coulomb pair force between atoms i and j + ---------------------------------------------------------------------- */ +template +template +KOKKOS_INLINE_FUNCTION +F_FLOAT PairLJCharmmCoulCharmmImplicitKokkos:: +compute_fcoul(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype, const F_FLOAT& factor_coul, const F_FLOAT& qtmp) const { + + const F_FLOAT r2inv = 1.0/rsq; + F_FLOAT forcecoul, switch1, switch2; + + forcecoul = 2.0 * qqrd2e * qtmp*q(j) * r2inv; + + if (rsq > cut_coul_innersq) { + switch1 = (cut_coulsq-rsq) * (cut_coulsq-rsq) * + (cut_coulsq + 2.0*rsq - 3.0*cut_coul_innersq) / denom_coul; + switch2 = 12.0*rsq * (cut_coulsq-rsq) * (rsq-cut_coul_innersq) / denom_coul; + forcecoul *= switch1 + 0.5*switch2; + } + + return forcecoul * r2inv * factor_coul; + +} + +/* ---------------------------------------------------------------------- + compute coulomb pair potential energy between atoms i and j + ---------------------------------------------------------------------- */ +template +template +KOKKOS_INLINE_FUNCTION +F_FLOAT PairLJCharmmCoulCharmmImplicitKokkos:: +compute_ecoul(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype, const F_FLOAT& factor_coul, const F_FLOAT& qtmp) const { + + const F_FLOAT r2inv = 1.0/rsq; + F_FLOAT ecoul, switch1; + + ecoul = qqrd2e * qtmp * q(j) * r2inv; + if (rsq > cut_coul_innersq) { + switch1 = (cut_coulsq-rsq) * (cut_coulsq-rsq) * + (cut_coulsq + 2.0*rsq - 3.0*cut_coul_innersq) / + denom_coul; + ecoul *= switch1; + } + + return ecoul * factor_coul; + +} + +/* ---------------------------------------------------------------------- + allocate all arrays +------------------------------------------------------------------------- */ + +template +void PairLJCharmmCoulCharmmImplicitKokkos::allocate() +{ + PairLJCharmmCoulCharmmImplicit::allocate(); + + int n = atom->ntypes; + + memory->destroy(cutsq); + memory->create_kokkos(k_cutsq,cutsq,n+1,n+1,"pair:cutsq"); + d_cutsq = k_cutsq.template view(); + + //memory->destroy(cut_ljsq); + memory->create_kokkos(k_cut_ljsq,n+1,n+1,"pair:cut_ljsq"); + d_cut_ljsq = k_cut_ljsq.template view(); + + memory->create_kokkos(k_cut_coulsq,n+1,n+1,"pair:cut_coulsq"); + d_cut_coulsq = k_cut_coulsq.template view(); + + k_params = Kokkos::DualView("PairLJCharmmCoulCharmmImplicit::params",n+1,n+1); + params = k_params.d_view; +} + +template +void PairLJCharmmCoulCharmmImplicitKokkos::init_tables(double cut_coul, double *cut_respa) +{ + Pair::init_tables(cut_coul,cut_respa); + + typedef typename ArrayTypes::t_ffloat_1d table_type; + typedef typename ArrayTypes::t_ffloat_1d host_table_type; + + int ntable = 1; + for (int i = 0; i < ncoultablebits; i++) ntable *= 2; + + + // Copy rtable and drtable + { + host_table_type h_table("HostTable",ntable); + table_type d_table("DeviceTable",ntable); + for(int i = 0; i < ntable; i++) { + h_table(i) = rtable[i]; + } + Kokkos::deep_copy(d_table,h_table); + d_rtable = d_table; + } + + { + host_table_type h_table("HostTable",ntable); + table_type d_table("DeviceTable",ntable); + for(int i = 0; i < ntable; i++) { + h_table(i) = drtable[i]; + } + Kokkos::deep_copy(d_table,h_table); + d_drtable = d_table; + } + + { + host_table_type h_table("HostTable",ntable); + table_type d_table("DeviceTable",ntable); + + // Copy ftable and dftable + for(int i = 0; i < ntable; i++) { + h_table(i) = ftable[i]; + } + Kokkos::deep_copy(d_table,h_table); + d_ftable = d_table; + } + + { + host_table_type h_table("HostTable",ntable); + table_type d_table("DeviceTable",ntable); + + for(int i = 0; i < ntable; i++) { + h_table(i) = dftable[i]; + } + Kokkos::deep_copy(d_table,h_table); + d_dftable = d_table; + } + + { + host_table_type h_table("HostTable",ntable); + table_type d_table("DeviceTable",ntable); + + // Copy ctable and dctable + for(int i = 0; i < ntable; i++) { + h_table(i) = ctable[i]; + } + Kokkos::deep_copy(d_table,h_table); + d_ctable = d_table; + } + + { + host_table_type h_table("HostTable",ntable); + table_type d_table("DeviceTable",ntable); + + for(int i = 0; i < ntable; i++) { + h_table(i) = dctable[i]; + } + Kokkos::deep_copy(d_table,h_table); + d_dctable = d_table; + } + + { + host_table_type h_table("HostTable",ntable); + table_type d_table("DeviceTable",ntable); + + // Copy etable and detable + for(int i = 0; i < ntable; i++) { + h_table(i) = etable[i]; + } + Kokkos::deep_copy(d_table,h_table); + d_etable = d_table; + } + + { + host_table_type h_table("HostTable",ntable); + table_type d_table("DeviceTable",ntable); + + for(int i = 0; i < ntable; i++) { + h_table(i) = detable[i]; + } + Kokkos::deep_copy(d_table,h_table); + d_detable = d_table; + } +} + + +/* ---------------------------------------------------------------------- + global settings +------------------------------------------------------------------------- */ + +template +void PairLJCharmmCoulCharmmImplicitKokkos::settings(int narg, char **arg) +{ + if (narg > 2) error->all(FLERR,"Illegal pair_style command"); + + PairLJCharmmCoulCharmmImplicit::settings(narg,arg); +} + +/* ---------------------------------------------------------------------- + init specific to this pair style +------------------------------------------------------------------------- */ + +template +void PairLJCharmmCoulCharmmImplicitKokkos::init_style() +{ + PairLJCharmmCoulCharmmImplicit::init_style(); + + // error if rRESPA with inner levels + + if (update->whichflag == 1 && strstr(update->integrate_style,"respa")) { + int respa = 0; + if (((Respa *) update->integrate)->level_inner >= 0) respa = 1; + if (((Respa *) update->integrate)->level_middle >= 0) respa = 2; + if (respa) + error->all(FLERR,"Cannot use Kokkos pair style with rRESPA inner/middle"); + } + + // irequest = neigh request made by parent class + + neighflag = lmp->kokkos->neighflag; + int irequest = neighbor->nrequest - 1; + + neighbor->requests[irequest]-> + kokkos_host = Kokkos::Impl::is_same::value && + !Kokkos::Impl::is_same::value; + neighbor->requests[irequest]-> + kokkos_device = Kokkos::Impl::is_same::value; + + if (neighflag == FULL) { + neighbor->requests[irequest]->full = 1; + neighbor->requests[irequest]->half = 0; + neighbor->requests[irequest]->full_cluster = 0; + } else if (neighflag == HALF || neighflag == HALFTHREAD) { + neighbor->requests[irequest]->full = 0; + neighbor->requests[irequest]->half = 1; + neighbor->requests[irequest]->full_cluster = 0; + } else { + error->all(FLERR,"Cannot use chosen neighbor list style with lj/charmm/coul/charmm/implicit/kk"); + } +} + +/* ---------------------------------------------------------------------- + init for one type pair i,j and corresponding j,i +------------------------------------------------------------------------- */ + +template +double PairLJCharmmCoulCharmmImplicitKokkos::init_one(int i, int j) +{ + double cutone = PairLJCharmmCoulCharmmImplicit::init_one(i,j); + double cut_ljsqm = cut_ljsq; + double cut_coulsqm = cut_coulsq; + + k_params.h_view(i,j).lj1 = lj1[i][j]; + k_params.h_view(i,j).lj2 = lj2[i][j]; + k_params.h_view(i,j).lj3 = lj3[i][j]; + k_params.h_view(i,j).lj4 = lj4[i][j]; + //k_params.h_view(i,j).offset = offset[i][j]; + k_params.h_view(i,j).cut_ljsq = cut_ljsqm; + k_params.h_view(i,j).cut_coulsq = cut_coulsqm; + + k_params.h_view(j,i) = k_params.h_view(i,j); + if(i(); + k_cut_ljsq.h_view(i,j) = cut_ljsqm; + k_cut_ljsq.template modify(); + k_cut_coulsq.h_view(i,j) = cut_coulsqm; + k_cut_coulsq.template modify(); + k_params.template modify(); + + return cutone; +} + + + +template class PairLJCharmmCoulCharmmImplicitKokkos; +#ifdef KOKKOS_HAVE_CUDA +template class PairLJCharmmCoulCharmmImplicitKokkos; +#endif diff --git a/src/KOKKOS/pair_lj_charmm_coul_charmm_implicit_kokkos.h b/src/KOKKOS/pair_lj_charmm_coul_charmm_implicit_kokkos.h new file mode 100644 index 0000000000..1db2157b6d --- /dev/null +++ b/src/KOKKOS/pair_lj_charmm_coul_charmm_implicit_kokkos.h @@ -0,0 +1,151 @@ +/* -*- c++ -*- ---------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + http://lammps.sandia.gov, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +#ifdef PAIR_CLASS + +PairStyle(lj/charmm/coul/charmm/implicit/kk,PairLJCharmmCoulCharmmImplicitKokkos) +PairStyle(lj/charmm/coul/charmm/implicit/kk/device,PairLJCharmmCoulCharmmImplicitKokkos) +PairStyle(lj/charmm/coul/charmm/implicit/kk/host,PairLJCharmmCoulCharmmImplicitKokkos) + +#else + +#ifndef LMP_PAIR_LJ_CHARMM_COUL_CHARMM_IMPLICIT_KOKKOS_H +#define LMP_PAIR_LJ_CHARMM_COUL_CHARMM_IMPLICIT_KOKKOS_H + +#include "pair_kokkos.h" +#include "pair_lj_charmm_coul_charmm_implicit.h" +#include "neigh_list_kokkos.h" + +namespace LAMMPS_NS { + +template +class PairLJCharmmCoulCharmmImplicitKokkos : public PairLJCharmmCoulCharmmImplicit { + public: + enum {EnabledNeighFlags=FULL|HALFTHREAD|HALF}; + enum {COUL_FLAG=1}; + typedef DeviceType device_type; + PairLJCharmmCoulCharmmImplicitKokkos(class LAMMPS *); + ~PairLJCharmmCoulCharmmImplicitKokkos(); + + void compute(int, int); + + void settings(int, char **); + void init_tables(double cut_coul, double *cut_respa); + void init_style(); + double init_one(int, int); + + struct params_lj_coul{ + params_lj_coul(){cut_ljsq=0;cut_coulsq=0;lj1=0;lj2=0;lj3=0;lj4=0;offset=0;}; + params_lj_coul(int i){cut_ljsq=0;cut_coulsq=0;lj1=0;lj2=0;lj3=0;lj4=0;offset=0;}; + F_FLOAT cut_ljsq,cut_coulsq,lj1,lj2,lj3,lj4,offset; + }; + + protected: + void cleanup_copy(); + + template + KOKKOS_INLINE_FUNCTION + F_FLOAT compute_fpair(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype) const; + + template + KOKKOS_INLINE_FUNCTION + F_FLOAT compute_fcoul(const F_FLOAT& rsq, const int& i, const int&j, const int& itype, + const int& jtype, const F_FLOAT& factor_coul, const F_FLOAT& qtmp) const; + + template + KOKKOS_INLINE_FUNCTION + F_FLOAT compute_evdwl(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype) const; + + template + KOKKOS_INLINE_FUNCTION + F_FLOAT compute_ecoul(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype, const F_FLOAT& factor_coul, const F_FLOAT& qtmp) const; + + Kokkos::DualView k_params; + typename Kokkos::DualView::t_dev_const params; + // hardwired to space for 15 atom types + params_lj_coul m_params[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; + + F_FLOAT m_cutsq[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; + F_FLOAT m_cut_ljsq[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; + F_FLOAT m_cut_coulsq[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; + typename ArrayTypes::t_x_array_randomread x; + typename ArrayTypes::t_x_array c_x; + typename ArrayTypes::t_f_array f; + typename ArrayTypes::t_int_1d_randomread type; + typename ArrayTypes::t_float_1d_randomread q; + + DAT::tdual_efloat_1d k_eatom; + DAT::tdual_virial_array k_vatom; + typename ArrayTypes::t_efloat_1d d_eatom; + typename ArrayTypes::t_virial_array d_vatom; + + int newton_pair; + + typename ArrayTypes::tdual_ffloat_2d k_cutsq; + typename ArrayTypes::t_ffloat_2d d_cutsq; + typename ArrayTypes::tdual_ffloat_2d k_cut_ljsq; + typename ArrayTypes::t_ffloat_2d d_cut_ljsq; + typename ArrayTypes::tdual_ffloat_2d k_cut_coulsq; + typename ArrayTypes::t_ffloat_2d d_cut_coulsq; + + typename ArrayTypes::t_ffloat_1d_randomread + d_rtable, d_drtable, d_ftable, d_dftable, + d_ctable, d_dctable, d_etable, d_detable; + class AtomKokkos *atomKK; + int neighflag; + int nlocal,nall,eflag,vflag; + + double special_coul[4]; + double special_lj[4]; + double qqrd2e; + + void allocate(); + + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend EV_FLOAT pair_compute_neighlist >(PairLJCharmmCoulCharmmImplicitKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist >(PairLJCharmmCoulCharmmImplicitKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist >(PairLJCharmmCoulCharmmImplicitKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute >(PairLJCharmmCoulCharmmImplicitKokkos*, + NeighListKokkos*); + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend EV_FLOAT pair_compute_neighlist >(PairLJCharmmCoulCharmmImplicitKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist >(PairLJCharmmCoulCharmmImplicitKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist >(PairLJCharmmCoulCharmmImplicitKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute >(PairLJCharmmCoulCharmmImplicitKokkos*, + NeighListKokkos*); + friend void pair_virial_fdotr_compute(PairLJCharmmCoulCharmmImplicitKokkos*); + +}; + +} + +#endif +#endif + +/* ERROR/WARNING messages: + +*/ diff --git a/src/KOKKOS/pair_lj_charmm_coul_charmm_kokkos.cpp b/src/KOKKOS/pair_lj_charmm_coul_charmm_kokkos.cpp new file mode 100644 index 0000000000..1e270731f1 --- /dev/null +++ b/src/KOKKOS/pair_lj_charmm_coul_charmm_kokkos.cpp @@ -0,0 +1,515 @@ +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + http://lammps.sandia.gov, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +/* ---------------------------------------------------------------------- + Contributing author: Ray Shan (SNL) +------------------------------------------------------------------------- */ + +#include "math.h" +#include "stdio.h" +#include "stdlib.h" +#include "string.h" +#include "pair_lj_charmm_coul_charmm_kokkos.h" +#include "kokkos.h" +#include "atom_kokkos.h" +#include "comm.h" +#include "force.h" +#include "neighbor.h" +#include "neigh_list.h" +#include "neigh_request.h" +#include "update.h" +#include "integrate.h" +#include "respa.h" +#include "math_const.h" +#include "memory.h" +#include "error.h" +#include "atom_masks.h" + +using namespace LAMMPS_NS; +using namespace MathConst; + +#define KOKKOS_CUDA_MAX_THREADS 256 +#define KOKKOS_CUDA_MIN_BLOCKS 8 + + +#define EWALD_F 1.12837917 +#define EWALD_P 0.3275911 +#define A1 0.254829592 +#define A2 -0.284496736 +#define A3 1.421413741 +#define A4 -1.453152027 +#define A5 1.061405429 + +/* ---------------------------------------------------------------------- */ + +template +PairLJCharmmCoulCharmmKokkos::PairLJCharmmCoulCharmmKokkos(LAMMPS *lmp):PairLJCharmmCoulCharmm(lmp) +{ + respa_enable = 0; + + atomKK = (AtomKokkos *) atom; + execution_space = ExecutionSpaceFromDevice::space; + datamask_read = X_MASK | F_MASK | TYPE_MASK | Q_MASK | ENERGY_MASK | VIRIAL_MASK; + datamask_modify = F_MASK | ENERGY_MASK | VIRIAL_MASK; + cutsq = NULL; + cut_ljsq = 0.0; + cut_coulsq = 0.0; + +} + +/* ---------------------------------------------------------------------- */ + +template +PairLJCharmmCoulCharmmKokkos::~PairLJCharmmCoulCharmmKokkos() +{ + if (!copymode) { + memory->destroy_kokkos(k_eatom,eatom); + memory->destroy_kokkos(k_vatom,vatom); + k_cutsq = DAT::tdual_ffloat_2d(); + k_cut_ljsq = DAT::tdual_ffloat_2d(); + k_cut_coulsq = DAT::tdual_ffloat_2d(); + memory->sfree(cutsq); + //memory->sfree(cut_ljsq); + //memory->sfree(cut_coulsq); + eatom = NULL; + vatom = NULL; + cutsq = NULL; + cut_ljsq = 0.0; + cut_coulsq = 0.0; + } +} + +/* ---------------------------------------------------------------------- */ + +template +void PairLJCharmmCoulCharmmKokkos::cleanup_copy() { + // WHY needed: this prevents parent copy from deallocating any arrays + allocated = 0; + cutsq = NULL; + cut_ljsq = 0.0; + eatom = NULL; + vatom = NULL; + ftable = NULL; +} + +/* ---------------------------------------------------------------------- */ + +template +void PairLJCharmmCoulCharmmKokkos::compute(int eflag_in, int vflag_in) +{ + eflag = eflag_in; + vflag = vflag_in; + + if (neighflag == FULL || neighflag == FULLCLUSTER) no_virial_fdotr_compute = 1; + + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = vflag_fdotr = 0; + + atomKK->sync(execution_space,datamask_read); + k_cutsq.template sync(); + k_cut_ljsq.template sync(); + k_cut_coulsq.template sync(); + k_params.template sync(); + if (eflag || vflag) atomKK->modified(execution_space,datamask_modify); + else atomKK->modified(execution_space,F_MASK); + + x = atomKK->k_x.view(); + c_x = atomKK->k_x.view(); + f = atomKK->k_f.view(); + q = atomKK->k_q.view(); + type = atomKK->k_type.view(); + nlocal = atom->nlocal; + nall = atom->nlocal + atom->nghost; + special_lj[0] = force->special_lj[0]; + special_lj[1] = force->special_lj[1]; + special_lj[2] = force->special_lj[2]; + special_lj[3] = force->special_lj[3]; + special_coul[0] = force->special_coul[0]; + special_coul[1] = force->special_coul[1]; + special_coul[2] = force->special_coul[2]; + special_coul[3] = force->special_coul[3]; + qqrd2e = force->qqrd2e; + newton_pair = force->newton_pair; + + // loop over neighbors of my atoms + + copymode = 1; + + EV_FLOAT ev; + if(ncoultablebits) + ev = pair_compute,CoulLongTable<1> > + (this,(NeighListKokkos*)list); + else + ev = pair_compute,CoulLongTable<0> > + (this,(NeighListKokkos*)list); + + + DeviceType::fence(); + + if (eflag) { + eng_vdwl += ev.evdwl; + eng_coul += ev.ecoul; + } + if (vflag_global) { + virial[0] += ev.v[0]; + virial[1] += ev.v[1]; + virial[2] += ev.v[2]; + virial[3] += ev.v[3]; + virial[4] += ev.v[4]; + virial[5] += ev.v[5]; + } + + if (vflag_fdotr) pair_virial_fdotr_compute(this); + + copymode = 0; +} + +/* ---------------------------------------------------------------------- + compute LJ CHARMM pair force between atoms i and j + ---------------------------------------------------------------------- */ +template +template +KOKKOS_INLINE_FUNCTION +F_FLOAT PairLJCharmmCoulCharmmKokkos:: +compute_fpair(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype) const { + const F_FLOAT r2inv = 1.0/rsq; + const F_FLOAT r6inv = r2inv*r2inv*r2inv; + F_FLOAT forcelj, switch1, switch2, englj; + + forcelj = r6inv * + ((STACKPARAMS?m_params[itype][jtype].lj1:params(itype,jtype).lj1)*r6inv - + (STACKPARAMS?m_params[itype][jtype].lj2:params(itype,jtype).lj2)); + + if (rsq > cut_lj_innersq) { + switch1 = (cut_ljsq-rsq) * (cut_ljsq-rsq) * + (cut_ljsq + 2.0*rsq - 3.0*cut_lj_innersq) / denom_lj; + switch2 = 12.0*rsq * (cut_ljsq-rsq) * (rsq-cut_lj_innersq) / denom_lj; + englj = r6inv * + ((STACKPARAMS?m_params[itype][jtype].lj3:params(itype,jtype).lj3)*r6inv - + (STACKPARAMS?m_params[itype][jtype].lj4:params(itype,jtype).lj4)); + forcelj = forcelj*switch1 + englj*switch2; + } + + return forcelj*r2inv; +} + +/* ---------------------------------------------------------------------- + compute LJ CHARMM pair potential energy between atoms i and j + ---------------------------------------------------------------------- */ +template +template +KOKKOS_INLINE_FUNCTION +F_FLOAT PairLJCharmmCoulCharmmKokkos:: +compute_evdwl(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype) const { + const F_FLOAT r2inv = 1.0/rsq; + const F_FLOAT r6inv = r2inv*r2inv*r2inv; + F_FLOAT englj, switch1; + + englj = r6inv * + ((STACKPARAMS?m_params[itype][jtype].lj3:params(itype,jtype).lj3)*r6inv - + (STACKPARAMS?m_params[itype][jtype].lj4:params(itype,jtype).lj4)); + + if (rsq > cut_lj_innersq) { + switch1 = (cut_ljsq-rsq) * (cut_ljsq-rsq) * + (cut_ljsq + 2.0*rsq - 3.0*cut_lj_innersq) / denom_lj; + englj *= switch1; + } + + return englj; + +} + +/* ---------------------------------------------------------------------- + compute coulomb pair force between atoms i and j + ---------------------------------------------------------------------- */ +template +template +KOKKOS_INLINE_FUNCTION +F_FLOAT PairLJCharmmCoulCharmmKokkos:: +compute_fcoul(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype, const F_FLOAT& factor_coul, const F_FLOAT& qtmp) const { + + const F_FLOAT r2inv = 1.0/rsq; + const F_FLOAT rinv = sqrt(r2inv); + F_FLOAT forcecoul, switch1, switch2; + + forcecoul = qqrd2e*qtmp*q(j) *rinv; + + if (rsq > cut_coul_innersq) { + switch1 = (cut_coulsq-rsq) * (cut_coulsq-rsq) * + (cut_coulsq + 2.0*rsq - 3.0*cut_coul_innersq) / denom_coul; + switch2 = 12.0*rsq * (cut_coulsq-rsq) * (rsq-cut_coul_innersq) / denom_coul; + forcecoul *= switch1 + switch2; + } + + return forcecoul * r2inv * factor_coul; + +} + +/* ---------------------------------------------------------------------- + compute coulomb pair potential energy between atoms i and j + ---------------------------------------------------------------------- */ +template +template +KOKKOS_INLINE_FUNCTION +F_FLOAT PairLJCharmmCoulCharmmKokkos:: +compute_ecoul(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype, const F_FLOAT& factor_coul, const F_FLOAT& qtmp) const { + + const F_FLOAT r2inv = 1.0/rsq; + const F_FLOAT rinv = sqrt(r2inv); + F_FLOAT ecoul, switch1; + + ecoul = qqrd2e * qtmp * q(j) * rinv; + if (rsq > cut_coul_innersq) { + switch1 = (cut_coulsq-rsq) * (cut_coulsq-rsq) * + (cut_coulsq + 2.0*rsq - 3.0*cut_coul_innersq) / + denom_coul; + ecoul *= switch1; + } + + return ecoul * factor_coul; + +} + +/* ---------------------------------------------------------------------- + allocate all arrays +------------------------------------------------------------------------- */ + +template +void PairLJCharmmCoulCharmmKokkos::allocate() +{ + PairLJCharmmCoulCharmm::allocate(); + + int n = atom->ntypes; + + memory->destroy(cutsq); + memory->create_kokkos(k_cutsq,cutsq,n+1,n+1,"pair:cutsq"); + d_cutsq = k_cutsq.template view(); + + //memory->destroy(cut_ljsq); + memory->create_kokkos(k_cut_ljsq,n+1,n+1,"pair:cut_ljsq"); + d_cut_ljsq = k_cut_ljsq.template view(); + + memory->create_kokkos(k_cut_coulsq,n+1,n+1,"pair:cut_coulsq"); + d_cut_coulsq = k_cut_coulsq.template view(); + + k_params = Kokkos::DualView("PairLJCharmmCoulCharmm::params",n+1,n+1); + params = k_params.d_view; +} + +template +void PairLJCharmmCoulCharmmKokkos::init_tables(double cut_coul, double *cut_respa) +{ + Pair::init_tables(cut_coul,cut_respa); + + typedef typename ArrayTypes::t_ffloat_1d table_type; + typedef typename ArrayTypes::t_ffloat_1d host_table_type; + + int ntable = 1; + for (int i = 0; i < ncoultablebits; i++) ntable *= 2; + + + // Copy rtable and drtable + { + host_table_type h_table("HostTable",ntable); + table_type d_table("DeviceTable",ntable); + for(int i = 0; i < ntable; i++) { + h_table(i) = rtable[i]; + } + Kokkos::deep_copy(d_table,h_table); + d_rtable = d_table; + } + + { + host_table_type h_table("HostTable",ntable); + table_type d_table("DeviceTable",ntable); + for(int i = 0; i < ntable; i++) { + h_table(i) = drtable[i]; + } + Kokkos::deep_copy(d_table,h_table); + d_drtable = d_table; + } + + { + host_table_type h_table("HostTable",ntable); + table_type d_table("DeviceTable",ntable); + + // Copy ftable and dftable + for(int i = 0; i < ntable; i++) { + h_table(i) = ftable[i]; + } + Kokkos::deep_copy(d_table,h_table); + d_ftable = d_table; + } + + { + host_table_type h_table("HostTable",ntable); + table_type d_table("DeviceTable",ntable); + + for(int i = 0; i < ntable; i++) { + h_table(i) = dftable[i]; + } + Kokkos::deep_copy(d_table,h_table); + d_dftable = d_table; + } + + { + host_table_type h_table("HostTable",ntable); + table_type d_table("DeviceTable",ntable); + + // Copy ctable and dctable + for(int i = 0; i < ntable; i++) { + h_table(i) = ctable[i]; + } + Kokkos::deep_copy(d_table,h_table); + d_ctable = d_table; + } + + { + host_table_type h_table("HostTable",ntable); + table_type d_table("DeviceTable",ntable); + + for(int i = 0; i < ntable; i++) { + h_table(i) = dctable[i]; + } + Kokkos::deep_copy(d_table,h_table); + d_dctable = d_table; + } + + { + host_table_type h_table("HostTable",ntable); + table_type d_table("DeviceTable",ntable); + + // Copy etable and detable + for(int i = 0; i < ntable; i++) { + h_table(i) = etable[i]; + } + Kokkos::deep_copy(d_table,h_table); + d_etable = d_table; + } + + { + host_table_type h_table("HostTable",ntable); + table_type d_table("DeviceTable",ntable); + + for(int i = 0; i < ntable; i++) { + h_table(i) = detable[i]; + } + Kokkos::deep_copy(d_table,h_table); + d_detable = d_table; + } +} + + +/* ---------------------------------------------------------------------- + global settings +------------------------------------------------------------------------- */ + +template +void PairLJCharmmCoulCharmmKokkos::settings(int narg, char **arg) +{ + if (narg > 2) error->all(FLERR,"Illegal pair_style command"); + + PairLJCharmmCoulCharmm::settings(narg,arg); +} + +/* ---------------------------------------------------------------------- + init specific to this pair style +------------------------------------------------------------------------- */ + +template +void PairLJCharmmCoulCharmmKokkos::init_style() +{ + PairLJCharmmCoulCharmm::init_style(); + + // error if rRESPA with inner levels + + if (update->whichflag == 1 && strstr(update->integrate_style,"respa")) { + int respa = 0; + if (((Respa *) update->integrate)->level_inner >= 0) respa = 1; + if (((Respa *) update->integrate)->level_middle >= 0) respa = 2; + if (respa) + error->all(FLERR,"Cannot use Kokkos pair style with rRESPA inner/middle"); + } + + // irequest = neigh request made by parent class + + neighflag = lmp->kokkos->neighflag; + int irequest = neighbor->nrequest - 1; + + neighbor->requests[irequest]-> + kokkos_host = Kokkos::Impl::is_same::value && + !Kokkos::Impl::is_same::value; + neighbor->requests[irequest]-> + kokkos_device = Kokkos::Impl::is_same::value; + + if (neighflag == FULL) { + neighbor->requests[irequest]->full = 1; + neighbor->requests[irequest]->half = 0; + neighbor->requests[irequest]->full_cluster = 0; + } else if (neighflag == HALF || neighflag == HALFTHREAD) { + neighbor->requests[irequest]->full = 0; + neighbor->requests[irequest]->half = 1; + neighbor->requests[irequest]->full_cluster = 0; + } else { + error->all(FLERR,"Cannot use chosen neighbor list style with lj/charmm/coul/charmm/kk"); + } +} + +/* ---------------------------------------------------------------------- + init for one type pair i,j and corresponding j,i +------------------------------------------------------------------------- */ + +template +double PairLJCharmmCoulCharmmKokkos::init_one(int i, int j) +{ + double cutone = PairLJCharmmCoulCharmm::init_one(i,j); + double cut_ljsqm = cut_ljsq; + double cut_coulsqm = cut_coulsq; + + k_params.h_view(i,j).lj1 = lj1[i][j]; + k_params.h_view(i,j).lj2 = lj2[i][j]; + k_params.h_view(i,j).lj3 = lj3[i][j]; + k_params.h_view(i,j).lj4 = lj4[i][j]; + //k_params.h_view(i,j).offset = offset[i][j]; + k_params.h_view(i,j).cut_ljsq = cut_ljsqm; + k_params.h_view(i,j).cut_coulsq = cut_coulsqm; + + k_params.h_view(j,i) = k_params.h_view(i,j); + if(i(); + k_cut_ljsq.h_view(i,j) = cut_ljsqm; + k_cut_ljsq.template modify(); + k_cut_coulsq.h_view(i,j) = cut_coulsqm; + k_cut_coulsq.template modify(); + k_params.template modify(); + + return cutone; +} + + + +template class PairLJCharmmCoulCharmmKokkos; +#ifdef KOKKOS_HAVE_CUDA +template class PairLJCharmmCoulCharmmKokkos; +#endif diff --git a/src/KOKKOS/pair_lj_charmm_coul_charmm_kokkos.h b/src/KOKKOS/pair_lj_charmm_coul_charmm_kokkos.h new file mode 100644 index 0000000000..74b7629ee3 --- /dev/null +++ b/src/KOKKOS/pair_lj_charmm_coul_charmm_kokkos.h @@ -0,0 +1,151 @@ +/* -*- c++ -*- ---------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + http://lammps.sandia.gov, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +#ifdef PAIR_CLASS + +PairStyle(lj/charmm/coul/charmm/kk,PairLJCharmmCoulCharmmKokkos) +PairStyle(lj/charmm/coul/charmm/kk/device,PairLJCharmmCoulCharmmKokkos) +PairStyle(lj/charmm/coul/charmm/kk/host,PairLJCharmmCoulCharmmKokkos) + +#else + +#ifndef LMP_PAIR_LJ_CHARMM_COUL_CHARMM_KOKKOS_H +#define LMP_PAIR_LJ_CHARMM_COUL_CHARMM_KOKKOS_H + +#include "pair_kokkos.h" +#include "pair_lj_charmm_coul_charmm.h" +#include "neigh_list_kokkos.h" + +namespace LAMMPS_NS { + +template +class PairLJCharmmCoulCharmmKokkos : public PairLJCharmmCoulCharmm { + public: + enum {EnabledNeighFlags=FULL|HALFTHREAD|HALF}; + enum {COUL_FLAG=1}; + typedef DeviceType device_type; + PairLJCharmmCoulCharmmKokkos(class LAMMPS *); + ~PairLJCharmmCoulCharmmKokkos(); + + void compute(int, int); + + void settings(int, char **); + void init_tables(double cut_coul, double *cut_respa); + void init_style(); + double init_one(int, int); + + struct params_lj_coul{ + params_lj_coul(){cut_ljsq=0;cut_coulsq=0;lj1=0;lj2=0;lj3=0;lj4=0;offset=0;}; + params_lj_coul(int i){cut_ljsq=0;cut_coulsq=0;lj1=0;lj2=0;lj3=0;lj4=0;offset=0;}; + F_FLOAT cut_ljsq,cut_coulsq,lj1,lj2,lj3,lj4,offset; + }; + + protected: + void cleanup_copy(); + + template + KOKKOS_INLINE_FUNCTION + F_FLOAT compute_fpair(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype) const; + + template + KOKKOS_INLINE_FUNCTION + F_FLOAT compute_fcoul(const F_FLOAT& rsq, const int& i, const int&j, const int& itype, + const int& jtype, const F_FLOAT& factor_coul, const F_FLOAT& qtmp) const; + + template + KOKKOS_INLINE_FUNCTION + F_FLOAT compute_evdwl(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype) const; + + template + KOKKOS_INLINE_FUNCTION + F_FLOAT compute_ecoul(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype, const F_FLOAT& factor_coul, const F_FLOAT& qtmp) const; + + Kokkos::DualView k_params; + typename Kokkos::DualView::t_dev_const params; + // hardwired to space for 15 atom types + params_lj_coul m_params[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; + + F_FLOAT m_cutsq[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; + F_FLOAT m_cut_ljsq[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; + F_FLOAT m_cut_coulsq[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; + typename ArrayTypes::t_x_array_randomread x; + typename ArrayTypes::t_x_array c_x; + typename ArrayTypes::t_f_array f; + typename ArrayTypes::t_int_1d_randomread type; + typename ArrayTypes::t_float_1d_randomread q; + + DAT::tdual_efloat_1d k_eatom; + DAT::tdual_virial_array k_vatom; + typename ArrayTypes::t_efloat_1d d_eatom; + typename ArrayTypes::t_virial_array d_vatom; + + int newton_pair; + + typename ArrayTypes::tdual_ffloat_2d k_cutsq; + typename ArrayTypes::t_ffloat_2d d_cutsq; + typename ArrayTypes::tdual_ffloat_2d k_cut_ljsq; + typename ArrayTypes::t_ffloat_2d d_cut_ljsq; + typename ArrayTypes::tdual_ffloat_2d k_cut_coulsq; + typename ArrayTypes::t_ffloat_2d d_cut_coulsq; + + typename ArrayTypes::t_ffloat_1d_randomread + d_rtable, d_drtable, d_ftable, d_dftable, + d_ctable, d_dctable, d_etable, d_detable; + class AtomKokkos *atomKK; + int neighflag; + int nlocal,nall,eflag,vflag; + + double special_coul[4]; + double special_lj[4]; + double qqrd2e; + + void allocate(); + + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend EV_FLOAT pair_compute_neighlist >(PairLJCharmmCoulCharmmKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist >(PairLJCharmmCoulCharmmKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist >(PairLJCharmmCoulCharmmKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute >(PairLJCharmmCoulCharmmKokkos*, + NeighListKokkos*); + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend EV_FLOAT pair_compute_neighlist >(PairLJCharmmCoulCharmmKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist >(PairLJCharmmCoulCharmmKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist >(PairLJCharmmCoulCharmmKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute >(PairLJCharmmCoulCharmmKokkos*, + NeighListKokkos*); + friend void pair_virial_fdotr_compute(PairLJCharmmCoulCharmmKokkos*); + +}; + +} + +#endif +#endif + +/* ERROR/WARNING messages: + +*/ diff --git a/src/KOKKOS/pair_lj_charmm_coul_long_kokkos.cpp b/src/KOKKOS/pair_lj_charmm_coul_long_kokkos.cpp new file mode 100644 index 0000000000..26119671fd --- /dev/null +++ b/src/KOKKOS/pair_lj_charmm_coul_long_kokkos.cpp @@ -0,0 +1,534 @@ +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + http://lammps.sandia.gov, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +/* ---------------------------------------------------------------------- + Contributing author: Ray Shan (SNL) +------------------------------------------------------------------------- */ + +#include "math.h" +#include "stdio.h" +#include "stdlib.h" +#include "string.h" +#include "pair_lj_charmm_coul_long_kokkos.h" +#include "kokkos.h" +#include "atom_kokkos.h" +#include "comm.h" +#include "force.h" +#include "neighbor.h" +#include "neigh_list.h" +#include "neigh_request.h" +#include "update.h" +#include "integrate.h" +#include "respa.h" +#include "math_const.h" +#include "memory.h" +#include "error.h" +#include "atom_masks.h" + +using namespace LAMMPS_NS; +using namespace MathConst; + +#define KOKKOS_CUDA_MAX_THREADS 256 +#define KOKKOS_CUDA_MIN_BLOCKS 8 + + +#define EWALD_F 1.12837917 +#define EWALD_P 0.3275911 +#define A1 0.254829592 +#define A2 -0.284496736 +#define A3 1.421413741 +#define A4 -1.453152027 +#define A5 1.061405429 + +/* ---------------------------------------------------------------------- */ + +template +PairLJCharmmCoulLongKokkos::PairLJCharmmCoulLongKokkos(LAMMPS *lmp):PairLJCharmmCoulLong(lmp) +{ + respa_enable = 0; + + atomKK = (AtomKokkos *) atom; + execution_space = ExecutionSpaceFromDevice::space; + datamask_read = X_MASK | F_MASK | TYPE_MASK | Q_MASK | ENERGY_MASK | VIRIAL_MASK; + datamask_modify = F_MASK | ENERGY_MASK | VIRIAL_MASK; + cutsq = NULL; + cut_ljsq = 0.0; + cut_coulsq = 0.0; + +} + +/* ---------------------------------------------------------------------- */ + +template +PairLJCharmmCoulLongKokkos::~PairLJCharmmCoulLongKokkos() +{ + if (!copymode) { + memory->destroy_kokkos(k_eatom,eatom); + memory->destroy_kokkos(k_vatom,vatom); + k_cutsq = DAT::tdual_ffloat_2d(); + k_cut_ljsq = DAT::tdual_ffloat_2d(); + k_cut_coulsq = DAT::tdual_ffloat_2d(); + memory->sfree(cutsq); + //memory->sfree(cut_ljsq); + //memory->sfree(cut_coulsq); + eatom = NULL; + vatom = NULL; + cutsq = NULL; + cut_ljsq = 0.0; + cut_coulsq = 0.0; + } +} + +/* ---------------------------------------------------------------------- */ + +template +void PairLJCharmmCoulLongKokkos::cleanup_copy() { + // WHY needed: this prevents parent copy from deallocating any arrays + allocated = 0; + cutsq = NULL; + cut_ljsq = 0.0; + eatom = NULL; + vatom = NULL; + ftable = NULL; +} + +/* ---------------------------------------------------------------------- */ + +template +void PairLJCharmmCoulLongKokkos::compute(int eflag_in, int vflag_in) +{ + eflag = eflag_in; + vflag = vflag_in; + + if (neighflag == FULL || neighflag == FULLCLUSTER) no_virial_fdotr_compute = 1; + + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = vflag_fdotr = 0; + + atomKK->sync(execution_space,datamask_read); + k_cutsq.template sync(); + k_cut_ljsq.template sync(); + k_cut_coulsq.template sync(); + k_params.template sync(); + if (eflag || vflag) atomKK->modified(execution_space,datamask_modify); + else atomKK->modified(execution_space,F_MASK); + + x = atomKK->k_x.view(); + c_x = atomKK->k_x.view(); + f = atomKK->k_f.view(); + q = atomKK->k_q.view(); + type = atomKK->k_type.view(); + nlocal = atom->nlocal; + nall = atom->nlocal + atom->nghost; + special_lj[0] = force->special_lj[0]; + special_lj[1] = force->special_lj[1]; + special_lj[2] = force->special_lj[2]; + special_lj[3] = force->special_lj[3]; + special_coul[0] = force->special_coul[0]; + special_coul[1] = force->special_coul[1]; + special_coul[2] = force->special_coul[2]; + special_coul[3] = force->special_coul[3]; + qqrd2e = force->qqrd2e; + newton_pair = force->newton_pair; + + // loop over neighbors of my atoms + + copymode = 1; + + EV_FLOAT ev; + if(ncoultablebits) + ev = pair_compute,CoulLongTable<1> > + (this,(NeighListKokkos*)list); + else + ev = pair_compute,CoulLongTable<0> > + (this,(NeighListKokkos*)list); + + + DeviceType::fence(); + + if (eflag) { + eng_vdwl += ev.evdwl; + eng_coul += ev.ecoul; + } + if (vflag_global) { + virial[0] += ev.v[0]; + virial[1] += ev.v[1]; + virial[2] += ev.v[2]; + virial[3] += ev.v[3]; + virial[4] += ev.v[4]; + virial[5] += ev.v[5]; + } + + if (vflag_fdotr) pair_virial_fdotr_compute(this); + + copymode = 0; +} + +/* ---------------------------------------------------------------------- + compute LJ CHARMM pair force between atoms i and j + ---------------------------------------------------------------------- */ +template +template +KOKKOS_INLINE_FUNCTION +F_FLOAT PairLJCharmmCoulLongKokkos:: +compute_fpair(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype) const { + const F_FLOAT r2inv = 1.0/rsq; + const F_FLOAT r6inv = r2inv*r2inv*r2inv; + F_FLOAT forcelj, switch1, switch2, englj; + + forcelj = r6inv * + ((STACKPARAMS?m_params[itype][jtype].lj1:params(itype,jtype).lj1)*r6inv - + (STACKPARAMS?m_params[itype][jtype].lj2:params(itype,jtype).lj2)); + + if (rsq > cut_lj_innersq) { + switch1 = (cut_ljsq-rsq) * (cut_ljsq-rsq) * + (cut_ljsq + 2.0*rsq - 3.0*cut_lj_innersq) / denom_lj; + switch2 = 12.0*rsq * (cut_ljsq-rsq) * (rsq-cut_lj_innersq) / denom_lj; + englj = r6inv * + ((STACKPARAMS?m_params[itype][jtype].lj3:params(itype,jtype).lj3)*r6inv - + (STACKPARAMS?m_params[itype][jtype].lj4:params(itype,jtype).lj4)); + forcelj = forcelj*switch1 + englj*switch2; + } + + return forcelj*r2inv; +} + +/* ---------------------------------------------------------------------- + compute LJ CHARMM pair potential energy between atoms i and j + ---------------------------------------------------------------------- */ +template +template +KOKKOS_INLINE_FUNCTION +F_FLOAT PairLJCharmmCoulLongKokkos:: +compute_evdwl(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype) const { + const F_FLOAT r2inv = 1.0/rsq; + const F_FLOAT r6inv = r2inv*r2inv*r2inv; + F_FLOAT englj, switch1; + + englj = r6inv * + ((STACKPARAMS?m_params[itype][jtype].lj3:params(itype,jtype).lj3)*r6inv - + (STACKPARAMS?m_params[itype][jtype].lj4:params(itype,jtype).lj4)); + + if (rsq > cut_lj_innersq) { + switch1 = (cut_ljsq-rsq) * (cut_ljsq-rsq) * + (cut_ljsq + 2.0*rsq - 3.0*cut_lj_innersq) / denom_lj; + englj *= switch1; + } + + return englj; + +} + +/* ---------------------------------------------------------------------- + compute coulomb pair force between atoms i and j + ---------------------------------------------------------------------- */ +template +template +KOKKOS_INLINE_FUNCTION +F_FLOAT PairLJCharmmCoulLongKokkos:: +compute_fcoul(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype, const F_FLOAT& factor_coul, const F_FLOAT& qtmp) const { + if(Specialisation::DoTable && rsq > tabinnersq) { + union_int_float_t rsq_lookup; + rsq_lookup.f = rsq; + const int itable = (rsq_lookup.i & ncoulmask) >> ncoulshiftbits; + const F_FLOAT fraction = (rsq_lookup.f - d_rtable[itable]) * d_drtable[itable]; + const F_FLOAT table = d_ftable[itable] + fraction*d_dftable[itable]; + F_FLOAT forcecoul = qtmp*q[j] * table; + if (factor_coul < 1.0) { + const F_FLOAT table = d_ctable[itable] + fraction*d_dctable[itable]; + const F_FLOAT prefactor = qtmp*q[j] * table; + forcecoul -= (1.0-factor_coul)*prefactor; + } + return forcecoul/rsq; + } else { + const F_FLOAT r = sqrt(rsq); + const F_FLOAT grij = g_ewald * r; + const F_FLOAT expm2 = exp(-grij*grij); + const F_FLOAT t = 1.0 / (1.0 + EWALD_P*grij); + const F_FLOAT rinv = 1.0/r; + const F_FLOAT erfc = t * (A1+t*(A2+t*(A3+t*(A4+t*A5)))) * expm2; + const F_FLOAT prefactor = qqrd2e * qtmp*q[j]*rinv; + F_FLOAT forcecoul = prefactor * (erfc + EWALD_F*grij*expm2); + if (factor_coul < 1.0) forcecoul -= (1.0-factor_coul)*prefactor; + + return forcecoul*rinv*rinv; + } +} + +/* ---------------------------------------------------------------------- + compute coulomb pair potential energy between atoms i and j + ---------------------------------------------------------------------- */ +template +template +KOKKOS_INLINE_FUNCTION +F_FLOAT PairLJCharmmCoulLongKokkos:: +compute_ecoul(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype, const F_FLOAT& factor_coul, const F_FLOAT& qtmp) const { + if(Specialisation::DoTable) { + union_int_float_t rsq_lookup; + rsq_lookup.f = rsq; + const int itable = (rsq_lookup.i & ncoulmask) >> ncoulshiftbits; + const F_FLOAT fraction = (rsq_lookup.f - d_rtable[itable]) * d_drtable[itable]; + const F_FLOAT table = d_etable[itable] + fraction*d_detable[itable]; + F_FLOAT ecoul = qtmp*q[j] * table; + if (factor_coul < 1.0) { + const F_FLOAT table = d_ctable[itable] + fraction*d_dctable[itable]; + const F_FLOAT prefactor = qtmp*q[j] * table; + ecoul -= (1.0-factor_coul)*prefactor; + } + return ecoul; + } else { + const F_FLOAT r = sqrt(rsq); + const F_FLOAT grij = g_ewald * r; + const F_FLOAT expm2 = exp(-grij*grij); + const F_FLOAT t = 1.0 / (1.0 + EWALD_P*grij); + const F_FLOAT erfc = t * (A1+t*(A2+t*(A3+t*(A4+t*A5)))) * expm2; + const F_FLOAT prefactor = qqrd2e * qtmp*q[j]/r; + F_FLOAT ecoul = prefactor * erfc; + if (factor_coul < 1.0) ecoul -= (1.0-factor_coul)*prefactor; + return ecoul; + } +} + +/* ---------------------------------------------------------------------- + allocate all arrays +------------------------------------------------------------------------- */ + +template +void PairLJCharmmCoulLongKokkos::allocate() +{ + PairLJCharmmCoulLong::allocate(); + + int n = atom->ntypes; + + memory->destroy(cutsq); + memory->create_kokkos(k_cutsq,cutsq,n+1,n+1,"pair:cutsq"); + d_cutsq = k_cutsq.template view(); + + //memory->destroy(cut_ljsq); + memory->create_kokkos(k_cut_ljsq,n+1,n+1,"pair:cut_ljsq"); + d_cut_ljsq = k_cut_ljsq.template view(); + + memory->create_kokkos(k_cut_coulsq,n+1,n+1,"pair:cut_coulsq"); + d_cut_coulsq = k_cut_coulsq.template view(); + + k_params = Kokkos::DualView("PairLJCharmmCoulLong::params",n+1,n+1); + params = k_params.d_view; +} + +template +void PairLJCharmmCoulLongKokkos::init_tables(double cut_coul, double *cut_respa) +{ + Pair::init_tables(cut_coul,cut_respa); + + typedef typename ArrayTypes::t_ffloat_1d table_type; + typedef typename ArrayTypes::t_ffloat_1d host_table_type; + + int ntable = 1; + for (int i = 0; i < ncoultablebits; i++) ntable *= 2; + + + // Copy rtable and drtable + { + host_table_type h_table("HostTable",ntable); + table_type d_table("DeviceTable",ntable); + for(int i = 0; i < ntable; i++) { + h_table(i) = rtable[i]; + } + Kokkos::deep_copy(d_table,h_table); + d_rtable = d_table; + } + + { + host_table_type h_table("HostTable",ntable); + table_type d_table("DeviceTable",ntable); + for(int i = 0; i < ntable; i++) { + h_table(i) = drtable[i]; + } + Kokkos::deep_copy(d_table,h_table); + d_drtable = d_table; + } + + { + host_table_type h_table("HostTable",ntable); + table_type d_table("DeviceTable",ntable); + + // Copy ftable and dftable + for(int i = 0; i < ntable; i++) { + h_table(i) = ftable[i]; + } + Kokkos::deep_copy(d_table,h_table); + d_ftable = d_table; + } + + { + host_table_type h_table("HostTable",ntable); + table_type d_table("DeviceTable",ntable); + + for(int i = 0; i < ntable; i++) { + h_table(i) = dftable[i]; + } + Kokkos::deep_copy(d_table,h_table); + d_dftable = d_table; + } + + { + host_table_type h_table("HostTable",ntable); + table_type d_table("DeviceTable",ntable); + + // Copy ctable and dctable + for(int i = 0; i < ntable; i++) { + h_table(i) = ctable[i]; + } + Kokkos::deep_copy(d_table,h_table); + d_ctable = d_table; + } + + { + host_table_type h_table("HostTable",ntable); + table_type d_table("DeviceTable",ntable); + + for(int i = 0; i < ntable; i++) { + h_table(i) = dctable[i]; + } + Kokkos::deep_copy(d_table,h_table); + d_dctable = d_table; + } + + { + host_table_type h_table("HostTable",ntable); + table_type d_table("DeviceTable",ntable); + + // Copy etable and detable + for(int i = 0; i < ntable; i++) { + h_table(i) = etable[i]; + } + Kokkos::deep_copy(d_table,h_table); + d_etable = d_table; + } + + { + host_table_type h_table("HostTable",ntable); + table_type d_table("DeviceTable",ntable); + + for(int i = 0; i < ntable; i++) { + h_table(i) = detable[i]; + } + Kokkos::deep_copy(d_table,h_table); + d_detable = d_table; + } +} + + +/* ---------------------------------------------------------------------- + global settings +------------------------------------------------------------------------- */ + +template +void PairLJCharmmCoulLongKokkos::settings(int narg, char **arg) +{ + if (narg > 2) error->all(FLERR,"Illegal pair_style command"); + + PairLJCharmmCoulLong::settings(narg,arg); +} + +/* ---------------------------------------------------------------------- + init specific to this pair style +------------------------------------------------------------------------- */ + +template +void PairLJCharmmCoulLongKokkos::init_style() +{ + PairLJCharmmCoulLong::init_style(); + + // error if rRESPA with inner levels + + if (update->whichflag == 1 && strstr(update->integrate_style,"respa")) { + int respa = 0; + if (((Respa *) update->integrate)->level_inner >= 0) respa = 1; + if (((Respa *) update->integrate)->level_middle >= 0) respa = 2; + if (respa) + error->all(FLERR,"Cannot use Kokkos pair style with rRESPA inner/middle"); + } + + // irequest = neigh request made by parent class + + neighflag = lmp->kokkos->neighflag; + int irequest = neighbor->nrequest - 1; + + neighbor->requests[irequest]-> + kokkos_host = Kokkos::Impl::is_same::value && + !Kokkos::Impl::is_same::value; + neighbor->requests[irequest]-> + kokkos_device = Kokkos::Impl::is_same::value; + + if (neighflag == FULL) { + neighbor->requests[irequest]->full = 1; + neighbor->requests[irequest]->half = 0; + neighbor->requests[irequest]->full_cluster = 0; + } else if (neighflag == HALF || neighflag == HALFTHREAD) { + neighbor->requests[irequest]->full = 0; + neighbor->requests[irequest]->half = 1; + neighbor->requests[irequest]->full_cluster = 0; + } else { + error->all(FLERR,"Cannot use chosen neighbor list style with lj/charmm/coul/long/kk"); + } +} + +/* ---------------------------------------------------------------------- + init for one type pair i,j and corresponding j,i +------------------------------------------------------------------------- */ + +template +double PairLJCharmmCoulLongKokkos::init_one(int i, int j) +{ + double cutone = PairLJCharmmCoulLong::init_one(i,j); + double cut_ljsqm = cut_ljsq; + double cut_coulsqm = cut_coulsq; + + k_params.h_view(i,j).lj1 = lj1[i][j]; + k_params.h_view(i,j).lj2 = lj2[i][j]; + k_params.h_view(i,j).lj3 = lj3[i][j]; + k_params.h_view(i,j).lj4 = lj4[i][j]; + //k_params.h_view(i,j).offset = offset[i][j]; + k_params.h_view(i,j).cut_ljsq = cut_ljsqm; + k_params.h_view(i,j).cut_coulsq = cut_coulsqm; + + k_params.h_view(j,i) = k_params.h_view(i,j); + if(i(); + k_cut_ljsq.h_view(i,j) = cut_ljsqm; + k_cut_ljsq.template modify(); + k_cut_coulsq.h_view(i,j) = cut_coulsqm; + k_cut_coulsq.template modify(); + k_params.template modify(); + + return cutone; +} + + + +template class PairLJCharmmCoulLongKokkos; +#ifdef KOKKOS_HAVE_CUDA +template class PairLJCharmmCoulLongKokkos; +#endif diff --git a/src/KOKKOS/pair_lj_charmm_coul_long_kokkos.h b/src/KOKKOS/pair_lj_charmm_coul_long_kokkos.h new file mode 100644 index 0000000000..0b9e7d48c6 --- /dev/null +++ b/src/KOKKOS/pair_lj_charmm_coul_long_kokkos.h @@ -0,0 +1,151 @@ +/* -*- c++ -*- ---------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + http://lammps.sandia.gov, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +#ifdef PAIR_CLASS + +PairStyle(lj/charmm/coul/long/kk,PairLJCharmmCoulLongKokkos) +PairStyle(lj/charmm/coul/long/kk/device,PairLJCharmmCoulLongKokkos) +PairStyle(lj/charmm/coul/long/kk/host,PairLJCharmmCoulLongKokkos) + +#else + +#ifndef LMP_PAIR_LJ_CHARMM_COUL_LONG_KOKKOS_H +#define LMP_PAIR_LJ_CHARMM_COUL_LONG_KOKKOS_H + +#include "pair_kokkos.h" +#include "pair_lj_charmm_coul_long.h" +#include "neigh_list_kokkos.h" + +namespace LAMMPS_NS { + +template +class PairLJCharmmCoulLongKokkos : public PairLJCharmmCoulLong { + public: + enum {EnabledNeighFlags=FULL|HALFTHREAD|HALF}; + enum {COUL_FLAG=1}; + typedef DeviceType device_type; + PairLJCharmmCoulLongKokkos(class LAMMPS *); + ~PairLJCharmmCoulLongKokkos(); + + void compute(int, int); + + void settings(int, char **); + void init_tables(double cut_coul, double *cut_respa); + void init_style(); + double init_one(int, int); + + struct params_lj_coul{ + params_lj_coul(){cut_ljsq=0;cut_coulsq=0;lj1=0;lj2=0;lj3=0;lj4=0;offset=0;}; + params_lj_coul(int i){cut_ljsq=0;cut_coulsq=0;lj1=0;lj2=0;lj3=0;lj4=0;offset=0;}; + F_FLOAT cut_ljsq,cut_coulsq,lj1,lj2,lj3,lj4,offset; + }; + + protected: + void cleanup_copy(); + + template + KOKKOS_INLINE_FUNCTION + F_FLOAT compute_fpair(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype) const; + + template + KOKKOS_INLINE_FUNCTION + F_FLOAT compute_fcoul(const F_FLOAT& rsq, const int& i, const int&j, const int& itype, + const int& jtype, const F_FLOAT& factor_coul, const F_FLOAT& qtmp) const; + + template + KOKKOS_INLINE_FUNCTION + F_FLOAT compute_evdwl(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype) const; + + template + KOKKOS_INLINE_FUNCTION + F_FLOAT compute_ecoul(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype, const F_FLOAT& factor_coul, const F_FLOAT& qtmp) const; + + Kokkos::DualView k_params; + typename Kokkos::DualView::t_dev_const params; + // hardwired to space for 15 atom types + params_lj_coul m_params[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; + + F_FLOAT m_cutsq[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; + F_FLOAT m_cut_ljsq[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; + F_FLOAT m_cut_coulsq[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; + typename ArrayTypes::t_x_array_randomread x; + typename ArrayTypes::t_x_array c_x; + typename ArrayTypes::t_f_array f; + typename ArrayTypes::t_int_1d_randomread type; + typename ArrayTypes::t_float_1d_randomread q; + + DAT::tdual_efloat_1d k_eatom; + DAT::tdual_virial_array k_vatom; + typename ArrayTypes::t_efloat_1d d_eatom; + typename ArrayTypes::t_virial_array d_vatom; + + int newton_pair; + + typename ArrayTypes::tdual_ffloat_2d k_cutsq; + typename ArrayTypes::t_ffloat_2d d_cutsq; + typename ArrayTypes::tdual_ffloat_2d k_cut_ljsq; + typename ArrayTypes::t_ffloat_2d d_cut_ljsq; + typename ArrayTypes::tdual_ffloat_2d k_cut_coulsq; + typename ArrayTypes::t_ffloat_2d d_cut_coulsq; + + typename ArrayTypes::t_ffloat_1d_randomread + d_rtable, d_drtable, d_ftable, d_dftable, + d_ctable, d_dctable, d_etable, d_detable; + class AtomKokkos *atomKK; + int neighflag; + int nlocal,nall,eflag,vflag; + + double special_coul[4]; + double special_lj[4]; + double qqrd2e; + + void allocate(); + + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend EV_FLOAT pair_compute_neighlist >(PairLJCharmmCoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist >(PairLJCharmmCoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist >(PairLJCharmmCoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute >(PairLJCharmmCoulLongKokkos*, + NeighListKokkos*); + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend EV_FLOAT pair_compute_neighlist >(PairLJCharmmCoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist >(PairLJCharmmCoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist >(PairLJCharmmCoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute >(PairLJCharmmCoulLongKokkos*, + NeighListKokkos*); + friend void pair_virial_fdotr_compute(PairLJCharmmCoulLongKokkos*); + +}; + +} + +#endif +#endif + +/* ERROR/WARNING messages: + +*/ diff --git a/src/KOKKOS/pair_lj_class2_coul_cut_kokkos.cpp b/src/KOKKOS/pair_lj_class2_coul_cut_kokkos.cpp new file mode 100644 index 0000000000..283b88b579 --- /dev/null +++ b/src/KOKKOS/pair_lj_class2_coul_cut_kokkos.cpp @@ -0,0 +1,354 @@ +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + http://lammps.sandia.gov, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +#include "math.h" +#include "stdio.h" +#include "stdlib.h" +#include "string.h" +#include "pair_lj_class2_coul_cut_kokkos.h" +#include "kokkos.h" +#include "atom_kokkos.h" +#include "comm.h" +#include "force.h" +#include "neighbor.h" +#include "neigh_list.h" +#include "neigh_request.h" +#include "update.h" +#include "integrate.h" +#include "respa.h" +#include "math_const.h" +#include "memory.h" +#include "error.h" +#include "atom_masks.h" + +using namespace LAMMPS_NS; +using namespace MathConst; + +#define KOKKOS_CUDA_MAX_THREADS 256 +#define KOKKOS_CUDA_MIN_BLOCKS 8 + +/* ---------------------------------------------------------------------- */ + +template +PairLJClass2CoulCutKokkos::PairLJClass2CoulCutKokkos(LAMMPS *lmp):PairLJClass2CoulCut(lmp) +{ + respa_enable = 0; + + atomKK = (AtomKokkos *) atom; + execution_space = ExecutionSpaceFromDevice::space; + datamask_read = X_MASK | F_MASK | TYPE_MASK | Q_MASK | ENERGY_MASK | VIRIAL_MASK; + datamask_modify = F_MASK | ENERGY_MASK | VIRIAL_MASK; + cutsq = NULL; + cut_ljsq = NULL; + cut_coulsq = NULL; + +} + +/* ---------------------------------------------------------------------- */ + +template +PairLJClass2CoulCutKokkos::~PairLJClass2CoulCutKokkos() +{ + if (!copymode) { + memory->destroy_kokkos(k_cutsq, cutsq); + memory->destroy_kokkos(k_cut_ljsq, cut_ljsq); + memory->destroy_kokkos(k_cut_coulsq, cut_coulsq); + } +} + +/* ---------------------------------------------------------------------- */ + +template +void PairLJClass2CoulCutKokkos::cleanup_copy() { + // WHY needed: this prevents parent copy from deallocating any arrays + allocated = 0; + cutsq = NULL; + cut_ljsq = NULL; + cut_coulsq = NULL; + eatom = NULL; + vatom = NULL; +} + +/* ---------------------------------------------------------------------- */ + +template +void PairLJClass2CoulCutKokkos::compute(int eflag_in, int vflag_in) +{ + eflag = eflag_in; + vflag = vflag_in; + + if (neighflag == FULL || neighflag == FULLCLUSTER) no_virial_fdotr_compute = 1; + + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = vflag_fdotr = 0; + + atomKK->sync(execution_space,datamask_read); + k_cutsq.template sync(); + k_cut_ljsq.template sync(); + k_cut_coulsq.template sync(); + k_params.template sync(); + if (eflag || vflag) atomKK->modified(execution_space,datamask_modify); + else atomKK->modified(execution_space,F_MASK); + + x = atomKK->k_x.view(); + c_x = atomKK->k_x.view(); + f = atomKK->k_f.view(); + q = atomKK->k_q.view(); + type = atomKK->k_type.view(); + nlocal = atom->nlocal; + nall = atom->nlocal + atom->nghost; + special_lj[0] = force->special_lj[0]; + special_lj[1] = force->special_lj[1]; + special_lj[2] = force->special_lj[2]; + special_lj[3] = force->special_lj[3]; + special_coul[0] = force->special_coul[0]; + special_coul[1] = force->special_coul[1]; + special_coul[2] = force->special_coul[2]; + special_coul[3] = force->special_coul[3]; + qqrd2e = force->qqrd2e; + newton_pair = force->newton_pair; + + // loop over neighbors of my atoms + + copymode = 1; + + EV_FLOAT ev = pair_compute,void > + (this,(NeighListKokkos*)list); + + DeviceType::fence(); + + if (eflag) { + eng_vdwl += ev.evdwl; + eng_coul += ev.ecoul; + } + if (vflag_global) { + virial[0] += ev.v[0]; + virial[1] += ev.v[1]; + virial[2] += ev.v[2]; + virial[3] += ev.v[3]; + virial[4] += ev.v[4]; + virial[5] += ev.v[5]; + } + + if (vflag_fdotr) virial_fdotr_compute(); + + copymode = 0; +} + +/* ---------------------------------------------------------------------- + compute LJ 12-6 pair force between atoms i and j + ---------------------------------------------------------------------- */ +template +template +KOKKOS_INLINE_FUNCTION +F_FLOAT PairLJClass2CoulCutKokkos:: +compute_fpair(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype) const { + (void) i; + (void) j; + const F_FLOAT r2inv = 1.0/rsq; + const F_FLOAT rinv = sqrt(r2inv); + const F_FLOAT r3inv = r2inv*rinv; + const F_FLOAT r6inv = r3inv*r3inv; + + const F_FLOAT forcelj = r6inv * + ((STACKPARAMS?m_params[itype][jtype].lj1:params(itype,jtype).lj1)*r3inv - + (STACKPARAMS?m_params[itype][jtype].lj2:params(itype,jtype).lj2)); + + return forcelj*r2inv; +} + +/* ---------------------------------------------------------------------- + compute coulomb pair force between atoms i and j + ---------------------------------------------------------------------- */ +template +template +KOKKOS_INLINE_FUNCTION +F_FLOAT PairLJClass2CoulCutKokkos:: +compute_fcoul(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype, const F_FLOAT& factor_coul, const F_FLOAT& qtmp) const { + const F_FLOAT r2inv = 1.0/rsq; + const F_FLOAT rinv = sqrt(r2inv); + F_FLOAT forcecoul; + + forcecoul = qqrd2e*qtmp*q(j) *rinv; + + return factor_coul*forcecoul*r2inv; +} + +/* ---------------------------------------------------------------------- + compute LJ 12-6 pair potential energy between atoms i and j + ---------------------------------------------------------------------- */ +template +template +KOKKOS_INLINE_FUNCTION +F_FLOAT PairLJClass2CoulCutKokkos:: +compute_evdwl(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype) const { + (void) i; + (void) j; + const F_FLOAT r2inv = 1.0/rsq; + const F_FLOAT rinv = sqrt(r2inv); + const F_FLOAT r3inv = r2inv*rinv; + const F_FLOAT r6inv = r3inv*r3inv; + + return r6inv*((STACKPARAMS?m_params[itype][jtype].lj3:params(itype,jtype).lj3)*r3inv - + (STACKPARAMS?m_params[itype][jtype].lj4:params(itype,jtype).lj4)) - + (STACKPARAMS?m_params[itype][jtype].offset:params(itype,jtype).offset); +} + +/* ---------------------------------------------------------------------- + compute coulomb pair potential energy between atoms i and j + ---------------------------------------------------------------------- */ +template +template +KOKKOS_INLINE_FUNCTION +F_FLOAT PairLJClass2CoulCutKokkos:: +compute_ecoul(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype, const F_FLOAT& factor_coul, const F_FLOAT& qtmp) const { + const F_FLOAT r2inv = 1.0/rsq; + const F_FLOAT rinv = sqrt(r2inv); + + return factor_coul*qqrd2e*qtmp*q(j)*rinv; + +} + +/* ---------------------------------------------------------------------- + allocate all arrays +------------------------------------------------------------------------- */ + +template +void PairLJClass2CoulCutKokkos::allocate() +{ + PairLJClass2CoulCut::allocate(); + + int n = atom->ntypes; + memory->destroy(cutsq); + memory->create_kokkos(k_cutsq,cutsq,n+1,n+1,"pair:cutsq"); + d_cutsq = k_cutsq.template view(); + memory->destroy(cut_ljsq); + memory->create_kokkos(k_cut_ljsq,cut_ljsq,n+1,n+1,"pair:cut_ljsq"); + d_cut_ljsq = k_cut_ljsq.template view(); + memory->destroy(cut_coulsq); + memory->create_kokkos(k_cut_coulsq,cut_coulsq,n+1,n+1,"pair:cut_coulsq"); + d_cut_coulsq = k_cut_coulsq.template view(); + k_params = Kokkos::DualView("PairLJClass2CoulCut::params",n+1,n+1); + params = k_params.d_view; +} + +/* ---------------------------------------------------------------------- + global settings +------------------------------------------------------------------------- */ + +template +void PairLJClass2CoulCutKokkos::settings(int narg, char **arg) +{ + if (narg > 2) error->all(FLERR,"Illegal pair_style command"); + + PairLJClass2CoulCut::settings(1,arg); +} + +/* ---------------------------------------------------------------------- + init specific to this pair style +------------------------------------------------------------------------- */ + +template +void PairLJClass2CoulCutKokkos::init_style() +{ + PairLJClass2CoulCut::init_style(); + + // error if rRESPA with inner levels + + if (update->whichflag == 1 && strstr(update->integrate_style,"respa")) { + int respa = 0; + if (((Respa *) update->integrate)->level_inner >= 0) respa = 1; + if (((Respa *) update->integrate)->level_middle >= 0) respa = 2; + if (respa) + error->all(FLERR,"Cannot use Kokkos pair style with rRESPA inner/middle"); + } + + // irequest = neigh request made by parent class + + neighflag = lmp->kokkos->neighflag; + int irequest = neighbor->nrequest - 1; + + neighbor->requests[irequest]-> + kokkos_host = Kokkos::Impl::is_same::value && + !Kokkos::Impl::is_same::value; + neighbor->requests[irequest]-> + kokkos_device = Kokkos::Impl::is_same::value; + + if (neighflag == FULL) { + neighbor->requests[irequest]->full = 1; + neighbor->requests[irequest]->half = 0; + neighbor->requests[irequest]->full_cluster = 0; + } else if (neighflag == HALF || neighflag == HALFTHREAD) { + neighbor->requests[irequest]->full = 0; + neighbor->requests[irequest]->half = 1; + neighbor->requests[irequest]->full_cluster = 0; + } else if (neighflag == N2) { + neighbor->requests[irequest]->full = 0; + neighbor->requests[irequest]->half = 0; + neighbor->requests[irequest]->full_cluster = 0; + } else if (neighflag == FULLCLUSTER) { + neighbor->requests[irequest]->full_cluster = 1; + neighbor->requests[irequest]->full = 1; + neighbor->requests[irequest]->half = 0; + } else { + error->all(FLERR,"Cannot use chosen neighbor list style with lj/class2/coul/cut/kk"); + } +} + +/* ---------------------------------------------------------------------- + init for one type pair i,j and corresponding j,i +------------------------------------------------------------------------- */ + +template +double PairLJClass2CoulCutKokkos::init_one(int i, int j) +{ + double cutone = PairLJClass2CoulCut::init_one(i,j); + double cut_ljsqm = cut_ljsq[i][j]; + double cut_coulsqm = cut_coulsq[i][j]; + + k_params.h_view(i,j).lj1 = lj1[i][j]; + k_params.h_view(i,j).lj2 = lj2[i][j]; + k_params.h_view(i,j).lj3 = lj3[i][j]; + k_params.h_view(i,j).lj4 = lj4[i][j]; + k_params.h_view(i,j).offset = offset[i][j]; + k_params.h_view(i,j).cut_ljsq = cut_ljsqm; + k_params.h_view(i,j).cut_coulsq = cut_coulsqm; + + k_params.h_view(j,i) = k_params.h_view(i,j); + if(i(); + k_cut_ljsq.h_view(i,j) = cut_ljsqm; + k_cut_ljsq.template modify(); + k_cut_coulsq.h_view(i,j) = cut_coulsqm; + k_cut_coulsq.template modify(); + k_params.template modify(); + + return cutone; +} + + + +template class PairLJClass2CoulCutKokkos; +#ifdef KOKKOS_HAVE_CUDA +template class PairLJClass2CoulCutKokkos; +#endif diff --git a/src/KOKKOS/pair_lj_class2_coul_cut_kokkos.h b/src/KOKKOS/pair_lj_class2_coul_cut_kokkos.h new file mode 100644 index 0000000000..ddbde32075 --- /dev/null +++ b/src/KOKKOS/pair_lj_class2_coul_cut_kokkos.h @@ -0,0 +1,131 @@ +/* -*- c++ -*- ---------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + http://lammps.sandia.gov, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +#ifdef PAIR_CLASS + +PairStyle(lj/class2/coul/cut/kk,PairLJClass2CoulCutKokkos) +PairStyle(lj/class2/coul/cut/kk/device,PairLJClass2CoulCutKokkos) +PairStyle(lj/class2/coul/cut/kk/host,PairLJClass2CoulCutKokkos) + +#else + +#ifndef LMP_PAIR_LJ_CLASS2_COUL_CUT_KOKKOS_H +#define LMP_PAIR_LJ_CLASS2_COUL_CUT_KOKKOS_H + +#include "pair_kokkos.h" +#include "pair_lj_class2_coul_cut.h" +#include "neigh_list_kokkos.h" + +namespace LAMMPS_NS { + +template +class PairLJClass2CoulCutKokkos : public PairLJClass2CoulCut { + public: + enum {EnabledNeighFlags=FULL|HALFTHREAD|HALF}; + enum {COUL_FLAG=1}; + typedef DeviceType device_type; + PairLJClass2CoulCutKokkos(class LAMMPS *); + ~PairLJClass2CoulCutKokkos(); + + void compute(int, int); + + void settings(int, char **); + void init_style(); + double init_one(int, int); + + struct params_lj_coul{ + params_lj_coul(){cut_ljsq=0;cut_coulsq=0;lj1=0;lj2=0;lj3=0;lj4=0;offset=0;}; + params_lj_coul(int i){cut_ljsq=0;cut_coulsq=0;lj1=0;lj2=0;lj3=0;lj4=0;offset=0;}; + F_FLOAT cut_ljsq,cut_coulsq,lj1,lj2,lj3,lj4,offset; + }; + + protected: + void cleanup_copy(); + + template + KOKKOS_INLINE_FUNCTION + F_FLOAT compute_fpair(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype) const; + + template + KOKKOS_INLINE_FUNCTION + F_FLOAT compute_fcoul(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype, const F_FLOAT& factor_coul, const F_FLOAT& qtmp) const; + + template + KOKKOS_INLINE_FUNCTION + F_FLOAT compute_evdwl(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype) const; + + template + KOKKOS_INLINE_FUNCTION + F_FLOAT compute_ecoul(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype, const F_FLOAT& factor_coul, const F_FLOAT& qtmp) const; + + Kokkos::DualView k_params; + typename Kokkos::DualView::t_dev_const params; + // hardwired to space for 15 atom types + params_lj_coul m_params[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; + + F_FLOAT m_cutsq[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; + F_FLOAT m_cut_ljsq[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; + F_FLOAT m_cut_coulsq[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; + typename ArrayTypes::t_x_array_randomread x; + typename ArrayTypes::t_x_array c_x; + typename ArrayTypes::t_f_array f; + typename ArrayTypes::t_int_1d_randomread type; + typename ArrayTypes::t_float_1d_randomread q; + typename ArrayTypes::t_efloat_1d d_eatom; + typename ArrayTypes::t_virial_array d_vatom; + + int newton_pair; + + typename ArrayTypes::tdual_ffloat_2d k_cutsq; + typename ArrayTypes::t_ffloat_2d d_cutsq; + typename ArrayTypes::tdual_ffloat_2d k_cut_ljsq; + typename ArrayTypes::t_ffloat_2d d_cut_ljsq; + typename ArrayTypes::tdual_ffloat_2d k_cut_coulsq; + typename ArrayTypes::t_ffloat_2d d_cut_coulsq; + + class AtomKokkos *atomKK; + int neighflag; + int nlocal,nall,eflag,vflag; + + double special_coul[4]; + double special_lj[4]; + double qqrd2e; + + void allocate(); + friend class PairComputeFunctor; + friend class PairComputeFunctor; + friend class PairComputeFunctor; + friend class PairComputeFunctor; + friend class PairComputeFunctor; + friend class PairComputeFunctor; + friend EV_FLOAT pair_compute_neighlist(PairLJClass2CoulCutKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairLJClass2CoulCutKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairLJClass2CoulCutKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute(PairLJClass2CoulCutKokkos*, + NeighListKokkos*); + +}; + +} + +#endif +#endif + +/* ERROR/WARNING messages: + +*/ diff --git a/src/KOKKOS/pair_lj_class2_coul_long_kokkos.cpp b/src/KOKKOS/pair_lj_class2_coul_long_kokkos.cpp new file mode 100644 index 0000000000..6bfba03b1b --- /dev/null +++ b/src/KOKKOS/pair_lj_class2_coul_long_kokkos.cpp @@ -0,0 +1,503 @@ +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + http://lammps.sandia.gov, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +#include "math.h" +#include "stdio.h" +#include "stdlib.h" +#include "string.h" +#include "pair_lj_class2_coul_long_kokkos.h" +#include "kokkos.h" +#include "atom_kokkos.h" +#include "comm.h" +#include "force.h" +#include "neighbor.h" +#include "neigh_list.h" +#include "neigh_request.h" +#include "update.h" +#include "integrate.h" +#include "respa.h" +#include "math_const.h" +#include "memory.h" +#include "error.h" +#include "atom_masks.h" + +using namespace LAMMPS_NS; +using namespace MathConst; + +#define KOKKOS_CUDA_MAX_THREADS 256 +#define KOKKOS_CUDA_MIN_BLOCKS 8 + + +#define EWALD_F 1.12837917 +#define EWALD_P 0.3275911 +#define A1 0.254829592 +#define A2 -0.284496736 +#define A3 1.421413741 +#define A4 -1.453152027 +#define A5 1.061405429 + +/* ---------------------------------------------------------------------- */ + +template +PairLJClass2CoulLongKokkos::PairLJClass2CoulLongKokkos(LAMMPS *lmp):PairLJClass2CoulLong(lmp) +{ + respa_enable = 0; + + atomKK = (AtomKokkos *) atom; + execution_space = ExecutionSpaceFromDevice::space; + datamask_read = X_MASK | F_MASK | TYPE_MASK | Q_MASK | ENERGY_MASK | VIRIAL_MASK; + datamask_modify = F_MASK | ENERGY_MASK | VIRIAL_MASK; + cutsq = NULL; + cut_ljsq = NULL; + cut_coulsq = 0.0; + +} + +/* ---------------------------------------------------------------------- */ + +template +PairLJClass2CoulLongKokkos::~PairLJClass2CoulLongKokkos() +{ + if (!copymode){ + memory->destroy_kokkos(k_cutsq, cutsq); + memory->destroy_kokkos(k_cut_ljsq, cut_ljsq); + } +} + +/* ---------------------------------------------------------------------- */ + +template +void PairLJClass2CoulLongKokkos::cleanup_copy() { + // WHY needed: this prevents parent copy from deallocating any arrays + allocated = 0; + cutsq = NULL; + cut_ljsq = NULL; + eatom = NULL; + vatom = NULL; + ftable = NULL; +} + +/* ---------------------------------------------------------------------- */ + +template +void PairLJClass2CoulLongKokkos::compute(int eflag_in, int vflag_in) +{ + eflag = eflag_in; + vflag = vflag_in; + + if (neighflag == FULL || neighflag == FULLCLUSTER) no_virial_fdotr_compute = 1; + + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = vflag_fdotr = 0; + + atomKK->sync(execution_space,datamask_read); + k_cutsq.template sync(); + k_cut_ljsq.template sync(); + k_cut_coulsq.template sync(); + k_params.template sync(); + if (eflag || vflag) atomKK->modified(execution_space,datamask_modify); + else atomKK->modified(execution_space,F_MASK); + + x = atomKK->k_x.view(); + c_x = atomKK->k_x.view(); + f = atomKK->k_f.view(); + q = atomKK->k_q.view(); + type = atomKK->k_type.view(); + nlocal = atom->nlocal; + nall = atom->nlocal + atom->nghost; + special_lj[0] = force->special_lj[0]; + special_lj[1] = force->special_lj[1]; + special_lj[2] = force->special_lj[2]; + special_lj[3] = force->special_lj[3]; + special_coul[0] = force->special_coul[0]; + special_coul[1] = force->special_coul[1]; + special_coul[2] = force->special_coul[2]; + special_coul[3] = force->special_coul[3]; + qqrd2e = force->qqrd2e; + newton_pair = force->newton_pair; + + // loop over neighbors of my atoms + + copymode = 1; + + EV_FLOAT ev; + if(ncoultablebits) + ev = pair_compute,CoulLongTable<1> > + (this,(NeighListKokkos*)list); + else + ev = pair_compute,CoulLongTable<0> > + (this,(NeighListKokkos*)list); + + + DeviceType::fence(); + + if (eflag) { + eng_vdwl += ev.evdwl; + eng_coul += ev.ecoul; + } + if (vflag_global) { + virial[0] += ev.v[0]; + virial[1] += ev.v[1]; + virial[2] += ev.v[2]; + virial[3] += ev.v[3]; + virial[4] += ev.v[4]; + virial[5] += ev.v[5]; + } + + if (vflag_fdotr) pair_virial_fdotr_compute(this); + + copymode = 0; +} + +/* ---------------------------------------------------------------------- + compute LJ 12-6 pair force between atoms i and j + ---------------------------------------------------------------------- */ +template +template +KOKKOS_INLINE_FUNCTION +F_FLOAT PairLJClass2CoulLongKokkos:: +compute_fpair(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype) const { + (void) i; + (void) j; + const F_FLOAT r2inv = 1.0/rsq; + const F_FLOAT rinv = sqrt(r2inv); + const F_FLOAT r3inv = r2inv*rinv; + const F_FLOAT r6inv = r3inv*r3inv; + + const F_FLOAT forcelj = r6inv * + ((STACKPARAMS?m_params[itype][jtype].lj1:params(itype,jtype).lj1)*r3inv - + (STACKPARAMS?m_params[itype][jtype].lj2:params(itype,jtype).lj2)); + + return forcelj*r2inv; +} + +/* ---------------------------------------------------------------------- + compute coulomb pair force between atoms i and j + ---------------------------------------------------------------------- */ +template +template +KOKKOS_INLINE_FUNCTION +F_FLOAT PairLJClass2CoulLongKokkos:: +compute_fcoul(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype, const F_FLOAT& factor_coul, const F_FLOAT& qtmp) const { + if(Specialisation::DoTable && rsq > tabinnersq) { + union_int_float_t rsq_lookup; + rsq_lookup.f = rsq; + const int itable = (rsq_lookup.i & ncoulmask) >> ncoulshiftbits; + const F_FLOAT fraction = (rsq_lookup.f - d_rtable[itable]) * d_drtable[itable]; + const F_FLOAT table = d_ftable[itable] + fraction*d_dftable[itable]; + F_FLOAT forcecoul = qtmp*q[j] * table; + if (factor_coul < 1.0) { + const F_FLOAT table = d_ctable[itable] + fraction*d_dctable[itable]; + const F_FLOAT prefactor = qtmp*q[j] * table; + forcecoul -= (1.0-factor_coul)*prefactor; + } + return forcecoul/rsq; + } else { + const F_FLOAT r = sqrt(rsq); + const F_FLOAT grij = g_ewald * r; + const F_FLOAT expm2 = exp(-grij*grij); + const F_FLOAT t = 1.0 / (1.0 + EWALD_P*grij); + const F_FLOAT rinv = 1.0/r; + const F_FLOAT erfc = t * (A1+t*(A2+t*(A3+t*(A4+t*A5)))) * expm2; + const F_FLOAT prefactor = qqrd2e * qtmp*q[j]*rinv; + F_FLOAT forcecoul = prefactor * (erfc + EWALD_F*grij*expm2); + if (factor_coul < 1.0) forcecoul -= (1.0-factor_coul)*prefactor; + + return forcecoul*rinv*rinv; + } +} + +/* ---------------------------------------------------------------------- + compute LJ 12-6 pair potential energy between atoms i and j + ---------------------------------------------------------------------- */ +template +template +KOKKOS_INLINE_FUNCTION +F_FLOAT PairLJClass2CoulLongKokkos:: +compute_evdwl(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype) const { + (void) i; + (void) j; + const F_FLOAT r2inv = 1.0/rsq; + const F_FLOAT rinv = sqrt(r2inv); + const F_FLOAT r3inv = r2inv*rinv; + const F_FLOAT r6inv = r3inv*r3inv; + + return r6inv*((STACKPARAMS?m_params[itype][jtype].lj3:params(itype,jtype).lj3)*r3inv - + (STACKPARAMS?m_params[itype][jtype].lj4:params(itype,jtype).lj4)) - + (STACKPARAMS?m_params[itype][jtype].offset:params(itype,jtype).offset); +} + +/* ---------------------------------------------------------------------- + compute coulomb pair potential energy between atoms i and j + ---------------------------------------------------------------------- */ +template +template +KOKKOS_INLINE_FUNCTION +F_FLOAT PairLJClass2CoulLongKokkos:: +compute_ecoul(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype, const F_FLOAT& factor_coul, const F_FLOAT& qtmp) const { + if(Specialisation::DoTable) { + union_int_float_t rsq_lookup; + rsq_lookup.f = rsq; + const int itable = (rsq_lookup.i & ncoulmask) >> ncoulshiftbits; + const F_FLOAT fraction = (rsq_lookup.f - d_rtable[itable]) * d_drtable[itable]; + const F_FLOAT table = d_etable[itable] + fraction*d_detable[itable]; + F_FLOAT ecoul = qtmp*q[j] * table; + if (factor_coul < 1.0) { + const F_FLOAT table = d_ctable[itable] + fraction*d_dctable[itable]; + const F_FLOAT prefactor = qtmp*q[j] * table; + ecoul -= (1.0-factor_coul)*prefactor; + } + return ecoul; + } else { + const F_FLOAT r = sqrt(rsq); + const F_FLOAT grij = g_ewald * r; + const F_FLOAT expm2 = exp(-grij*grij); + const F_FLOAT t = 1.0 / (1.0 + EWALD_P*grij); + const F_FLOAT erfc = t * (A1+t*(A2+t*(A3+t*(A4+t*A5)))) * expm2; + const F_FLOAT prefactor = qqrd2e * qtmp*q[j]/r; + F_FLOAT ecoul = prefactor * erfc; + if (factor_coul < 1.0) ecoul -= (1.0-factor_coul)*prefactor; + return ecoul; + } +} + +/* ---------------------------------------------------------------------- + allocate all arrays +------------------------------------------------------------------------- */ + +template +void PairLJClass2CoulLongKokkos::allocate() +{ + PairLJClass2CoulLong::allocate(); + + int n = atom->ntypes; + memory->destroy(cutsq); + memory->create_kokkos(k_cutsq,cutsq,n+1,n+1,"pair:cutsq"); + d_cutsq = k_cutsq.template view(); + memory->destroy(cut_ljsq); + memory->create_kokkos(k_cut_ljsq,cut_ljsq,n+1,n+1,"pair:cut_ljsq"); + d_cut_ljsq = k_cut_ljsq.template view(); + + memory->create_kokkos(k_cut_coulsq,n+1,n+1,"pair:cut_coulsq"); + d_cut_coulsq = k_cut_coulsq.template view(); + k_params = Kokkos::DualView("PairLJClass2CoulLong::params",n+1,n+1); + params = k_params.d_view; +} + +template +void PairLJClass2CoulLongKokkos::init_tables(double cut_coul, double *cut_respa) +{ + Pair::init_tables(cut_coul,cut_respa); + + typedef typename ArrayTypes::t_ffloat_1d table_type; + typedef typename ArrayTypes::t_ffloat_1d host_table_type; + + int ntable = 1; + for (int i = 0; i < ncoultablebits; i++) ntable *= 2; + + + // Copy rtable and drtable + { + host_table_type h_table("HostTable",ntable); + table_type d_table("DeviceTable",ntable); + for(int i = 0; i < ntable; i++) { + h_table(i) = rtable[i]; + } + Kokkos::deep_copy(d_table,h_table); + d_rtable = d_table; + } + + { + host_table_type h_table("HostTable",ntable); + table_type d_table("DeviceTable",ntable); + for(int i = 0; i < ntable; i++) { + h_table(i) = drtable[i]; + } + Kokkos::deep_copy(d_table,h_table); + d_drtable = d_table; + } + + { + host_table_type h_table("HostTable",ntable); + table_type d_table("DeviceTable",ntable); + + // Copy ftable and dftable + for(int i = 0; i < ntable; i++) { + h_table(i) = ftable[i]; + } + Kokkos::deep_copy(d_table,h_table); + d_ftable = d_table; + } + + { + host_table_type h_table("HostTable",ntable); + table_type d_table("DeviceTable",ntable); + + for(int i = 0; i < ntable; i++) { + h_table(i) = dftable[i]; + } + Kokkos::deep_copy(d_table,h_table); + d_dftable = d_table; + } + + { + host_table_type h_table("HostTable",ntable); + table_type d_table("DeviceTable",ntable); + + // Copy ctable and dctable + for(int i = 0; i < ntable; i++) { + h_table(i) = ctable[i]; + } + Kokkos::deep_copy(d_table,h_table); + d_ctable = d_table; + } + + { + host_table_type h_table("HostTable",ntable); + table_type d_table("DeviceTable",ntable); + + for(int i = 0; i < ntable; i++) { + h_table(i) = dctable[i]; + } + Kokkos::deep_copy(d_table,h_table); + d_dctable = d_table; + } + + { + host_table_type h_table("HostTable",ntable); + table_type d_table("DeviceTable",ntable); + + // Copy etable and detable + for(int i = 0; i < ntable; i++) { + h_table(i) = etable[i]; + } + Kokkos::deep_copy(d_table,h_table); + d_etable = d_table; + } + + { + host_table_type h_table("HostTable",ntable); + table_type d_table("DeviceTable",ntable); + + for(int i = 0; i < ntable; i++) { + h_table(i) = detable[i]; + } + Kokkos::deep_copy(d_table,h_table); + d_detable = d_table; + } +} + + +/* ---------------------------------------------------------------------- + global settings +------------------------------------------------------------------------- */ + +template +void PairLJClass2CoulLongKokkos::settings(int narg, char **arg) +{ + if (narg > 2) error->all(FLERR,"Illegal pair_style command"); + + PairLJClass2CoulLong::settings(narg,arg); +} + +/* ---------------------------------------------------------------------- + init specific to this pair style +------------------------------------------------------------------------- */ + +template +void PairLJClass2CoulLongKokkos::init_style() +{ + PairLJClass2CoulLong::init_style(); + + // error if rRESPA with inner levels + + if (update->whichflag == 1 && strstr(update->integrate_style,"respa")) { + int respa = 0; + if (((Respa *) update->integrate)->level_inner >= 0) respa = 1; + if (((Respa *) update->integrate)->level_middle >= 0) respa = 2; + if (respa) + error->all(FLERR,"Cannot use Kokkos pair style with rRESPA inner/middle"); + } + + // irequest = neigh request made by parent class + + neighflag = lmp->kokkos->neighflag; + int irequest = neighbor->nrequest - 1; + + neighbor->requests[irequest]-> + kokkos_host = Kokkos::Impl::is_same::value && + !Kokkos::Impl::is_same::value; + neighbor->requests[irequest]-> + kokkos_device = Kokkos::Impl::is_same::value; + + if (neighflag == FULL) { + neighbor->requests[irequest]->full = 1; + neighbor->requests[irequest]->half = 0; + neighbor->requests[irequest]->full_cluster = 0; + } else if (neighflag == HALF || neighflag == HALFTHREAD) { + neighbor->requests[irequest]->full = 0; + neighbor->requests[irequest]->half = 1; + neighbor->requests[irequest]->full_cluster = 0; + } else { + error->all(FLERR,"Cannot use chosen neighbor list style with lj/class2/coul/long/kk"); + } +} + +/* ---------------------------------------------------------------------- + init for one type pair i,j and corresponding j,i +------------------------------------------------------------------------- */ + +template +double PairLJClass2CoulLongKokkos::init_one(int i, int j) +{ + double cutone = PairLJClass2CoulLong::init_one(i,j); + double cut_ljsqm = cut_ljsq[i][j]; + double cut_coulsqm = cut_coulsq; + + k_params.h_view(i,j).lj1 = lj1[i][j]; + k_params.h_view(i,j).lj2 = lj2[i][j]; + k_params.h_view(i,j).lj3 = lj3[i][j]; + k_params.h_view(i,j).lj4 = lj4[i][j]; + k_params.h_view(i,j).offset = offset[i][j]; + k_params.h_view(i,j).cut_ljsq = cut_ljsqm; + k_params.h_view(i,j).cut_coulsq = cut_coulsqm; + + k_params.h_view(j,i) = k_params.h_view(i,j); + if(i(); + k_cut_ljsq.h_view(i,j) = cut_ljsqm; + k_cut_ljsq.template modify(); + k_cut_coulsq.h_view(i,j) = cut_coulsqm; + k_cut_coulsq.template modify(); + k_params.template modify(); + + return cutone; +} + + + +template class PairLJClass2CoulLongKokkos; +#ifdef KOKKOS_HAVE_CUDA +template class PairLJClass2CoulLongKokkos; +#endif diff --git a/src/KOKKOS/pair_lj_class2_coul_long_kokkos.h b/src/KOKKOS/pair_lj_class2_coul_long_kokkos.h new file mode 100644 index 0000000000..7f9b3ebc50 --- /dev/null +++ b/src/KOKKOS/pair_lj_class2_coul_long_kokkos.h @@ -0,0 +1,147 @@ +/* -*- c++ -*- ---------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + http://lammps.sandia.gov, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +#ifdef PAIR_CLASS + +PairStyle(lj/class2/coul/long/kk,PairLJClass2CoulLongKokkos) +PairStyle(lj/class2/coul/long/kk/device,PairLJClass2CoulLongKokkos) +PairStyle(lj/class2/coul/long/kk/host,PairLJClass2CoulLongKokkos) + +#else + +#ifndef LMP_PAIR_LJ_CLASS2_COUL_LONG_KOKKOS_H +#define LMP_PAIR_LJ_CLASS2_COUL_LONG_KOKKOS_H + +#include "pair_kokkos.h" +#include "pair_lj_class2_coul_long.h" +#include "neigh_list_kokkos.h" + +namespace LAMMPS_NS { + +template +class PairLJClass2CoulLongKokkos : public PairLJClass2CoulLong { + public: + enum {EnabledNeighFlags=FULL|HALFTHREAD|HALF}; + enum {COUL_FLAG=1}; + typedef DeviceType device_type; + PairLJClass2CoulLongKokkos(class LAMMPS *); + ~PairLJClass2CoulLongKokkos(); + + void compute(int, int); + + void settings(int, char **); + void init_tables(double cut_coul, double *cut_respa); + void init_style(); + double init_one(int, int); + + struct params_lj_coul{ + params_lj_coul(){cut_ljsq=0;cut_coulsq=0;lj1=0;lj2=0;lj3=0;lj4=0;offset=0;}; + params_lj_coul(int i){cut_ljsq=0;cut_coulsq=0;lj1=0;lj2=0;lj3=0;lj4=0;offset=0;}; + F_FLOAT cut_ljsq,cut_coulsq,lj1,lj2,lj3,lj4,offset; + }; + + protected: + void cleanup_copy(); + + template + KOKKOS_INLINE_FUNCTION + F_FLOAT compute_fpair(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype) const; + + template + KOKKOS_INLINE_FUNCTION + F_FLOAT compute_fcoul(const F_FLOAT& rsq, const int& i, const int&j, const int& itype, + const int& jtype, const F_FLOAT& factor_coul, const F_FLOAT& qtmp) const; + + template + KOKKOS_INLINE_FUNCTION + F_FLOAT compute_evdwl(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype) const; + + template + KOKKOS_INLINE_FUNCTION + F_FLOAT compute_ecoul(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype, const F_FLOAT& factor_coul, const F_FLOAT& qtmp) const; + + Kokkos::DualView k_params; + typename Kokkos::DualView::t_dev_const params; + // hardwired to space for 15 atom types + params_lj_coul m_params[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; + + F_FLOAT m_cutsq[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; + F_FLOAT m_cut_ljsq[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; + F_FLOAT m_cut_coulsq[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; + typename ArrayTypes::t_x_array_randomread x; + typename ArrayTypes::t_x_array c_x; + typename ArrayTypes::t_f_array f; + typename ArrayTypes::t_int_1d_randomread type; + typename ArrayTypes::t_float_1d_randomread q; + typename ArrayTypes::t_efloat_1d d_eatom; + typename ArrayTypes::t_virial_array d_vatom; + + int newton_pair; + + typename ArrayTypes::tdual_ffloat_2d k_cutsq; + typename ArrayTypes::t_ffloat_2d d_cutsq; + typename ArrayTypes::tdual_ffloat_2d k_cut_ljsq; + typename ArrayTypes::t_ffloat_2d d_cut_ljsq; + typename ArrayTypes::tdual_ffloat_2d k_cut_coulsq; + typename ArrayTypes::t_ffloat_2d d_cut_coulsq; + + typename ArrayTypes::t_ffloat_1d_randomread + d_rtable, d_drtable, d_ftable, d_dftable, + d_ctable, d_dctable, d_etable, d_detable; + class AtomKokkos *atomKK; + int neighflag; + int nlocal,nall,eflag,vflag; + + double special_coul[4]; + double special_lj[4]; + double qqrd2e; + + void allocate(); + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend EV_FLOAT pair_compute_neighlist >(PairLJClass2CoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist >(PairLJClass2CoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist >(PairLJClass2CoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute >(PairLJClass2CoulLongKokkos*, + NeighListKokkos*); + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend EV_FLOAT pair_compute_neighlist >(PairLJClass2CoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist >(PairLJClass2CoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist >(PairLJClass2CoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute >(PairLJClass2CoulLongKokkos*, + NeighListKokkos*); + friend void pair_virial_fdotr_compute(PairLJClass2CoulLongKokkos*); + +}; + +} + +#endif +#endif + +/* ERROR/WARNING messages: + +*/ diff --git a/src/KOKKOS/pair_lj_class2_kokkos.cpp b/src/KOKKOS/pair_lj_class2_kokkos.cpp new file mode 100644 index 0000000000..62d228dfb1 --- /dev/null +++ b/src/KOKKOS/pair_lj_class2_kokkos.cpp @@ -0,0 +1,281 @@ +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + http://lammps.sandia.gov, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +/* ---------------------------------------------------------------------- + Contributing author: Ray Shan (SNL) +------------------------------------------------------------------------- */ + +#include "math.h" +#include "stdio.h" +#include "stdlib.h" +#include "string.h" +#include "pair_lj_class2_kokkos.h" +#include "kokkos.h" +#include "atom_kokkos.h" +#include "comm.h" +#include "force.h" +#include "neighbor.h" +#include "neigh_list.h" +#include "neigh_request.h" +#include "update.h" +#include "integrate.h" +#include "respa.h" +#include "math_const.h" +#include "memory.h" +#include "error.h" +#include "atom_masks.h" + +using namespace LAMMPS_NS; +using namespace MathConst; + +#define KOKKOS_CUDA_MAX_THREADS 256 +#define KOKKOS_CUDA_MIN_BLOCKS 8 + +/* ---------------------------------------------------------------------- */ + +template +PairLJClass2Kokkos::PairLJClass2Kokkos(LAMMPS *lmp) : PairLJClass2(lmp) +{ + respa_enable = 0; + + atomKK = (AtomKokkos *) atom; + execution_space = ExecutionSpaceFromDevice::space; + datamask_read = X_MASK | F_MASK | TYPE_MASK | ENERGY_MASK | VIRIAL_MASK; + datamask_modify = F_MASK | ENERGY_MASK | VIRIAL_MASK; + cutsq = NULL; +} + +/* ---------------------------------------------------------------------- */ + +template +PairLJClass2Kokkos::~PairLJClass2Kokkos() +{ + if (allocated) { + k_cutsq = DAT::tdual_ffloat_2d(); + memory->sfree(cutsq); + cutsq = NULL; + } +} + +/* ---------------------------------------------------------------------- */ + +template +void PairLJClass2Kokkos::cleanup_copy() { + // WHY needed: this prevents parent copy from deallocating any arrays + allocated = 0; + cutsq = NULL; + eatom = NULL; + vatom = NULL; +} + +/* ---------------------------------------------------------------------- */ + +template +void PairLJClass2Kokkos::compute(int eflag_in, int vflag_in) +{ + eflag = eflag_in; + vflag = vflag_in; + + + if (neighflag == FULL || neighflag == FULLCLUSTER) no_virial_fdotr_compute = 1; + + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = vflag_fdotr = 0; + + atomKK->sync(execution_space,datamask_read); + k_cutsq.template sync(); + k_params.template sync(); + if (eflag || vflag) atomKK->modified(execution_space,datamask_modify); + else atomKK->modified(execution_space,F_MASK); + + x = atomKK->k_x.view(); + c_x = atomKK->k_x.view(); + f = atomKK->k_f.view(); + type = atomKK->k_type.view(); + tag = atomKK->k_tag.view(); + nlocal = atom->nlocal; + nall = atom->nlocal + atom->nghost; + newton_pair = force->newton_pair; + special_lj[0] = force->special_lj[0]; + special_lj[1] = force->special_lj[1]; + special_lj[2] = force->special_lj[2]; + special_lj[3] = force->special_lj[3]; + + // loop over neighbors of my atoms + + EV_FLOAT ev = pair_compute,void >(this,(NeighListKokkos*)list); + DeviceType::fence(); + + if (eflag) eng_vdwl += ev.evdwl; + if (vflag_global) { + virial[0] += ev.v[0]; + virial[1] += ev.v[1]; + virial[2] += ev.v[2]; + virial[3] += ev.v[3]; + virial[4] += ev.v[4]; + virial[5] += ev.v[5]; + } + + if (vflag_fdotr) pair_virial_fdotr_compute(this); +} + +template +template +KOKKOS_INLINE_FUNCTION +F_FLOAT PairLJClass2Kokkos:: +compute_fpair(const F_FLOAT& rsq, const int& i, const int&j, const int& itype, const int& jtype) const { + (void) i; + (void) j; + const F_FLOAT r2inv = 1.0/rsq; + const F_FLOAT rinv = sqrt(r2inv); + const F_FLOAT r3inv = r2inv*rinv; + const F_FLOAT r6inv = r3inv*r3inv; + + const F_FLOAT forcelj = r6inv * + ((STACKPARAMS?m_params[itype][jtype].lj1:params(itype,jtype).lj1)*r3inv - + (STACKPARAMS?m_params[itype][jtype].lj2:params(itype,jtype).lj2)); + + return forcelj*r2inv; + +} + +template +template +KOKKOS_INLINE_FUNCTION +F_FLOAT PairLJClass2Kokkos:: +compute_evdwl(const F_FLOAT& rsq, const int& i, const int&j, const int& itype, const int& jtype) const { + (void) i; + (void) j; + const F_FLOAT r2inv = 1.0/rsq; + const F_FLOAT rinv = sqrt(r2inv); + const F_FLOAT r3inv = r2inv*rinv; + const F_FLOAT r6inv = r3inv*r3inv; + + return r6inv*((STACKPARAMS?m_params[itype][jtype].lj3:params(itype,jtype).lj3)*r3inv - + (STACKPARAMS?m_params[itype][jtype].lj4:params(itype,jtype).lj4)) - + (STACKPARAMS?m_params[itype][jtype].offset:params(itype,jtype).offset); +} + +/* ---------------------------------------------------------------------- + allocate all arrays +------------------------------------------------------------------------- */ + +template +void PairLJClass2Kokkos::allocate() +{ + PairLJClass2::allocate(); + + int n = atom->ntypes; + memory->destroy(cutsq); + memory->create_kokkos(k_cutsq,cutsq,n+1,n+1,"pair:cutsq"); + d_cutsq = k_cutsq.template view(); + k_params = Kokkos::DualView("PairLJClass2::params",n+1,n+1); + params = k_params.d_view; +} + +/* ---------------------------------------------------------------------- + global settings +------------------------------------------------------------------------- */ + +template +void PairLJClass2Kokkos::settings(int narg, char **arg) +{ + if (narg > 2) error->all(FLERR,"Illegal pair_style command"); + + PairLJClass2::settings(1,arg); +} + +/* ---------------------------------------------------------------------- + init specific to this pair style +------------------------------------------------------------------------- */ + +template +void PairLJClass2Kokkos::init_style() +{ + PairLJClass2::init_style(); + + // error if rRESPA with inner levels + + if (update->whichflag == 1 && strstr(update->integrate_style,"respa")) { + int respa = 0; + if (((Respa *) update->integrate)->level_inner >= 0) respa = 1; + if (((Respa *) update->integrate)->level_middle >= 0) respa = 2; + if (respa) + error->all(FLERR,"Cannot use Kokkos pair style with rRESPA inner/middle"); + } + + // irequest = neigh request made by parent class + + neighflag = lmp->kokkos->neighflag; + int irequest = neighbor->nrequest - 1; + + neighbor->requests[irequest]-> + kokkos_host = Kokkos::Impl::is_same::value && + !Kokkos::Impl::is_same::value; + neighbor->requests[irequest]-> + kokkos_device = Kokkos::Impl::is_same::value; + + if (neighflag == FULL) { + neighbor->requests[irequest]->full = 1; + neighbor->requests[irequest]->half = 0; + neighbor->requests[irequest]->full_cluster = 0; + } else if (neighflag == HALF || neighflag == HALFTHREAD) { + neighbor->requests[irequest]->full = 0; + neighbor->requests[irequest]->half = 1; + neighbor->requests[irequest]->full_cluster = 0; + } else if (neighflag == N2) { + neighbor->requests[irequest]->full = 0; + neighbor->requests[irequest]->half = 0; + neighbor->requests[irequest]->full_cluster = 0; + } else if (neighflag == FULLCLUSTER) { + neighbor->requests[irequest]->full_cluster = 1; + neighbor->requests[irequest]->full = 1; + neighbor->requests[irequest]->half = 0; + } else { + error->all(FLERR,"Cannot use chosen neighbor list style with lj/class2/kk"); + } +} + +/* ---------------------------------------------------------------------- + init for one type pair i,j and corresponding j,i +------------------------------------------------------------------------- */ + +template +double PairLJClass2Kokkos::init_one(int i, int j) +{ + double cutone = PairLJClass2::init_one(i,j); + + k_params.h_view(i,j).lj1 = lj1[i][j]; + k_params.h_view(i,j).lj2 = lj2[i][j]; + k_params.h_view(i,j).lj3 = lj3[i][j]; + k_params.h_view(i,j).lj4 = lj4[i][j]; + k_params.h_view(i,j).offset = offset[i][j]; + k_params.h_view(i,j).cutsq = cutone*cutone; + k_params.h_view(j,i) = k_params.h_view(i,j); + if(i(); + k_params.template modify(); + + return cutone; +} + + + +template class PairLJClass2Kokkos; +#ifdef KOKKOS_HAVE_CUDA +template class PairLJClass2Kokkos; +#endif diff --git a/src/KOKKOS/pair_lj_class2_kokkos.h b/src/KOKKOS/pair_lj_class2_kokkos.h new file mode 100644 index 0000000000..79556acc20 --- /dev/null +++ b/src/KOKKOS/pair_lj_class2_kokkos.h @@ -0,0 +1,125 @@ +/* -*- c++ -*- ---------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + http://lammps.sandia.gov, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +#ifdef PAIR_CLASS + +PairStyle(lj/class2/kk,PairLJClass2Kokkos) +PairStyle(lj/class2/kk/device,PairLJClass2Kokkos) +PairStyle(lj/class2/kk/host,PairLJClass2Kokkos) + +#else + +#ifndef LMP_PAIR_LJ_CLASS2_KOKKOS_H +#define LMP_PAIR_LJ_CLASS2_KOKKOS_H + +#include "pair_kokkos.h" +#include "pair_lj_class2.h" +#include "neigh_list_kokkos.h" + +namespace LAMMPS_NS { + +template +class PairLJClass2Kokkos : public PairLJClass2 { + public: + enum {EnabledNeighFlags=FULL|HALFTHREAD|HALF|N2|FULLCLUSTER}; + enum {COUL_FLAG=0}; + typedef DeviceType device_type; + PairLJClass2Kokkos(class LAMMPS *); + ~PairLJClass2Kokkos(); + + void compute(int, int); + + void settings(int, char **); + void init_style(); + double init_one(int, int); + + struct params_lj{ + params_lj(){cutsq=0,lj1=0;lj2=0;lj3=0;lj4=0;offset=0;}; + params_lj(int i){cutsq=0,lj1=0;lj2=0;lj3=0;lj4=0;offset=0;}; + F_FLOAT cutsq,lj1,lj2,lj3,lj4,offset; + }; + + protected: + void cleanup_copy(); + + template + KOKKOS_INLINE_FUNCTION + F_FLOAT compute_fpair(const F_FLOAT& rsq, const int& i, const int&j, const int& itype, const int& jtype) const; + + template + KOKKOS_INLINE_FUNCTION + F_FLOAT compute_evdwl(const F_FLOAT& rsq, const int& i, const int&j, const int& itype, const int& jtype) const; + + template + KOKKOS_INLINE_FUNCTION + F_FLOAT compute_ecoul(const F_FLOAT& rsq, const int& i, const int&j, const int& itype, const int& jtype) const { + return 0.0; + } + + template + KOKKOS_INLINE_FUNCTION + F_FLOAT compute_fcoul(const F_FLOAT& rsq, const int& i, const int&j, const int& itype, + const int& jtype, const F_FLOAT& factor_coul, const F_FLOAT& qtmp) const { + return 0.0; + } + + Kokkos::DualView k_params; + typename Kokkos::DualView::t_dev_const params; + params_lj m_params[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; // hardwired to space for 15 atom types + F_FLOAT m_cutsq[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; + typename ArrayTypes::t_x_array_randomread x; + typename ArrayTypes::t_x_array c_x; + typename ArrayTypes::t_f_array f; + typename ArrayTypes::t_int_1d_randomread type; + typename ArrayTypes::t_efloat_1d d_eatom; + typename ArrayTypes::t_virial_array d_vatom; + typename ArrayTypes::t_tagint_1d tag; + + int newton_pair; + double special_lj[4]; + + typename ArrayTypes::tdual_ffloat_2d k_cutsq; + typename ArrayTypes::t_ffloat_2d d_cutsq; + + class AtomKokkos *atomKK; + int neighflag; + int nlocal,nall,eflag,vflag; + + void allocate(); + friend class PairComputeFunctor; + friend class PairComputeFunctor; + friend class PairComputeFunctor; + friend class PairComputeFunctor; + friend class PairComputeFunctor; + friend class PairComputeFunctor; + friend class PairComputeFunctor; + friend class PairComputeFunctor; + friend class PairComputeFunctor; + friend class PairComputeFunctor; + friend EV_FLOAT pair_compute_neighlist(PairLJClass2Kokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairLJClass2Kokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairLJClass2Kokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairLJClass2Kokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_fullcluster(PairLJClass2Kokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute(PairLJClass2Kokkos*,NeighListKokkos*); + friend void pair_virial_fdotr_compute(PairLJClass2Kokkos*); +}; + +} + +#endif +#endif + +/* ERROR/WARNING messages: + +*/ diff --git a/src/KOKKOS/pair_lj_cut_coul_debye_kokkos.cpp b/src/KOKKOS/pair_lj_cut_coul_debye_kokkos.cpp new file mode 100644 index 0000000000..92908a62ab --- /dev/null +++ b/src/KOKKOS/pair_lj_cut_coul_debye_kokkos.cpp @@ -0,0 +1,375 @@ +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + http://lammps.sandia.gov, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +/* ---------------------------------------------------------------------- + Contributing author: Ray Shan (SNL) +------------------------------------------------------------------------- */ + +#include "math.h" +#include "stdio.h" +#include "stdlib.h" +#include "string.h" +#include "pair_lj_cut_coul_debye_kokkos.h" +#include "kokkos.h" +#include "atom_kokkos.h" +#include "comm.h" +#include "force.h" +#include "neighbor.h" +#include "neigh_list.h" +#include "neigh_request.h" +#include "update.h" +#include "integrate.h" +#include "respa.h" +#include "math_const.h" +#include "memory.h" +#include "error.h" +#include "atom_masks.h" + +using namespace LAMMPS_NS; +using namespace MathConst; + +#define KOKKOS_CUDA_MAX_THREADS 256 +#define KOKKOS_CUDA_MIN_BLOCKS 8 + +/* ---------------------------------------------------------------------- */ + +template +PairLJCutCoulDebyeKokkos::PairLJCutCoulDebyeKokkos(LAMMPS *lmp):PairLJCutCoulDebye(lmp) +{ + respa_enable = 0; + + atomKK = (AtomKokkos *) atom; + execution_space = ExecutionSpaceFromDevice::space; + datamask_read = X_MASK | F_MASK | TYPE_MASK | Q_MASK | ENERGY_MASK | VIRIAL_MASK; + datamask_modify = F_MASK | ENERGY_MASK | VIRIAL_MASK; + cutsq = NULL; + cut_ljsq = NULL; + cut_coulsq = NULL; + +} + +/* ---------------------------------------------------------------------- */ + +template +PairLJCutCoulDebyeKokkos::~PairLJCutCoulDebyeKokkos() +{ + if (!copymode) { + memory->destroy_kokkos(k_cutsq, cutsq); + memory->destroy_kokkos(k_cut_ljsq, cut_ljsq); + memory->destroy_kokkos(k_cut_coulsq, cut_coulsq); + } +} + +/* ---------------------------------------------------------------------- */ + +template +void PairLJCutCoulDebyeKokkos::cleanup_copy() { + // WHY needed: this prevents parent copy from deallocating any arrays + allocated = 0; + cutsq = NULL; + cut_ljsq = NULL; + cut_coulsq = NULL; + eatom = NULL; + vatom = NULL; +} + +/* ---------------------------------------------------------------------- */ + +template +void PairLJCutCoulDebyeKokkos::compute(int eflag_in, int vflag_in) +{ + eflag = eflag_in; + vflag = vflag_in; + + if (neighflag == FULL || neighflag == FULLCLUSTER) no_virial_fdotr_compute = 1; + + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = vflag_fdotr = 0; + + atomKK->sync(execution_space,datamask_read); + k_cutsq.template sync(); + k_cut_ljsq.template sync(); + k_cut_coulsq.template sync(); + k_params.template sync(); + if (eflag || vflag) atomKK->modified(execution_space,datamask_modify); + else atomKK->modified(execution_space,F_MASK); + + x = atomKK->k_x.view(); + c_x = atomKK->k_x.view(); + f = atomKK->k_f.view(); + q = atomKK->k_q.view(); + type = atomKK->k_type.view(); + nlocal = atom->nlocal; + nall = atom->nlocal + atom->nghost; + special_lj[0] = force->special_lj[0]; + special_lj[1] = force->special_lj[1]; + special_lj[2] = force->special_lj[2]; + special_lj[3] = force->special_lj[3]; + special_coul[0] = force->special_coul[0]; + special_coul[1] = force->special_coul[1]; + special_coul[2] = force->special_coul[2]; + special_coul[3] = force->special_coul[3]; + qqrd2e = force->qqrd2e; + newton_pair = force->newton_pair; + + // loop over neighbors of my atoms + + copymode = 1; + + EV_FLOAT ev = pair_compute,void > + (this,(NeighListKokkos*)list); + + DeviceType::fence(); + + if (eflag) { + eng_vdwl += ev.evdwl; + eng_coul += ev.ecoul; + } + if (vflag_global) { + virial[0] += ev.v[0]; + virial[1] += ev.v[1]; + virial[2] += ev.v[2]; + virial[3] += ev.v[3]; + virial[4] += ev.v[4]; + virial[5] += ev.v[5]; + } + + if (vflag_fdotr) virial_fdotr_compute(); + + copymode = 0; +} + +/* ---------------------------------------------------------------------- + compute LJ 12-6 pair force between atoms i and j + ---------------------------------------------------------------------- */ +template +template +KOKKOS_INLINE_FUNCTION +F_FLOAT PairLJCutCoulDebyeKokkos:: +compute_fpair(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype) const { + const F_FLOAT r2inv = 1.0/rsq; + const F_FLOAT r6inv = r2inv*r2inv*r2inv; + F_FLOAT forcelj; + + forcelj = r6inv * + ((STACKPARAMS?m_params[itype][jtype].lj1:params(itype,jtype).lj1)*r6inv - + (STACKPARAMS?m_params[itype][jtype].lj2:params(itype,jtype).lj2)); + + return forcelj*r2inv; +} + +/* ---------------------------------------------------------------------- + compute coulomb pair force between atoms i and j + ---------------------------------------------------------------------- */ +template +template +KOKKOS_INLINE_FUNCTION +F_FLOAT PairLJCutCoulDebyeKokkos:: +compute_fcoul(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype, const F_FLOAT& factor_coul, const F_FLOAT& qtmp) const { + + const F_FLOAT r2inv = 1.0/rsq; + const F_FLOAT rinv = sqrt(r2inv); + const F_FLOAT r = 1.0/rinv; + const F_FLOAT screening = exp(-kappa*r); + F_FLOAT forcecoul; + + forcecoul = qqrd2e * qtmp * q(j) * screening * (kappa + rinv); + + return factor_coul*forcecoul*r2inv; + +} + +/* ---------------------------------------------------------------------- + compute LJ 12-6 pair potential energy between atoms i and j + ---------------------------------------------------------------------- */ +template +template +KOKKOS_INLINE_FUNCTION +F_FLOAT PairLJCutCoulDebyeKokkos:: +compute_evdwl(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype) const { + const F_FLOAT r2inv = 1.0/rsq; + const F_FLOAT r6inv = r2inv*r2inv*r2inv; + + return r6inv* + ((STACKPARAMS?m_params[itype][jtype].lj3:params(itype,jtype).lj3)*r6inv + - (STACKPARAMS?m_params[itype][jtype].lj4:params(itype,jtype).lj4)) + - (STACKPARAMS?m_params[itype][jtype].offset:params(itype,jtype).offset); + +} + +/* ---------------------------------------------------------------------- + compute coulomb pair potential energy between atoms i and j + ---------------------------------------------------------------------- */ +template +template +KOKKOS_INLINE_FUNCTION +F_FLOAT PairLJCutCoulDebyeKokkos:: +compute_ecoul(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype, const F_FLOAT& factor_coul, const F_FLOAT& qtmp) const { + + const F_FLOAT r2inv = 1.0/rsq; + const F_FLOAT rinv = sqrt(r2inv); + const F_FLOAT r = 1.0/rinv; + const F_FLOAT screening = exp(-kappa*r); + + return factor_coul * qqrd2e * qtmp * q(j) * rinv * screening; +} + + +/* ---------------------------------------------------------------------- + allocate all arrays +------------------------------------------------------------------------- */ + +template +void PairLJCutCoulDebyeKokkos::allocate() +{ + PairLJCutCoulDebye::allocate(); + + int n = atom->ntypes; + memory->destroy(cutsq); + memory->create_kokkos(k_cutsq,cutsq,n+1,n+1,"pair:cutsq"); + d_cutsq = k_cutsq.template view(); + memory->destroy(cut_ljsq); + memory->create_kokkos(k_cut_ljsq,cut_ljsq,n+1,n+1,"pair:cut_ljsq"); + d_cut_ljsq = k_cut_ljsq.template view(); + memory->destroy(cut_coulsq); + memory->create_kokkos(k_cut_coulsq,cut_coulsq,n+1,n+1,"pair:cut_coulsq"); + d_cut_coulsq = k_cut_coulsq.template view(); + k_params = Kokkos::DualView("PairLJCutCoulDebye::params",n+1,n+1); + params = k_params.d_view; +} + +/* ---------------------------------------------------------------------- + global settings +------------------------------------------------------------------------- */ + +template +void PairLJCutCoulDebyeKokkos::settings(int narg, char **arg) +{ + if (narg < 2 || narg > 3) error->all(FLERR,"Illegal pair_style command"); + + kappa = force->numeric(FLERR,arg[0]); + cut_lj_global = force->numeric(FLERR,arg[1]); + if (narg == 2) cut_coul_global = cut_lj_global; + else cut_coul_global = force->numeric(FLERR,arg[2]); + + // reset cutoffs that were previously set from data file + + if (allocated) { + int i,j; + for (i = 1; i <= atom->ntypes; i++) + for (j = i+1; j <= atom->ntypes; j++) + if (setflag[i][j] == 1) { + cut_lj[i][j] = cut_lj_global; + cut_coul[i][j] = cut_coul_global; + } + } +} + +/* ---------------------------------------------------------------------- + init specific to this pair style +------------------------------------------------------------------------- */ + +template +void PairLJCutCoulDebyeKokkos::init_style() +{ + PairLJCutCoulDebye::init_style(); + + // error if rRESPA with inner levels + + if (update->whichflag == 1 && strstr(update->integrate_style,"respa")) { + int respa = 0; + if (((Respa *) update->integrate)->level_inner >= 0) respa = 1; + if (((Respa *) update->integrate)->level_middle >= 0) respa = 2; + if (respa) + error->all(FLERR,"Cannot use Kokkos pair style with rRESPA inner/middle"); + } + + // irequest = neigh request made by parent class + + neighflag = lmp->kokkos->neighflag; + int irequest = neighbor->nrequest - 1; + + neighbor->requests[irequest]-> + kokkos_host = Kokkos::Impl::is_same::value && + !Kokkos::Impl::is_same::value; + neighbor->requests[irequest]-> + kokkos_device = Kokkos::Impl::is_same::value; + + if (neighflag == FULL) { + neighbor->requests[irequest]->full = 1; + neighbor->requests[irequest]->half = 0; + neighbor->requests[irequest]->full_cluster = 0; + } else if (neighflag == HALF || neighflag == HALFTHREAD) { + neighbor->requests[irequest]->full = 0; + neighbor->requests[irequest]->half = 1; + neighbor->requests[irequest]->full_cluster = 0; + } else if (neighflag == N2) { + neighbor->requests[irequest]->full = 0; + neighbor->requests[irequest]->half = 0; + neighbor->requests[irequest]->full_cluster = 0; + } else if (neighflag == FULLCLUSTER) { + neighbor->requests[irequest]->full_cluster = 1; + neighbor->requests[irequest]->full = 1; + neighbor->requests[irequest]->half = 0; + } else { + error->all(FLERR,"Cannot use chosen neighbor list style with lj/cut/coul/debye/kk"); + } +} + +/* ---------------------------------------------------------------------- + init for one type pair i,j and corresponding j,i +------------------------------------------------------------------------- */ + +template +double PairLJCutCoulDebyeKokkos::init_one(int i, int j) +{ + double cutone = PairLJCutCoulDebye::init_one(i,j); + double cut_ljsqm = cut_ljsq[i][j]; + double cut_coulsqm = cut_coulsq[i][j]; + + k_params.h_view(i,j).lj1 = lj1[i][j]; + k_params.h_view(i,j).lj2 = lj2[i][j]; + k_params.h_view(i,j).lj3 = lj3[i][j]; + k_params.h_view(i,j).lj4 = lj4[i][j]; + k_params.h_view(i,j).offset = offset[i][j]; + k_params.h_view(i,j).cut_ljsq = cut_ljsqm; + k_params.h_view(i,j).cut_coulsq = cut_coulsqm; + + k_params.h_view(j,i) = k_params.h_view(i,j); + if(i(); + k_cut_ljsq.h_view(i,j) = cut_ljsqm; + k_cut_ljsq.template modify(); + k_cut_coulsq.h_view(i,j) = cut_coulsqm; + k_cut_coulsq.template modify(); + k_params.template modify(); + + return cutone; +} + + + +template class PairLJCutCoulDebyeKokkos; +#ifdef KOKKOS_HAVE_CUDA +template class PairLJCutCoulDebyeKokkos; +#endif diff --git a/src/KOKKOS/pair_lj_cut_coul_debye_kokkos.h b/src/KOKKOS/pair_lj_cut_coul_debye_kokkos.h new file mode 100644 index 0000000000..0e8d0c2547 --- /dev/null +++ b/src/KOKKOS/pair_lj_cut_coul_debye_kokkos.h @@ -0,0 +1,131 @@ +/* -*- c++ -*- ---------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + http://lammps.sandia.gov, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +#ifdef PAIR_CLASS + +PairStyle(lj/cut/coul/debye/kk,PairLJCutCoulDebyeKokkos) +PairStyle(lj/cut/coul/debye/kk/device,PairLJCutCoulDebyeKokkos) +PairStyle(lj/cut/coul/debye/kk/host,PairLJCutCoulDebyeKokkos) + +#else + +#ifndef LMP_PAIR_LJ_CUT_COUL_DEBYE_KOKKOS_H +#define LMP_PAIR_LJ_CUT_COUL_DEBYE_KOKKOS_H + +#include "pair_kokkos.h" +#include "pair_lj_cut_coul_debye.h" +#include "neigh_list_kokkos.h" + +namespace LAMMPS_NS { + +template +class PairLJCutCoulDebyeKokkos : public PairLJCutCoulDebye { + public: + enum {EnabledNeighFlags=FULL|HALFTHREAD|HALF}; + enum {COUL_FLAG=1}; + typedef DeviceType device_type; + PairLJCutCoulDebyeKokkos(class LAMMPS *); + ~PairLJCutCoulDebyeKokkos(); + + void compute(int, int); + + void settings(int, char **); + void init_style(); + double init_one(int, int); + + struct params_lj_coul{ + params_lj_coul(){cut_ljsq=0;cut_coulsq=0;lj1=0;lj2=0;lj3=0;lj4=0;offset=0;}; + params_lj_coul(int i){cut_ljsq=0;cut_coulsq=0;lj1=0;lj2=0;lj3=0;lj4=0;offset=0;}; + F_FLOAT cut_ljsq,cut_coulsq,lj1,lj2,lj3,lj4,offset; + }; + + protected: + void cleanup_copy(); + + template + KOKKOS_INLINE_FUNCTION + F_FLOAT compute_fpair(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype) const; + + template + KOKKOS_INLINE_FUNCTION + F_FLOAT compute_fcoul(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype, const F_FLOAT& factor_coul, const F_FLOAT& qtmp) const; + + template + KOKKOS_INLINE_FUNCTION + F_FLOAT compute_evdwl(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype) const; + + template + KOKKOS_INLINE_FUNCTION + F_FLOAT compute_ecoul(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype, const F_FLOAT& factor_coul, const F_FLOAT& qtmp) const; + + Kokkos::DualView k_params; + typename Kokkos::DualView::t_dev_const params; + // hardwired to space for 15 atom types + params_lj_coul m_params[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; + + F_FLOAT m_cutsq[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; + F_FLOAT m_cut_ljsq[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; + F_FLOAT m_cut_coulsq[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; + typename ArrayTypes::t_x_array_randomread x; + typename ArrayTypes::t_x_array c_x; + typename ArrayTypes::t_f_array f; + typename ArrayTypes::t_int_1d_randomread type; + typename ArrayTypes::t_float_1d_randomread q; + typename ArrayTypes::t_efloat_1d d_eatom; + typename ArrayTypes::t_virial_array d_vatom; + + int newton_pair; + + typename ArrayTypes::tdual_ffloat_2d k_cutsq; + typename ArrayTypes::t_ffloat_2d d_cutsq; + typename ArrayTypes::tdual_ffloat_2d k_cut_ljsq; + typename ArrayTypes::t_ffloat_2d d_cut_ljsq; + typename ArrayTypes::tdual_ffloat_2d k_cut_coulsq; + typename ArrayTypes::t_ffloat_2d d_cut_coulsq; + + class AtomKokkos *atomKK; + int neighflag; + int nlocal,nall,eflag,vflag; + + double special_coul[4]; + double special_lj[4]; + double qqrd2e; + + void allocate(); + friend class PairComputeFunctor; + friend class PairComputeFunctor; + friend class PairComputeFunctor; + friend class PairComputeFunctor; + friend class PairComputeFunctor; + friend class PairComputeFunctor; + friend EV_FLOAT pair_compute_neighlist(PairLJCutCoulDebyeKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairLJCutCoulDebyeKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairLJCutCoulDebyeKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute(PairLJCutCoulDebyeKokkos*, + NeighListKokkos*); + +}; + +} + +#endif +#endif + +/* ERROR/WARNING messages: + +*/ diff --git a/src/KOKKOS/pair_lj_cut_coul_dsf_kokkos.cpp b/src/KOKKOS/pair_lj_cut_coul_dsf_kokkos.cpp new file mode 100644 index 0000000000..2c74fa91ca --- /dev/null +++ b/src/KOKKOS/pair_lj_cut_coul_dsf_kokkos.cpp @@ -0,0 +1,366 @@ +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + http://lammps.sandia.gov, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +/* ---------------------------------------------------------------------- + Contributing author: Ray Shan (SNL) +------------------------------------------------------------------------- */ + +#include "math.h" +#include "stdio.h" +#include "stdlib.h" +#include "string.h" +#include "pair_lj_cut_coul_dsf_kokkos.h" +#include "kokkos.h" +#include "atom_kokkos.h" +#include "comm.h" +#include "force.h" +#include "neighbor.h" +#include "neigh_list.h" +#include "neigh_request.h" +#include "update.h" +#include "integrate.h" +#include "respa.h" +#include "math_const.h" +#include "memory.h" +#include "error.h" +#include "atom_masks.h" + +using namespace LAMMPS_NS; +using namespace MathConst; + +#define KOKKOS_CUDA_MAX_THREADS 256 +#define KOKKOS_CUDA_MIN_BLOCKS 8 + +#define EWALD_F 1.12837917 +#define EWALD_P 0.3275911 +#define A1 0.254829592 +#define A2 -0.284496736 +#define A3 1.421413741 +#define A4 -1.453152027 +#define A5 1.061405429 + +/* ---------------------------------------------------------------------- */ + +template +PairLJCutCoulDSFKokkos::PairLJCutCoulDSFKokkos(LAMMPS *lmp):PairLJCutCoulDSF(lmp) +{ + respa_enable = 0; + + atomKK = (AtomKokkos *) atom; + execution_space = ExecutionSpaceFromDevice::space; + datamask_read = X_MASK | F_MASK | TYPE_MASK | Q_MASK | ENERGY_MASK | VIRIAL_MASK; + datamask_modify = F_MASK | ENERGY_MASK | VIRIAL_MASK; + cutsq = NULL; + cut_ljsq = NULL; + //cut_coulsq = NULL; + +} + +/* ---------------------------------------------------------------------- */ + +template +PairLJCutCoulDSFKokkos::~PairLJCutCoulDSFKokkos() +{ + if (!copymode) { + memory->destroy_kokkos(k_cutsq, cutsq); + memory->destroy_kokkos(k_cut_ljsq, cut_ljsq); + //memory->destroy_kokkos(k_cut_coulsq, cut_coulsq); + } +} + +/* ---------------------------------------------------------------------- */ + +template +void PairLJCutCoulDSFKokkos::cleanup_copy() { + // WHY needed: this prevents parent copy from deallocating any arrays + allocated = 0; + cutsq = NULL; + cut_ljsq = NULL; + //cut_coulsq = NULL; + eatom = NULL; + vatom = NULL; +} + +/* ---------------------------------------------------------------------- */ + +template +void PairLJCutCoulDSFKokkos::compute(int eflag_in, int vflag_in) +{ + eflag = eflag_in; + vflag = vflag_in; + + if (neighflag == FULL || neighflag == FULLCLUSTER) no_virial_fdotr_compute = 1; + + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = vflag_fdotr = 0; + + atomKK->sync(execution_space,datamask_read); + k_cutsq.template sync(); + k_cut_ljsq.template sync(); + k_cut_coulsq.template sync(); + k_params.template sync(); + if (eflag || vflag) atomKK->modified(execution_space,datamask_modify); + else atomKK->modified(execution_space,F_MASK); + + x = atomKK->k_x.view(); + c_x = atomKK->k_x.view(); + f = atomKK->k_f.view(); + q = atomKK->k_q.view(); + type = atomKK->k_type.view(); + nlocal = atom->nlocal; + nall = atom->nlocal + atom->nghost; + special_lj[0] = force->special_lj[0]; + special_lj[1] = force->special_lj[1]; + special_lj[2] = force->special_lj[2]; + special_lj[3] = force->special_lj[3]; + special_coul[0] = force->special_coul[0]; + special_coul[1] = force->special_coul[1]; + special_coul[2] = force->special_coul[2]; + special_coul[3] = force->special_coul[3]; + qqrd2e = force->qqrd2e; + newton_pair = force->newton_pair; + + // loop over neighbors of my atoms + + EV_FLOAT ev; + + copymode = 1; + + int inum = list->inum; + + for (int ii = 0; ii < inum; ii ++) { + //int i = list->ilist[ii]; + double qtmp = atom->q[ii]; + eng_coul += -(e_shift/2.0 + alpha/MY_PIS) * qtmp*qtmp*qqrd2e; + } + + ev = pair_compute,void > + (this,(NeighListKokkos*)list); + + DeviceType::fence(); + + if (eflag) { + eng_vdwl += ev.evdwl; + eng_coul += ev.ecoul; + } + if (vflag_global) { + virial[0] += ev.v[0]; + virial[1] += ev.v[1]; + virial[2] += ev.v[2]; + virial[3] += ev.v[3]; + virial[4] += ev.v[4]; + virial[5] += ev.v[5]; + } + + if (vflag_fdotr) virial_fdotr_compute(); + + copymode = 0; +} + +/* ---------------------------------------------------------------------- + compute LJ 12-6 pair force between atoms i and j + ---------------------------------------------------------------------- */ +template +template +KOKKOS_INLINE_FUNCTION +F_FLOAT PairLJCutCoulDSFKokkos:: +compute_fpair(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype) const { + const F_FLOAT r2inv = 1.0/rsq; + const F_FLOAT r6inv = r2inv*r2inv*r2inv; + F_FLOAT forcelj; + + forcelj = r6inv * + ((STACKPARAMS?m_params[itype][jtype].lj1:params(itype,jtype).lj1)*r6inv - + (STACKPARAMS?m_params[itype][jtype].lj2:params(itype,jtype).lj2)); + + return forcelj*r2inv; +} + +/* ---------------------------------------------------------------------- + compute LJ 12-6 pair potential energy between atoms i and j + ---------------------------------------------------------------------- */ +template +template +KOKKOS_INLINE_FUNCTION +F_FLOAT PairLJCutCoulDSFKokkos:: +compute_evdwl(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype) const { + const F_FLOAT r2inv = 1.0/rsq; + const F_FLOAT r6inv = r2inv*r2inv*r2inv; + + return r6inv* + ((STACKPARAMS?m_params[itype][jtype].lj3:params(itype,jtype).lj3)*r6inv + - (STACKPARAMS?m_params[itype][jtype].lj4:params(itype,jtype).lj4)) + - (STACKPARAMS?m_params[itype][jtype].offset:params(itype,jtype).offset); + +} + +/* ---------------------------------------------------------------------- + compute coulomb pair force between atoms i and j + ---------------------------------------------------------------------- */ +template +template +KOKKOS_INLINE_FUNCTION +F_FLOAT PairLJCutCoulDSFKokkos:: +compute_fcoul(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype, const F_FLOAT& factor_coul, const F_FLOAT& qtmp) const { + + const F_FLOAT r2inv = 1.0/rsq; + const F_FLOAT r = sqrt(rsq); + const F_FLOAT prefactor = factor_coul * qqrd2e * qtmp * q(j); + const F_FLOAT erfcd = exp(-alpha*alpha*rsq); + const F_FLOAT t = 1.0 / (1.0 + EWALD_P*alpha*r); + const F_FLOAT erfcc = t * (A1+t*(A2+t*(A3+t*(A4+t*A5)))) * erfcd; + + return prefactor * (erfcc/r + 2.0*alpha/MY_PIS * erfcd + r*f_shift) * + r2inv; +} + +/* ---------------------------------------------------------------------- + compute coulomb pair potential energy between atoms i and j + ---------------------------------------------------------------------- */ +template +template +KOKKOS_INLINE_FUNCTION +F_FLOAT PairLJCutCoulDSFKokkos:: +compute_ecoul(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype, const F_FLOAT& factor_coul, const F_FLOAT& qtmp) const { + + const F_FLOAT r = sqrt(rsq); + const F_FLOAT prefactor = factor_coul * qqrd2e * qtmp * q(j); + const F_FLOAT erfcd = exp(-alpha*alpha*rsq); + const F_FLOAT t = 1.0 / (1.0 + EWALD_P*alpha*r); + const F_FLOAT erfcc = t * (A1+t*(A2+t*(A3+t*(A4+t*A5)))) * erfcd; + + return prefactor * (erfcc - r*e_shift - rsq*f_shift) / r; + +} + +/* ---------------------------------------------------------------------- + allocate all arrays +------------------------------------------------------------------------- */ + +template +void PairLJCutCoulDSFKokkos::allocate() +{ + PairLJCutCoulDSF::allocate(); + + int n = atom->ntypes; + memory->destroy(cutsq); + memory->create_kokkos(k_cutsq,cutsq,n+1,n+1,"pair:cutsq"); + d_cutsq = k_cutsq.template view(); + memory->destroy(cut_ljsq); + memory->create_kokkos(k_cut_ljsq,cut_ljsq,n+1,n+1,"pair:cut_ljsq"); + d_cut_ljsq = k_cut_ljsq.template view(); + //memory->destroy(cut_coulsq); + memory->create_kokkos(k_cut_coulsq,n+1,n+1,"pair:cut_coulsq"); + d_cut_coulsq = k_cut_coulsq.template view(); + k_params = Kokkos::DualView("PairLJCutCoulDSF::params",n+1,n+1); + params = k_params.d_view; +} + +/* ---------------------------------------------------------------------- + init specific to this pair style +------------------------------------------------------------------------- */ + +template +void PairLJCutCoulDSFKokkos::init_style() +{ + PairLJCutCoulDSF::init_style(); + + // error if rRESPA with inner levels + + if (update->whichflag == 1 && strstr(update->integrate_style,"respa")) { + int respa = 0; + if (((Respa *) update->integrate)->level_inner >= 0) respa = 1; + if (((Respa *) update->integrate)->level_middle >= 0) respa = 2; + if (respa) + error->all(FLERR,"Cannot use Kokkos pair style with rRESPA inner/middle"); + } + + // irequest = neigh request made by parent class + + neighflag = lmp->kokkos->neighflag; + int irequest = neighbor->nrequest - 1; + + neighbor->requests[irequest]-> + kokkos_host = Kokkos::Impl::is_same::value && + !Kokkos::Impl::is_same::value; + neighbor->requests[irequest]-> + kokkos_device = Kokkos::Impl::is_same::value; + + if (neighflag == FULL) { + neighbor->requests[irequest]->full = 1; + neighbor->requests[irequest]->half = 0; + neighbor->requests[irequest]->full_cluster = 0; + } else if (neighflag == HALF || neighflag == HALFTHREAD) { + neighbor->requests[irequest]->full = 0; + neighbor->requests[irequest]->half = 1; + neighbor->requests[irequest]->full_cluster = 0; + } else if (neighflag == N2) { + neighbor->requests[irequest]->full = 0; + neighbor->requests[irequest]->half = 0; + neighbor->requests[irequest]->full_cluster = 0; + } else if (neighflag == FULLCLUSTER) { + neighbor->requests[irequest]->full_cluster = 1; + neighbor->requests[irequest]->full = 1; + neighbor->requests[irequest]->half = 0; + } else { + error->all(FLERR,"Cannot use chosen neighbor list style with lj/cut/coul/cut/kk"); + } +} + +/* ---------------------------------------------------------------------- + init for one type pair i,j and corresponding j,i +------------------------------------------------------------------------- */ + +template +double PairLJCutCoulDSFKokkos::init_one(int i, int j) +{ + double cutone = PairLJCutCoulDSF::init_one(i,j); + double cut_ljsqm = cut_ljsq[i][j]; + double cut_coulsqm = cut_coulsq; + + k_params.h_view(i,j).lj1 = lj1[i][j]; + k_params.h_view(i,j).lj2 = lj2[i][j]; + k_params.h_view(i,j).lj3 = lj3[i][j]; + k_params.h_view(i,j).lj4 = lj4[i][j]; + k_params.h_view(i,j).offset = offset[i][j]; + k_params.h_view(i,j).cut_ljsq = cut_ljsqm; + k_params.h_view(i,j).cut_coulsq = cut_coulsqm; + + k_params.h_view(j,i) = k_params.h_view(i,j); + if(i(); + k_cut_ljsq.h_view(i,j) = cut_ljsqm; + k_cut_ljsq.template modify(); + k_cut_coulsq.h_view(i,j) = cut_coulsqm; + k_cut_coulsq.template modify(); + k_params.template modify(); + + return cutone; +} + + + +template class PairLJCutCoulDSFKokkos; +#ifdef KOKKOS_HAVE_CUDA +template class PairLJCutCoulDSFKokkos; +#endif diff --git a/src/KOKKOS/pair_lj_cut_coul_dsf_kokkos.h b/src/KOKKOS/pair_lj_cut_coul_dsf_kokkos.h new file mode 100644 index 0000000000..bf58c91f51 --- /dev/null +++ b/src/KOKKOS/pair_lj_cut_coul_dsf_kokkos.h @@ -0,0 +1,130 @@ +/* -*- c++ -*- ---------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + http://lammps.sandia.gov, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +#ifdef PAIR_CLASS + +PairStyle(lj/cut/coul/dsf/kk,PairLJCutCoulDSFKokkos) +PairStyle(lj/cut/coul/dsf/kk/device,PairLJCutCoulDSFKokkos) +PairStyle(lj/cut/coul/dsf/kk/host,PairLJCutCoulDSFKokkos) + +#else + +#ifndef LMP_PAIR_LJ_CUT_COUL_DSF_KOKKOS_H +#define LMP_PAIR_LJ_CUT_COUL_DSF_KOKKOS_H + +#include "pair_kokkos.h" +#include "pair_lj_cut_coul_dsf.h" +#include "neigh_list_kokkos.h" + +namespace LAMMPS_NS { + +template +class PairLJCutCoulDSFKokkos : public PairLJCutCoulDSF { + public: + enum {EnabledNeighFlags=FULL|HALFTHREAD|HALF}; + enum {COUL_FLAG=1}; + typedef DeviceType device_type; + PairLJCutCoulDSFKokkos(class LAMMPS *); + ~PairLJCutCoulDSFKokkos(); + + void compute(int, int); + + void init_style(); + double init_one(int, int); + + struct params_lj_coul{ + params_lj_coul(){cut_ljsq=0;cut_coulsq=0;lj1=0;lj2=0;lj3=0;lj4=0;offset=0;}; + params_lj_coul(int i){cut_ljsq=0;cut_coulsq=0;lj1=0;lj2=0;lj3=0;lj4=0;offset=0;}; + F_FLOAT cut_ljsq,cut_coulsq,lj1,lj2,lj3,lj4,offset; + }; + + protected: + void cleanup_copy(); + + template + KOKKOS_INLINE_FUNCTION + F_FLOAT compute_fpair(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype) const; + + template + KOKKOS_INLINE_FUNCTION + F_FLOAT compute_fcoul(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype, const F_FLOAT& factor_coul, const F_FLOAT& qtmp) const; + + template + KOKKOS_INLINE_FUNCTION + F_FLOAT compute_evdwl(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype) const; + + template + KOKKOS_INLINE_FUNCTION + F_FLOAT compute_ecoul(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype, const F_FLOAT& factor_coul, const F_FLOAT& qtmp) const; + + Kokkos::DualView k_params; + typename Kokkos::DualView::t_dev_const params; + // hardwired to space for 15 atom types + params_lj_coul m_params[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; + + F_FLOAT m_cutsq[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; + F_FLOAT m_cut_ljsq[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; + F_FLOAT m_cut_coulsq[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; + typename ArrayTypes::t_x_array_randomread x; + typename ArrayTypes::t_x_array c_x; + typename ArrayTypes::t_f_array f; + typename ArrayTypes::t_int_1d_randomread type; + typename ArrayTypes::t_float_1d_randomread q; + typename ArrayTypes::t_efloat_1d d_eatom; + typename ArrayTypes::t_virial_array d_vatom; + + int newton_pair; + + typename ArrayTypes::tdual_ffloat_2d k_cutsq; + typename ArrayTypes::t_ffloat_2d d_cutsq; + typename ArrayTypes::tdual_ffloat_2d k_cut_ljsq; + typename ArrayTypes::t_ffloat_2d d_cut_ljsq; + typename ArrayTypes::tdual_ffloat_2d k_cut_coulsq; + typename ArrayTypes::t_ffloat_2d d_cut_coulsq; + + class AtomKokkos *atomKK; + int neighflag; + int nlocal,nall,eflag,vflag; + + double special_coul[4]; + double special_lj[4]; + double qqrd2e; + + void allocate(); + friend class PairComputeFunctor; + friend class PairComputeFunctor; + friend class PairComputeFunctor; + friend class PairComputeFunctor; + friend class PairComputeFunctor; + friend class PairComputeFunctor; + friend EV_FLOAT pair_compute_neighlist(PairLJCutCoulDSFKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairLJCutCoulDSFKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairLJCutCoulDSFKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute(PairLJCutCoulDSFKokkos*, + NeighListKokkos*); + +}; + +} + +#endif +#endif + +/* ERROR/WARNING messages: + +*/ diff --git a/src/KOKKOS/pair_lj_expand_kokkos.cpp b/src/KOKKOS/pair_lj_expand_kokkos.cpp new file mode 100644 index 0000000000..43efff0205 --- /dev/null +++ b/src/KOKKOS/pair_lj_expand_kokkos.cpp @@ -0,0 +1,285 @@ +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + http://lammps.sandia.gov, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +/* ---------------------------------------------------------------------- + Contributing author: Ray Shan (SNL) +------------------------------------------------------------------------- */ + +#include "math.h" +#include "stdio.h" +#include "stdlib.h" +#include "string.h" +#include "pair_lj_expand_kokkos.h" +#include "kokkos.h" +#include "atom_kokkos.h" +#include "comm.h" +#include "force.h" +#include "neighbor.h" +#include "neigh_list.h" +#include "neigh_request.h" +#include "update.h" +#include "integrate.h" +#include "respa.h" +#include "math_const.h" +#include "memory.h" +#include "error.h" +#include "atom_masks.h" + +using namespace LAMMPS_NS; +using namespace MathConst; + +#define KOKKOS_CUDA_MAX_THREADS 256 +#define KOKKOS_CUDA_MIN_BLOCKS 8 + +/* ---------------------------------------------------------------------- */ + +template +PairLJExpandKokkos::PairLJExpandKokkos(LAMMPS *lmp) : PairLJExpand(lmp) +{ + respa_enable = 0; + + atomKK = (AtomKokkos *) atom; + execution_space = ExecutionSpaceFromDevice::space; + datamask_read = X_MASK | F_MASK | TYPE_MASK | ENERGY_MASK | VIRIAL_MASK; + datamask_modify = F_MASK | ENERGY_MASK | VIRIAL_MASK; + cutsq = NULL; +} + +/* ---------------------------------------------------------------------- */ + +template +PairLJExpandKokkos::~PairLJExpandKokkos() +{ + if (!copymode) { + k_cutsq = DAT::tdual_ffloat_2d(); + memory->sfree(cutsq); + cutsq = NULL; + } +} + +/* ---------------------------------------------------------------------- */ + +template +void PairLJExpandKokkos::cleanup_copy() { + // WHY needed: this prevents parent copy from deallocating any arrays + allocated = 0; + cutsq = NULL; + eatom = NULL; + vatom = NULL; +} + +/* ---------------------------------------------------------------------- */ + +template +void PairLJExpandKokkos::compute(int eflag_in, int vflag_in) +{ + eflag = eflag_in; + vflag = vflag_in; + + if (neighflag == FULL || neighflag == FULLCLUSTER) no_virial_fdotr_compute = 1; + + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = vflag_fdotr = 0; + + atomKK->sync(execution_space,datamask_read); + k_cutsq.template sync(); + k_params.template sync(); + if (eflag || vflag) atomKK->modified(execution_space,datamask_modify); + else atomKK->modified(execution_space,F_MASK); + + x = atomKK->k_x.view(); + c_x = atomKK->k_x.view(); + f = atomKK->k_f.view(); + type = atomKK->k_type.view(); + tag = atomKK->k_tag.view(); + nlocal = atom->nlocal; + nall = atom->nlocal + atom->nghost; + newton_pair = force->newton_pair; + special_lj[0] = force->special_lj[0]; + special_lj[1] = force->special_lj[1]; + special_lj[2] = force->special_lj[2]; + special_lj[3] = force->special_lj[3]; + + // loop over neighbors of my atoms + + copymode = 1; + + EV_FLOAT ev = pair_compute,void >(this,(NeighListKokkos*)list); + DeviceType::fence(); + + if (eflag) eng_vdwl += ev.evdwl; + if (vflag_global) { + virial[0] += ev.v[0]; + virial[1] += ev.v[1]; + virial[2] += ev.v[2]; + virial[3] += ev.v[3]; + virial[4] += ev.v[4]; + virial[5] += ev.v[5]; + } + + if (vflag_fdotr) pair_virial_fdotr_compute(this); + + copymode = 0; +} + +template +template +KOKKOS_INLINE_FUNCTION +F_FLOAT PairLJExpandKokkos:: +compute_fpair(const F_FLOAT& rsq, const int& i, const int&j, const int& itype, const int& jtype) const { + + const F_FLOAT r = sqrt(rsq); + const F_FLOAT rshift = r - (STACKPARAMS?m_params[itype][jtype].shift:params(itype,jtype).shift); + const F_FLOAT rshiftsq = rshift*rshift; + const F_FLOAT r2inv = 1.0/rshiftsq; + const F_FLOAT r6inv = r2inv*r2inv*r2inv; + + const F_FLOAT forcelj = r6inv * + ((STACKPARAMS?m_params[itype][jtype].lj1:params(itype,jtype).lj1)*r6inv - + (STACKPARAMS?m_params[itype][jtype].lj2:params(itype,jtype).lj2)); + + return forcelj/rshift/r; + +} + +template +template +KOKKOS_INLINE_FUNCTION +F_FLOAT PairLJExpandKokkos:: +compute_evdwl(const F_FLOAT& rsq, const int& i, const int&j, const int& itype, const int& jtype) const { + + const F_FLOAT r = sqrt(rsq); + const F_FLOAT rshift = r - (STACKPARAMS?m_params[itype][jtype].shift:params(itype,jtype).shift); + const F_FLOAT rshiftsq = rshift*rshift; + const F_FLOAT r2inv = 1.0/rshiftsq; + const F_FLOAT r6inv = r2inv*r2inv*r2inv; + + return r6inv*((STACKPARAMS?m_params[itype][jtype].lj3:params(itype,jtype).lj3)*r6inv - + (STACKPARAMS?m_params[itype][jtype].lj4:params(itype,jtype).lj4)) - + (STACKPARAMS?m_params[itype][jtype].offset:params(itype,jtype).offset); +} + +/* ---------------------------------------------------------------------- + allocate all arrays +------------------------------------------------------------------------- */ + +template +void PairLJExpandKokkos::allocate() +{ + PairLJExpand::allocate(); + + int n = atom->ntypes; + memory->destroy(cutsq); + memory->create_kokkos(k_cutsq,cutsq,n+1,n+1,"pair:cutsq"); + d_cutsq = k_cutsq.template view(); + k_params = Kokkos::DualView("PairLJExpand::params",n+1,n+1); + params = k_params.d_view; +} + +/* ---------------------------------------------------------------------- + global settings +------------------------------------------------------------------------- */ + +template +void PairLJExpandKokkos::settings(int narg, char **arg) +{ + if (narg != 1) error->all(FLERR,"Illegal pair_style command"); + + PairLJExpand::settings(1,arg); +} + +/* ---------------------------------------------------------------------- + init specific to this pair style +------------------------------------------------------------------------- */ + +template +void PairLJExpandKokkos::init_style() +{ + PairLJExpand::init_style(); + + // error if rRESPA with inner levels + + if (update->whichflag == 1 && strstr(update->integrate_style,"respa")) { + int respa = 0; + if (((Respa *) update->integrate)->level_inner >= 0) respa = 1; + if (((Respa *) update->integrate)->level_middle >= 0) respa = 2; + if (respa) + error->all(FLERR,"Cannot use Kokkos pair style with rRESPA inner/middle"); + } + + // irequest = neigh request made by parent class + + neighflag = lmp->kokkos->neighflag; + int irequest = neighbor->nrequest - 1; + + neighbor->requests[irequest]-> + kokkos_host = Kokkos::Impl::is_same::value && + !Kokkos::Impl::is_same::value; + neighbor->requests[irequest]-> + kokkos_device = Kokkos::Impl::is_same::value; + + if (neighflag == FULL) { + neighbor->requests[irequest]->full = 1; + neighbor->requests[irequest]->half = 0; + neighbor->requests[irequest]->full_cluster = 0; + } else if (neighflag == HALF || neighflag == HALFTHREAD) { + neighbor->requests[irequest]->full = 0; + neighbor->requests[irequest]->half = 1; + neighbor->requests[irequest]->full_cluster = 0; + } else if (neighflag == N2) { + neighbor->requests[irequest]->full = 0; + neighbor->requests[irequest]->half = 0; + neighbor->requests[irequest]->full_cluster = 0; + } else if (neighflag == FULLCLUSTER) { + neighbor->requests[irequest]->full_cluster = 1; + neighbor->requests[irequest]->full = 1; + neighbor->requests[irequest]->half = 0; + } else { + error->all(FLERR,"Cannot use chosen neighbor list style with lj/expand/kk"); + } +} + +/* ---------------------------------------------------------------------- + init for one type pair i,j and corresponding j,i +------------------------------------------------------------------------- */ + +template +double PairLJExpandKokkos::init_one(int i, int j) +{ + double cutone = PairLJExpand::init_one(i,j); + + k_params.h_view(i,j).lj1 = lj1[i][j]; + k_params.h_view(i,j).lj2 = lj2[i][j]; + k_params.h_view(i,j).lj3 = lj3[i][j]; + k_params.h_view(i,j).lj4 = lj4[i][j]; + k_params.h_view(i,j).offset = offset[i][j]; + k_params.h_view(i,j).shift = shift[i][j]; + k_params.h_view(i,j).cutsq = cutone*cutone; + k_params.h_view(j,i) = k_params.h_view(i,j); + if(i(); + k_params.template modify(); + + return cutone; +} + + + +template class PairLJExpandKokkos; +#ifdef KOKKOS_HAVE_CUDA +template class PairLJExpandKokkos; +#endif diff --git a/src/KOKKOS/pair_lj_expand_kokkos.h b/src/KOKKOS/pair_lj_expand_kokkos.h new file mode 100644 index 0000000000..237ad7c848 --- /dev/null +++ b/src/KOKKOS/pair_lj_expand_kokkos.h @@ -0,0 +1,125 @@ +/* -*- c++ -*- ---------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + http://lammps.sandia.gov, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +#ifdef PAIR_CLASS + +PairStyle(lj/expand/kk,PairLJExpandKokkos) +PairStyle(lj/expand/kk/device,PairLJExpandKokkos) +PairStyle(lj/expand/kk/host,PairLJExpandKokkos) + +#else + +#ifndef LMP_PAIR_LJ_EXPAND_KOKKOS_H +#define LMP_PAIR_LJ_EXPAND_KOKKOS_H + +#include "pair_kokkos.h" +#include "pair_lj_expand.h" +#include "neigh_list_kokkos.h" + +namespace LAMMPS_NS { + +template +class PairLJExpandKokkos : public PairLJExpand { + public: + enum {EnabledNeighFlags=FULL|HALFTHREAD|HALF|N2|FULLCLUSTER}; + enum {COUL_FLAG=0}; + typedef DeviceType device_type; + PairLJExpandKokkos(class LAMMPS *); + ~PairLJExpandKokkos(); + + void compute(int, int); + + void settings(int, char **); + void init_style(); + double init_one(int, int); + + struct params_lj{ + params_lj(){cutsq=0,lj1=0;lj2=0;lj3=0;lj4=0;offset=0;shift=0;}; + params_lj(int i){cutsq=0,lj1=0;lj2=0;lj3=0;lj4=0;offset=0;shift=0;}; + F_FLOAT cutsq,lj1,lj2,lj3,lj4,offset,shift; + }; + + protected: + void cleanup_copy(); + + template + KOKKOS_INLINE_FUNCTION + F_FLOAT compute_fpair(const F_FLOAT& rsq, const int& i, const int&j, const int& itype, const int& jtype) const; + + template + KOKKOS_INLINE_FUNCTION + F_FLOAT compute_evdwl(const F_FLOAT& rsq, const int& i, const int&j, const int& itype, const int& jtype) const; + + template + KOKKOS_INLINE_FUNCTION + F_FLOAT compute_ecoul(const F_FLOAT& rsq, const int& i, const int&j, const int& itype, const int& jtype) const { + return 0.0; + } + + template + KOKKOS_INLINE_FUNCTION + F_FLOAT compute_fcoul(const F_FLOAT& rsq, const int& i, const int&j, const int& itype, + const int& jtype, const F_FLOAT& factor_coul, const F_FLOAT& qtmp) const { + return 0.0; + } + + Kokkos::DualView k_params; + typename Kokkos::DualView::t_dev_const params; + params_lj m_params[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; // hardwired to space for 15 atom types + F_FLOAT m_cutsq[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; + typename ArrayTypes::t_x_array_randomread x; + typename ArrayTypes::t_x_array c_x; + typename ArrayTypes::t_f_array f; + typename ArrayTypes::t_int_1d_randomread type; + typename ArrayTypes::t_efloat_1d d_eatom; + typename ArrayTypes::t_virial_array d_vatom; + typename ArrayTypes::t_tagint_1d tag; + + int newton_pair; + double special_lj[4]; + + typename ArrayTypes::tdual_ffloat_2d k_cutsq; + typename ArrayTypes::t_ffloat_2d d_cutsq; + + class AtomKokkos *atomKK; + int neighflag; + int nlocal,nall,eflag,vflag; + + void allocate(); + friend class PairComputeFunctor; + friend class PairComputeFunctor; + friend class PairComputeFunctor; + friend class PairComputeFunctor; + friend class PairComputeFunctor; + friend class PairComputeFunctor; + friend class PairComputeFunctor; + friend class PairComputeFunctor; + friend class PairComputeFunctor; + friend class PairComputeFunctor; + friend EV_FLOAT pair_compute_neighlist(PairLJExpandKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairLJExpandKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairLJExpandKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairLJExpandKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_fullcluster(PairLJExpandKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute(PairLJExpandKokkos*,NeighListKokkos*); + friend void pair_virial_fdotr_compute(PairLJExpandKokkos*); +}; + +} + +#endif +#endif + +/* ERROR/WARNING messages: + +*/ diff --git a/src/KOKKOS/pair_lj_gromacs_coul_gromacs_kokkos.cpp b/src/KOKKOS/pair_lj_gromacs_coul_gromacs_kokkos.cpp new file mode 100644 index 0000000000..6fd07bd67c --- /dev/null +++ b/src/KOKKOS/pair_lj_gromacs_coul_gromacs_kokkos.cpp @@ -0,0 +1,501 @@ +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + http://lammps.sandia.gov, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +/* ---------------------------------------------------------------------- + Contributing author: Ray Shan (SNL) +------------------------------------------------------------------------- */ + +#include "math.h" +#include "stdio.h" +#include "stdlib.h" +#include "string.h" +#include "pair_lj_gromacs_coul_gromacs_kokkos.h" +#include "kokkos.h" +#include "atom_kokkos.h" +#include "comm.h" +#include "force.h" +#include "neighbor.h" +#include "neigh_list.h" +#include "neigh_request.h" +#include "update.h" +#include "integrate.h" +#include "respa.h" +#include "math_const.h" +#include "memory.h" +#include "error.h" +#include "atom_masks.h" + +using namespace LAMMPS_NS; +using namespace MathConst; + +#define KOKKOS_CUDA_MAX_THREADS 256 +#define KOKKOS_CUDA_MIN_BLOCKS 8 + +/* ---------------------------------------------------------------------- */ + +template +PairLJGromacsCoulGromacsKokkos::PairLJGromacsCoulGromacsKokkos(LAMMPS *lmp):PairLJGromacsCoulGromacs(lmp) +{ + respa_enable = 0; + + atomKK = (AtomKokkos *) atom; + execution_space = ExecutionSpaceFromDevice::space; + datamask_read = X_MASK | F_MASK | TYPE_MASK | Q_MASK | ENERGY_MASK | VIRIAL_MASK; + datamask_modify = F_MASK | ENERGY_MASK | VIRIAL_MASK; + cutsq = NULL; + cut_ljsq = 0.0; + cut_coulsq = 0.0; + +} + +/* ---------------------------------------------------------------------- */ + +template +PairLJGromacsCoulGromacsKokkos::~PairLJGromacsCoulGromacsKokkos() +{ + if (!copymode) { + memory->destroy_kokkos(k_eatom,eatom); + memory->destroy_kokkos(k_vatom,vatom); + k_cutsq = DAT::tdual_ffloat_2d(); + k_cut_ljsq = DAT::tdual_ffloat_2d(); + k_cut_coulsq = DAT::tdual_ffloat_2d(); + memory->sfree(cutsq); + //memory->sfree(cut_ljsq); + //memory->sfree(cut_coulsq); + eatom = NULL; + vatom = NULL; + cutsq = NULL; + cut_ljsq = 0.0; + cut_coulsq = 0.0; + } +} + +/* ---------------------------------------------------------------------- */ + +template +void PairLJGromacsCoulGromacsKokkos::cleanup_copy() { + // WHY needed: this prevents parent copy from deallocating any arrays + allocated = 0; + cutsq = NULL; + cut_ljsq = 0.0; + eatom = NULL; + vatom = NULL; + ftable = NULL; +} + +/* ---------------------------------------------------------------------- */ + +template +void PairLJGromacsCoulGromacsKokkos::compute(int eflag_in, int vflag_in) +{ + eflag = eflag_in; + vflag = vflag_in; + + if (neighflag == FULL || neighflag == FULLCLUSTER) no_virial_fdotr_compute = 1; + + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = vflag_fdotr = 0; + + atomKK->sync(execution_space,datamask_read); + k_cutsq.template sync(); + k_cut_ljsq.template sync(); + k_cut_coulsq.template sync(); + k_params.template sync(); + if (eflag || vflag) atomKK->modified(execution_space,datamask_modify); + else atomKK->modified(execution_space,F_MASK); + + x = atomKK->k_x.view(); + c_x = atomKK->k_x.view(); + f = atomKK->k_f.view(); + q = atomKK->k_q.view(); + type = atomKK->k_type.view(); + nlocal = atom->nlocal; + nall = atom->nlocal + atom->nghost; + special_lj[0] = force->special_lj[0]; + special_lj[1] = force->special_lj[1]; + special_lj[2] = force->special_lj[2]; + special_lj[3] = force->special_lj[3]; + special_coul[0] = force->special_coul[0]; + special_coul[1] = force->special_coul[1]; + special_coul[2] = force->special_coul[2]; + special_coul[3] = force->special_coul[3]; + qqrd2e = force->qqrd2e; + newton_pair = force->newton_pair; + + // loop over neighbors of my atoms + + copymode = 1; + + EV_FLOAT ev; + if(ncoultablebits) + ev = pair_compute,CoulLongTable<1> > + (this,(NeighListKokkos*)list); + else + ev = pair_compute,CoulLongTable<0> > + (this,(NeighListKokkos*)list); + + + DeviceType::fence(); + + if (eflag) { + eng_vdwl += ev.evdwl; + eng_coul += ev.ecoul; + } + if (vflag_global) { + virial[0] += ev.v[0]; + virial[1] += ev.v[1]; + virial[2] += ev.v[2]; + virial[3] += ev.v[3]; + virial[4] += ev.v[4]; + virial[5] += ev.v[5]; + } + + if (vflag_fdotr) pair_virial_fdotr_compute(this); + + copymode = 0; +} + +/* ---------------------------------------------------------------------- + compute LJ GROMACS pair force between atoms i and j + ---------------------------------------------------------------------- */ +template +template +KOKKOS_INLINE_FUNCTION +F_FLOAT PairLJGromacsCoulGromacsKokkos:: +compute_fpair(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype) const { + + const F_FLOAT r2inv = 1.0/rsq; + const F_FLOAT r6inv = r2inv*r2inv*r2inv; + F_FLOAT forcelj = r6inv * + ((STACKPARAMS?m_params[itype][jtype].lj1:params(itype,jtype).lj1)*r6inv - + (STACKPARAMS?m_params[itype][jtype].lj2:params(itype,jtype).lj2)); + + if (rsq > cut_lj_innersq) { + const F_FLOAT r = sqrt(rsq); + const F_FLOAT tlj = r - cut_lj_inner; + const F_FLOAT fswitch = r*tlj*tlj* + ((STACKPARAMS?m_params[itype][jtype].ljsw1:params(itype,jtype).ljsw1) + + (STACKPARAMS?m_params[itype][jtype].ljsw2:params(itype,jtype).ljsw2)*tlj); + forcelj += fswitch; + } + return forcelj*r2inv; +} + +/* ---------------------------------------------------------------------- + compute LJ GROMACS pair potential energy between atoms i and j + ---------------------------------------------------------------------- */ +template +template +KOKKOS_INLINE_FUNCTION +F_FLOAT PairLJGromacsCoulGromacsKokkos:: +compute_evdwl(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype) const { + + const F_FLOAT r2inv = 1.0/rsq; + const F_FLOAT r6inv = r2inv*r2inv*r2inv; + F_FLOAT englj = r6inv * + ((STACKPARAMS?m_params[itype][jtype].lj3:params(itype,jtype).lj3)*r6inv - + (STACKPARAMS?m_params[itype][jtype].lj4:params(itype,jtype).lj4)); + englj += (STACKPARAMS?m_params[itype][jtype].ljsw5:params(itype,jtype).ljsw5); + + if (rsq > cut_lj_innersq) { + const F_FLOAT r = sqrt(rsq); + const F_FLOAT tlj = r - cut_lj_inner; + const F_FLOAT eswitch = tlj*tlj*tlj * + ((STACKPARAMS?m_params[itype][jtype].ljsw3:params(itype,jtype).ljsw3) + + (STACKPARAMS?m_params[itype][jtype].ljsw4:params(itype,jtype).ljsw4)*tlj); + englj += eswitch; + } + return englj; +} + +/* ---------------------------------------------------------------------- + compute coulomb pair force between atoms i and j + ---------------------------------------------------------------------- */ +template +template +KOKKOS_INLINE_FUNCTION +F_FLOAT PairLJGromacsCoulGromacsKokkos:: +compute_fcoul(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype, const F_FLOAT& factor_coul, const F_FLOAT& qtmp) const { + + const F_FLOAT r2inv = 1.0/rsq; + const F_FLOAT rinv = sqrt(r2inv); + F_FLOAT forcecoul = qqrd2e*qtmp*q(j) *rinv; + + if (rsq > cut_coul_innersq) { + const F_FLOAT r = 1.0/rinv; + const F_FLOAT tc = r - cut_coul_inner; + const F_FLOAT fcoulswitch = qqrd2e * qtmp*q(j)*r*tc*tc*(coulsw1 + coulsw2*tc); + forcecoul += fcoulswitch; + } + return forcecoul * r2inv * factor_coul; +} + +/* ---------------------------------------------------------------------- + compute coulomb pair potential energy between atoms i and j + ---------------------------------------------------------------------- */ +template +template +KOKKOS_INLINE_FUNCTION +F_FLOAT PairLJGromacsCoulGromacsKokkos:: +compute_ecoul(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype, const F_FLOAT& factor_coul, const F_FLOAT& qtmp) const { + + const F_FLOAT r2inv = 1.0/rsq; + const F_FLOAT rinv = sqrt(r2inv); + F_FLOAT ecoul = qqrd2e * qtmp * q(j) * (rinv-coulsw5); + + if (rsq > cut_coul_innersq) { + const F_FLOAT r = 1.0/rinv; + const F_FLOAT tc = r - cut_coul_inner; + const F_FLOAT ecoulswitch = tc*tc*tc * (coulsw3 + coulsw4*tc); + ecoul += qqrd2e*qtmp*q(j)*ecoulswitch; + } + return ecoul * factor_coul; +} + +/* ---------------------------------------------------------------------- + allocate all arrays +------------------------------------------------------------------------- */ + +template +void PairLJGromacsCoulGromacsKokkos::allocate() +{ + PairLJGromacsCoulGromacs::allocate(); + + int n = atom->ntypes; + + memory->destroy(cutsq); + memory->create_kokkos(k_cutsq,cutsq,n+1,n+1,"pair:cutsq"); + d_cutsq = k_cutsq.template view(); + + //memory->destroy(cut_ljsq); + memory->create_kokkos(k_cut_ljsq,n+1,n+1,"pair:cut_ljsq"); + d_cut_ljsq = k_cut_ljsq.template view(); + + memory->create_kokkos(k_cut_coulsq,n+1,n+1,"pair:cut_coulsq"); + d_cut_coulsq = k_cut_coulsq.template view(); + + k_params = Kokkos::DualView("PairLJGromacsCoulGromacs::params",n+1,n+1); + params = k_params.d_view; +} + +template +void PairLJGromacsCoulGromacsKokkos::init_tables(double cut_coul, double *cut_respa) +{ + Pair::init_tables(cut_coul,cut_respa); + + typedef typename ArrayTypes::t_ffloat_1d table_type; + typedef typename ArrayTypes::t_ffloat_1d host_table_type; + + int ntable = 1; + for (int i = 0; i < ncoultablebits; i++) ntable *= 2; + + + // Copy rtable and drtable + { + host_table_type h_table("HostTable",ntable); + table_type d_table("DeviceTable",ntable); + for(int i = 0; i < ntable; i++) { + h_table(i) = rtable[i]; + } + Kokkos::deep_copy(d_table,h_table); + d_rtable = d_table; + } + + { + host_table_type h_table("HostTable",ntable); + table_type d_table("DeviceTable",ntable); + for(int i = 0; i < ntable; i++) { + h_table(i) = drtable[i]; + } + Kokkos::deep_copy(d_table,h_table); + d_drtable = d_table; + } + + { + host_table_type h_table("HostTable",ntable); + table_type d_table("DeviceTable",ntable); + + // Copy ftable and dftable + for(int i = 0; i < ntable; i++) { + h_table(i) = ftable[i]; + } + Kokkos::deep_copy(d_table,h_table); + d_ftable = d_table; + } + + { + host_table_type h_table("HostTable",ntable); + table_type d_table("DeviceTable",ntable); + + for(int i = 0; i < ntable; i++) { + h_table(i) = dftable[i]; + } + Kokkos::deep_copy(d_table,h_table); + d_dftable = d_table; + } + + { + host_table_type h_table("HostTable",ntable); + table_type d_table("DeviceTable",ntable); + + // Copy ctable and dctable + for(int i = 0; i < ntable; i++) { + h_table(i) = ctable[i]; + } + Kokkos::deep_copy(d_table,h_table); + d_ctable = d_table; + } + + { + host_table_type h_table("HostTable",ntable); + table_type d_table("DeviceTable",ntable); + + for(int i = 0; i < ntable; i++) { + h_table(i) = dctable[i]; + } + Kokkos::deep_copy(d_table,h_table); + d_dctable = d_table; + } + + { + host_table_type h_table("HostTable",ntable); + table_type d_table("DeviceTable",ntable); + + // Copy etable and detable + for(int i = 0; i < ntable; i++) { + h_table(i) = etable[i]; + } + Kokkos::deep_copy(d_table,h_table); + d_etable = d_table; + } + + { + host_table_type h_table("HostTable",ntable); + table_type d_table("DeviceTable",ntable); + + for(int i = 0; i < ntable; i++) { + h_table(i) = detable[i]; + } + Kokkos::deep_copy(d_table,h_table); + d_detable = d_table; + } +} + + +/* ---------------------------------------------------------------------- + global settings +------------------------------------------------------------------------- */ + +template +void PairLJGromacsCoulGromacsKokkos::settings(int narg, char **arg) +{ + if (narg > 2) error->all(FLERR,"Illegal pair_style command"); + + PairLJGromacsCoulGromacs::settings(narg,arg); +} + +/* ---------------------------------------------------------------------- + init specific to this pair style +------------------------------------------------------------------------- */ + +template +void PairLJGromacsCoulGromacsKokkos::init_style() +{ + PairLJGromacsCoulGromacs::init_style(); + + // error if rRESPA with inner levels + + if (update->whichflag == 1 && strstr(update->integrate_style,"respa")) { + int respa = 0; + if (((Respa *) update->integrate)->level_inner >= 0) respa = 1; + if (((Respa *) update->integrate)->level_middle >= 0) respa = 2; + if (respa) + error->all(FLERR,"Cannot use Kokkos pair style with rRESPA inner/middle"); + } + + // irequest = neigh request made by parent class + + neighflag = lmp->kokkos->neighflag; + int irequest = neighbor->nrequest - 1; + + neighbor->requests[irequest]-> + kokkos_host = Kokkos::Impl::is_same::value && + !Kokkos::Impl::is_same::value; + neighbor->requests[irequest]-> + kokkos_device = Kokkos::Impl::is_same::value; + + if (neighflag == FULL) { + neighbor->requests[irequest]->full = 1; + neighbor->requests[irequest]->half = 0; + neighbor->requests[irequest]->full_cluster = 0; + } else if (neighflag == HALF || neighflag == HALFTHREAD) { + neighbor->requests[irequest]->full = 0; + neighbor->requests[irequest]->half = 1; + neighbor->requests[irequest]->full_cluster = 0; + } else { + error->all(FLERR,"Cannot use chosen neighbor list style with lj/gromacs/coul/gromacs/kk"); + } +} + +/* ---------------------------------------------------------------------- + init for one type pair i,j and corresponding j,i +------------------------------------------------------------------------- */ + +template +double PairLJGromacsCoulGromacsKokkos::init_one(int i, int j) +{ + double cutone = PairLJGromacsCoulGromacs::init_one(i,j); + double cut_ljsqm = cut_ljsq; + double cut_coulsqm = cut_coulsq; + + k_params.h_view(i,j).lj1 = lj1[i][j]; + k_params.h_view(i,j).lj2 = lj2[i][j]; + k_params.h_view(i,j).lj3 = lj3[i][j]; + k_params.h_view(i,j).lj4 = lj4[i][j]; + k_params.h_view(i,j).ljsw1 = ljsw1[i][j]; + k_params.h_view(i,j).ljsw2 = ljsw2[i][j]; + k_params.h_view(i,j).ljsw3 = ljsw3[i][j]; + k_params.h_view(i,j).ljsw4 = ljsw4[i][j]; + k_params.h_view(i,j).ljsw5 = ljsw5[i][j]; + k_params.h_view(i,j).cut_ljsq = cut_ljsqm; + k_params.h_view(i,j).cut_coulsq = cut_coulsqm; + + k_params.h_view(j,i) = k_params.h_view(i,j); + if(i(); + k_cut_ljsq.h_view(i,j) = cut_ljsqm; + k_cut_ljsq.template modify(); + k_cut_coulsq.h_view(i,j) = cut_coulsqm; + k_cut_coulsq.template modify(); + k_params.template modify(); + + return cutone; +} + + + +template class PairLJGromacsCoulGromacsKokkos; +#ifdef KOKKOS_HAVE_CUDA +template class PairLJGromacsCoulGromacsKokkos; +#endif diff --git a/src/KOKKOS/pair_lj_gromacs_coul_gromacs_kokkos.h b/src/KOKKOS/pair_lj_gromacs_coul_gromacs_kokkos.h new file mode 100644 index 0000000000..19cf349e7b --- /dev/null +++ b/src/KOKKOS/pair_lj_gromacs_coul_gromacs_kokkos.h @@ -0,0 +1,151 @@ +/* -*- c++ -*- ---------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + http://lammps.sandia.gov, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +#ifdef PAIR_CLASS + +PairStyle(lj/gromacs/coul/gromacs/kk,PairLJGromacsCoulGromacsKokkos) +PairStyle(lj/gromacs/coul/gromacs/kk/device,PairLJGromacsCoulGromacsKokkos) +PairStyle(lj/gromacs/coul/gromacs/kk/host,PairLJGromacsCoulGromacsKokkos) + +#else + +#ifndef LMP_PAIR_LJ_GROMACS_COUL_GROMACS_KOKKOS_H +#define LMP_PAIR_LJ_GROMACS_COUL_GROMACS_KOKKOS_H + +#include "pair_kokkos.h" +#include "pair_lj_gromacs_coul_gromacs.h" +#include "neigh_list_kokkos.h" + +namespace LAMMPS_NS { + +template +class PairLJGromacsCoulGromacsKokkos : public PairLJGromacsCoulGromacs { + public: + enum {EnabledNeighFlags=FULL|HALFTHREAD|HALF}; + enum {COUL_FLAG=1}; + typedef DeviceType device_type; + PairLJGromacsCoulGromacsKokkos(class LAMMPS *); + ~PairLJGromacsCoulGromacsKokkos(); + + void compute(int, int); + + void settings(int, char **); + void init_tables(double cut_coul, double *cut_respa); + void init_style(); + double init_one(int, int); + + struct params_lj_coul{ + params_lj_coul(){cut_ljsq=0;cut_coulsq=0;lj1=0;lj2=0;lj3=0;lj4=0;offset=0;ljsw1=0;ljsw2=0;ljsw3=0;ljsw4=0;ljsw5=0;}; + params_lj_coul(int i){cut_ljsq=0;cut_coulsq=0;lj1=0;lj2=0;lj3=0;lj4=0;offset=0;ljsw1=0;ljsw2=0;ljsw3=0;ljsw4=0;ljsw5=0;}; + F_FLOAT cut_ljsq,cut_coulsq,lj1,lj2,lj3,lj4,offset,ljsw1,ljsw2,ljsw3,ljsw4,ljsw5; + }; + + protected: + void cleanup_copy(); + + template + KOKKOS_INLINE_FUNCTION + F_FLOAT compute_fpair(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype) const; + + template + KOKKOS_INLINE_FUNCTION + F_FLOAT compute_fcoul(const F_FLOAT& rsq, const int& i, const int&j, const int& itype, + const int& jtype, const F_FLOAT& factor_coul, const F_FLOAT& qtmp) const; + + template + KOKKOS_INLINE_FUNCTION + F_FLOAT compute_evdwl(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype) const; + + template + KOKKOS_INLINE_FUNCTION + F_FLOAT compute_ecoul(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype, const F_FLOAT& factor_coul, const F_FLOAT& qtmp) const; + + Kokkos::DualView k_params; + typename Kokkos::DualView::t_dev_const params; + // hardwired to space for 15 atom types + params_lj_coul m_params[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; + + F_FLOAT m_cutsq[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; + F_FLOAT m_cut_ljsq[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; + F_FLOAT m_cut_coulsq[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; + typename ArrayTypes::t_x_array_randomread x; + typename ArrayTypes::t_x_array c_x; + typename ArrayTypes::t_f_array f; + typename ArrayTypes::t_int_1d_randomread type; + typename ArrayTypes::t_float_1d_randomread q; + + DAT::tdual_efloat_1d k_eatom; + DAT::tdual_virial_array k_vatom; + typename ArrayTypes::t_efloat_1d d_eatom; + typename ArrayTypes::t_virial_array d_vatom; + + int newton_pair; + + typename ArrayTypes::tdual_ffloat_2d k_cutsq; + typename ArrayTypes::t_ffloat_2d d_cutsq; + typename ArrayTypes::tdual_ffloat_2d k_cut_ljsq; + typename ArrayTypes::t_ffloat_2d d_cut_ljsq; + typename ArrayTypes::tdual_ffloat_2d k_cut_coulsq; + typename ArrayTypes::t_ffloat_2d d_cut_coulsq; + + typename ArrayTypes::t_ffloat_1d_randomread + d_rtable, d_drtable, d_ftable, d_dftable, + d_ctable, d_dctable, d_etable, d_detable; + class AtomKokkos *atomKK; + int neighflag; + int nlocal,nall,eflag,vflag; + + double special_coul[4]; + double special_lj[4]; + double qqrd2e; + + void allocate(); + + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend EV_FLOAT pair_compute_neighlist >(PairLJGromacsCoulGromacsKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist >(PairLJGromacsCoulGromacsKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist >(PairLJGromacsCoulGromacsKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute >(PairLJGromacsCoulGromacsKokkos*, + NeighListKokkos*); + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend EV_FLOAT pair_compute_neighlist >(PairLJGromacsCoulGromacsKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist >(PairLJGromacsCoulGromacsKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist >(PairLJGromacsCoulGromacsKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute >(PairLJGromacsCoulGromacsKokkos*, + NeighListKokkos*); + friend void pair_virial_fdotr_compute(PairLJGromacsCoulGromacsKokkos*); + +}; + +} + +#endif +#endif + +/* ERROR/WARNING messages: + +*/ diff --git a/src/KOKKOS/pair_lj_gromacs_kokkos.cpp b/src/KOKKOS/pair_lj_gromacs_kokkos.cpp new file mode 100644 index 0000000000..be9d5faaf1 --- /dev/null +++ b/src/KOKKOS/pair_lj_gromacs_kokkos.cpp @@ -0,0 +1,333 @@ +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + http://lammps.sandia.gov, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +/* ---------------------------------------------------------------------- + Contributing author: Ray Shan (SNL) +------------------------------------------------------------------------- */ + +#include "math.h" +#include "stdio.h" +#include "stdlib.h" +#include "string.h" +#include "pair_lj_gromacs_kokkos.h" +#include "kokkos.h" +#include "atom_kokkos.h" +#include "comm.h" +#include "force.h" +#include "neighbor.h" +#include "neigh_list.h" +#include "neigh_request.h" +#include "update.h" +#include "integrate.h" +#include "respa.h" +#include "math_const.h" +#include "memory.h" +#include "error.h" +#include "atom_masks.h" + +using namespace LAMMPS_NS; +using namespace MathConst; + +#define KOKKOS_CUDA_MAX_THREADS 256 +#define KOKKOS_CUDA_MIN_BLOCKS 8 + +/* ---------------------------------------------------------------------- */ + +template +PairLJGromacsKokkos::PairLJGromacsKokkos(LAMMPS *lmp):PairLJGromacs(lmp) +{ + respa_enable = 0; + + atomKK = (AtomKokkos *) atom; + execution_space = ExecutionSpaceFromDevice::space; + datamask_read = X_MASK | F_MASK | TYPE_MASK | Q_MASK | ENERGY_MASK | VIRIAL_MASK; + datamask_modify = F_MASK | ENERGY_MASK | VIRIAL_MASK; + cutsq = NULL; + cut_inner = NULL; + cut_inner_sq = NULL; + +} + +/* ---------------------------------------------------------------------- */ + +template +PairLJGromacsKokkos::~PairLJGromacsKokkos() +{ + if (!copymode) { + memory->destroy_kokkos(k_eatom,eatom); + memory->destroy_kokkos(k_vatom,vatom); + k_cutsq = DAT::tdual_ffloat_2d(); + k_cut_inner_sq = DAT::tdual_ffloat_2d(); + memory->sfree(cutsq); + eatom = NULL; + vatom = NULL; + cutsq = NULL; + cut_inner = NULL; + cut_inner_sq = NULL; + } +} + +/* ---------------------------------------------------------------------- */ + +template +void PairLJGromacsKokkos::cleanup_copy() { + // WHY needed: this prevents parent copy from deallocating any arrays + allocated = 0; + cutsq = NULL; + cut_inner = NULL; + cut_inner_sq = NULL; + eatom = NULL; + vatom = NULL; +} + +/* ---------------------------------------------------------------------- */ + +template +void PairLJGromacsKokkos::compute(int eflag_in, int vflag_in) +{ + eflag = eflag_in; + vflag = vflag_in; + + if (neighflag == FULL || neighflag == FULLCLUSTER) no_virial_fdotr_compute = 1; + + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = vflag_fdotr = 0; + + atomKK->sync(execution_space,datamask_read); + k_cutsq.template sync(); + k_cut_inner.template sync(); + k_cut_inner_sq.template sync(); + k_params.template sync(); + if (eflag || vflag) atomKK->modified(execution_space,datamask_modify); + else atomKK->modified(execution_space,F_MASK); + + x = atomKK->k_x.view(); + c_x = atomKK->k_x.view(); + f = atomKK->k_f.view(); + q = atomKK->k_q.view(); + type = atomKK->k_type.view(); + nlocal = atom->nlocal; + nall = atom->nlocal + atom->nghost; + special_lj[0] = force->special_lj[0]; + special_lj[1] = force->special_lj[1]; + special_lj[2] = force->special_lj[2]; + special_lj[3] = force->special_lj[3]; + qqrd2e = force->qqrd2e; + newton_pair = force->newton_pair; + + // loop over neighbors of my atoms + + copymode = 1; + + EV_FLOAT ev = pair_compute,CoulLongTable<0> > + (this,(NeighListKokkos*)list); + + DeviceType::fence(); + + if (eflag) { + eng_vdwl += ev.evdwl; + eng_coul += 0.0; + } + if (vflag_global) { + virial[0] += ev.v[0]; + virial[1] += ev.v[1]; + virial[2] += ev.v[2]; + virial[3] += ev.v[3]; + virial[4] += ev.v[4]; + virial[5] += ev.v[5]; + } + + if (vflag_fdotr) pair_virial_fdotr_compute(this); + + copymode = 0; +} + +/* ---------------------------------------------------------------------- + compute LJ GROMACS pair force between atoms i and j + ---------------------------------------------------------------------- */ +template +template +KOKKOS_INLINE_FUNCTION +F_FLOAT PairLJGromacsKokkos:: +compute_fpair(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype) const { + + const F_FLOAT r2inv = 1.0/rsq; + const F_FLOAT r6inv = r2inv*r2inv*r2inv; + F_FLOAT forcelj = r6inv * + ((STACKPARAMS?m_params[itype][jtype].lj1:params(itype,jtype).lj1)*r6inv - + (STACKPARAMS?m_params[itype][jtype].lj2:params(itype,jtype).lj2)); + + if (rsq > (STACKPARAMS?m_params[itype][jtype].cut_inner_sq:params(itype,jtype).cut_inner_sq)) { + const F_FLOAT r = sqrt(rsq); + const F_FLOAT tlj = r - (STACKPARAMS?m_params[itype][jtype].cut_inner:params(itype,jtype).cut_inner); + const F_FLOAT fswitch = r*tlj*tlj* + ((STACKPARAMS?m_params[itype][jtype].ljsw1:params(itype,jtype).ljsw1) + + (STACKPARAMS?m_params[itype][jtype].ljsw2:params(itype,jtype).ljsw2)*tlj); + forcelj += fswitch; + } + return forcelj*r2inv; +} + +/* ---------------------------------------------------------------------- + compute LJ GROMACS pair potential energy between atoms i and j + ---------------------------------------------------------------------- */ +template +template +KOKKOS_INLINE_FUNCTION +F_FLOAT PairLJGromacsKokkos:: +compute_evdwl(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype) const { + + const F_FLOAT r2inv = 1.0/rsq; + const F_FLOAT r6inv = r2inv*r2inv*r2inv; + F_FLOAT englj = r6inv * + ((STACKPARAMS?m_params[itype][jtype].lj3:params(itype,jtype).lj3)*r6inv - + (STACKPARAMS?m_params[itype][jtype].lj4:params(itype,jtype).lj4)); + englj += (STACKPARAMS?m_params[itype][jtype].ljsw5:params(itype,jtype).ljsw5); + + if (rsq > (STACKPARAMS?m_params[itype][jtype].cut_inner_sq:params(itype,jtype).cut_inner_sq)) { + const F_FLOAT r = sqrt(rsq); + const F_FLOAT tlj = r - (STACKPARAMS?m_params[itype][jtype].cut_inner:params(itype,jtype).cut_inner); + const F_FLOAT eswitch = tlj*tlj*tlj * + ((STACKPARAMS?m_params[itype][jtype].ljsw3:params(itype,jtype).ljsw3) + + (STACKPARAMS?m_params[itype][jtype].ljsw4:params(itype,jtype).ljsw4)*tlj); + englj += eswitch; + } + return englj; +} + +/* ---------------------------------------------------------------------- + allocate all arrays +------------------------------------------------------------------------- */ + +template +void PairLJGromacsKokkos::allocate() +{ + PairLJGromacs::allocate(); + + int n = atom->ntypes; + + memory->destroy(cutsq); + memory->create_kokkos(k_cutsq,cutsq,n+1,n+1,"pair:cutsq"); + d_cutsq = k_cutsq.template view(); + + memory->destroy(cut_inner); + memory->create_kokkos(k_cut_inner,cut_inner,n+1,n+1,"pair:cut_inner"); + d_cut_inner = k_cut_inner.template view(); + + memory->destroy(cut_inner_sq); + memory->create_kokkos(k_cut_inner_sq,cut_inner_sq,n+1,n+1,"pair:cut_inner_sq"); + d_cut_inner_sq = k_cut_inner_sq.template view(); + + k_params = Kokkos::DualView("PairLJGromacs::params",n+1,n+1); + params = k_params.d_view; +} + +/* ---------------------------------------------------------------------- + global settings +------------------------------------------------------------------------- */ + +template +void PairLJGromacsKokkos::settings(int narg, char **arg) +{ + if (narg != 2) error->all(FLERR,"Illegal pair_style command"); + + PairLJGromacs::settings(narg,arg); +} + +/* ---------------------------------------------------------------------- + init specific to this pair style +------------------------------------------------------------------------- */ + +template +void PairLJGromacsKokkos::init_style() +{ + PairLJGromacs::init_style(); + + // error if rRESPA with inner levels + + if (update->whichflag == 1 && strstr(update->integrate_style,"respa")) { + int respa = 0; + if (((Respa *) update->integrate)->level_inner >= 0) respa = 1; + if (((Respa *) update->integrate)->level_middle >= 0) respa = 2; + if (respa) + error->all(FLERR,"Cannot use Kokkos pair style with rRESPA inner/middle"); + } + + // irequest = neigh request made by parent class + + neighflag = lmp->kokkos->neighflag; + int irequest = neighbor->nrequest - 1; + + neighbor->requests[irequest]-> + kokkos_host = Kokkos::Impl::is_same::value && + !Kokkos::Impl::is_same::value; + neighbor->requests[irequest]-> + kokkos_device = Kokkos::Impl::is_same::value; + + if (neighflag == FULL) { + neighbor->requests[irequest]->full = 1; + neighbor->requests[irequest]->half = 0; + neighbor->requests[irequest]->full_cluster = 0; + } else if (neighflag == HALF || neighflag == HALFTHREAD) { + neighbor->requests[irequest]->full = 0; + neighbor->requests[irequest]->half = 1; + neighbor->requests[irequest]->full_cluster = 0; + } else { + error->all(FLERR,"Cannot use chosen neighbor list style with lj/gromacs/kk"); + } +} + +/* ---------------------------------------------------------------------- + init for one type pair i,j and corresponding j,i +------------------------------------------------------------------------- */ + +template +double PairLJGromacsKokkos::init_one(int i, int j) +{ + double cutone = PairLJGromacs::init_one(i,j); + double cut_inner_sqm = cut_inner_sq[i][j]; + + k_params.h_view(i,j).lj1 = lj1[i][j]; + k_params.h_view(i,j).lj2 = lj2[i][j]; + k_params.h_view(i,j).lj3 = lj3[i][j]; + k_params.h_view(i,j).lj4 = lj4[i][j]; + k_params.h_view(i,j).ljsw1 = ljsw1[i][j]; + k_params.h_view(i,j).ljsw2 = ljsw2[i][j]; + k_params.h_view(i,j).ljsw3 = ljsw3[i][j]; + k_params.h_view(i,j).ljsw4 = ljsw4[i][j]; + k_params.h_view(i,j).ljsw5 = ljsw5[i][j]; + k_params.h_view(i,j).cut_inner_sq = cut_inner_sqm; + k_params.h_view(i,j).cut_inner = cut_inner[i][j]; + + k_params.h_view(j,i) = k_params.h_view(i,j); + if(i(); + k_cut_inner_sq.h_view(i,j) = cut_inner_sqm; + k_cut_inner_sq.template modify(); + k_params.template modify(); + + return cutone; +} + +template class PairLJGromacsKokkos; +#ifdef KOKKOS_HAVE_CUDA +template class PairLJGromacsKokkos; +#endif diff --git a/src/KOKKOS/pair_lj_gromacs_kokkos.h b/src/KOKKOS/pair_lj_gromacs_kokkos.h new file mode 100644 index 0000000000..c7a25eefaf --- /dev/null +++ b/src/KOKKOS/pair_lj_gromacs_kokkos.h @@ -0,0 +1,153 @@ +/* -*- c++ -*- ---------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + http://lammps.sandia.gov, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +#ifdef PAIR_CLASS + +PairStyle(lj/gromacs/kk,PairLJGromacsKokkos) +PairStyle(lj/gromacs/kk/device,PairLJGromacsKokkos) +PairStyle(lj/gromacs/kk/host,PairLJGromacsKokkos) + +#else + +#ifndef LMP_PAIR_LJ_GROMACS_KOKKOS_H +#define LMP_PAIR_LJ_GROMACS_KOKKOS_H + +#include "pair_kokkos.h" +#include "pair_lj_gromacs.h" +#include "neigh_list_kokkos.h" + +namespace LAMMPS_NS { + +template +class PairLJGromacsKokkos : public PairLJGromacs { + public: + enum {EnabledNeighFlags=FULL|HALFTHREAD|HALF}; + enum {COUL_FLAG=0}; + typedef DeviceType device_type; + PairLJGromacsKokkos(class LAMMPS *); + ~PairLJGromacsKokkos(); + + void compute(int, int); + + void settings(int, char **); + void init_style(); + double init_one(int, int); + + struct params_lj{ + params_lj(){cut_inner_sq=0;cut_inner=0;lj1=0;lj2=0;lj3=0;lj4=0;offset=0;ljsw1=0;ljsw2=0;ljsw3=0;ljsw4=0;ljsw5=0;}; + params_lj(int i){cut_inner_sq=0;cut_inner=0;lj1=0;lj2=0;lj3=0;lj4=0;offset=0;ljsw1=0;ljsw2=0;ljsw3=0;ljsw4=0;ljsw5=0;}; + F_FLOAT cut_inner_sq,cut_inner,lj1,lj2,lj3,lj4,offset,ljsw1,ljsw2,ljsw3,ljsw4,ljsw5; + }; + + protected: + void cleanup_copy(); + + template + KOKKOS_INLINE_FUNCTION + F_FLOAT compute_fpair(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype) const; + + template + KOKKOS_INLINE_FUNCTION + F_FLOAT compute_fcoul(const F_FLOAT& rsq, const int& i, const int&j, const int& itype, + const int& jtype, const F_FLOAT& factor_coul, const F_FLOAT& qtmp) const { + return 0.0; + } + + template + KOKKOS_INLINE_FUNCTION + F_FLOAT compute_evdwl(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype) const; + + template + KOKKOS_INLINE_FUNCTION + F_FLOAT compute_ecoul(const F_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype, const F_FLOAT& factor_coul, const F_FLOAT& qtmp) const{ + return 0.0; + } + + Kokkos::DualView k_params; + typename Kokkos::DualView::t_dev_const params; + // hardwired to space for 15 atom types + params_lj m_params[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; + + F_FLOAT m_cutsq[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; + F_FLOAT m_cut_inner[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; + F_FLOAT m_cut_inner_sq[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; + typename ArrayTypes::t_x_array_randomread x; + typename ArrayTypes::t_x_array c_x; + typename ArrayTypes::t_f_array f; + typename ArrayTypes::t_int_1d_randomread type; + typename ArrayTypes::t_float_1d_randomread q; + + DAT::tdual_efloat_1d k_eatom; + DAT::tdual_virial_array k_vatom; + typename ArrayTypes::t_efloat_1d d_eatom; + typename ArrayTypes::t_virial_array d_vatom; + + int newton_pair; + + typename ArrayTypes::tdual_ffloat_2d k_cutsq; + typename ArrayTypes::t_ffloat_2d d_cutsq; + typename ArrayTypes::tdual_ffloat_2d k_cut_inner; + typename ArrayTypes::t_ffloat_2d d_cut_inner; + typename ArrayTypes::tdual_ffloat_2d k_cut_inner_sq; + typename ArrayTypes::t_ffloat_2d d_cut_inner_sq; + + typename ArrayTypes::t_ffloat_1d_randomread + d_rtable, d_drtable, d_ftable, d_dftable, + d_ctable, d_dctable, d_etable, d_detable; + class AtomKokkos *atomKK; + int neighflag; + int nlocal,nall,eflag,vflag; + + double special_lj[4]; + double qqrd2e; + + void allocate(); + + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend EV_FLOAT pair_compute_neighlist >(PairLJGromacsKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist >(PairLJGromacsKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist >(PairLJGromacsKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute >(PairLJGromacsKokkos*, + NeighListKokkos*); + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend class PairComputeFunctor >; + friend EV_FLOAT pair_compute_neighlist >(PairLJGromacsKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist >(PairLJGromacsKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist >(PairLJGromacsKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute >(PairLJGromacsKokkos*, + NeighListKokkos*); + friend void pair_virial_fdotr_compute(PairLJGromacsKokkos*); + +}; + +} + +#endif +#endif + +/* ERROR/WARNING messages: + +*/ From 550b6b0a973a21eb538eb1dbe93095122e52ff98 Mon Sep 17 00:00:00 2001 From: sjplimp Date: Fri, 27 Mar 2015 13:56:40 +0000 Subject: [PATCH 05/22] git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@13306 f3b2605a-c512-4ea7-a41b-209d697bcdaa --- doc/Section_commands.html | 20 ++++++++++---------- doc/Section_commands.txt | 30 +++++++++++++++--------------- doc/atom_style.html | 2 +- doc/atom_style.txt | 2 +- doc/pair_buck.html | 4 ++++ doc/pair_buck.txt | 2 ++ doc/pair_class2.html | 6 ++++++ doc/pair_class2.txt | 3 +++ doc/pair_coul.html | 4 ++++ doc/pair_coul.txt | 2 ++ doc/pair_lj.html | 4 ++++ doc/pair_lj.txt | 2 ++ 12 files changed, 54 insertions(+), 27 deletions(-) diff --git a/doc/Section_commands.html b/doc/Section_commands.html index 3ee7047b55..be6c905d1f 100644 --- a/doc/Section_commands.html +++ b/doc/Section_commands.html @@ -491,20 +491,20 @@ KOKKOS, o = USER-OMP, t = OPT. nonehybridhybrid/overlayadp (o) airebo (o)beck (go)bodybop born (go)born/coul/long (cgo)born/coul/msm (o)born/coul/wolf (go) -brownian (o)brownian/poly (o)buck (cgko)buck/coul/cut (cgo) -buck/coul/long (cgo)buck/coul/msm (o)buck/long/coul/long (o)colloid (go) -comb (o)comb3coul/cut (gko)coul/debye (go) -coul/dsf (gko)coul/long (go)coul/msmcoul/streitz +brownian (o)brownian/poly (o)buck (cgko)buck/coul/cut (cgko) +buck/coul/long (cgko)buck/coul/msm (o)buck/long/coul/long (o)colloid (go) +comb (o)comb3coul/cut (gko)coul/debye (gko) +coul/dsf (gko)coul/long (gko)coul/msmcoul/streitz coul/wolf (ko)dpd (o)dpd/tstat (o)dsmc eam (cgkot)eam/alloy (cgot)eam/fs (cgot)eim (o) gauss (go)gayberne (gio)gran/hertz/history (o)gran/hooke (co) gran/hooke/history (o)hbond/dreiding/lj (o)hbond/dreiding/morse (o)kim -lcbopline/lj (o)lj/charmm/coul/charmm (co)lj/charmm/coul/charmm/implicit (co) -lj/charmm/coul/long (cgio)lj/charmm/coul/msmlj/class2 (cgo)lj/class2/coul/cut (co) -lj/class2/coul/long (cgo)lj/cut (cgikot)lj/cut/coul/cut (cgko)lj/cut/coul/debye (cgo) -lj/cut/coul/dsf (go)lj/cut/coul/long (cgikot)lj/cut/coul/msm (go)lj/cut/dipole/cut (go) -lj/cut/dipole/longlj/cut/tip4p/cut (o)lj/cut/tip4p/long (ot)lj/expand (cgo) -lj/gromacs (cgo)lj/gromacs/coul/gromacs (co)lj/long/coul/long (o)lj/long/dipole/long +lcbopline/lj (o)lj/charmm/coul/charmm (cko)lj/charmm/coul/charmm/implicit (cko) +lj/charmm/coul/long (cgiko)lj/charmm/coul/msmlj/class2 (cgko)lj/class2/coul/cut (cko) +lj/class2/coul/long (cgko)lj/cut (cgikot)lj/cut/coul/cut (cgko)lj/cut/coul/debye (cgko) +lj/cut/coul/dsf (gko)lj/cut/coul/long (cgikot)lj/cut/coul/msm (go)lj/cut/dipole/cut (go) +lj/cut/dipole/longlj/cut/tip4p/cut (o)lj/cut/tip4p/long (ot)lj/expand (cgko) +lj/gromacs (cgko)lj/gromacs/coul/gromacs (cko)lj/long/coul/long (o)lj/long/dipole/long lj/long/tip4p/longlj/smooth (co)lj/smooth/linear (o)lj96/cut (cgo) lubricate (o)lubricate/poly (o)lubricateUlubricateU/poly meam (o)mie/cut (o)morse (cgot)nb3b/harmonic (o) diff --git a/doc/Section_commands.txt b/doc/Section_commands.txt index 92d6a6d350..e31670f17e 100644 --- a/doc/Section_commands.txt +++ b/doc/Section_commands.txt @@ -751,17 +751,17 @@ KOKKOS, o = USER-OMP, t = OPT. "brownian (o)"_pair_brownian.html, "brownian/poly (o)"_pair_brownian.html, "buck (cgko)"_pair_buck.html, -"buck/coul/cut (cgo)"_pair_buck.html, -"buck/coul/long (cgo)"_pair_buck.html, +"buck/coul/cut (cgko)"_pair_buck.html, +"buck/coul/long (cgko)"_pair_buck.html, "buck/coul/msm (o)"_pair_buck.html, "buck/long/coul/long (o)"_pair_buck_long.html, "colloid (go)"_pair_colloid.html, "comb (o)"_pair_comb.html, "comb3"_pair_comb.html, "coul/cut (gko)"_pair_coul.html, -"coul/debye (go)"_pair_coul.html, +"coul/debye (gko)"_pair_coul.html, "coul/dsf (gko)"_pair_coul.html, -"coul/long (go)"_pair_coul.html, +"coul/long (gko)"_pair_coul.html, "coul/msm"_pair_coul.html, "coul/streitz"_pair_coul.html, "coul/wolf (ko)"_pair_coul.html, @@ -782,26 +782,26 @@ KOKKOS, o = USER-OMP, t = OPT. "kim"_pair_kim.html, "lcbop"_pair_lcbop.html, "line/lj (o)"_pair_line_lj.html, -"lj/charmm/coul/charmm (co)"_pair_charmm.html, -"lj/charmm/coul/charmm/implicit (co)"_pair_charmm.html, -"lj/charmm/coul/long (cgio)"_pair_charmm.html, +"lj/charmm/coul/charmm (cko)"_pair_charmm.html, +"lj/charmm/coul/charmm/implicit (cko)"_pair_charmm.html, +"lj/charmm/coul/long (cgiko)"_pair_charmm.html, "lj/charmm/coul/msm"_pair_charmm.html, -"lj/class2 (cgo)"_pair_class2.html, -"lj/class2/coul/cut (co)"_pair_class2.html, -"lj/class2/coul/long (cgo)"_pair_class2.html, +"lj/class2 (cgko)"_pair_class2.html, +"lj/class2/coul/cut (cko)"_pair_class2.html, +"lj/class2/coul/long (cgko)"_pair_class2.html, "lj/cut (cgikot)"_pair_lj.html, "lj/cut/coul/cut (cgko)"_pair_lj.html, -"lj/cut/coul/debye (cgo)"_pair_lj.html, -"lj/cut/coul/dsf (go)"_pair_lj.html, +"lj/cut/coul/debye (cgko)"_pair_lj.html, +"lj/cut/coul/dsf (gko)"_pair_lj.html, "lj/cut/coul/long (cgikot)"_pair_lj.html, "lj/cut/coul/msm (go)"_pair_lj.html, "lj/cut/dipole/cut (go)"_pair_dipole.html, "lj/cut/dipole/long"_pair_dipole.html, "lj/cut/tip4p/cut (o)"_pair_lj.html, "lj/cut/tip4p/long (ot)"_pair_lj.html, -"lj/expand (cgo)"_pair_lj_expand.html, -"lj/gromacs (cgo)"_pair_gromacs.html, -"lj/gromacs/coul/gromacs (co)"_pair_gromacs.html, +"lj/expand (cgko)"_pair_lj_expand.html, +"lj/gromacs (cgko)"_pair_gromacs.html, +"lj/gromacs/coul/gromacs (cko)"_pair_gromacs.html, "lj/long/coul/long (o)"_pair_lj_long.html, "lj/long/dipole/long"_pair_dipole.html, "lj/long/tip4p/long"_pair_lj_long.html, diff --git a/doc/atom_style.html b/doc/atom_style.html index c0ee353523..6c690b135f 100644 --- a/doc/atom_style.html +++ b/doc/atom_style.html @@ -26,7 +26,7 @@ template-ID = ID of molecule template specified in a separate molecule command hybrid args = list of one or more sub-styles, each with their args -

  • accelerated styles (with same args) = angle/cuda or angle/kokkos or atomic/cuda or atomic/kokkos or bond/kokkos or charge/cuda or charge/kokkos or full/cuda or full/kokkos or molecular/kokkos +
  • accelerated styles (with same args) = angle/cuda or angle/kk or atomic/cuda or atomic/kk or bond/kk or charge/cuda or charge/kk or full/cuda or full/kk or molecular/kk diff --git a/doc/atom_style.txt b/doc/atom_style.txt index ef2427c254..4750cbfbdd 100644 --- a/doc/atom_style.txt +++ b/doc/atom_style.txt @@ -24,7 +24,7 @@ style = {angle} or {atomic} or {body} or {bond} or {charge} or {dipole} or \ template-ID = ID of molecule template specified in a separate "molecule"_molecule.html command {hybrid} args = list of one or more sub-styles, each with their args :pre -accelerated styles (with same args) = {angle/cuda} or {angle/kokkos} or {atomic/cuda} or {atomic/kokkos} or {bond/kokkos} or {charge/cuda} or {charge/kokkos} or {full/cuda} or {full/kokkos} or {molecular/kokkos} :l +accelerated styles (with same args) = {angle/cuda} or {angle/kk} or {atomic/cuda} or {atomic/kk} or {bond/kk} or {charge/cuda} or {charge/kk} or {full/cuda} or {full/kk} or {molecular/kk} :l :ule [Examples:] diff --git a/doc/pair_buck.html b/doc/pair_buck.html index 8671839fef..1e14667251 100644 --- a/doc/pair_buck.html +++ b/doc/pair_buck.html @@ -25,6 +25,8 @@

    pair_style buck/coul/cut/gpu command

    +

    pair_style buck/coul/cut/kk command +

    pair_style buck/coul/cut/omp command

    pair_style buck/coul/long command @@ -33,6 +35,8 @@

    pair_style buck/coul/long/gpu command

    +

    pair_style buck/coul/long/kk command +

    pair_style buck/coul/long/omp command

    pair_style buck/coul/msm command diff --git a/doc/pair_buck.txt b/doc/pair_buck.txt index bdda6501d8..2409c24ee9 100644 --- a/doc/pair_buck.txt +++ b/doc/pair_buck.txt @@ -14,10 +14,12 @@ pair_style buck/omp command :h3 pair_style buck/coul/cut command :h3 pair_style buck/coul/cut/cuda command :h3 pair_style buck/coul/cut/gpu command :h3 +pair_style buck/coul/cut/kk command :h3 pair_style buck/coul/cut/omp command :h3 pair_style buck/coul/long command :h3 pair_style buck/coul/long/cuda command :h3 pair_style buck/coul/long/gpu command :h3 +pair_style buck/coul/long/kk command :h3 pair_style buck/coul/long/omp command :h3 pair_style buck/coul/msm command :h3 pair_style buck/coul/msm/omp command :h3 diff --git a/doc/pair_class2.html b/doc/pair_class2.html index e461829e5b..58c66b927c 100644 --- a/doc/pair_class2.html +++ b/doc/pair_class2.html @@ -15,12 +15,16 @@

    pair_style lj/class2/gpu command

    +

    pair_style lj/class2/kk command +

    pair_style lj/class2/omp command

    pair_style lj/class2/coul/cut command

    pair_style lj/class2/coul/cut/cuda command

    +

    pair_style lj/class2/coul/cut/kk command +

    pair_style lj/class2/coul/cut/omp command

    pair_style lj/class2/coul/long command @@ -29,6 +33,8 @@

    pair_style lj/class2/coul/long/gpu command

    +

    pair_style lj/class2/coul/long/kk command +

    pair_style lj/class2/coul/long/omp command

    Syntax: diff --git a/doc/pair_class2.txt b/doc/pair_class2.txt index 906e25f63e..66ba2b7f30 100644 --- a/doc/pair_class2.txt +++ b/doc/pair_class2.txt @@ -9,13 +9,16 @@ pair_style lj/class2 command :h3 pair_style lj/class2/cuda command :h3 pair_style lj/class2/gpu command :h3 +pair_style lj/class2/kk command :h3 pair_style lj/class2/omp command :h3 pair_style lj/class2/coul/cut command :h3 pair_style lj/class2/coul/cut/cuda command :h3 +pair_style lj/class2/coul/cut/kk command :h3 pair_style lj/class2/coul/cut/omp command :h3 pair_style lj/class2/coul/long command :h3 pair_style lj/class2/coul/long/cuda command :h3 pair_style lj/class2/coul/long/gpu command :h3 +pair_style lj/class2/coul/long/kk command :h3 pair_style lj/class2/coul/long/omp command :h3 [Syntax:] diff --git a/doc/pair_coul.html b/doc/pair_coul.html index 466dfd33c1..176e331f89 100644 --- a/doc/pair_coul.html +++ b/doc/pair_coul.html @@ -21,6 +21,8 @@

    pair_style coul/debye/gpu command

    +

    pair_style coul/debye/kk command +

    pair_style coul/debye/omp command

    pair_style coul/dsf command @@ -37,6 +39,8 @@

    pair_style coul/long/gpu command

    +

    pair_style coul/long/kk command +

    pair_style coul/msm command

    pair_style coul/msm/omp command diff --git a/doc/pair_coul.txt b/doc/pair_coul.txt index 46fbf307f0..a6fbda3785 100644 --- a/doc/pair_coul.txt +++ b/doc/pair_coul.txt @@ -12,6 +12,7 @@ pair_style coul/cut/kk command :h3 pair_style coul/cut/omp command :h3 pair_style coul/debye command :h3 pair_style coul/debye/gpu command :h3 +pair_style coul/debye/kk command :h3 pair_style coul/debye/omp command :h3 pair_style coul/dsf command :h3 pair_style coul/dsf/gpu command :h3 @@ -20,6 +21,7 @@ pair_style coul/dsf/omp command :h3 pair_style coul/long command :h3 pair_style coul/long/omp command :h3 pair_style coul/long/gpu command :h3 +pair_style coul/long/kk command :h3 pair_style coul/msm command :h3 pair_style coul/msm/omp command :h3 pair_style coul/streitz command :h3 diff --git a/doc/pair_lj.html b/doc/pair_lj.html index bcdf8e56d1..1a8c57f73a 100644 --- a/doc/pair_lj.html +++ b/doc/pair_lj.html @@ -37,12 +37,16 @@

    pair_style lj/cut/coul/debye/gpu command

    +

    pair_style lj/cut/coul/debye/kk command +

    pair_style lj/cut/coul/debye/omp command

    pair_style lj/cut/coul/dsf command

    pair_style lj/cut/coul/dsf/gpu command

    +

    pair_style lj/cut/coul/dsf/kk command +

    pair_style lj/cut/coul/dsf/omp command

    pair_style lj/cut/coul/long command diff --git a/doc/pair_lj.txt b/doc/pair_lj.txt index a308d81f8c..1a9fea5eef 100644 --- a/doc/pair_lj.txt +++ b/doc/pair_lj.txt @@ -20,9 +20,11 @@ pair_style lj/cut/coul/cut/omp command :h3 pair_style lj/cut/coul/debye command :h3 pair_style lj/cut/coul/debye/cuda command :h3 pair_style lj/cut/coul/debye/gpu command :h3 +pair_style lj/cut/coul/debye/kk command :h3 pair_style lj/cut/coul/debye/omp command :h3 pair_style lj/cut/coul/dsf command :h3 pair_style lj/cut/coul/dsf/gpu command :h3 +pair_style lj/cut/coul/dsf/kk command :h3 pair_style lj/cut/coul/dsf/omp command :h3 pair_style lj/cut/coul/long command :h3 pair_style lj/cut/coul/long/cuda command :h3 From 118418eb14d1b76716a5244f9496ec6bcaa4ef20 Mon Sep 17 00:00:00 2001 From: sjplimp Date: Fri, 27 Mar 2015 13:59:28 +0000 Subject: [PATCH 06/22] git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@13307 f3b2605a-c512-4ea7-a41b-209d697bcdaa --- src/version.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/version.h b/src/version.h index f4a4ffa83a..7e55002a99 100644 --- a/src/version.h +++ b/src/version.h @@ -1 +1 @@ -#define LAMMPS_VERSION "25 Mar 2015" +#define LAMMPS_VERSION "27 Mar 2015" From fc64a9a443d6fe331abbaf01c48a3bbe3e7cfae2 Mon Sep 17 00:00:00 2001 From: sjplimp Date: Fri, 27 Mar 2015 13:59:30 +0000 Subject: [PATCH 07/22] git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@13308 f3b2605a-c512-4ea7-a41b-209d697bcdaa --- doc/Manual.html | 4 ++-- doc/Manual.txt | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/Manual.html b/doc/Manual.html index 685c5e36f0..107ac89afe 100644 --- a/doc/Manual.html +++ b/doc/Manual.html @@ -1,7 +1,7 @@ LAMMPS Users Manual - + @@ -22,7 +22,7 @@

    LAMMPS Documentation

    -

    25 Mar 2015 version +

    27 Mar 2015 version

    Version info:

    diff --git a/doc/Manual.txt b/doc/Manual.txt index 89f4c53a60..fd18a5ef3a 100644 --- a/doc/Manual.txt +++ b/doc/Manual.txt @@ -1,6 +1,6 @@ LAMMPS Users Manual - + @@ -18,7 +18,7 @@

    LAMMPS Documentation :c,h3 -25 Mar 2015 version :c,h4 +27 Mar 2015 version :c,h4 Version info: :h4 From f314fbc9cdba2ff76b1cd85da2e665ade3d193f6 Mon Sep 17 00:00:00 2001 From: stamoor Date: Fri, 27 Mar 2015 14:56:28 +0000 Subject: [PATCH 08/22] Fixing some Kokkos issues git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@13310 f3b2605a-c512-4ea7-a41b-209d697bcdaa --- src/KOKKOS/pair_coul_cut_kokkos.h | 9 ++++----- src/KOKKOS/pair_coul_dsf_kokkos.h | 2 +- src/KOKKOS/pair_coul_wolf_kokkos.h | 2 +- src/KOKKOS/pair_table_kokkos.h | 2 +- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/KOKKOS/pair_coul_cut_kokkos.h b/src/KOKKOS/pair_coul_cut_kokkos.h index 03202c4099..29b16d94b8 100644 --- a/src/KOKKOS/pair_coul_cut_kokkos.h +++ b/src/KOKKOS/pair_coul_cut_kokkos.h @@ -31,7 +31,7 @@ namespace LAMMPS_NS { template class PairCoulCutKokkos : public PairCoulCut { public: - enum {EnabledNeighFlags=FULL&HALFTHREAD&HALF}; + enum {EnabledNeighFlags=FULL|HALFTHREAD|HALF}; enum {COUL_FLAG=1}; typedef DeviceType device_type; PairCoulCutKokkos(class LAMMPS *); @@ -114,13 +114,12 @@ class PairCoulCutKokkos : public PairCoulCut { friend class PairComputeFunctor; friend class PairComputeFunctor; friend class PairComputeFunctor; - friend class PairComputeFunctor; - friend class PairComputeFunctor; friend class PairComputeFunctor; friend class PairComputeFunctor; friend class PairComputeFunctor; - friend class PairComputeFunctor; - friend class PairComputeFunctor; + friend EV_FLOAT pair_compute_neighlist(PairCoulCutKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairCoulCutKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairCoulCutKokkos*,NeighListKokkos*); friend EV_FLOAT pair_compute(PairCoulCutKokkos*, NeighListKokkos*); friend void pair_virial_fdotr_compute(PairCoulCutKokkos*); diff --git a/src/KOKKOS/pair_coul_dsf_kokkos.h b/src/KOKKOS/pair_coul_dsf_kokkos.h index 7fe68aa10b..342a96d844 100755 --- a/src/KOKKOS/pair_coul_dsf_kokkos.h +++ b/src/KOKKOS/pair_coul_dsf_kokkos.h @@ -34,7 +34,7 @@ struct TagPairCoulDSFKernelA{}; template class PairCoulDSFKokkos : public PairCoulDSF { public: - enum {EnabledNeighFlags=FULL&HALFTHREAD&HALF}; + enum {EnabledNeighFlags=FULL|HALFTHREAD|HALF}; enum {COUL_FLAG=1}; typedef DeviceType device_type; typedef EV_FLOAT value_type; diff --git a/src/KOKKOS/pair_coul_wolf_kokkos.h b/src/KOKKOS/pair_coul_wolf_kokkos.h index fccfd4bdce..2ae184f351 100755 --- a/src/KOKKOS/pair_coul_wolf_kokkos.h +++ b/src/KOKKOS/pair_coul_wolf_kokkos.h @@ -34,7 +34,7 @@ struct TagPairCoulWolfKernelA{}; template class PairCoulWolfKokkos : public PairCoulWolf { public: - enum {EnabledNeighFlags=FULL&HALFTHREAD&HALF}; + enum {EnabledNeighFlags=FULL|HALFTHREAD|HALF}; enum {COUL_FLAG=1}; typedef DeviceType device_type; typedef EV_FLOAT value_type; diff --git a/src/KOKKOS/pair_table_kokkos.h b/src/KOKKOS/pair_table_kokkos.h index c59a05f866..f497626ba7 100644 --- a/src/KOKKOS/pair_table_kokkos.h +++ b/src/KOKKOS/pair_table_kokkos.h @@ -41,7 +41,7 @@ template class PairTableKokkos : public Pair { public: - enum {EnabledNeighFlags=FULL&HALFTHREAD&HALF&N2&FULLCLUSTER}; + enum {EnabledNeighFlags=FULL|HALFTHREAD|HALF|N2|FULLCLUSTER}; enum {COUL_FLAG=0}; typedef DeviceType device_type; From b3d89e0b426494170fd1a2c9eeea7863d233b281 Mon Sep 17 00:00:00 2001 From: stamoor Date: Fri, 27 Mar 2015 15:24:42 +0000 Subject: [PATCH 09/22] Fixing another Kokkos issue git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@13311 f3b2605a-c512-4ea7-a41b-209d697bcdaa --- src/KOKKOS/Install.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/KOKKOS/Install.sh b/src/KOKKOS/Install.sh index c28f68280e..e0a51745da 100644 --- a/src/KOKKOS/Install.sh +++ b/src/KOKKOS/Install.sh @@ -118,13 +118,13 @@ action pair_lj_cut_coul_debye_kokkos.cpp action pair_lj_cut_coul_debye_kokkos.h action pair_lj_cut_coul_dsf_kokkos.cpp action pair_lj_cut_coul_dsf_kokkos.h -action pair_lj_cut_coul_long_kokkos.cpp pair_lj_cut_coul_long.cpp pair_lj_cut_coul_long_kokkos.cpp pair_lj_cut_co.cpp -action pair_lj_cut_coul_long_kokkos.h pair_lj_cut_coul_long.h pair_lj_cut_coul_long_kokkos.h pair_lj_cut_co.h +action pair_lj_cut_coul_long_kokkos.cpp pair_lj_cut_coul_long.cpp +action pair_lj_cut_coul_long_kokkos.h pair_lj_cut_coul_long.h action pair_lj_cut_kokkos.cpp action pair_lj_cut_kokkos.h action pair_lj_expand_kokkos.cpp action pair_lj_expand_kokkos.h -action pair_lj_gromacs_coul_gromacs_kokkos.cp +action pair_lj_gromacs_coul_gromacs_kokkos.cpp action pair_lj_gromacs_coul_gromacs_kokkos.h action pair_lj_gromacs_kokkos.cpp action pair_lj_gromacs_kokkos.h From 43d48e60ed6f1f71e555af3a89cc649540f2e3e0 Mon Sep 17 00:00:00 2001 From: sjplimp Date: Fri, 27 Mar 2015 16:07:03 +0000 Subject: [PATCH 10/22] git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@13312 f3b2605a-c512-4ea7-a41b-209d697bcdaa --- src/KOKKOS/Install.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/src/KOKKOS/Install.sh b/src/KOKKOS/Install.sh index e0a51745da..d857476c46 100644 --- a/src/KOKKOS/Install.sh +++ b/src/KOKKOS/Install.sh @@ -26,7 +26,6 @@ action () { touch ../accelerator_kokkos.h touch ../memory.h -touch ../special.cpp # list of files with optional dependcies From fd1e7078b4e74919dfcf0b6d4a78c6854c0e1a9f Mon Sep 17 00:00:00 2001 From: stamoor Date: Fri, 27 Mar 2015 16:08:31 +0000 Subject: [PATCH 11/22] Fixing Kokkos issue git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@13313 f3b2605a-c512-4ea7-a41b-209d697bcdaa --- src/KOKKOS/Install.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/KOKKOS/Install.sh b/src/KOKKOS/Install.sh index d857476c46..8217609514 100644 --- a/src/KOKKOS/Install.sh +++ b/src/KOKKOS/Install.sh @@ -82,8 +82,8 @@ action neighbor_kokkos.cpp action neighbor_kokkos.h action pair_buck_coul_cut_kokkos.cpp action pair_buck_coul_cut_kokkos.h -action pair_buck_coul_long_kokkos.cpp -action pair_buck_coul_long_kokkos.h +action pair_buck_coul_long_kokkos.cpp pair_buck_coul_long.cpp +action pair_buck_coul_long_kokkos.h pair_buck_coul_long.h action pair_buck_kokkos.cpp action pair_buck_kokkos.h action pair_coul_cut_kokkos.cpp @@ -92,8 +92,8 @@ action pair_coul_debye_kokkos.cpp action pair_coul_debye_kokkos.h action pair_coul_dsf_kokkos.cpp action pair_coul_dsf_kokkos.h -action pair_coul_long_kokkos.cpp -action pair_coul_long_kokkos.h +action pair_coul_long_kokkos.cpp pair_coul_long.cpp +action pair_coul_long_kokkos.h pair_coul_long.h action pair_coul_wolf_kokkos.cpp action pair_coul_wolf_kokkos.h action pair_eam_kokkos.cpp pair_eam.cpp From c56fbcd1a38d02278fa858b41537e626cbea287e Mon Sep 17 00:00:00 2001 From: sjplimp Date: Fri, 27 Mar 2015 19:55:56 +0000 Subject: [PATCH 12/22] git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@13315 f3b2605a-c512-4ea7-a41b-209d697bcdaa --- src/neighbor.cpp | 3 ++- src/special.cpp | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/neighbor.cpp b/src/neighbor.cpp index 37e6696ffd..d2face512f 100644 --- a/src/neighbor.cpp +++ b/src/neighbor.cpp @@ -876,7 +876,8 @@ void Neighbor::init() int bond_off = 0; int angle_off = 0; for (i = 0; i < modify->nfix; i++) - if (strcmp(modify->fix[i]->style,"shake") == 0) + if ((strcmp(modify->fix[i]->style,"shake") == 0) + || (strcmp(modify->fix[i]->style,"rattle") == 0)) bond_off = angle_off = 1; if (force->bond && force->bond_match("quartic")) bond_off = 1; diff --git a/src/special.cpp b/src/special.cpp index 420a8388ab..6b969e0006 100644 --- a/src/special.cpp +++ b/src/special.cpp @@ -220,7 +220,7 @@ void Special::build() // extract count from buffer that has cycled back to me // nspecial[i][1] = # of 1-3 neighbors of atom i - j = 0; +< j = 0; for (i = 0; i < nlocal; i++) { nspecial[i][1] = buf[j]; j += 2 + nspecial[i][0]; From 507adef0787f84fe225c19b01798f6846de51e6b Mon Sep 17 00:00:00 2001 From: sjplimp Date: Fri, 27 Mar 2015 19:56:16 +0000 Subject: [PATCH 13/22] git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@13316 f3b2605a-c512-4ea7-a41b-209d697bcdaa --- src/special.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/special.cpp b/src/special.cpp index 6b969e0006..420a8388ab 100644 --- a/src/special.cpp +++ b/src/special.cpp @@ -220,7 +220,7 @@ void Special::build() // extract count from buffer that has cycled back to me // nspecial[i][1] = # of 1-3 neighbors of atom i -< j = 0; + j = 0; for (i = 0; i < nlocal; i++) { nspecial[i][1] = buf[j]; j += 2 + nspecial[i][0]; From 514c7c313f8c285a2017b48dabfcfcf0896ebfa4 Mon Sep 17 00:00:00 2001 From: sjplimp Date: Fri, 27 Mar 2015 19:57:05 +0000 Subject: [PATCH 14/22] git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@13317 f3b2605a-c512-4ea7-a41b-209d697bcdaa --- src/version.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/version.h b/src/version.h index 7e55002a99..eff88cd933 100644 --- a/src/version.h +++ b/src/version.h @@ -1 +1 @@ -#define LAMMPS_VERSION "27 Mar 2015" +#define LAMMPS_VERSION "28 Mar 2015" From bc06bcf854c124a3e3d89109e5908d624730ff23 Mon Sep 17 00:00:00 2001 From: sjplimp Date: Fri, 27 Mar 2015 19:57:11 +0000 Subject: [PATCH 15/22] git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@13318 f3b2605a-c512-4ea7-a41b-209d697bcdaa --- doc/Manual.html | 4 ++-- doc/Manual.txt | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/Manual.html b/doc/Manual.html index 107ac89afe..380eb61817 100644 --- a/doc/Manual.html +++ b/doc/Manual.html @@ -1,7 +1,7 @@ LAMMPS Users Manual - + @@ -22,7 +22,7 @@

    LAMMPS Documentation

    -

    27 Mar 2015 version +

    28 Mar 2015 version

    Version info:

    diff --git a/doc/Manual.txt b/doc/Manual.txt index fd18a5ef3a..45c637f1e4 100644 --- a/doc/Manual.txt +++ b/doc/Manual.txt @@ -1,6 +1,6 @@ LAMMPS Users Manual - + @@ -18,7 +18,7 @@

    LAMMPS Documentation :c,h3 -27 Mar 2015 version :c,h4 +28 Mar 2015 version :c,h4 Version info: :h4 From 9435c9dcb15aa500eb4f0e65cb3ea9b51b2ca6e6 Mon Sep 17 00:00:00 2001 From: sjplimp Date: Fri, 27 Mar 2015 20:39:27 +0000 Subject: [PATCH 16/22] git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@13320 f3b2605a-c512-4ea7-a41b-209d697bcdaa --- src/CORESHELL/compute_temp_cs.cpp | 7 +- src/USER-FEP/compute_fep.h | 1 - src/USER-MOLFILE/dump_molfile.cpp | 2 +- src/USER-OMP/Install.sh | 13 +- src/XTC/dump_xtc.cpp | 2 +- src/domain.cpp | 8 +- src/dump_dcd.cpp | 2 +- src/fix_ave_chunk.cpp | 1 - src/fix_temp_csld.cpp | 307 ++++++++++++++++++++++++++++++ src/fix_temp_csld.h | 101 ++++++++++ src/fix_temp_csvr.cpp | 166 ++++++++++------ src/fix_temp_csvr.h | 10 +- src/force.cpp | 18 +- src/variable.cpp | 24 +-- 14 files changed, 566 insertions(+), 96 deletions(-) create mode 100644 src/fix_temp_csld.cpp create mode 100644 src/fix_temp_csld.h diff --git a/src/CORESHELL/compute_temp_cs.cpp b/src/CORESHELL/compute_temp_cs.cpp index 6d0aa2514a..7512d48afd 100644 --- a/src/CORESHELL/compute_temp_cs.cpp +++ b/src/CORESHELL/compute_temp_cs.cpp @@ -54,9 +54,6 @@ ComputeTempCS::ComputeTempCS(LAMMPS *lmp, int narg, char **arg) : tempbias = 1; extarray = 0; - int *mask = atom->mask; - int nlocal = atom->nlocal; - // find and define groupbits for core and shell groups cgroup = group->find(arg[3]); @@ -226,7 +223,6 @@ void ComputeTempCS::dof_compute() double ComputeTempCS::compute_scalar() { - int i; double vthermal[3]; invoked_scalar = update->ntimestep; @@ -280,7 +276,6 @@ void ComputeTempCS::compute_vector() double **v = atom->v; int *mask = atom->mask; - tagint *molecule = atom->molecule; int *type = atom->type; double *mass = atom->mass; double *rmass = atom->rmass; @@ -340,7 +335,7 @@ void ComputeTempCS::vcm_pairs() double *partner = fix->vstore; tagint partnerID; - for (int i = 0; i < nlocal; i++) { + for (i = 0; i < nlocal; i++) { if ((mask[i] & groupbit) && (mask[i] & groupbit_c || mask[i] & groupbit_s)) { if (rmass) massone = rmass[i]; diff --git a/src/USER-FEP/compute_fep.h b/src/USER-FEP/compute_fep.h index 7c60a68f71..51fcbd5ea6 100644 --- a/src/USER-FEP/compute_fep.h +++ b/src/USER-FEP/compute_fep.h @@ -42,7 +42,6 @@ class ComputeFEP : public Compute { int tailflag, volumeflag; int fepinitflag; int eflag, vflag; - int sys_qsum_update_flag; double temp_fep; int nmax; diff --git a/src/USER-MOLFILE/dump_molfile.cpp b/src/USER-MOLFILE/dump_molfile.cpp index b0e4d54f61..add7bf695b 100644 --- a/src/USER-MOLFILE/dump_molfile.cpp +++ b/src/USER-MOLFILE/dump_molfile.cpp @@ -81,7 +81,7 @@ DumpMolfile::DumpMolfile(LAMMPS *lmp, int narg, char **arg) // allocate global array for atom coords bigint n = group->count(igroup); - if (n > MAXSMALLINT/sizeof(float)) + if (n > static_cast(MAXSMALLINT/3/sizeof(float))) error->all(FLERR,"Too many atoms for dump molfile"); if (n < 1) error->all(FLERR,"Not enough atoms for dump molfile"); diff --git a/src/USER-OMP/Install.sh b/src/USER-OMP/Install.sh index 547fa074e6..85b44f1bee 100644 --- a/src/USER-OMP/Install.sh +++ b/src/USER-OMP/Install.sh @@ -51,11 +51,14 @@ if (test $mode = 1) then sed -i -e 's|^PKG_INC =[ \t]*|&-DLMP_USER_OMP |' ../Makefile.package fi - # need to delete a bunch of depenency files because they indirectly depend on user_cuda.h + # need to delete a bunch of dependency files because they + # indirectly depend on user_cuda.h + for f in finish.d modify_cuda.d do \ rm -f ../Obj_*/$f done + # force rebuild of files with LMP_USER_OMP switch touch ../accelerator_omp.h @@ -66,6 +69,14 @@ elif (test $mode = 0) then sed -i -e 's/[^ \t]*OMP[^ \t]* //' ../Makefile.package fi + # need to delete a bunch of dependency files because they + # indirectly depend on user_cuda.h + + for f in finish.d modify_cuda.d + do \ + rm -f ../Obj_*/$f + done + # force rebuild of files with LMP_USER_OMP switch touch ../accelerator_omp.h diff --git a/src/XTC/dump_xtc.cpp b/src/XTC/dump_xtc.cpp index 5f7bee27db..7b8afbd3a9 100644 --- a/src/XTC/dump_xtc.cpp +++ b/src/XTC/dump_xtc.cpp @@ -70,7 +70,7 @@ DumpXTC::DumpXTC(LAMMPS *lmp, int narg, char **arg) : Dump(lmp, narg, arg) // allocate global array for atom coords bigint n = group->count(igroup); - if (n > MAXSMALLINT/3/sizeof(float)) + if (n > static_cast(MAXSMALLINT/3/sizeof(float))) error->all(FLERR,"Too many atoms for dump xtc"); natoms = static_cast (n); diff --git a/src/domain.cpp b/src/domain.cpp index 005678c952..da93f50720 100644 --- a/src/domain.cpp +++ b/src/domain.cpp @@ -451,9 +451,13 @@ void Domain::reset_box() set_global_box(); set_local_box(); - // if shrink-wrapped & kspace is defined (i.e. using MSM) call setup() + // if shrink-wrapped & kspace is defined (i.e. using MSM), call setup() + // also call init() (to test for compatibility) ? - if (nonperiodic == 2 && force->kspace) force->kspace->setup(); + if (nonperiodic == 2 && force->kspace) { + //force->kspace->init(); + force->kspace->setup(); + } // if shrink-wrapped & triclinic, re-convert to lamda coords for new box // re-invoke pbc() b/c x2lamda result can be outside [0,1] due to roundoff diff --git a/src/dump_dcd.cpp b/src/dump_dcd.cpp index a4a6e4f704..c679df62b9 100644 --- a/src/dump_dcd.cpp +++ b/src/dump_dcd.cpp @@ -68,7 +68,7 @@ DumpDCD::DumpDCD(LAMMPS *lmp, int narg, char **arg) : Dump(lmp, narg, arg) // allocate global array for atom coords bigint n = group->count(igroup); - if (n > MAXSMALLINT/sizeof(float)) + if (n > static_cast(MAXSMALLINT/3/sizeof(float))) error->all(FLERR,"Too many atoms for dump dcd"); natoms = static_cast (n); diff --git a/src/fix_ave_chunk.cpp b/src/fix_ave_chunk.cpp index 2eb3f9dce1..7a7935c5bb 100644 --- a/src/fix_ave_chunk.cpp +++ b/src/fix_ave_chunk.cpp @@ -574,7 +574,6 @@ void FixAveChunk::end_of_step() // sum within each chunk, only include atoms in fix group // compute/fix/variable may invoke computes so wrap with clear/add - double **x = atom->x; int *mask = atom->mask; int nlocal = atom->nlocal; diff --git a/src/fix_temp_csld.cpp b/src/fix_temp_csld.cpp new file mode 100644 index 0000000000..e394f06e58 --- /dev/null +++ b/src/fix_temp_csld.cpp @@ -0,0 +1,307 @@ +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + http://lammps.sandia.gov, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +/* ---------------------------------------------------------------------- + Contributing author: Axel Kohlmeyer (Temple U) +------------------------------------------------------------------------- */ + +#include "string.h" +#include "stdlib.h" +#include "math.h" +#include "fix_temp_csld.h" +#include "atom.h" +#include "force.h" +#include "memory.h" +#include "comm.h" +#include "input.h" +#include "variable.h" +#include "group.h" +#include "update.h" +#include "modify.h" +#include "compute.h" +#include "random_mars.h" +#include "error.h" + +using namespace LAMMPS_NS; +using namespace FixConst; + +enum{NOBIAS,BIAS}; +enum{CONSTANT,EQUAL}; + +/* ---------------------------------------------------------------------- */ + +FixTempCSLD::FixTempCSLD(LAMMPS *lmp, int narg, char **arg) : + Fix(lmp, narg, arg) +{ + if (narg != 7) error->all(FLERR,"Illegal fix temp/csld command"); + + // CSLD thermostat should be applied every step + + nevery = 1; + scalar_flag = 1; + global_freq = nevery; + dynamic_group_allow = 1; + extscalar = 1; + + tstr = NULL; + if (strstr(arg[3],"v_") == arg[3]) { + int n = strlen(&arg[3][2]) + 1; + tstr = new char[n]; + strcpy(tstr,&arg[3][2]); + tstyle = EQUAL; + } else { + t_start = force->numeric(FLERR,arg[3]); + t_target = t_start; + tstyle = CONSTANT; + } + + t_stop = force->numeric(FLERR,arg[4]); + t_period = force->numeric(FLERR,arg[5]); + int seed = force->inumeric(FLERR,arg[6]); + + // error checks + + if (t_period <= 0.0) error->all(FLERR,"Illegal fix temp/csld command"); + if (seed <= 0) error->all(FLERR,"Illegal fix temp/csld command"); + + random = new RanMars(lmp,seed + comm->me); + + // create a new compute temp style + // id = fix-ID + temp, compute group = fix group + + int n = strlen(id) + 6; + id_temp = new char[n]; + strcpy(id_temp,id); + strcat(id_temp,"_temp"); + + char **newarg = new char*[3]; + newarg[0] = id_temp; + newarg[1] = group->names[igroup]; + newarg[2] = (char *) "temp"; + modify->add_compute(3,newarg); + delete [] newarg; + tflag = 1; + + vhold = NULL; + nmax = -1; + energy = 0.0; +} + +/* ---------------------------------------------------------------------- */ + +FixTempCSLD::~FixTempCSLD() +{ + delete [] tstr; + + // delete temperature if fix created it + + if (tflag) modify->delete_compute(id_temp); + delete [] id_temp; + + delete random; + memory->destroy(vhold); + vhold = NULL; + nmax = -1; +} + +/* ---------------------------------------------------------------------- */ + +int FixTempCSLD::setmask() +{ + int mask = 0; + mask |= END_OF_STEP; + mask |= THERMO_ENERGY; + return mask; +} + +/* ---------------------------------------------------------------------- */ + +void FixTempCSLD::init() +{ + + // we cannot handle constraints via rattle or shake correctly. + + int has_shake = 0; + for (int i = 0; i < modify->nfix; i++) + if ((strcmp(modify->fix[i]->style,"shake") == 0) + || (strcmp(modify->fix[i]->style,"rattle") == 0)) ++has_shake; + + if (has_shake > 0) + error->all(FLERR,"Fix temp/csld is not compatible with fix rattle or fix shake"); + + // check variable + + if (tstr) { + tvar = input->variable->find(tstr); + if (tvar < 0) + error->all(FLERR,"Variable name for fix temp/csld does not exist"); + if (input->variable->equalstyle(tvar)) tstyle = EQUAL; + else error->all(FLERR,"Variable for fix temp/csld is invalid style"); + } + + int icompute = modify->find_compute(id_temp); + if (icompute < 0) + error->all(FLERR,"Temperature ID for fix temp/csld does not exist"); + temperature = modify->compute[icompute]; + + if (temperature->tempbias) which = BIAS; + else which = NOBIAS; +} + +/* ---------------------------------------------------------------------- */ + +void FixTempCSLD::end_of_step() +{ + + // set current t_target + // if variable temp, evaluate variable, wrap with clear/add + + double delta = update->ntimestep - update->beginstep; + + if (delta != 0.0) delta /= update->endstep - update->beginstep; + if (tstyle == CONSTANT) + t_target = t_start + delta * (t_stop-t_start); + else { + modify->clearstep_compute(); + t_target = input->variable->compute_equal(tvar); + if (t_target < 0.0) + error->one(FLERR, + "Fix temp/csld variable returned negative temperature"); + modify->addstep_compute(update->ntimestep + nevery); + } + + double t_current = temperature->compute_scalar(); + double ekin_old = t_current * 0.5 * temperature->dof * force->boltz; + + double * const * const v = atom->v; + const int * const mask = atom->mask; + const int * const type = atom->type; + const int nlocal = atom->nlocal; + + // adjust holding space, if needed and copy existing velocities + + if (nmax < atom->nlocal) { + nmax = atom->nlocal + 1; + memory->destroy(vhold); + memory->create(vhold,nmax,3,"csld:vhold"); + } + + // The CSLD thermostat is a linear combination of old and new velocities, + // where the new ones are randomly chosen from a gaussian distribution. + // see Bussi and Parrinello, Phys. Rev. E (2007). + + for (int i = 0; i < nlocal; i++) { + if (mask[i] & groupbit) { + double m; + if (atom->rmass_flag) m = atom->rmass[i]; + else m = atom->mass[type[i]]; + + const double factor = 1.0/sqrt(m); + const double vx = random->gaussian() * factor; + vhold[i][0] = v[i][0]; + v[i][0] = vx; + const double vy = random->gaussian() * factor; + vhold[i][1] = v[i][1]; + v[i][1] = vy; + const double vz = random->gaussian() * factor; + vhold[i][2] = v[i][2]; + v[i][2] = vz; + } + } + + // mixing factors + const double c1 = exp(-update->dt/t_period); + const double c2 = sqrt((1.0-c1*c1)*t_target/temperature->compute_scalar()); + + if (which == NOBIAS) { + for (int i = 0; i < nlocal; i++) { + if (mask[i] & groupbit) { + v[i][0] = vhold[i][0]*c1 + v[i][0]*c2; + v[i][1] = vhold[i][1]*c1 + v[i][1]*c2; + v[i][2] = vhold[i][2]*c1 + v[i][2]*c2; + } + } + } else { + for (int i = 0; i < nlocal; i++) { + if (mask[i] & groupbit) { + temperature->remove_bias(i,vhold[i]); + v[i][0] = vhold[i][0]*c1 + v[i][0]*c2; + v[i][1] = vhold[i][1]*c1 + v[i][1]*c2; + v[i][2] = vhold[i][2]*c1 + v[i][2]*c2; + temperature->restore_bias(i,v[i]); + } + } + } + + // tally the kinetic energy transferred between heat bath and system + + t_current = temperature->compute_scalar(); + energy += ekin_old - t_current * 0.5 * temperature->dof * force->boltz; +} + +/* ---------------------------------------------------------------------- */ + +int FixTempCSLD::modify_param(int narg, char **arg) +{ + if (strcmp(arg[0],"temp") == 0) { + if (narg < 2) error->all(FLERR,"Illegal fix_modify command"); + if (tflag) { + modify->delete_compute(id_temp); + tflag = 0; + } + delete [] id_temp; + int n = strlen(arg[1]) + 1; + id_temp = new char[n]; + strcpy(id_temp,arg[1]); + + int icompute = modify->find_compute(id_temp); + if (icompute < 0) + error->all(FLERR,"Could not find fix_modify temperature ID"); + temperature = modify->compute[icompute]; + + if (temperature->tempflag == 0) + error->all(FLERR, + "Fix_modify temperature ID does not compute temperature"); + if (temperature->igroup != igroup && comm->me == 0) + error->warning(FLERR,"Group for fix_modify temp != fix group"); + return 2; + } + return 0; +} + +/* ---------------------------------------------------------------------- */ + +void FixTempCSLD::reset_target(double t_new) +{ + t_target = t_start = t_stop = t_new; +} + +/* ---------------------------------------------------------------------- */ + +double FixTempCSLD::compute_scalar() +{ + return energy; +} + +/* ---------------------------------------------------------------------- + extract thermostat properties +------------------------------------------------------------------------- */ + +void *FixTempCSLD::extract(const char *str, int &dim) +{ + dim=0; + if (strcmp(str,"t_target") == 0) { + return &t_target; + } + return NULL; +} diff --git a/src/fix_temp_csld.h b/src/fix_temp_csld.h new file mode 100644 index 0000000000..3c4ddeefb4 --- /dev/null +++ b/src/fix_temp_csld.h @@ -0,0 +1,101 @@ +/* -*- c++ -*- ---------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + http://lammps.sandia.gov, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +#ifdef FIX_CLASS + +FixStyle(temp/csld,FixTempCSLD) + +#else + +#ifndef LMP_FIX_TEMP_CSLD_H +#define LMP_FIX_TEMP_CSLD_H + +#include "fix.h" + +namespace LAMMPS_NS { + +class FixTempCSLD : public Fix { + public: + FixTempCSLD(class LAMMPS *, int, char **); + ~FixTempCSLD(); + int setmask(); + void init(); + void end_of_step(); + int modify_param(int, char **); + void reset_target(double); + virtual double compute_scalar(); + virtual void *extract(const char *, int &); + + private: + double t_start,t_stop,t_period,t_target; + double **vhold; + double energy; + int nmax,which; + int tstyle,tvar; + char *tstr; + + char *id_temp; + class Compute *temperature; + int tflag; + + class RanMars *random; +}; + +} + +#endif +#endif + +/* ERROR/WARNING messages: + +E: Illegal ... command + +Self-explanatory. Check the input script syntax and compare to the +documentation for the command. You can use -echo screen as a +command-line option when running LAMMPS to see the offending line. + +E: Fix temp/csld is not compatible with fix rattle or fix shake + +These two commands cannot currently be used together with fix temp/csld. + +E: Variable name for fix temp/csld does not exist + +Self-explanatory. + +E: Variable for fix temp/csld is invalid style + +Only equal-style variables can be used. + +E: Temperature ID for fix temp/csld does not exist + +Self-explanatory. + +E: Fix temp/csld variable returned negative temperature + +Self-explanatory. + +E: Could not find fix_modify temperature ID + +The compute ID for computing temperature does not exist. + +E: Fix_modify temperature ID does not compute temperature + +The compute ID assigned to the fix must compute temperature. + +W: Group for fix_modify temp != fix group + +The fix_modify command is specifying a temperature computation that +computes a temperature on a different group of atoms than the fix +itself operates on. This is probably not what you want to do. + +*/ diff --git a/src/fix_temp_csvr.cpp b/src/fix_temp_csvr.cpp index a8c0d9b508..09ffb951dd 100644 --- a/src/fix_temp_csvr.cpp +++ b/src/fix_temp_csvr.cpp @@ -12,7 +12,8 @@ ------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- - Contributing author: Axel Kohlmeyer (ICTP, Italy) + Contributing author: Axel Kohlmeyer (Temple U) + Based on code by Paulo Raiteri (Curtin U) and Giovanni Bussi (SISSA) ------------------------------------------------------------------------- */ #include "string.h" @@ -38,6 +39,78 @@ using namespace FixConst; enum{NOBIAS,BIAS}; enum{CONSTANT,EQUAL}; +double FixTempCSVR::gamdev(const int ia) +{ + int j; + double am,e,s,v1,v2,x,y; + + if (ia < 1) return 0.0; + if (ia < 6) { + x=1.0; + for (j=1; j<=ia; j++) + x *= random->uniform(); + x = -log(x); + } else { + restart: + do { + do { + do { + v1 = random->uniform(); + v2 = 2.0*random->uniform() - 1.0; + } while (v1*v1 + v2*v2 > 1.0); + + y=v2/v1; + am=ia-1; + s=sqrt(2.0*am+1.0); + x=s*y+am; + } while (x <= 0.0); + + if (am*log(x/am)-s*y < -700 || v1<0.00001) { + goto restart; + } + + e=(1.0+y*y)*exp(am*log(x/am)-s*y); + } while (random->uniform() > e); + } + return x; +} + +/* ------------------------------------------------------------------- + returns the sum of n independent gaussian noises squared + (i.e. equivalent to summing the square of the return values of nn + calls to gasdev) +---------------------------------------------------------------------- */ +double FixTempCSVR::sumnoises(int nn) { + if (nn == 0) { + return 0.0; + } else if (nn == 1) { + const double rr = random->gaussian(); + return rr*rr; + } else if (nn % 2 == 0) { + return 2.0 * gamdev(nn / 2); + } else { + const double rr = random->gaussian(); + return 2.0 * gamdev((nn-1) / 2) + rr*rr; + } + return 0.0; +} + +/* ------------------------------------------------------------------- + returns the scaling factor for velocities to thermalize + the system so it samples the canonical ensemble +---------------------------------------------------------------------- */ + +double FixTempCSVR::resamplekin(double ekin_old, double ekin_new){ + const double tdof = temperature->dof; + const double c1 = exp(-update->dt/t_period); + const double c2 = (1.0-c1)*ekin_new/ekin_old/tdof; + const double r1 = random->gaussian(); + const double r2 = sumnoises(tdof - 1); + + const double scale = c1 + c2*(r1*r1+r2) + 2.0*r1*sqrt(c1*c2); + return sqrt(scale); +} + /* ---------------------------------------------------------------------- */ FixTempCSVR::FixTempCSVR(LAMMPS *lmp, int narg, char **arg) : @@ -48,8 +121,10 @@ FixTempCSVR::FixTempCSVR(LAMMPS *lmp, int narg, char **arg) : // CSVR thermostat should be applied every step nevery = 1; + scalar_flag = 1; global_freq = nevery; dynamic_group_allow = 1; + extscalar = 1; tstr = NULL; if (strstr(arg[3],"v_") == arg[3]) { @@ -72,6 +147,8 @@ FixTempCSVR::FixTempCSVR(LAMMPS *lmp, int narg, char **arg) : if (t_period <= 0.0) error->all(FLERR,"Illegal fix temp/csvr command"); if (seed <= 0) error->all(FLERR,"Illegal fix temp/csvr command"); + random = new RanMars(lmp,seed + comm->me); + // create a new compute temp style // id = fix-ID + temp, compute group = fix group @@ -88,9 +165,6 @@ FixTempCSVR::FixTempCSVR(LAMMPS *lmp, int narg, char **arg) : delete [] newarg; tflag = 1; - random = new RanMars(lmp,seed + comm->me); - - vhold = NULL; nmax = -1; energy = 0.0; } @@ -107,8 +181,6 @@ FixTempCSVR::~FixTempCSVR() delete [] id_temp; delete random; - memory->destroy(vhold); - vhold = NULL; nmax = -1; } @@ -118,6 +190,7 @@ int FixTempCSVR::setmask() { int mask = 0; mask |= END_OF_STEP; + mask |= THERMO_ENERGY; return mask; } @@ -125,15 +198,7 @@ int FixTempCSVR::setmask() void FixTempCSVR::init() { - // we cannot handle shake correctly at the moment - int has_shake = 0; - for (int i = 0; i < modify->nfix; i++) - if (strcmp(modify->fix[i]->style,"shake") == 0) ++has_shake; - - if (has_shake > 0) - error->all(FLERR,"Fix temp/csvr is not compatible with fix shake"); - // check variable if (tstr) { @@ -175,65 +240,45 @@ void FixTempCSVR::end_of_step() modify->addstep_compute(update->ntimestep + nevery); } + const double t_current = temperature->compute_scalar(); + const double efactor = 0.5 * temperature->dof * force->boltz; + const double ekin_old = t_current * efactor; + const double ekin_new = t_target * efactor; + + // compute velocity scaling factor on root node and broadcast + double lamda; + if (comm->me == 0) { + lamda = resamplekin(ekin_old, ekin_new); + } + MPI_Bcast(&lamda,1,MPI_DOUBLE,0,world); + double * const * const v = atom->v; const int * const mask = atom->mask; - const int * const type = atom->type; const int nlocal = atom->nlocal; - // adjust holding space, if needed and copy existing velocities - - if (nmax < atom->nlocal) { - nmax = atom->nlocal + 1; - memory->destroy(vhold); - memory->create(vhold,nmax,3,"csvr:vhold"); - } - - // The CSVR thermostat is a linear combination of old and new velocities, - // where the new ones are randomly chosen from a gaussian distribution. - // see Bussi and Parrinello, Phys. Rev. E (2007). - - for (int i = 0; i < nlocal; i++) { - if (mask[i] & groupbit) { - double m; - if (atom->rmass_flag) m = atom->rmass[i]; - else m = atom->mass[type[i]]; - - const double factor = 1.0/sqrt(m); - const double vx = random->gaussian() * factor; - vhold[i][0] = v[i][0]; - v[i][0] = vx; - const double vy = random->gaussian() * factor; - vhold[i][1] = v[i][1]; - v[i][1] = vy; - const double vz = random->gaussian() * factor; - vhold[i][2] = v[i][2]; - v[i][2] = vz; - } - } - - // mixing factors - const double c1 = exp(-update->dt/t_period); - const double c2 = sqrt((1.0-c1*c1)*t_target/temperature->compute_scalar()); - if (which == NOBIAS) { for (int i = 0; i < nlocal; i++) { if (mask[i] & groupbit) { - v[i][0] = vhold[i][0]*c1 + v[i][0]*c2; - v[i][1] = vhold[i][1]*c1 + v[i][1]*c2; - v[i][2] = vhold[i][2]*c1 + v[i][2]*c2; + v[i][0] *= lamda; + v[i][1] *= lamda; + v[i][2] *= lamda; } } } else { for (int i = 0; i < nlocal; i++) { if (mask[i] & groupbit) { - temperature->remove_bias(i,vhold[i]); - v[i][0] = vhold[i][0]*c1 + v[i][0]*c2; - v[i][1] = vhold[i][1]*c1 + v[i][1]*c2; - v[i][2] = vhold[i][2]*c1 + v[i][2]*c2; + temperature->remove_bias(i,v[i]); + v[i][0] *= lamda; + v[i][1] *= lamda; + v[i][2] *= lamda; temperature->restore_bias(i,v[i]); } } } + + // tally the kinetic energy transferred between heat bath and system + + energy += ekin_old * (1.0 - lamda*lamda); } /* ---------------------------------------------------------------------- */ @@ -273,6 +318,13 @@ void FixTempCSVR::reset_target(double t_new) t_target = t_start = t_stop = t_new; } +/* ---------------------------------------------------------------------- */ + +double FixTempCSVR::compute_scalar() +{ + return energy; +} + /* ---------------------------------------------------------------------- extract thermostat properties ------------------------------------------------------------------------- */ diff --git a/src/fix_temp_csvr.h b/src/fix_temp_csvr.h index 8fcdddb404..48e7cbce8e 100644 --- a/src/fix_temp_csvr.h +++ b/src/fix_temp_csvr.h @@ -33,11 +33,11 @@ class FixTempCSVR : public Fix { void end_of_step(); int modify_param(int, char **); void reset_target(double); + virtual double compute_scalar(); virtual void *extract(const char *, int &); private: double t_start,t_stop,t_period,t_target; - double **vhold; double energy; int nmax,which; int tstyle,tvar; @@ -48,6 +48,11 @@ class FixTempCSVR : public Fix { int tflag; class RanMars *random; + + private: + double resamplekin(double, double); + double sumnoises(int); + double gamdev(int); }; } @@ -63,9 +68,6 @@ Self-explanatory. Check the input script syntax and compare to the documentation for the command. You can use -echo screen as a command-line option when running LAMMPS to see the offending line. -E: Fix temp/csvr is not compatible with fix shake - -These two commands cannot currently be used toghether. E: Variable name for fix temp/csvr does not exist diff --git a/src/force.cpp b/src/force.cpp index 71eb0add9d..ac6f455321 100644 --- a/src/force.cpp +++ b/src/force.cpp @@ -677,21 +677,21 @@ void Force::set_special(int narg, char **arg) iarg += 1; } else if (strcmp(arg[iarg],"lj/coul") == 0) { if (iarg+4 > narg) error->all(FLERR,"Illegal special_bonds command"); - special_lj[1] = special_coul[1] = atof(arg[iarg+1]); - special_lj[2] = special_coul[2] = atof(arg[iarg+2]); - special_lj[3] = special_coul[3] = atof(arg[iarg+3]); + special_lj[1] = special_coul[1] = numeric(FLERR,arg[iarg+1]); + special_lj[2] = special_coul[2] = numeric(FLERR,arg[iarg+2]); + special_lj[3] = special_coul[3] = numeric(FLERR,arg[iarg+3]); iarg += 4; } else if (strcmp(arg[iarg],"lj") == 0) { if (iarg+4 > narg) error->all(FLERR,"Illegal special_bonds command"); - special_lj[1] = atof(arg[iarg+1]); - special_lj[2] = atof(arg[iarg+2]); - special_lj[3] = atof(arg[iarg+3]); + special_lj[1] = numeric(FLERR,arg[iarg+1]); + special_lj[2] = numeric(FLERR,arg[iarg+2]); + special_lj[3] = numeric(FLERR,arg[iarg+3]); iarg += 4; } else if (strcmp(arg[iarg],"coul") == 0) { if (iarg+4 > narg) error->all(FLERR,"Illegal special_bonds command"); - special_coul[1] = atof(arg[iarg+1]); - special_coul[2] = atof(arg[iarg+2]); - special_coul[3] = atof(arg[iarg+3]); + special_coul[1] = numeric(FLERR,arg[iarg+1]); + special_coul[2] = numeric(FLERR,arg[iarg+2]); + special_coul[3] = numeric(FLERR,arg[iarg+3]); iarg += 4; } else if (strcmp(arg[iarg],"angle") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal special_bonds command"); diff --git a/src/variable.cpp b/src/variable.cpp index f9828a4a12..df14be27a8 100644 --- a/src/variable.cpp +++ b/src/variable.cpp @@ -2308,8 +2308,8 @@ double Variable::collapse_tree(Tree *tree) else if (update->ntimestep < ivalue2) { int offset = update->ntimestep - ivalue1; tree->value = ivalue1 + (offset/ivalue3)*ivalue3 + ivalue3; - if (tree->value > ivalue2) tree->value = 9.0e18; - } else tree->value = 9.0e18; + if (tree->value > ivalue2) tree->value = MAXBIGINT; + } else tree->value = MAXBIGINT; return tree->value; } @@ -2345,10 +2345,10 @@ double Variable::collapse_tree(Tree *tree) if (istep > ivalue5) { int offset = ivalue5 - ivalue1; istep = ivalue1 + (offset/ivalue3)*ivalue3 + ivalue3; - if (istep > ivalue2) istep = 9.0e18; + if (istep > ivalue2) istep = MAXBIGINT; } } - } else istep = 9.0e18; + } else istep = MAXBIGINT; tree->value = istep; return tree->value; } @@ -2633,8 +2633,8 @@ double Variable::eval_tree(Tree *tree, int i) else if (update->ntimestep < ivalue2) { int offset = update->ntimestep - ivalue1; arg = ivalue1 + (offset/ivalue3)*ivalue3 + ivalue3; - if (arg > ivalue2) arg = 9.0e18; - } else arg = 9.0e18; + if (arg > ivalue2) arg = MAXBIGINT; + } else arg = MAXBIGINT; return arg; } @@ -2665,10 +2665,10 @@ double Variable::eval_tree(Tree *tree, int i) if (istep > ivalue5) { int offset = ivalue5 - ivalue1; istep = ivalue1 + (offset/ivalue3)*ivalue3 + ivalue3; - if (istep > ivalue2) istep = 9.0e18; + if (istep > ivalue2) istep = MAXBIGINT; } } - } else istep = 9.0e18; + } else istep = MAXBIGINT; arg = istep; return arg; } @@ -3141,8 +3141,8 @@ int Variable::math_function(char *word, char *contents, Tree **tree, else if (update->ntimestep < ivalue2) { int offset = update->ntimestep - ivalue1; value = ivalue1 + (offset/ivalue3)*ivalue3 + ivalue3; - if (value > ivalue2) value = 9.0e18; - } else value = 9.0e18; + if (value > ivalue2) value = MAXBIGINT; + } else value = MAXBIGINT; argstack[nargstack++] = value; } @@ -3176,10 +3176,10 @@ int Variable::math_function(char *word, char *contents, Tree **tree, if (istep > ivalue5) { int offset = ivalue5 - ivalue1; istep = ivalue1 + (offset/ivalue3)*ivalue3 + ivalue3; - if (istep > ivalue2) istep = 9.0e18; + if (istep > ivalue2) istep = MAXBIGINT; } } - } else istep = 9.0e18; + } else istep = MAXBIGINT; double value = istep; argstack[nargstack++] = value; } From 8d1033f0d98245a7d00ca0b8704ac58f4cd06f85 Mon Sep 17 00:00:00 2001 From: sjplimp Date: Fri, 27 Mar 2015 20:39:41 +0000 Subject: [PATCH 17/22] git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@13321 f3b2605a-c512-4ea7-a41b-209d697bcdaa --- doc/fix_temp_csvr.html | 73 +++++++++++++++++++++++++++++------------- doc/fix_temp_csvr.txt | 70 +++++++++++++++++++++++++++------------- 2 files changed, 98 insertions(+), 45 deletions(-) diff --git a/doc/fix_temp_csvr.html b/doc/fix_temp_csvr.html index 7d8e4bc17b..609e7691d9 100644 --- a/doc/fix_temp_csvr.html +++ b/doc/fix_temp_csvr.html @@ -11,13 +11,17 @@

    fix temp/csvr command

    +

    fix temp/csld command +

    Syntax:

    fix ID group-ID temp/csvr Tstart Tstop Tdamp seed 
     
    +
    fix ID group-ID temp/csld Tstart Tstop Tdamp seed 
    +
    • ID, group-ID are documented in fix command -
    • temp/csvr = style name of this fix command +
    • temp/csvr or temp/csld = style name of this fix command
    • Tstart,Tstop = desired temperature at start/end of run @@ -31,17 +35,26 @@

      fix 1 all temp/csvr 300.0 300.0 100.0 54324 
       
      +
      fix 1 all temp/csld 100.0 300.0 10.0 123321 
      +

      Description:

      -

      Adjust the temperature with a CSVR thermostat (Bussi), which -updates the velocities to a linear combination of the current -velocities with a gaussian distribution at the desired temperature in -every timestep. +

      Adjust the temperature with a canonical sampling thermostat that uses +global velocity rescaling with Hamiltonian dynamics (temp/csvr) +(Bussi1), or Langevin dynamics (temp/csld) (Bussi2). +In the case of temp/csvr the thermostat is similar to the empirical +Berendsen thermostat in temp/berendsen, but +chooses the actual scaling factor from a suitably chosen (gaussian) +distribution rather than having it determined from the time constant +directly. In the second case the velocities are updated to a linear +combination of the current velocities with a gaussian distribution +of velocities at the desired temperature. Both termostats are applied +in every timestep.

      The thermostat is applied to only the translational degrees of freedom for the particles, which is an important consideration for finite-size particles which have rotational degrees of freedom are being -thermostatted with this fix. The translational degrees of freedom can +thermostatted with these fixes. The translational degrees of freedom can also have a bias velocity removed from them before thermostatting takes place; see the description below.

      @@ -64,11 +77,11 @@ keywords for the simulation box parameters and timestep and elapsed time. Thus it is easy to specify a time-dependent temperature.

      IMPORTANT NOTE: Unlike the fix nvt command which -performs Nose/Hoover thermostatting AND time integration, this fix -does NOT perform time integration. It only modifies velocities to +performs Nose/Hoover thermostatting AND time integration, these fixes +do NOT perform time integration. They only modify velocities to effect thermostatting. Thus you must use a separate time integration fix, like fix nve to actually update the positions of -atoms using the modified velocities. Likewise, this fix should not +atoms using the modified velocities. Likewise, these fixes should not normally be used on atoms that also have their temperature controlled by another fix - e.g. by fix nvt or fix langevin commands. @@ -77,7 +90,7 @@ langevin commands. a discussion of different ways to compute temperature and perform thermostatting.

      -

      This fix computes a temperature each timestep. To do this, the fix +

      These fixes compute a temperature each timestep. To do this, the fix creates its own compute of style "temp", as if this command had been issued:

      @@ -97,7 +110,7 @@ custom command using the appropriate compute-ID. It also means that changing attributes of thermo_temp will have no effect on this fix.

      -

      Like other fixes that perform thermostatting, this fix can be used +

      Like other fixes that perform thermostatting, these fixes can be used with compute commands that calculate a temperature after removing a "bias" from the atom velocities. E.g. removing the center-of-mass velocity from a group of atoms or only calculating @@ -116,24 +129,37 @@ thermal degrees of freedom, and the bias is added back in.

      Restart, fix_modify, output, run start/stop, minimize info:

      -

      No information about this fix is written to binary restart +

      No information about these fixes are written to binary restart files.

      -

      The fix_modify temp option is supported by this -fix. You can use it to assign a temperature compute -you have defined to this fix which will be used in its thermostatting +

      The fix_modify temp option is supported by these +fixes. You can use it to assign a temperature compute +you have defined to these fixes which will be used in its thermostatting procedure, as described above. For consistency, the group used by -this fix and by the compute should be the same. +these fixes and by the compute should be the same.

      -

      This fix can ramp its target temperature over multiple runs, using the -start and stop keywords of the run command. See the +

      These fixes can ramp its target temperature over multiple runs, using +the start and stop keywords of the run command. See the run command for details of how to do this.

      -

      This fix is not invoked during energy minimization. +

      These fixes are not invoked during energy minimization. +

      +

      These fixes compute a global scalar which can be accessed by various +output commands. The scalar is the +cummulative energy change due to the fix. The scalar value +calculated by this fix is "extensive".

      Restrictions:

      -

      This fix is not compatible with fix shake. +

      These fixes are not compatible with fix shake. +

      +

      The fix can be used with dynamic groups as defined by the +group command. Likewise it can be used with groups to +which atoms are added or deleted over time, e.g. a deposition +simulation. However, the conservation properties of the thermostat +and barostat are defined for systems with a static set of atoms. You +may observe odd behavior if the atoms in a group vary dramatically +over time or the atom count becomes very small.

      Related commands:

      @@ -146,8 +172,11 @@ temp/rescale, fix langevin,


      - + -

      (Bussi) Bussi and Parrinello, Phys. Rev. E (2007) +(Bussi1) Bussi, Donadio and Parrinello, J. Chem. Phys. 126, 014101(2007) + + +

      (Bussi2) Bussi and Parrinello, Phys. Rev. E 75, 056707 (2007)

      diff --git a/doc/fix_temp_csvr.txt b/doc/fix_temp_csvr.txt index daa2136638..024998e0e6 100644 --- a/doc/fix_temp_csvr.txt +++ b/doc/fix_temp_csvr.txt @@ -7,13 +7,15 @@ :line fix temp/csvr command :h3 +fix temp/csld command :h3 [Syntax:] fix ID group-ID temp/csvr Tstart Tstop Tdamp seed :pre +fix ID group-ID temp/csld Tstart Tstop Tdamp seed :pre ID, group-ID are documented in "fix"_fix.html command :ulb,l -temp/csvr = style name of this fix command :l +temp/csvr or temp/csld = style name of this fix command :l Tstart,Tstop = desired temperature at start/end of run :l Tstart can be a variable (see below) :pre Tdamp = temperature damping parameter (time units) :l @@ -22,18 +24,26 @@ seed = random number seed to use for white noise (positive integer) :l,ule [Examples:] fix 1 all temp/csvr 300.0 300.0 100.0 54324 :pre +fix 1 all temp/csld 100.0 300.0 10.0 123321 :pre [Description:] -Adjust the temperature with a CSVR thermostat "(Bussi)"_#Bussi, which -updates the velocities to a linear combination of the current -velocities with a gaussian distribution at the desired temperature in -every timestep. +Adjust the temperature with a canonical sampling thermostat that uses +global velocity rescaling with Hamiltonian dynamics ({temp/csvr}) +"(Bussi1)"_#Bussi1, or Langevin dynamics ({temp/csld}) "(Bussi2)"_#Bussi2. +In the case of {temp/csvr} the thermostat is similar to the empirical +Berendsen thermostat in "temp/berendsen"_fix_temp_berendsen.html, but +chooses the actual scaling factor from a suitably chosen (gaussian) +distribution rather than having it determined from the time constant +directly. In the second case the velocities are updated to a linear +combination of the current velocities with a gaussian distribution +of velocities at the desired temperature. Both termostats are applied +in every timestep. The thermostat is applied to only the translational degrees of freedom for the particles, which is an important consideration for finite-size particles which have rotational degrees of freedom are being -thermostatted with this fix. The translational degrees of freedom can +thermostatted with these fixes. The translational degrees of freedom can also have a bias velocity removed from them before thermostatting takes place; see the description below. @@ -56,11 +66,11 @@ keywords for the simulation box parameters and timestep and elapsed time. Thus it is easy to specify a time-dependent temperature. IMPORTANT NOTE: Unlike the "fix nvt"_fix_nh.html command which -performs Nose/Hoover thermostatting AND time integration, this fix -does NOT perform time integration. It only modifies velocities to +performs Nose/Hoover thermostatting AND time integration, these fixes +do NOT perform time integration. They only modify velocities to effect thermostatting. Thus you must use a separate time integration fix, like "fix nve"_fix_nve.html to actually update the positions of -atoms using the modified velocities. Likewise, this fix should not +atoms using the modified velocities. Likewise, these fixes should not normally be used on atoms that also have their temperature controlled by another fix - e.g. by "fix nvt"_fix_nh.html or "fix langevin"_fix_langevin.html commands. @@ -69,7 +79,7 @@ See "this howto section"_Section_howto.html#howto_16 of the manual for a discussion of different ways to compute temperature and perform thermostatting. -This fix computes a temperature each timestep. To do this, the fix +These fixes compute a temperature each timestep. To do this, the fix creates its own compute of style "temp", as if this command had been issued: @@ -89,7 +99,7 @@ custom"_thermo_style.html command using the appropriate compute-ID. It also means that changing attributes of {thermo_temp} will have no effect on this fix. -Like other fixes that perform thermostatting, this fix can be used +Like other fixes that perform thermostatting, these fixes can be used with "compute commands"_compute.html that calculate a temperature after removing a "bias" from the atom velocities. E.g. removing the center-of-mass velocity from a group of atoms or only calculating @@ -108,24 +118,37 @@ thermal degrees of freedom, and the bias is added back in. [Restart, fix_modify, output, run start/stop, minimize info:] -No information about this fix is written to "binary restart +No information about these fixes are written to "binary restart files"_restart.html. -The "fix_modify"_fix_modify.html {temp} option is supported by this -fix. You can use it to assign a temperature "compute"_compute.html -you have defined to this fix which will be used in its thermostatting +The "fix_modify"_fix_modify.html {temp} option is supported by these +fixes. You can use it to assign a temperature "compute"_compute.html +you have defined to these fixes which will be used in its thermostatting procedure, as described above. For consistency, the group used by -this fix and by the compute should be the same. +these fixes and by the compute should be the same. -This fix can ramp its target temperature over multiple runs, using the -{start} and {stop} keywords of the "run"_run.html command. See the +These fixes can ramp its target temperature over multiple runs, using +the {start} and {stop} keywords of the "run"_run.html command. See the "run"_run.html command for details of how to do this. -This fix is not invoked during "energy minimization"_minimize.html. +These fixes are not invoked during "energy minimization"_minimize.html. + +These fixes compute a global scalar which can be accessed by various +"output commands"_Section_howto.html#howto_15. The scalar is the +cummulative energy change due to the fix. The scalar value +calculated by this fix is "extensive". [Restrictions:] -This fix is not compatible with "fix shake"_fix_shake.html. +These fixes are not compatible with "fix shake"_fix_shake.html. + +The fix can be used with dynamic groups as defined by the +"group"_group.html command. Likewise it can be used with groups to +which atoms are added or deleted over time, e.g. a deposition +simulation. However, the conservation properties of the thermostat +and barostat are defined for systems with a static set of atoms. You +may observe odd behavior if the atoms in a group vary dramatically +over time or the atom count becomes very small. [Related commands:] @@ -138,6 +161,7 @@ temp/rescale"_fix_temp_rescale.html, "fix langevin"_fix_langevin.html, :line -:link(Bussi) - -[(Bussi)] Bussi and Parrinello, Phys. Rev. E (2007) +:link(Bussi1) +[(Bussi1)] Bussi, Donadio and Parrinello, J. Chem. Phys. 126, 014101(2007) +:link(Bussi2) +[(Bussi2)] Bussi and Parrinello, Phys. Rev. E 75, 056707 (2007) From 48d0d2a7b6099b4154f022f53905b4d6ec74e369 Mon Sep 17 00:00:00 2001 From: sjplimp Date: Fri, 27 Mar 2015 20:40:30 +0000 Subject: [PATCH 18/22] git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@13322 f3b2605a-c512-4ea7-a41b-209d697bcdaa --- doc/fix_temp_csvr.html | 30 +++++++++++++++--------------- doc/fix_temp_csvr.txt | 30 +++++++++++++++--------------- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/doc/fix_temp_csvr.html b/doc/fix_temp_csvr.html index 609e7691d9..184aa14a19 100644 --- a/doc/fix_temp_csvr.html +++ b/doc/fix_temp_csvr.html @@ -41,21 +41,21 @@

      Adjust the temperature with a canonical sampling thermostat that uses global velocity rescaling with Hamiltonian dynamics (temp/csvr) -(Bussi1), or Langevin dynamics (temp/csld) (Bussi2). -In the case of temp/csvr the thermostat is similar to the empirical -Berendsen thermostat in temp/berendsen, but -chooses the actual scaling factor from a suitably chosen (gaussian) -distribution rather than having it determined from the time constant -directly. In the second case the velocities are updated to a linear -combination of the current velocities with a gaussian distribution -of velocities at the desired temperature. Both termostats are applied -in every timestep. +(Bussi1), or Langevin dynamics (temp/csld) +(Bussi2). In the case of temp/csvr the thermostat is +similar to the empirical Berendsen thermostat in +temp/berendsen, but chooses the actual +scaling factor from a suitably chosen (gaussian) distribution rather +than having it determined from the time constant directly. In the +second case the velocities are updated to a linear combination of the +current velocities with a gaussian distribution of velocities at the +desired temperature. Both termostats are applied in every timestep.

      The thermostat is applied to only the translational degrees of freedom for the particles, which is an important consideration for finite-size particles which have rotational degrees of freedom are being -thermostatted with these fixes. The translational degrees of freedom can -also have a bias velocity removed from them before thermostatting +thermostatted with these fixes. The translational degrees of freedom +can also have a bias velocity removed from them before thermostatting takes place; see the description below.

      The desired temperature at each timestep is a ramped value during the @@ -78,10 +78,10 @@ time. Thus it is easy to specify a time-dependent temperature.

      IMPORTANT NOTE: Unlike the fix nvt command which performs Nose/Hoover thermostatting AND time integration, these fixes -do NOT perform time integration. They only modify velocities to -effect thermostatting. Thus you must use a separate time integration -fix, like fix nve to actually update the positions of -atoms using the modified velocities. Likewise, these fixes should not +do NOT perform time integration. They only modify velocities to effect +thermostatting. Thus you must use a separate time integration fix, +like fix nve to actually update the positions of atoms +using the modified velocities. Likewise, these fixes should not normally be used on atoms that also have their temperature controlled by another fix - e.g. by fix nvt or fix langevin commands. diff --git a/doc/fix_temp_csvr.txt b/doc/fix_temp_csvr.txt index 024998e0e6..1d78a8625f 100644 --- a/doc/fix_temp_csvr.txt +++ b/doc/fix_temp_csvr.txt @@ -30,21 +30,21 @@ fix 1 all temp/csld 100.0 300.0 10.0 123321 :pre Adjust the temperature with a canonical sampling thermostat that uses global velocity rescaling with Hamiltonian dynamics ({temp/csvr}) -"(Bussi1)"_#Bussi1, or Langevin dynamics ({temp/csld}) "(Bussi2)"_#Bussi2. -In the case of {temp/csvr} the thermostat is similar to the empirical -Berendsen thermostat in "temp/berendsen"_fix_temp_berendsen.html, but -chooses the actual scaling factor from a suitably chosen (gaussian) -distribution rather than having it determined from the time constant -directly. In the second case the velocities are updated to a linear -combination of the current velocities with a gaussian distribution -of velocities at the desired temperature. Both termostats are applied -in every timestep. +"(Bussi1)"_#Bussi1, or Langevin dynamics ({temp/csld}) +"(Bussi2)"_#Bussi2. In the case of {temp/csvr} the thermostat is +similar to the empirical Berendsen thermostat in +"temp/berendsen"_fix_temp_berendsen.html, but chooses the actual +scaling factor from a suitably chosen (gaussian) distribution rather +than having it determined from the time constant directly. In the +second case the velocities are updated to a linear combination of the +current velocities with a gaussian distribution of velocities at the +desired temperature. Both termostats are applied in every timestep. The thermostat is applied to only the translational degrees of freedom for the particles, which is an important consideration for finite-size particles which have rotational degrees of freedom are being -thermostatted with these fixes. The translational degrees of freedom can -also have a bias velocity removed from them before thermostatting +thermostatted with these fixes. The translational degrees of freedom +can also have a bias velocity removed from them before thermostatting takes place; see the description below. The desired temperature at each timestep is a ramped value during the @@ -67,10 +67,10 @@ time. Thus it is easy to specify a time-dependent temperature. IMPORTANT NOTE: Unlike the "fix nvt"_fix_nh.html command which performs Nose/Hoover thermostatting AND time integration, these fixes -do NOT perform time integration. They only modify velocities to -effect thermostatting. Thus you must use a separate time integration -fix, like "fix nve"_fix_nve.html to actually update the positions of -atoms using the modified velocities. Likewise, these fixes should not +do NOT perform time integration. They only modify velocities to effect +thermostatting. Thus you must use a separate time integration fix, +like "fix nve"_fix_nve.html to actually update the positions of atoms +using the modified velocities. Likewise, these fixes should not normally be used on atoms that also have their temperature controlled by another fix - e.g. by "fix nvt"_fix_nh.html or "fix langevin"_fix_langevin.html commands. From 5e65993d98b0fbd0693ebaee8fc8d50d80b8fba9 Mon Sep 17 00:00:00 2001 From: sjplimp Date: Fri, 27 Mar 2015 20:41:05 +0000 Subject: [PATCH 19/22] git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@13323 f3b2605a-c512-4ea7-a41b-209d697bcdaa --- doc/Section_commands.html | 6 +++--- doc/Section_commands.txt | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/doc/Section_commands.html b/doc/Section_commands.html index be6c905d1f..468b182cdc 100644 --- a/doc/Section_commands.html +++ b/doc/Section_commands.html @@ -422,9 +422,9 @@ g = GPU, i = USER-INTEL, k = KOKKOS, o = USER-OMP, t = OPT. qeq/comb (o)qeq/dynamicqeq/pointqeq/shieldedqeq/slaterreax/bondsrecenterrestrain rigid (o)rigid/nph (o)rigid/npt (o)rigid/nve (o)rigid/nvt (o)rigid/small (o)rigid/small/nphrigid/small/npt rigid/small/nverigid/small/nvtsetforce (c)shake (c)springspring/rgspring/selfsrd -store/forcestore/statetemp/berendsen (c)temp/csvrtemp/rescale (c)tfmcthermal/conductivitytmd -ttmtune/kspacevectorviscosityviscous (c)wall/colloidwall/granwall/harmonic -wall/lj1043wall/lj126wall/lj93wall/pistonwall/reflectwall/regionwall/srd +store/forcestore/statetemp/berendsen (c)temp/csldtemp/csvrtemp/rescale (c)tfmcthermal/conductivity +tmdttmtune/kspacevectorviscosityviscous (c)wall/colloidwall/gran +wall/harmonicwall/lj1043wall/lj126wall/lj93wall/pistonwall/reflectwall/regionwall/srd

      These are additional fix styles in USER packages, which can be used if diff --git a/doc/Section_commands.txt b/doc/Section_commands.txt index e31670f17e..6d38447280 100644 --- a/doc/Section_commands.txt +++ b/doc/Section_commands.txt @@ -570,6 +570,7 @@ g = GPU, i = USER-INTEL, k = KOKKOS, o = USER-OMP, t = OPT. "store/force"_fix_store_force.html, "store/state"_fix_store_state.html, "temp/berendsen (c)"_fix_temp_berendsen.html, +"temp/csld"_fix_temp_csvr.html, "temp/csvr"_fix_temp_csvr.html, "temp/rescale (c)"_fix_temp_rescale.html, "tfmc"_fix_tfmc.html, From d78fd732234d75321fc8c8a00490218c86d6c3db Mon Sep 17 00:00:00 2001 From: sjplimp Date: Fri, 27 Mar 2015 20:47:17 +0000 Subject: [PATCH 20/22] git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@13324 f3b2605a-c512-4ea7-a41b-209d697bcdaa --- doc/fix_temp_csvr.html | 8 ++++---- doc/fix_temp_csvr.txt | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/doc/fix_temp_csvr.html b/doc/fix_temp_csvr.html index 184aa14a19..41c6e7400e 100644 --- a/doc/fix_temp_csvr.html +++ b/doc/fix_temp_csvr.html @@ -46,10 +46,10 @@ global velocity rescaling with Hamiltonian dynamics (temp/csvr) similar to the empirical Berendsen thermostat in temp/berendsen, but chooses the actual scaling factor from a suitably chosen (gaussian) distribution rather -than having it determined from the time constant directly. In the -second case the velocities are updated to a linear combination of the -current velocities with a gaussian distribution of velocities at the -desired temperature. Both termostats are applied in every timestep. +than having it determined from the time constant directly. In the case +of temp/csld the velocities are updated to a linear combination of +the current velocities with a gaussian distribution of velocities at +the desired temperature. Both termostats are applied every timestep.

      The thermostat is applied to only the translational degrees of freedom for the particles, which is an important consideration for finite-size diff --git a/doc/fix_temp_csvr.txt b/doc/fix_temp_csvr.txt index 1d78a8625f..4f77e4f977 100644 --- a/doc/fix_temp_csvr.txt +++ b/doc/fix_temp_csvr.txt @@ -35,10 +35,10 @@ global velocity rescaling with Hamiltonian dynamics ({temp/csvr}) similar to the empirical Berendsen thermostat in "temp/berendsen"_fix_temp_berendsen.html, but chooses the actual scaling factor from a suitably chosen (gaussian) distribution rather -than having it determined from the time constant directly. In the -second case the velocities are updated to a linear combination of the -current velocities with a gaussian distribution of velocities at the -desired temperature. Both termostats are applied in every timestep. +than having it determined from the time constant directly. In the case +of {temp/csld} the velocities are updated to a linear combination of +the current velocities with a gaussian distribution of velocities at +the desired temperature. Both termostats are applied every timestep. The thermostat is applied to only the translational degrees of freedom for the particles, which is an important consideration for finite-size From bff784b313ce9d9304ba9a60009e20e197b28301 Mon Sep 17 00:00:00 2001 From: sjplimp Date: Fri, 27 Mar 2015 20:48:26 +0000 Subject: [PATCH 21/22] git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@13326 f3b2605a-c512-4ea7-a41b-209d697bcdaa --- src/version.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/version.h b/src/version.h index eff88cd933..8b186daa41 100644 --- a/src/version.h +++ b/src/version.h @@ -1 +1 @@ -#define LAMMPS_VERSION "28 Mar 2015" +#define LAMMPS_VERSION "29 Mar 2015" From 77996f48fb1afd7fa5aed1aaf3f337b5f183f84d Mon Sep 17 00:00:00 2001 From: sjplimp Date: Fri, 27 Mar 2015 20:48:28 +0000 Subject: [PATCH 22/22] git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@13327 f3b2605a-c512-4ea7-a41b-209d697bcdaa --- doc/Manual.html | 4 ++-- doc/Manual.txt | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/Manual.html b/doc/Manual.html index 380eb61817..5fd78b6c8e 100644 --- a/doc/Manual.html +++ b/doc/Manual.html @@ -1,7 +1,7 @@ LAMMPS Users Manual - + @@ -22,7 +22,7 @@

      LAMMPS Documentation

      -

      28 Mar 2015 version +

      29 Mar 2015 version

      Version info:

      diff --git a/doc/Manual.txt b/doc/Manual.txt index 45c637f1e4..e88e001638 100644 --- a/doc/Manual.txt +++ b/doc/Manual.txt @@ -1,6 +1,6 @@ LAMMPS Users Manual - + @@ -18,7 +18,7 @@

      LAMMPS Documentation :c,h3 -28 Mar 2015 version :c,h4 +29 Mar 2015 version :c,h4 Version info: :h4