USER-DPD Kokkos: Add "#ifdef DPD_USE_RAN_MARS" toggle

Also, initialize the rand_pool with a seed in init_style()
This commit is contained in:
Tim Mattox
2017-02-28 12:49:11 -05:00
parent a5507b291d
commit 2b78ac2146
4 changed files with 46 additions and 16 deletions

View File

@ -90,7 +90,7 @@ FixShardlowKokkos<DeviceType>::FixShardlowKokkos(LAMMPS *lmp, int narg, char **a
// if(k_pairDPDE){
comm_forward = 3;
comm_reverse = 5;
#ifdef USE_RAND_MARS
#ifdef DPD_USE_RAN_MARS
maxRNG = 0;
pp_random = NULL;
#else
@ -124,11 +124,13 @@ template<class DeviceType>
FixShardlowKokkos<DeviceType>::~FixShardlowKokkos()
{
ghostmax = 0;
#ifdef DPD_USE_RAN_MARS
if (pp_random) {
for (int i = 1; i < maxRNG; ++i) delete pp_random[i];
delete[] pp_random;
pp_random = NULL;
}
#endif
}
/* ---------------------------------------------------------------------- */
@ -427,7 +429,7 @@ void FixShardlowKokkos<DeviceType>::ssa_update_dpde(
int start_ii, int count, int id
)
{
#ifdef USE_RAND_MARS
#ifdef DPD_USE_RAN_MARS
class RanMars *pRNG = pp_random[id];
#else
rand_type rand_gen = p_rand_pool->get_state();
@ -505,7 +507,7 @@ void FixShardlowKokkos<DeviceType>::ssa_update_dpde(
double halfsigma_ij = STACKPARAMS?m_params[itype][jtype].halfsigma:params(itype,jtype).halfsigma;
double halfgamma_ij = halfsigma_ij*halfsigma_ij*boltz_inv*theta_ij_inv;
#ifdef USE_RAND_MARS
#ifdef DPD_USE_RAN_MARS
double sigmaRand = halfsigma_ij*wr*dtsqrt*ftm2v * pRNG->gaussian();
#else
double sigmaRand = halfsigma_ij*wr*dtsqrt*ftm2v * rand_gen.normal();
@ -518,7 +520,7 @@ void FixShardlowKokkos<DeviceType>::ssa_update_dpde(
// Compute uCond
double kappa_ij = STACKPARAMS?m_params[itype][jtype].kappa:params(itype,jtype).kappa;
double alpha_ij = STACKPARAMS?m_params[itype][jtype].alpha:params(itype,jtype).alpha;
#ifdef USE_RAND_MARS
#ifdef DPD_USE_RAN_MARS
double del_uCond = alpha_ij*wr*dtsqrt * pRNG->gaussian();
#else
double del_uCond = alpha_ij*wr*dtsqrt * rand_gen.normal();
@ -598,7 +600,7 @@ void FixShardlowKokkos<DeviceType>::ssa_update_dpde(
ii++;
}
#ifndef USE_RAND_MARS
#ifndef DPD_USE_RAN_MARS
p_rand_pool->free_state(rand_gen);
#endif
}
@ -628,6 +630,7 @@ void FixShardlowKokkos<DeviceType>::initial_integrate(int vflag)
ssa_gitemLoc = np_ssa->ssa_gitemLoc;
ssa_gitemLen = np_ssa->ssa_gitemLen;
#ifdef DPD_USE_RAN_MARS
int maxWorkItemCt = (int) ssa_itemLoc.dimension_1();
if (maxWorkItemCt > maxRNG) {
if (pp_random) {
@ -642,6 +645,7 @@ void FixShardlowKokkos<DeviceType>::initial_integrate(int vflag)
}
pp_random[0] = k_pairDPDE->random;
}
#endif
#ifdef DEBUG_PAIR_CT
for (int i = 0; i < 2; ++i)

View File

@ -70,15 +70,14 @@ class FixShardlowKokkos : public FixShardlow {
protected:
// class PairDPDfdt *pairDPD;
PairDPDfdtEnergyKokkos<DeviceType> *k_pairDPDE;
// Kokkos::Random_XorShift64_Pool<DeviceType> *p_rand_pool;
// Kokkos::Random_XorShift64_Pool<DeviceType> rand_pool;
// typedef typename Kokkos::Random_XorShift64_Pool<DeviceType>::generator_type rand_type;
// RandPoolWrap *p_rand_pool;
// typedef RandWrap rand_type;
#ifdef DPD_USE_RAN_MARS
int maxRNG;
class RanMars **pp_random;
#else
Kokkos::Random_XorShift64_Pool<DeviceType> *p_rand_pool;
typedef typename Kokkos::Random_XorShift64_Pool<DeviceType>::generator_type rand_type;
#endif
Kokkos::DualView<params_ssa**,Kokkos::LayoutRight,DeviceType> k_params;
typename Kokkos::DualView<params_ssa**,

View File

@ -43,7 +43,12 @@ using namespace LAMMPS_NS;
template<class DeviceType>
PairDPDfdtEnergyKokkos<DeviceType>::PairDPDfdtEnergyKokkos(LAMMPS *lmp) :
PairDPDfdtEnergy(lmp),rand_pool(12345 /* not actually used, seed + comm->me */, lmp)
PairDPDfdtEnergy(lmp),
#ifdef DPD_USE_RAN_MARS
rand_pool(0 /* unused */, lmp)
#else
rand_pool()
#endif
{
atomKK = (AtomKokkos *) atom;
execution_space = ExecutionSpaceFromDevice<DeviceType>::space;
@ -68,7 +73,9 @@ PairDPDfdtEnergyKokkos<DeviceType>::~PairDPDfdtEnergyKokkos()
memory->destroy_kokkos(k_cutsq,cutsq);
#ifdef DPD_USE_RAN_MARS
rand_pool.destroy();
#endif
}
/* ----------------------------------------------------------------------
@ -101,7 +108,11 @@ void PairDPDfdtEnergyKokkos<DeviceType>::init_style()
error->all(FLERR,"Cannot use chosen neighbor list style with reax/c/kk");
}
#ifdef DPD_USE_RAN_MARS
rand_pool.init(random,seed);
#else
rand_pool.init(seed + comm->me,DeviceType::max_hardware_threads());
#endif
}
/* ---------------------------------------------------------------------- */

View File

@ -22,11 +22,25 @@ PairStyle(dpd/fdt/energy/kk/host,PairDPDfdtEnergyKokkos<LMPHostType>)
#ifndef LMP_PAIR_DPD_FDT_ENERGY_KOKKOS_H
#define LMP_PAIR_DPD_FDT_ENERGY_KOKKOS_H
#ifndef ALLOW_NON_DETERMINISTIC_DPD
#ifdef KOKKOS_HAVE_CUDA
//FIXME print some warning
#endif
#ifndef DPD_USE_RAN_MARS
#define DPD_USE_RAN_MARS
#endif
#endif
#include "pair_dpd_fdt_energy.h"
#include "pair_kokkos.h"
#include "kokkos_type.h"
#include "Kokkos_Random.hpp"
#ifdef DPD_USE_RAN_MARS
#include "rand_pool_wrap_kokkos.h"
#else
#include "Kokkos_Random.hpp"
#endif
namespace LAMMPS_NS {
@ -89,11 +103,13 @@ class PairDPDfdtEnergyKokkos : public PairDPDfdtEnergy {
DAT::tdual_efloat_1d k_duCond,k_duMech;
// Kokkos::Random_XorShift64_Pool<DeviceType> rand_pool;
// typedef typename Kokkos::Random_XorShift64_Pool<DeviceType>::generator_type rand_type;
#ifdef DPD_USE_RAN_MARS
RandPoolWrap rand_pool;
typedef RandWrap rand_type;
#else
Kokkos::Random_XorShift64_Pool<DeviceType> rand_pool;
typedef typename Kokkos::Random_XorShift64_Pool<DeviceType>::generator_type rand_type;
#endif
typename ArrayTypes<DeviceType>::tdual_ffloat_2d k_cutsq;
typename ArrayTypes<DeviceType>::t_ffloat_2d d_cutsq;