Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
mpiInfo.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
16
19#include "fmt/core.h"
20#include "shamcomm/logs.hpp"
21#include "shamcomm/mpi.hpp"
22#include "shamcomm/mpiInfo.hpp"
24
25namespace shamcomm {
26
35
44
51 bool fetched = false;
52
54 if (!fetched) {
56 "MPI capabilities have not been fetched yet");
57 }
58 return mpi_cuda_aware;
59 }
60
62 if (!fetched) {
64 "MPI capabilities have not been fetched yet");
65 }
66 return mpi_rocm_aware;
67 }
68
69 std::optional<StateMPI_Aware> _forced_state;
70
71 void fetch_mpi_capabilities(std::optional<StateMPI_Aware> forced_state) {
72
73 _forced_state = forced_state;
74
75 logs::debug_ln("Comm", "fetching mpi capabilities...");
76#ifdef FOUND_MPI_EXT
77 logs::debug_mpi_ln("Comm", "FOUND_MPI_EXT is defined");
78 // detect MPI cuda aware
79 #if defined(MPIX_CUDA_AWARE_SUPPORT)
80 logs::debug_mpi_ln("Comm", "MPIX_CUDA_AWARE_SUPPORT is defined");
81 if (1 == MPIX_Query_cuda_support()) {
83 } else {
85 }
86 #else /* !defined(MPIX_CUDA_AWARE_SUPPORT) */
88 #endif /* MPIX_CUDA_AWARE_SUPPORT */
89
90 // detect MPI rocm aware
91 #if defined(MPIX_ROCM_AWARE_SUPPORT)
92 logs::debug_mpi_ln("Comm", "MPIX_ROCM_AWARE_SUPPORT is defined");
93 if (1 == MPIX_Query_rocm_support()) {
95 } else {
97 }
98 #else /* !defined(MPIX_ROCM_AWARE_SUPPORT) */
100 #endif /* MPIX_ROCM_AWARE_SUPPORT */
101#else
104#endif
105
106 if (forced_state) {
107 mpi_cuda_aware = *forced_state;
108 mpi_rocm_aware = *forced_state;
109 }
110
111 fetched = true;
112 }
113
114 std::optional<StateMPI_Aware> should_force_dgpu_state() { return _forced_state; }
115
117 using namespace shambase::term_colors;
118
119 auto print_state = [](const std::string &log, StateMPI_Aware state) {
120 switch (mpi_cuda_aware) {
121 case Yes: logs::print_ln(" - " + log + " :", col8b_green() + "Yes" + reset()); break;
122 case No : logs::print_ln(" - " + log + " :", col8b_red() + "No" + reset()); break;
123 case Unknown:
124 logs::print_ln(" - " + log + " :", col8b_yellow() + "Unknown" + reset());
125 break;
126 case ForcedYes:
127 logs::print_ln(" - " + log + " :", col8b_yellow() + "Forced Yes" + reset());
128 break;
129 case ForcedNo:
130 logs::print_ln(" - " + log + " :", col8b_yellow() + "Forced No" + reset());
131 break;
132 }
133 };
134
135 print_state("MPI CUDA-AWARE ", mpi_cuda_aware);
136 print_state("MPI ROCM-AWARE ", mpi_rocm_aware);
137
138 if (_forced_state) {
139 print_state("MPI Forced DGPU ", *_forced_state);
140 }
141 }
142
144 logs::print_ln(" - World size :", world_size());
145 logs::print_ln(" - MPI max tag :", mpi_max_tag_value());
146 }
147
148 std::string get_process_name() {
149
150 // Get the name of the processor
151 char processor_name[MPI_MAX_PROCESSOR_NAME];
152 int name_len;
153
154 int err_code = MPI_Get_processor_name(processor_name, &name_len);
155
156 if (err_code != MPI_SUCCESS) {
157 shambase::throw_with_loc<std::runtime_error>("failed getting the process name");
158 }
159
160 return {processor_name};
161 }
162} // namespace shamcomm
This header file contains utility functions related to exception handling in the code.
Provide information about MPI capabilities.
Use this header to include MPI properly.
void print_ln()
Prints a log message with multiple arguments followed by a newline.
void throw_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Throw an exception and append the source location to it.
namespace for communication related stuff
void print_mpi_comm_info()
Print the MPI communicator infos.
Definition mpiInfo.cpp:143
StateMPI_Aware mpi_rocm_aware
MPI ROCm aware capability.
Definition mpiInfo.cpp:43
StateMPI_Aware
Enum to describe the MPI capabilities.
Definition mpiInfo.hpp:28
@ ForcedYes
Feature forced on by the user.
Definition mpiInfo.hpp:44
@ Unknown
The MPI implementation does not if the feature is supported.
Definition mpiInfo.hpp:32
@ ForcedNo
Feature forced off by the user.
Definition mpiInfo.hpp:48
@ No
The MPI implementation does not support the feature.
Definition mpiInfo.hpp:40
@ Yes
The MPI implementation supports the feature.
Definition mpiInfo.hpp:36
std::optional< StateMPI_Aware > should_force_dgpu_state()
Should DGPU should be forced.
Definition mpiInfo.cpp:114
i32 world_size()
Gives the size of the MPI communicator.
Definition worldInfo.cpp:39
i32 mpi_max_tag_value()
Gets the maximum value of the MPI tag.
Definition worldInfo.cpp:37
void fetch_mpi_capabilities(std::optional< StateMPI_Aware > forced_state)
Fetch the MPI capabilities.
Definition mpiInfo.cpp:71
StateMPI_Aware get_mpi_cuda_aware_status()
Get the MPI CUDA aware capability.
Definition mpiInfo.cpp:53
std::string get_process_name()
Get the process name.
Definition mpiInfo.cpp:148
StateMPI_Aware get_mpi_rocm_aware_status()
Get the MPI ROCM aware capability.
Definition mpiInfo.cpp:61
void print_mpi_capabilities()
Print the MPI capabilities.
Definition mpiInfo.cpp:116
bool fetched
Has the MPI capabilities been fetched?
Definition mpiInfo.cpp:51
StateMPI_Aware mpi_cuda_aware
MPI CUDA aware capability.
Definition mpiInfo.cpp:34
void debug_mpi_ln(std::string module_name, Types... var2)
Prints a log message with multiple arguments followed by a newline.
Definition logs.hpp:132
void debug_ln(std::string module_name, Types... var2)
Prints a log message with multiple arguments followed by a newline.
Definition logs.hpp:132
const std::string reset()
Get the reset terminal escape char.
const std::string col8b_yellow()
Get the yellow terminal escape char.
const std::string col8b_green()
Get the green terminal escape char.
const std::string col8b_red()
Get the red terminal escape char.
Functions related to the MPI communicator.