Porting fix freeze to Kokkos.
This commit is contained in:
@ -34,7 +34,7 @@ class FixFreeze : public Fix {
|
||||
void post_force_respa(int, int, int);
|
||||
double compute_vector(int);
|
||||
|
||||
private:
|
||||
protected:
|
||||
int force_flag;
|
||||
double foriginal[3],foriginal_all[3];
|
||||
};
|
||||
|
||||
@ -97,6 +97,8 @@ action fix_deform_kokkos.cpp
|
||||
action fix_deform_kokkos.h
|
||||
action fix_eos_table_rx_kokkos.cpp fix_eos_table_rx.cpp
|
||||
action fix_eos_table_rx_kokkos.h fix_eos_table_rx.h
|
||||
action fix_freeze_kokkos.cpp
|
||||
action fix_freeze_kokkos.h
|
||||
action fix_gravity_kokkos.cpp
|
||||
action fix_gravity_kokkos.h
|
||||
action fix_langevin_kokkos.cpp
|
||||
|
||||
124
src/KOKKOS/fix_freeze_kokkos.cpp
Normal file
124
src/KOKKOS/fix_freeze_kokkos.cpp
Normal file
@ -0,0 +1,124 @@
|
||||
/* ----------------------------------------------------------------------
|
||||
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 "fix_freeze_kokkos.h"
|
||||
#include "atom_masks.h"
|
||||
#include "atom_kokkos.h"
|
||||
|
||||
using namespace LAMMPS_NS;
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
template<class DeviceType>
|
||||
FixFreezeKokkos<DeviceType>::FixFreezeKokkos(LAMMPS *lmp, int narg, char **arg) :
|
||||
FixFreeze(lmp, narg, arg)
|
||||
{
|
||||
kokkosable = 1;
|
||||
atomKK = (AtomKokkos *)atom;
|
||||
execution_space = ExecutionSpaceFromDevice<DeviceType>::space;
|
||||
|
||||
datamask_read = F_MASK | MASK_MASK;
|
||||
datamask_modify = F_MASK | TORQUE_MASK;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
template<class DeviceType>
|
||||
int FixFreezeKokkos<DeviceType>::setmask()
|
||||
{
|
||||
return FixFreeze::setmask();
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
template<class DeviceType>
|
||||
void FixFreezeKokkos<DeviceType>::init()
|
||||
{
|
||||
FixFreeze::init();
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
template<class DeviceType>
|
||||
void FixFreezeKokkos<DeviceType>::setup(int vflag)
|
||||
{
|
||||
FixFreeze::setup(vflag);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
template<class DeviceType>
|
||||
void FixFreezeKokkos<DeviceType>::post_force(int vflag)
|
||||
{
|
||||
atomKK->sync(execution_space,datamask_read);
|
||||
atomKK->modified(execution_space,datamask_modify);
|
||||
|
||||
f = atomKK->k_f.view<DeviceType>();
|
||||
torque = atomKK->k_torque.view<DeviceType>();
|
||||
mask = atomKK->k_mask.view<DeviceType>();
|
||||
|
||||
int nlocal = atom->nlocal;
|
||||
if (igroup == atom->firstgroup) nlocal = atom->nfirst;
|
||||
|
||||
force_flag = 0;
|
||||
copymode = 1;
|
||||
OriginalForce original;
|
||||
Kokkos::parallel_reduce(nlocal, *this, original);
|
||||
copymode = 0;
|
||||
|
||||
foriginal[0] = original.values[0];
|
||||
foriginal[1] = original.values[1];
|
||||
foriginal[2] = original.values[2];
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
template<class DeviceType>
|
||||
void FixFreezeKokkos<DeviceType>::post_force_respa(int vflag, int ilevel, int iloop)
|
||||
{
|
||||
post_force(vflag);
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
return components of total force on fix group before force was changed
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
template<class DeviceType>
|
||||
double FixFreezeKokkos<DeviceType>::compute_vector(int n)
|
||||
{
|
||||
return FixFreeze::compute_vector(n);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
template<class DeviceType>
|
||||
void FixFreezeKokkos<DeviceType>::operator()(const int i, OriginalForce &original) const {
|
||||
if (mask[i] & groupbit) {
|
||||
original.values[0] += f(i,0);
|
||||
original.values[1] += f(i,1);
|
||||
original.values[2] += f(i,2);
|
||||
f(i,0) = 0.0;
|
||||
f(i,1) = 0.0;
|
||||
f(i,2) = 0.0;
|
||||
torque(i,0) = 0.0;
|
||||
torque(i,1) = 0.0;
|
||||
torque(i,2) = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
namespace LAMMPS_NS {
|
||||
template class FixFreezeKokkos<LMPDeviceType>;
|
||||
#ifdef KOKKOS_HAVE_CUDA
|
||||
template class FixFreezeKokkos<LMPHostType>;
|
||||
#endif
|
||||
}
|
||||
80
src/KOKKOS/fix_freeze_kokkos.h
Normal file
80
src/KOKKOS/fix_freeze_kokkos.h
Normal file
@ -0,0 +1,80 @@
|
||||
/* -*- 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(freeze/kk,FixFreezeKokkos<LMPDeviceType>)
|
||||
FixStyle(freeze/kk/device,FixFreezeKokkos<LMPDeviceType>)
|
||||
FixStyle(freeze/kk/host,FixFreezeKokkos<LMPHostType>)
|
||||
|
||||
#else
|
||||
|
||||
#ifndef LMP_FIX_FREEZE_KOKKOS_H
|
||||
#define LMP_FIX_FREEZE_KOKKOS_H
|
||||
|
||||
#include "fix_freeze.h"
|
||||
#include "kokkos_type.h"
|
||||
|
||||
namespace LAMMPS_NS {
|
||||
|
||||
template<class DeviceType>
|
||||
class FixFreezeKokkos : public FixFreeze {
|
||||
public:
|
||||
struct OriginalForce {
|
||||
double values[3];
|
||||
|
||||
KOKKOS_INLINE_FUNCTION
|
||||
OriginalForce() {
|
||||
values[0] = 0;
|
||||
values[1] = 0;
|
||||
values[2] = 0;
|
||||
}
|
||||
|
||||
KOKKOS_INLINE_FUNCTION
|
||||
OriginalForce &operator+=(const OriginalForce &rhs) {
|
||||
values[0] += rhs.values[0];
|
||||
values[1] += rhs.values[1];
|
||||
values[2] += rhs.values[2];
|
||||
return *this;
|
||||
}
|
||||
|
||||
KOKKOS_INLINE_FUNCTION
|
||||
volatile OriginalForce &operator+=(const volatile OriginalForce &rhs) volatile {
|
||||
values[0] += rhs.values[0];
|
||||
values[1] += rhs.values[1];
|
||||
values[2] += rhs.values[2];
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
FixFreezeKokkos(class LAMMPS *, int, char **);
|
||||
int setmask();
|
||||
void init();
|
||||
void setup(int);
|
||||
void post_force(int);
|
||||
void post_force_respa(int, int, int);
|
||||
double compute_vector(int);
|
||||
|
||||
KOKKOS_INLINE_FUNCTION
|
||||
void operator()(const int i, OriginalForce &original) const;
|
||||
|
||||
private:
|
||||
typename ArrayTypes<DeviceType>::t_f_array f;
|
||||
typename ArrayTypes<DeviceType>::t_f_array torque;
|
||||
typename ArrayTypes<DeviceType>::t_int_1d mask;
|
||||
};
|
||||
|
||||
} // namespace LAMMPS_NS
|
||||
|
||||
#endif // LMP_FIX_FREEZE_KOKKOS_H
|
||||
#endif // FIX_CLASS
|
||||
Reference in New Issue
Block a user