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

Fix issue with compute_duarray

parent 73968f10
Loading
Loading
Loading
Loading
+6 −5
Original line number Diff line number Diff line
@@ -309,7 +309,7 @@ void PairSNAPKokkos<DeviceType>::operator() (TagPairSNAPBeta,const typename Kokk
  const int ii = team.league_rank();
  const int i = d_ilist[ii];
  const int itype = type[i];
  const int ielem = d_map[itype];
  const int ielem = map[itype];
  Kokkos::View<double*,Kokkos::LayoutRight,DeviceType,Kokkos::MemoryTraits<Kokkos::Unmanaged>>
    d_coeffi(d_coeffelem,ielem,Kokkos::ALL);

@@ -601,12 +601,13 @@ void PairSNAPKokkos<DeviceType>::operator() (TagPairSNAPCompute<NEIGHFLAG,EVFLAG
    int j = my_sna.inside[jj];

    my_sna.compute_duidrj(team,&my_sna.rij(jj,0),
                           my_sna.wj[jj],my_sna.rcutij[jj]);
                           my_sna.wj[jj],my_sna.rcutij[jj],jj);

    Kokkos::single(Kokkos::PerThread(team), [&] (){

      F_FLOAT fij[3];
      my_sna.compute_deidrj(team,fij);
      
    Kokkos::single(Kokkos::PerThread(team), [&] (){
      a_f(i,0) += fij[0];
      a_f(i,1) += fij[1];
      a_f(i,2) += fij[2];
+6 −5
Original line number Diff line number Diff line
@@ -88,7 +88,7 @@ inline
  // functions for derivatives

  KOKKOS_INLINE_FUNCTION
  void compute_duidrj(const typename Kokkos::TeamPolicy<DeviceType>::member_type& team, double*, double, double); //ForceSNAP
  void compute_duidrj(const typename Kokkos::TeamPolicy<DeviceType>::member_type& team, double*, double, double, int); //ForceSNAP
  KOKKOS_INLINE_FUNCTION
  void compute_dbidrj(const typename Kokkos::TeamPolicy<DeviceType>::member_type& team); //ForceSNAP
  KOKKOS_INLINE_FUNCTION
@@ -123,10 +123,11 @@ inline
  t_sna_1d ulisttot_r, ulisttot_i;
  t_sna_1d_atomic ulisttot_r_a, ulisttot_i_a;
  t_sna_1d zlist_r, zlist_i;
  t_sna_2d ulist_r_ij, ulist_i_ij;

  // Per InFlight Interaction
  t_sna_1d ulist_r, ulist_i;
  t_sna_1d_atomic ylist_r, ylist_i;
  t_sna_1d ylist_r, ylist_i;

  // derivatives of data
  t_sna_2d dulist_r, dulist_i;
@@ -171,13 +172,13 @@ inline
  KOKKOS_INLINE_FUNCTION
  void addself_uarraytot(const typename Kokkos::TeamPolicy<DeviceType>::member_type& team, double); // compute_ui
  KOKKOS_INLINE_FUNCTION
  void add_uarraytot(const typename Kokkos::TeamPolicy<DeviceType>::member_type& team, double, double, double); // compute_ui
  void add_uarraytot(const typename Kokkos::TeamPolicy<DeviceType>::member_type& team, double, double, double, int); // compute_ui

  KOKKOS_INLINE_FUNCTION
  void compute_uarray(const typename Kokkos::TeamPolicy<DeviceType>::member_type& team,
                      double, double, double,
                      double, double); // compute_ui
  inline
  KOKKOS_INLINE_FUNCTION
  double deltacg(int, int, int);  // init_clebsch_gordan

inline
@@ -185,7 +186,7 @@ inline
  KOKKOS_INLINE_FUNCTION
  void compute_duarray(const typename Kokkos::TeamPolicy<DeviceType>::member_type& team,
                       double, double, double, // compute_duidrj
                       double, double, double, double, double);
                       double, double, double, double, double, int);

  // Sets the style for the switching function
  // 0 = none
+26 −7
Original line number Diff line number Diff line
@@ -289,7 +289,7 @@ void SNAKokkos<DeviceType>::compute_ui(const typename Kokkos::TeamPolicy<DeviceT

    compute_uarray(team,x, y, z, z0, r);
    //Kokkos::single(Kokkos::PerThread(team), [&] (){
    add_uarraytot(team,r, wj[j], rcutij[j]);
    add_uarraytot(team,r, wj[j], rcutij[j], j);
    //});
  });

@@ -780,7 +780,7 @@ void SNAKokkos<DeviceType>::compute_dbidrj(const typename Kokkos::TeamPolicy<Dev
template<class DeviceType>
KOKKOS_INLINE_FUNCTION
void SNAKokkos<DeviceType>::compute_duidrj(const typename Kokkos::TeamPolicy<DeviceType>::member_type& team,
                         double* rij, double wj, double rcut)
                         double* rij, double wj, double rcut, int jj)
{
  double rsq, r, x, y, z, z0, theta0, cs, sn;
  double dz0dr;
@@ -797,7 +797,7 @@ void SNAKokkos<DeviceType>::compute_duidrj(const typename Kokkos::TeamPolicy<Dev
  z0 = r * cs / sn;
  dz0dr = z0 / r - (r*rscale0) * (rsq + z0 * z0) / rsq;

  compute_duarray(team, x, y, z, z0, r, dz0dr, wj, rcut);
  compute_duarray(team, x, y, z, z0, r, dz0dr, wj, rcut, jj);
}

/* ---------------------------------------------------------------------- */
@@ -846,7 +846,8 @@ void SNAKokkos<DeviceType>::addself_uarraytot(const typename Kokkos::TeamPolicy<

template<class DeviceType>
KOKKOS_INLINE_FUNCTION
void SNAKokkos<DeviceType>::add_uarraytot(const typename Kokkos::TeamPolicy<DeviceType>::member_type& team, double r, double wj, double rcut)
void SNAKokkos<DeviceType>::add_uarraytot(const typename Kokkos::TeamPolicy<DeviceType>::member_type& team,
                                          double r, double wj, double rcut, int j)
{
  const double sfac = compute_sfac(r, rcut) * wj;

@@ -854,10 +855,19 @@ void SNAKokkos<DeviceType>::add_uarraytot(const typename Kokkos::TeamPolicy<Devi
  const double* const ptr_i = ulist_i.data();
  double* const ptrtot_r = ulisttot_r.data();
  double* const ptrtot_i = ulisttot_i.data();

  Kokkos::View<double*,Kokkos::LayoutRight,DeviceType,Kokkos::MemoryTraits<Kokkos::Unmanaged>>
    ulist_r_j(ulist_r_ij,j,Kokkos::ALL);
  Kokkos::View<double*,Kokkos::LayoutRight,DeviceType,Kokkos::MemoryTraits<Kokkos::Unmanaged>>
    ulist_i_j(ulist_i_ij,j,Kokkos::ALL);

  Kokkos::parallel_for(Kokkos::ThreadVectorRange(team,ulisttot_r.span()),
      [&] (const int& i) {
    Kokkos::atomic_add(ptrtot_r+i, sfac * ptr_r[i]);
    Kokkos::atomic_add(ptrtot_i+i, sfac * ptr_i[i]);

    ulist_r_j(i) = ulist_r(i);
    ulist_i_j(i) = ulist_i(i);
  });
}

@@ -962,7 +972,7 @@ KOKKOS_INLINE_FUNCTION
void SNAKokkos<DeviceType>::compute_duarray(const typename Kokkos::TeamPolicy<DeviceType>::member_type& team,
                          double x, double y, double z,
                          double z0, double r, double dz0dr,
                          double wj, double rcut)
                          double wj, double rcut, int jj)
{
  double r0inv;
  double a_r, a_i, b_r, b_i;
@@ -1006,6 +1016,11 @@ void SNAKokkos<DeviceType>::compute_duarray(const typename Kokkos::TeamPolicy<De
  db_i[0] += -r0inv;
  db_r[1] += r0inv;

  Kokkos::View<double*,Kokkos::LayoutRight,DeviceType,Kokkos::MemoryTraits<Kokkos::Unmanaged>>
    ulist_r(ulist_r_ij,jj,Kokkos::ALL);
  Kokkos::View<double*,Kokkos::LayoutRight,DeviceType,Kokkos::MemoryTraits<Kokkos::Unmanaged>>
    ulist_i(ulist_i_ij,jj,Kokkos::ALL);

  dulist_r(0,0) = 0.0;
  dulist_r(0,1) = 0.0;
  dulist_r(0,2) = 0.0;
@@ -1135,6 +1150,8 @@ void SNAKokkos<DeviceType>::create_team_scratch_arrays(const typename Kokkos::Te
  rcutij = t_sna_1d(team.team_scratch(1),nmax);
  wj = t_sna_1d(team.team_scratch(1),nmax);
  inside = t_sna_1i(team.team_scratch(1),nmax);
  ulist_r_ij = t_sna_2d(team.team_scratch(1),nmax,idxu_max);
  ulist_i_ij = t_sna_2d(team.team_scratch(1),nmax,idxu_max);
}

template<class DeviceType>
@@ -1151,6 +1168,7 @@ T_INT SNAKokkos<DeviceType>::size_team_scratch_arrays() {
  size += t_sna_1d::shmem_size(nmax); // rcutij
  size += t_sna_1d::shmem_size(nmax); // wj
  size += t_sna_1i::shmem_size(nmax); // inside
  size += t_sna_2d::shmem_size(nmax,idxu_max)*2; // ulist_ij

  return size;
}
@@ -1567,6 +1585,7 @@ double SNAKokkos<DeviceType>::memory_usage()
  bytes += nmax * sizeof(int);                           // inside
  bytes += nmax * sizeof(double);                        // wj
  bytes += nmax * sizeof(double);                        // rcutij
  bytes += nmax * idxu_max * sizeof(double) * 2;         // ulist_ij

  return bytes;
}
+1 −1
Original line number Diff line number Diff line
@@ -263,7 +263,7 @@ void ComputeSNADAtom::compute_peratom()
        const int j = snaptr->inside[jj];
        snaptr->compute_duidrj(snaptr->rij[jj],
                                    snaptr->wj[jj],
                                    snaptr->rcutij[jj]);
                                    snaptr->rcutij[jj],jj);
        snaptr->compute_dbidrj();

        // Accumulate -dBi/dRi, -dBi/dRj
+1 −1
Original line number Diff line number Diff line
@@ -258,7 +258,7 @@ void ComputeSNAVAtom::compute_peratom()

        snaptr->compute_duidrj(snaptr->rij[jj],
                                    snaptr->wj[jj],
                                    snaptr->rcutij[jj]);
                                    snaptr->rcutij[jj],jj);
        snaptr->compute_dbidrj();

        // Accumulate -dBi/dRi*Ri, -dBi/dRj*Rj
Loading