https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Functions
MooseInit.C File Reference

Go to the source code of this file.

Functions

void SigHandler (int signum)
 
void RegisterSigHandler ()
 
int getLocalRank ()
 
void initializeCuda ()
 

Function Documentation

◆ getLocalRank()

int getLocalRank ( )

Definition at line 53 of file MooseInit.C.

54{
55 static constexpr std::array local_rank_vars{
56 "OMPI_COMM_WORLD_LOCAL_RANK", // Open MPI
57 "MV2_COMM_WORLD_LOCAL_RANK", // MVAPICH2
58 "MPI_LOCALRANKID", // Intel MPI / some MPICH environments
59 "PMI_LOCAL_RANK", // PMI-based launchers
60 "PALS_LOCAL_RANKID", // HPE Cray PALS
61 "SLURM_LOCALID", // Slurm
62 "FLUX_TASK_LOCAL_ID" // Flux
63 };
64
65 for (const char * variable : local_rank_vars)
66 {
67 const char * value = std::getenv(variable);
68 if (!value)
69 continue;
70
71 int rank;
72 const char * end = value + std::char_traits<char>::length(value);
73 const auto [ptr, error] = std::from_chars(value, end, rank);
74
75 if (error != std::errc{} || ptr != end || rank < 0)
76 throw std::runtime_error(std::string("Invalid local rank in ") + variable + ": " + value);
77
78 return rank;
79 }
80
81 // Not launched through a recognized MPI/process-manager environment.
82 return 0;
83}
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)

Referenced by initializeCuda().

◆ initializeCuda()

void initializeCuda ( )

NOTE: Some GPU-aware MPI implementations initialize accelerator-related resources during MPI_Init() and may associate those resources with the device that is current at that time. Therefore, select the GPU device before MPI initialization.

Open MPI explicitly recommends selecting the accelerator before MPI_Init(), using OMPI_COMM_WORLD_LOCAL_RANK for per-node device assignment. In particular, we have observed that failing to do so can prevent initialization of the smcuda BTL (the transfer component for fast shared-memory GPU communication), causing GPU communication to fall back to a much slower PCI path instead of using NVLink, with over 100x performance difference in some cases. MVAPICH2 also supports selecting the CUDA device before MPI_Init() using MV2_COMM_WORLD_LOCAL_RANK. MPICH does not appear to require early device selection, but initializing the GPU runtime before MPI_Init() is expected to be harmless.

The mapping used here (local_rank % num_gpus) is intended to establish the device used by Kokkos. It is not yet known whether this mapping is appropriate for other GPU packages supported by MOOSE.

TODO: Add HIP and SYCL device selection if needed.

Definition at line 87 of file MooseInit.C.

88{
89 int local_rank = getLocalRank();
90
111 int num_gpus = 0;
112 cudaGetDeviceCount(&num_gpus);
113
114 if (num_gpus)
115 {
116 int device = local_rank % num_gpus;
117 cudaSetDevice(device);
118 }
119}
int getLocalRank()
Definition MooseInit.C:53

Referenced by MooseDeviceInit::MooseDeviceInit().

◆ RegisterSigHandler()

void RegisterSigHandler ( )

Definition at line 47 of file MooseInit.C.

48{
49 signal(SIGUSR1, SigHandler);
50}
void SigHandler(int signum)
Definition MooseInit.C:40

Referenced by MooseInit::MooseInit().

◆ SigHandler()

void SigHandler ( int  signum)

Definition at line 40 of file MooseInit.C.

41{
43 return;
44}
volatile std::sig_atomic_t interrupt_signal_number
Used by the signal handler to determine if we should write a checkpoint file out at any point during ...
Definition Moose.C:928

Referenced by RegisterSigHandler().