Skip to content

Commit

Permalink
Convert C-style code to C++
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleFromKitware committed Sep 13, 2019
1 parent 6b109b7 commit a1b3ebe
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions packages/kokkos/core/src/impl/Kokkos_Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
#include <cstdlib>
#include <stack>
#include <cerrno>
#include <string>

//----------------------------------------------------------------------------

Expand All @@ -73,27 +74,25 @@ int get_ctest_gpu(const char* local_rank_str, const char* ctest_kokkos_device_ty
// Get the resource types allocated to this process
std::ostringstream ctest_process;
ctest_process << "CTEST_PROCESS_" << local_rank;
auto ctest_process_str = std::getenv(ctest_process.str().c_str());
auto const* ctest_process_str = std::getenv(ctest_process.str().c_str());
if (!ctest_process_str) {
return 0;
}

// Look for the device type specified in CTEST_KOKKOS_DEVICE_TYPE
bool found_device = false;
auto begin = ctest_process_str;
auto comma = std::strchr(begin, ',');
while (comma) {
if (!std::strncmp(begin, ctest_kokkos_device_type, comma - begin)) {
std::string ctest_process_cxx_str = ctest_process_str;
std::istringstream instream(ctest_process_cxx_str);
while (true) {
std::string devName;
std::getline(instream, devName, ',');
if (devName == ctest_kokkos_device_type) {
found_device = true;
break;
}
begin = comma + 1;
comma = std::strchr(begin, ',');
}

// Check the last element (after the last comma)
if (!found_device && !strcmp(begin, ctest_kokkos_device_type)) {
found_device = true;
if (instream.eof() || devName.length() == 0) {
break;
}
}

if (!found_device) {
Expand All @@ -112,7 +111,7 @@ int get_ctest_gpu(const char* local_rank_str, const char* ctest_kokkos_device_ty
return 0;
}

const char* colon = std::strchr(resource_str, ',');
auto const* colon = std::strchr(resource_str, ',');
if (!colon || strncmp(resource_str, "id:", 3)) {
return 0;
}
Expand Down Expand Up @@ -158,12 +157,12 @@ setenv("MEMKIND_HBW_NODES", "1", 0);
const int skip_device = args.skip_device;
// if the exact device is not set, but ndevices was given, assign round-robin using on-node MPI rank
if (use_gpu < 0) {
auto local_rank_str = std::getenv("OMPI_COMM_WORLD_LOCAL_RANK"); //OpenMPI
auto const* local_rank_str = std::getenv("OMPI_COMM_WORLD_LOCAL_RANK"); //OpenMPI
if (!local_rank_str) local_rank_str = std::getenv("MV2_COMM_WORLD_LOCAL_RANK"); //MVAPICH2
if (!local_rank_str) local_rank_str = std::getenv("SLURM_LOCALID"); //SLURM

auto ctest_kokkos_device_type = std::getenv("CTEST_KOKKOS_DEVICE_TYPE"); //CTest
auto ctest_process_count_str = std::getenv("CTEST_PROCESS_COUNT"); //CTest
auto const* ctest_kokkos_device_type = std::getenv("CTEST_KOKKOS_DEVICE_TYPE"); //CTest
auto const* ctest_process_count_str = std::getenv("CTEST_PROCESS_COUNT"); //CTest
if (ctest_kokkos_device_type && ctest_process_count_str && local_rank_str) {
use_gpu = get_ctest_gpu(local_rank_str, ctest_kokkos_device_type, ctest_process_count_str);
} else if (ndevices >= 0) {
Expand Down

0 comments on commit a1b3ebe

Please sign in to comment.