Commit b84a2481 authored by Aidan Thompson's avatar Aidan Thompson
Browse files

Merge remote-tracking branch 'charlie/chem_snap' into ml_chem_snap

parents 909e6048 09c2dec7
Loading
Loading
Loading
Loading

cmake/2826.patch

deleted100644 → 0
+0 −13
Original line number Diff line number Diff line
diff --git a/lib/kokkos/containers/src/Kokkos_ScatterView.hpp b/lib/kokkos/containers/src/Kokkos_ScatterView.hpp
index a8c05e3..1d83aed 100644
--- a/lib/kokkos/containers/src/Kokkos_ScatterView.hpp
+++ b/lib/kokkos/containers/src/Kokkos_ScatterView.hpp
@@ -681,7 +681,7 @@ class ScatterView<DataType
                    ,contribution>
 {
 public:
-  typedef Kokkos::View<DataType, Layout, ExecSpace> original_view_type;
+  typedef Kokkos::View<DataType, Layout, Kokkos::Device<ExecSpace, Kokkos::Cuda::memory_space> > original_view_type;
   typedef typename original_view_type::value_type original_value_type;
   typedef typename original_view_type::reference_type original_reference_type;
   friend class ScatterAccess<DataType, Op, ExecSpace, Layout, ScatterNonDuplicated, contribution, ScatterNonAtomic>;
+20 −10
Original line number Diff line number Diff line
if(PKG_KOKKOS)
  find_package(Kokkos 3 QUIET)
  if(Kokkos_FOUND)
    set(DOWNLOAD_KOKKOS_DEFAULT OFF)
  else()
    set(DOWNLOAD_KOKKOS_DEFAULT ON)
  endif()
  option(DOWNLOAD_KOKKOS "Download the KOKKOS library instead of using an already installed one" ${DOWNLOAD_KOKKOS_DEFAULT})
  option(EXTERNAL_KOKKOS "Build against external kokkos library" OFF)
  option(DOWNLOAD_KOKKOS "Download the KOKKOS library instead of using the bundled one" OFF)
  if(DOWNLOAD_KOKKOS)
    if(CMAKE_VERSION VERSION_LESS 3.11)
      message(FATAL_ERROR "Downloading kokkos currently only works with cmake-3.11 and higher")
    endif()
    message(STATUS "KOKKOS download requested - we will build our own")
    # Workaround for cross compilation with MinGW where ${CMAKE_INSTALL_LIBDIR}
    # is a full path, so we need to remove the prefix
    string(REPLACE ${CMAKE_INSTALL_PREFIX} "" _KOKKOS_LIBDIR ${CMAKE_INSTALL_LIBDIR})
    file(DOWNLOAD https://github.com/kokkos/kokkos/compare/3.0.00...stanmoore1:lammps.diff ${CMAKE_CURRENT_BINARY_DIR}/kokkos-lammps.patch)
    include(ExternalProject)
    ExternalProject_Add(kokkos_build
      URL https://github.com/kokkos/kokkos/archive/3.0.00.tar.gz
      URL_MD5 281c7093aa3a603276e93abdf4be23b9
      PATCH_COMMAND patch -p3 < ${CMAKE_CURRENT_SOURCE_DIR}/2826.patch
      PATCH_COMMAND patch -p1 < ${CMAKE_CURRENT_BINARY_DIR}/kokkos-lammps.patch
      CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR> ${CMAKE_REQUEST_PIC}
      -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
      -DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM} -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
@@ -26,13 +25,24 @@ if(PKG_KOKKOS)
    set(KOKKOS_LIBRARIES ${INSTALL_DIR}/${_KOKKOS_LIBDIR}/libkokkoscore.a) 
    set(KOKKOS_INCLUDE_DIRS ${INSTALL_DIR}/include)
    include_directories(${KOKKOS_INCLUDE_DIRS})
    list(APPEND LAMMPS_LINK_LIBS ${KOKKOS_LIBRARIES})
  else()
    list(APPEND LAMMPS_LINK_LIBS ${KOKKOS_LIBRARIES} ${CMAKE_DL_LIBS})
  elseif(EXTERNAL_KOKKOS)
    find_package(Kokkos 3)
    if(NOT Kokkos_FOUND)
      message(FATAL_ERROR "KOKKOS library not found, help CMake to find it by setting KOKKOS_LIBRARY, or set DOWNLOAD_KOKKOS=ON to download it")
    endif()
    list(APPEND LAMMPS_LINK_LIBS Kokkos::kokkos)
  else()
    set(LAMMPS_LIB_KOKKOS_SRC_DIR ${LAMMPS_LIB_SOURCE_DIR}/kokkos)
    set(LAMMPS_LIB_KOKKOS_BIN_DIR ${LAMMPS_LIB_BINARY_DIR}/kokkos)
    add_subdirectory(${LAMMPS_LIB_KOKKOS_SRC_DIR} ${LAMMPS_LIB_KOKKOS_BIN_DIR})

    set(Kokkos_INCLUDE_DIRS ${LAMMPS_LIB_KOKKOS_SRC_DIR}/core/src
                            ${LAMMPS_LIB_KOKKOS_SRC_DIR}/containers/src
                            ${LAMMPS_LIB_KOKKOS_SRC_DIR}/algorithms/src
                            ${LAMMPS_LIB_KOKKOS_BIN_DIR})
    include_directories(${Kokkos_INCLUDE_DIRS})
    list(APPEND LAMMPS_LINK_LIBS kokkos)
  endif()
  add_definitions(-DLMP_KOKKOS)

+6 −4
Original line number Diff line number Diff line
@@ -40,7 +40,7 @@ ComputeSnap::ComputeSnap(LAMMPS *lmp, int narg, char **arg) :
  extarray = 0;

  double rfac0, rmin0;
  int twojmax, switchflag, bzeroflag, bnormflag;
  int twojmax, switchflag, bzeroflag;
  radelem = NULL;
  wjelem = NULL;

@@ -54,7 +54,6 @@ ComputeSnap::ComputeSnap(LAMMPS *lmp, int narg, char **arg) :
  rmin0 = 0.0;
  switchflag = 1;
  bzeroflag = 1;
  bnormflag = 0;
  quadraticflag = 0;
  alloyflag = 0;
  wselfallflag = 0;
@@ -113,10 +112,9 @@ ComputeSnap::ComputeSnap(LAMMPS *lmp, int narg, char **arg) :
      quadraticflag = atoi(arg[iarg+1]);
      iarg += 2;
    } else if (strcmp(arg[iarg],"alloyflag") == 0) {
      if (iarg+2+ntypes > narg)
      if (iarg+2 > narg)
        error->all(FLERR,"Illegal compute snap command");
      alloyflag = 1;
      bnormflag = 1;
      memory->create(map,ntypes+1,"compute_snap:map");
      nelements = force->inumeric(FLERR,arg[iarg+1]);
      for(int i = 0; i < ntypes; i++) {
@@ -168,6 +166,8 @@ ComputeSnap::~ComputeSnap()
  memory->destroy(wjelem);
  memory->destroy(cutsq);
  delete snaptr;

  if (alloyflag) memory->destroy(map);
}

/* ---------------------------------------------------------------------- */
@@ -541,6 +541,8 @@ double ComputeSnap::memory_usage()
    sizeof(double);                                     // snapall
  bytes += nmax*size_peratom * sizeof(double);          // snap_peratom
  bytes += snaptr->memory_usage();                      // SNA object
  int n = atom->ntypes+1;
  bytes += n*sizeof(int);        // map

  return bytes;
}
+18 −5
Original line number Diff line number Diff line
@@ -162,7 +162,10 @@ void PairSNAP::compute(int eflag, int vflag)

    // compute Ui, Yi for atom I

    if (alloyflag)
      snaptr->compute_ui(ninside, ielem);
    else
      snaptr->compute_ui(ninside, 0);

    // for neighbors of I within cutoff:
    // compute Fij = dEi/dRj = -dEi/dRi
@@ -175,8 +178,12 @@ void PairSNAP::compute(int eflag, int vflag)

    for (int jj = 0; jj < ninside; jj++) {
      int j = snaptr->inside[jj];
      if(alloyflag)
        snaptr->compute_duidrj(snaptr->rij[jj], snaptr->wj[jj],
                               snaptr->rcutij[jj],jj, snaptr->element[jj]);
      else
        snaptr->compute_duidrj(snaptr->rij[jj], snaptr->wj[jj],
                               snaptr->rcutij[jj],jj, 0);

      snaptr->compute_deidrj(fij);

@@ -329,9 +336,15 @@ void PairSNAP::compute_bispectrum()
      }
    }

    if (alloyflag)
      snaptr->compute_ui(ninside, ielem);
    else
      snaptr->compute_ui(ninside, 0);
    snaptr->compute_zi();
    if (alloyflag)
      snaptr->compute_bi(ielem);
    else
      snaptr->compute_bi(0);

    for (int icoeff = 0; icoeff < ncoeff; icoeff++){
      bispectrum[ii][icoeff] = snaptr->blist[icoeff];
+27 −77
Original line number Diff line number Diff line
@@ -120,7 +120,11 @@ SNA::SNA(LAMMPS* lmp, double rfac0_in, int twojmax_in,
  bnorm_flag = alloy_flag_in;
  alloy_flag = alloy_flag_in;
  wselfall_flag = wselfall_flag_in;

  if (alloy_flag)
    nelements = nelements_in;
  else
    nelements = 1;

  twojmax = twojmax_in;

@@ -277,8 +281,6 @@ void SNA::build_indexlist()
            idxz[idxz_count].mb1min = MAX(0, (2 * mb - j - j2 + j1) / 2);
            idxz[idxz_count].mb2max = (2 * mb - j - (2 * idxz[idxz_count].mb1min - j1) + j2) / 2;
            idxz[idxz_count].nb = MIN(j1, (2 * mb - j + j2 + j1) / 2) - idxz[idxz_count].mb1min + 1;
            idxz[idxz_count].ma = ma;
            idxz[idxz_count].mb = mb;
            // apply to z(j1,j2,j,ma,mb) to unique element of y(j)

            const int jju = idxu_block[j] + (j+1)*mb + ma;
@@ -336,7 +338,6 @@ void SNA::compute_ui(int jnum, int ielem)
  //   utot(j,ma,mb) += u(r0;j,ma,mb) for all j,ma,mb

  zero_uarraytot(ielem);
  addself_uarraytot(wself, ielem);

  for(int j = 0; j < jnum; j++) {
    x = rij[j][0];
@@ -350,7 +351,10 @@ void SNA::compute_ui(int jnum, int ielem)
    z0 = r / tan(theta0);

    compute_uarray(x, y, z, z0, r, j);
    if (alloy_flag)
      add_uarraytot(r, wj[j], rcutij[j], j, element[j]);
    else
      add_uarraytot(r, wj[j], rcutij[j], j, 0);
  }

}
@@ -438,8 +442,6 @@ void SNA::compute_yi(const double* beta)
  int jju;
  double betaj;
  int itriple;
  int jelem;
  double temp;

  for(int ielem1 = 0; ielem1 < nelements; ielem1++)
    for(int j = 0; j <= twojmax; j++) {
@@ -464,8 +466,6 @@ void SNA::compute_yi(const double* beta)
          const int mb1min = idxz[jjz].mb1min;
          const int mb2max = idxz[jjz].mb2max;
          const int nb = idxz[jjz].nb;
          const int ma = idxz[jjz].ma;
          const int mb = idxz[jjz].mb;

          const double *cgblock = cglist + idxcg_block[j1][j2][j];

@@ -518,65 +518,29 @@ void SNA::compute_yi(const double* beta)
        jju = idxz[jjz].jju;
        for(int elem3 = 0; elem3 < nelements; elem3++) {
        // pick out right beta value
          if (alloy_flag) {
          if (j >= j1) {
            const int jjb = idxb_block[j1][j2][j];
              itriple = ((elem3 * nelements + elem2) * nelements + elem1) * idxb_max + jjb;
              if (j1 ==j && j2 == j && elem1 == elem2 && elem1 == elem3) betaj = 3 * beta[itriple];
              else if (j1 == j && j2 == j && elem2 == elem3 && elem1!=elem3)
                  betaj =
                      2 * (beta[itriple] + beta[((elem1 * nelements + elem2) * nelements + elem3) * idxb_max + jjb]);
              else if (j1 == j && j2 == j && elem1 == elem2 && elem1 != elem3)
                betaj = beta[itriple] + beta[((elem2 * nelements + elem1) * nelements + elem3) * idxb_max + jjb] +
                        beta[((elem1 * nelements + elem3) * nelements + elem2) * idxb_max + jjb];
              else if (j1 ==j && (elem1 == elem3 || elem2 == elem3)) // this line covers quite a few cases
                betaj = 2 * beta[itriple];
              else if (j1 == j && j2 != j && elem2 == elem1 && elem1 != elem3)
                betaj = beta[itriple] + beta[((elem1 * nelements + elem2) * nelements + elem3) * idxb_max + jjb];
              else
                betaj = beta[((elem1 * nelements + elem2) * nelements + elem3) * idxb_max + jjb];
            itriple = ((elem1 * nelements + elem2) * nelements + elem3) * idxb_max + jjb;
            if (j1 == j) {
              if (j2 == j) betaj = 3*beta[itriple];
              else betaj = 2*beta[itriple];
            } else betaj = beta[itriple];
          } else if (j >= j2) {
            const int jjb = idxb_block[j][j2][j1];
            itriple = ((elem3 * nelements + elem2) * nelements + elem1) * idxb_max + jjb;
              if (j2 == j) {
                if (elem3 == elem2)
                  betaj = 2 * beta[itriple];
                else if (elem1 == elem2)
                  betaj = beta[itriple] + beta[((elem1 * nelements + elem3) * nelements + elem2) * idxb_max + jjb];
                else if (elem1 == elem3)
                  betaj = beta[itriple] + beta[((elem2 * nelements + elem1) * nelements + elem3) * idxb_max + jjb];
              } else
                betaj = beta[itriple];
            if (j2 == j) betaj = 2*beta[itriple];
            else betaj = beta[itriple];
          } else {
            const int jjb = idxb_block[j2][j][j1];
            itriple = ((elem2 * nelements + elem3) * nelements + elem1) * idxb_max + jjb;
            betaj = beta[itriple];
          }
          } else {
            if (j >= j1) {
              const int jjb = idxb_block[j1][j2][j];
              if (j1 == j) {
                if (j2 == j) betaj = 3*beta[jjb];
                else betaj = 2*beta[jjb];
              } else betaj = beta[jjb];
            } else if (j >= j2) {
              const int jjb = idxb_block[j][j2][j1];
              if (j2 == j) betaj = 2*beta[jjb];
              else betaj = beta[jjb];
            } else {
              const int jjb = idxb_block[j2][j][j1];
              betaj = beta[jjb];
            }
          }

          if (!bnorm_flag && j1 > j)
            betaj *= (j1 + 1) / (j + 1.0);

          ylist_r[elem3 * idxu_max + jju] += betaj * ztmp_r;
          ylist_i[elem3 * idxu_max + jju] += betaj * ztmp_i;
          //if (elem3==0 && j ==4 &&  ma==2 &&  mb==0)
          //  fprintf(screen, "%i %i %i %i %i %i %f %f %f\n", elem1, elem2, elem3, j, j1, j2, betaj, ztmp_r, ylist_r[elem3 * idxu_max + jju]);

        }
      } // end loop over jjz
    }
@@ -1023,20 +987,6 @@ void SNA::zero_uarraytot(int ielem)
  }
}

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

void SNA::addself_uarraytot(double wself_in, int ielem)
{
  // for (int j = 0; j <= twojmax; j++) {
  //   int jju = idxu_block[j];
  //   for (int ma = 0; ma <= j; ma++) {
  //     ulisttot_r[ielem*idxu_max+jju] = wself_in;
  //     ulisttot_i[ielem*idxu_max+jju] = 0.0;
  //     jju += j+2;
  //   }
  // }
}

/* ----------------------------------------------------------------------
   add Wigner U-functions for one neighbor to the total
------------------------------------------------------------------------- */
Loading