From e2f263b8270778edf43fa256f29ed16be333d846 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 27 Oct 2022 17:04:10 -0400 Subject: [PATCH] protect against division by zero --- src/KOKKOS/kokkos.cpp | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/src/KOKKOS/kokkos.cpp b/src/KOKKOS/kokkos.cpp index dcdc26c13b..6506c86462 100644 --- a/src/KOKKOS/kokkos.cpp +++ b/src/KOKKOS/kokkos.cpp @@ -144,28 +144,36 @@ KokkosLMP::KokkosLMP(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp) set_flag = 1; } if ((str = getenv("MPT_LRANK"))) { - int local_rank = atoi(str); - device = local_rank % ngpus; - if (device >= skip_gpu) device++; - set_flag = 1; + if (ngpus > 0) { + int local_rank = atoi(str); + device = local_rank % ngpus; + if (device >= skip_gpu) device++; + set_flag = 1; + } } if ((str = getenv("MV2_COMM_WORLD_LOCAL_RANK"))) { - int local_rank = atoi(str); - device = local_rank % ngpus; - if (device >= skip_gpu) device++; - set_flag = 1; + if (ngpus > 0) { + int local_rank = atoi(str); + device = local_rank % ngpus; + if (device >= skip_gpu) device++; + set_flag = 1; + } } if ((str = getenv("OMPI_COMM_WORLD_LOCAL_RANK"))) { - int local_rank = atoi(str); - device = local_rank % ngpus; - if (device >= skip_gpu) device++; - set_flag = 1; + if (ngpus > 0) { + int local_rank = atoi(str); + device = local_rank % ngpus; + if (device >= skip_gpu) device++; + set_flag = 1; + } } if ((str = getenv("PMI_LOCAL_RANK"))) { - int local_rank = atoi(str); - device = local_rank % ngpus; - if (device >= skip_gpu) device++; - set_flag = 1; + if (ngpus > 0) { + int local_rank = atoi(str); + device = local_rank % ngpus; + if (device >= skip_gpu) device++; + set_flag = 1; + } } if (ngpus > 1 && !set_flag)