Commit dce6c9ed authored by Stan Moore's avatar Stan Moore
Browse files

Merge branch 'pr-747' into develop

parents b0f9ae04 19325227
Loading
Loading
Loading
Loading
+83 −30
Original line number Diff line number Diff line
@@ -72,6 +72,9 @@ template<class DeviceType>
FixQEqReaxKokkos<DeviceType>::~FixQEqReaxKokkos()
{
  if (copymode) return;

  memoryKK->destroy_kokkos(k_s_hist,s_hist);
  memoryKK->destroy_kokkos(k_t_hist,t_hist);
}

/* ---------------------------------------------------------------------- */
@@ -157,25 +160,11 @@ void FixQEqReaxKokkos<DeviceType>::init_shielding_k()
template<class DeviceType>
void FixQEqReaxKokkos<DeviceType>::init_hist()
{
  int i,j;

  k_s_hist = DAT::tdual_ffloat_2d("qeq/kk:s_hist",atom->nmax,nprev);
  d_s_hist = k_s_hist.template view<DeviceType>();
  h_s_hist = k_s_hist.h_view;
  k_t_hist = DAT::tdual_ffloat_2d("qeq/kk:t_hist",atom->nmax,nprev);
  d_t_hist = k_t_hist.template view<DeviceType>();
  h_t_hist = k_t_hist.h_view;

  for( i = 0; i < atom->nmax; i++ )
    for( j = 0; j < nprev; j++ )
      k_s_hist.h_view(i,j) = k_t_hist.h_view(i,j) = 0.0;

  k_s_hist.template modify<LMPHostType>();
  k_s_hist.template sync<DeviceType>();

  k_t_hist.template modify<LMPHostType>();
  k_t_hist.template sync<DeviceType>();
  Kokkos::deep_copy(d_s_hist,0.0);
  Kokkos::deep_copy(d_t_hist,0.0);

  k_s_hist.template modify<DeviceType>();
  k_t_hist.template modify<DeviceType>();
}

/* ---------------------------------------------------------------------- */
@@ -235,6 +224,8 @@ void FixQEqReaxKokkos<DeviceType>::pre_force(int vflag)
  Kokkos::parallel_scan(inum,computeH_functor);

  // init_matvec
  k_s_hist.template sync<DeviceType>();
  k_t_hist.template sync<DeviceType>();
  FixQEqReaxKokkosMatVecFunctor<DeviceType> matvec_functor(this);
  Kokkos::parallel_for(inum,matvec_functor);

@@ -262,6 +253,8 @@ void FixQEqReaxKokkos<DeviceType>::pre_force(int vflag)

  // calculate_Q();
  calculate_q();
  k_s_hist.template modify<DeviceType>();
  k_t_hist.template modify<DeviceType>();

  copymode = 0;

@@ -334,14 +327,6 @@ void FixQEqReaxKokkos<DeviceType>::allocate_array()
    k_d = DAT::tdual_ffloat_1d("qeq/kk:h_d",nmax);
    d_d = k_d.template view<DeviceType>();
    h_d = k_d.h_view;

    k_s_hist = DAT::tdual_ffloat_2d("qeq/kk:s_hist",nmax,nprev);
    d_s_hist = k_s_hist.template view<DeviceType>();
    h_s_hist = k_s_hist.h_view;

    k_t_hist = DAT::tdual_ffloat_2d("qeq/kk:t_hist",nmax,nprev);
    d_t_hist = k_t_hist.template view<DeviceType>();
    h_t_hist = k_t_hist.h_view;
  }

  // init_storage
@@ -369,8 +354,6 @@ void FixQEqReaxKokkos<DeviceType>::zero_item(int ii) const
    d_o[i] = 0.0;
    d_r[i] = 0.0;
    d_d[i] = 0.0;
    //for( int j = 0; j < nprev; j++ )
      //d_s_hist(i,j) = d_t_hist(i,j) = 0.0;
  }

}
@@ -462,7 +445,7 @@ double FixQEqReaxKokkos<DeviceType>::calculate_H_k(const F_FLOAT &r, const F_FLO

template<class DeviceType>
KOKKOS_INLINE_FUNCTION
void FixQEqReaxKokkos<DeviceType>::mat_vec_item(int ii) const
void FixQEqReaxKokkos<DeviceType>::matvec_item(int ii) const
{
  const int i = d_ilist[ii];
  const int itype = type(i);
@@ -1183,7 +1166,77 @@ double FixQEqReaxKokkos<DeviceType>::memory_usage()
  return bytes;
}

/* ---------------------------------------------------------------------- */\
/* ----------------------------------------------------------------------
   allocate fictitious charge arrays
------------------------------------------------------------------------- */

template<class DeviceType>
void FixQEqReaxKokkos<DeviceType>::grow_arrays(int nmax)
{
  k_s_hist.template sync<LMPHostType>(); // force reallocation on host
  k_t_hist.template sync<LMPHostType>();

  memoryKK->grow_kokkos(k_s_hist,s_hist,nmax,nprev,"qeq:s_hist");
  memoryKK->grow_kokkos(k_t_hist,t_hist,nmax,nprev,"qeq:t_hist");

  d_s_hist = k_s_hist.template view<DeviceType>();
  d_t_hist = k_t_hist.template view<DeviceType>();

  k_s_hist.template modify<LMPHostType>();
  k_t_hist.template modify<LMPHostType>();
}

/* ----------------------------------------------------------------------
   copy values within fictitious charge arrays
------------------------------------------------------------------------- */

template<class DeviceType>
void FixQEqReaxKokkos<DeviceType>::copy_arrays(int i, int j, int delflag)
{
  k_s_hist.template sync<LMPHostType>();
  k_t_hist.template sync<LMPHostType>();

  for (int m = 0; m < nprev; m++) {
    s_hist[j][m] = s_hist[i][m];
    t_hist[j][m] = t_hist[i][m];
  }

  k_s_hist.template modify<LMPHostType>();
  k_t_hist.template modify<LMPHostType>();
}

/* ----------------------------------------------------------------------
   pack values in local atom-based array for exchange with another proc
------------------------------------------------------------------------- */

template<class DeviceType>
int FixQEqReaxKokkos<DeviceType>::pack_exchange(int i, double *buf)
{
  k_s_hist.template sync<LMPHostType>();
  k_t_hist.template sync<LMPHostType>();

  for (int m = 0; m < nprev; m++) buf[m] = s_hist[i][m];
  for (int m = 0; m < nprev; m++) buf[nprev+m] = t_hist[i][m];
  return nprev*2;
}

/* ----------------------------------------------------------------------
   unpack values in local atom-based array from exchange with another proc
------------------------------------------------------------------------- */

template<class DeviceType>
int FixQEqReaxKokkos<DeviceType>::unpack_exchange(int nlocal, double *buf)
{
  for (int m = 0; m < nprev; m++) s_hist[nlocal][m] = buf[m];
  for (int m = 0; m < nprev; m++) t_hist[nlocal][m] = buf[nprev+m];

  k_s_hist.template modify<LMPHostType>();
  k_t_hist.template modify<LMPHostType>();

  return nprev*2;
}

/* ---------------------------------------------------------------------- */

namespace LAMMPS_NS {
template class FixQEqReaxKokkos<LMPDeviceType>;
+7 −3
Original line number Diff line number Diff line
@@ -57,7 +57,7 @@ class FixQEqReaxKokkos : public FixQEqReax {
  void compute_h_item(int, int &, const bool &) const;

  KOKKOS_INLINE_FUNCTION
  void mat_vec_item(int) const;
  void matvec_item(int) const;

  KOKKOS_INLINE_FUNCTION
  void sparse12_item(int) const;
@@ -145,7 +145,7 @@ class FixQEqReaxKokkos : public FixQEqReax {
  void unpack_reverse_comm(int, int *, double *);
  double memory_usage();

 protected:
 private:
  int inum;
  int allocated_flag;

@@ -210,6 +210,10 @@ class FixQEqReaxKokkos : public FixQEqReax {
  typename AT::t_int_2d d_sendlist;
  typename AT::t_xfloat_1d_um v_buf;

  void grow_arrays(int);
  void copy_arrays(int, int, int);
  int pack_exchange(int, double *);
  int unpack_exchange(int, double *);
};

template <class DeviceType>
@@ -235,7 +239,7 @@ struct FixQEqReaxKokkosMatVecFunctor {
  };
  KOKKOS_INLINE_FUNCTION
  void operator()(const int ii) const {
    c.mat_vec_item(ii);
    c.matvec_item(ii);
  }
};

+9 −9
Original line number Diff line number Diff line
@@ -122,15 +122,15 @@ class FixQEqReax : public Fix {
  //int GMRES(double*,double*);
  virtual void sparse_matvec(sparse_matrix*,double*,double*);

  int pack_forward_comm(int, int *, double *, int, int *);
  void unpack_forward_comm(int, int, double *);
  int pack_reverse_comm(int, int, double *);
  void unpack_reverse_comm(int, int *, double *);
  double memory_usage();
  void grow_arrays(int);
  void copy_arrays(int, int, int);
  int pack_exchange(int, double *);
  int unpack_exchange(int, double *);
  virtual int pack_forward_comm(int, int *, double *, int, int *);
  virtual void unpack_forward_comm(int, int, double *);
  virtual int pack_reverse_comm(int, int, double *);
  virtual void unpack_reverse_comm(int, int *, double *);
  virtual double memory_usage();
  virtual void grow_arrays(int);
  virtual void copy_arrays(int, int, int);
  virtual int pack_exchange(int, double *);
  virtual int unpack_exchange(int, double *);

  virtual double parallel_norm( double*, int );
  virtual double parallel_dot( double*, double*, int );