diff --git a/src/KOKKOS/kokkos.cpp b/src/KOKKOS/kokkos.cpp index 03626a5c6c..8882c97a42 100644 --- a/src/KOKKOS/kokkos.cpp +++ b/src/KOKKOS/kokkos.cpp @@ -31,8 +31,13 @@ KokkosLMP::KokkosLMP(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp) kokkos_exists = 1; lmp->kokkos = this; + int me = 0; + MPI_Comm_rank(world,&me); + if (me == 0) error->message(FLERR,"KOKKOS mode is enabled"); + // process any command-line args that invoke Kokkos settings + int ngpu = 0; int device = 0; num_threads = 1; numa = 1; @@ -46,8 +51,11 @@ KokkosLMP::KokkosLMP(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp) } else if (strcmp(arg[iarg],"g") == 0 || strcmp(arg[iarg],"gpus") == 0) { +#ifndef KOKKOS_HAVE_CUDA + error->all(FLERR,"GPUs are requested but Kokkos has not been compiled for CUDA"); +#endif if (iarg+2 > narg) error->all(FLERR,"Invalid Kokkos command-line args"); - int ngpu = atoi(arg[iarg+1]); + ngpu = atoi(arg[iarg+1]); int skip_gpu = 9999; if (iarg+2 < narg && isdigit(arg[iarg+2][0])) { @@ -88,7 +96,15 @@ KokkosLMP::KokkosLMP(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp) // initialize Kokkos + if (me == 0) { + if (screen) fprintf(screen," using %d GPU(s)\n",ngpu); + if (logfile) fprintf(logfile," using %d GPU(s)\n",ngpu); + } + #ifdef KOKKOS_HAVE_CUDA + if (ngpu <= 0) + error->all(FLERR,"Kokkos has been compiled for CUDA but no GPUs are requested"); + Kokkos::HostSpace::execution_space::initialize(num_threads,numa); Kokkos::Cuda::SelectDevice select_device(device); Kokkos::Cuda::initialize(select_device); diff --git a/src/lammps.cpp b/src/lammps.cpp index bb1f0e507c..94a267db8a 100644 --- a/src/lammps.cpp +++ b/src/lammps.cpp @@ -500,9 +500,6 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) error->all(FLERR,"Cannot use -kokkos on without KOKKOS installed"); } - MPI_Comm_rank(world,&me); - if (kokkos && me == 0) error->message(FLERR,"KOKKOS mode is enabled"); - // allocate CiteMe class if enabled if (citeflag) citeme = new CiteMe(this);