Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
local_rank.cpp
Go to the documentation of this file.
1// -------------------------------------------------------//
2//
3// SHAMROCK code for hydrodynamics
4// Copyright (c) 2021-2026 Timothée David--Cléris <tim.shamrock@proton.me>
5// SPDX-License-Identifier: CeCILL Free Software License Agreement v2.1
6// Shamrock is licensed under the CeCILL 2.1 License, see LICENSE for more information
7//
8// -------------------------------------------------------//
9
19#include <optional>
20
21namespace shamcomm {
22 std::optional<u32> node_local_rank() {
23
24 if (MV2_COMM_WORLD_LOCAL_RANK) {
25 return std::atoi(MV2_COMM_WORLD_LOCAL_RANK->c_str());
26 }
27
28 if (OMPI_COMM_WORLD_LOCAL_RANK) {
29 return std::atoi(OMPI_COMM_WORLD_LOCAL_RANK->c_str());
30 }
31
32 if (MPI_LOCALRANKID) {
33 return std::atoi(MPI_LOCALRANKID->c_str());
34 }
35
36 if (SLURM_PROCID) {
37 return std::atoi(SLURM_PROCID->c_str());
38 }
39
40 if (LOCAL_RANK) {
41 return std::atoi(LOCAL_RANK->c_str());
42 }
43
44 if (PALS_LOCAL_RANKID) {
45 return std::atoi(PALS_LOCAL_RANKID->c_str());
46 }
47
48 return {};
49 }
50
51 bool is_main_node_rank(u32 main_local_rank_id) {
52 auto loc_r = node_local_rank();
53 return (loc_r) ? *loc_r == main_local_rank_id : true;
54 }
55
56} // namespace shamcomm
std::uint32_t u32
32 bit unsigned integer
namespace for communication related stuff