Function opensn::BindDevice

Function Documentation

void opensn::BindDevice(MPI_Comm comm)

Selects the GPU that this MPI rank uses.

Ranks on a node that see the same set of GPUs, in any order, share them round-robin in node-local rank order. A scheduler or launcher that gives each rank its own GPUs, by restricting the GPUs a rank can see (for example with CUDA_VISIBLE_DEVICES, ROCR_VISIBLE_DEVICES or ONEAPI_DEVICE_SELECTOR), puts each rank in a set of its own, so the rank uses the first GPU it was given.

With CUDA or HIP, PETSc and OpenSn share the runtime’s current device, and PETSc selects its device while it initializes. When PETSc has a CUDA or HIP backend, this therefore sets its -device_select_cuda or -device_select_hip option, whichever matches that backend, to the selected device. Selecting a different PETSc device, for example through PETSC_OPTIONS, makes PETSc and OpenSn use different GPUs. With SYCL, PETSc keeps its own selection, which does not change the device OpenSn uses.

Call once per process, after MPI is initialized and before PetscInitialize or any GPU work. Collective over comm. Does nothing without GPU support or on a rank that sees no GPU. If listing or selecting the GPUs fails on any rank, every rank throws std::runtime_error after the collective calls. The message of a rank that failed names the rank and the cause.