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
18#include "fmt/core.h"
19#include "shamcomm/logs.hpp"
20#include "shamcomm/mpi.hpp"
21#include "shamcomm/mpiInfo.hpp"
23
24namespace shamcomm {
25
34
43
50 bool fetched = false;
51
53 if (!fetched) {
55 "MPI capabilities have not been fetched yet");
56 }
57 return mpi_cuda_aware;
58 }
59
61 if (!fetched) {
63 "MPI capabilities have not been fetched yet");
64 }
65 return mpi_rocm_aware;
66 }
67
68 std::optional<StateMPI_Aware> _forced_state;
69
70 void fetch_mpi_capabilities(std::optional<StateMPI_Aware> forced_state) {
71
72 _forced_state = forced_state;
73
74 logs::debug_ln("Comm", "fetching mpi capabilities...");
75#ifdef FOUND_MPI_EXT
76 logs::debug_mpi_ln("Comm", "FOUND_MPI_EXT is defined");
77 // detect MPI cuda aware
78 #if defined(MPIX_CUDA_AWARE_SUPPORT)
79 logs::debug_mpi_ln("Comm", "MPIX_CUDA_AWARE_SUPPORT is defined");
80 if (1 == MPIX_Query_cuda_support()) {
82 } else {
84 }
85 #else /* !defined(MPIX_CUDA_AWARE_SUPPORT) */
87 #endif /* MPIX_CUDA_AWARE_SUPPORT */
88
89 // detect MPI rocm aware
90 #if defined(MPIX_ROCM_AWARE_SUPPORT)
91 logs::debug_mpi_ln("Comm", "MPIX_ROCM_AWARE_SUPPORT is defined");
92 if (1 == MPIX_Query_rocm_support()) {
94 } else {
96 }
97 #else /* !defined(MPIX_ROCM_AWARE_SUPPORT) */
99 #endif /* MPIX_ROCM_AWARE_SUPPORT */
100#else
103#endif
104
105 if (forced_state) {
106 mpi_cuda_aware = *forced_state;
107 mpi_rocm_aware = *forced_state;
108 }
109
110 fetched = true;
111 }
112
113 std::optional<StateMPI_Aware> should_force_dgpu_state() { return _forced_state; }
114
116 using namespace shambase::term_colors;
117
118 auto print_state = [](const std::string &log, StateMPI_Aware state) {
119 switch (mpi_cuda_aware) {
120 case Yes: logs::print_ln(" - " + log + " :", col8b_green() + "Yes" + reset()); break;
121 case No : logs::print_ln(" - " + log + " :", col8b_red() + "No" + reset()); break;
122 case Unknown:
123 logs::print_ln(" - " + log + " :", col8b_yellow() + "Unknown" + reset());
124 break;
125 case ForcedYes:
126 logs::print_ln(" - " + log + " :", col8b_yellow() + "Forced Yes" + reset());
127 break;
128 case ForcedNo:
129 logs::print_ln(" - " + log + " :", col8b_yellow() + "Forced No" + reset());
130 break;
131 }
132 };
133
134 print_state("MPI CUDA-AWARE ", mpi_cuda_aware);
135 print_state("MPI ROCM-AWARE ", mpi_rocm_aware);
136
137 if (_forced_state) {
138 print_state("MPI Forced DGPU ", *_forced_state);
139 }
140 }
141
143 logs::print_ln(" - World size :", world_size());
144 logs::print_ln(" - MPI max tag :", mpi_max_tag_value());
145 }
146
147 std::string get_process_name() {
148
149 // Get the name of the processor
150 char processor_name[MPI_MAX_PROCESSOR_NAME];
151 int name_len;
152
153 int err_code = MPI_Get_processor_name(processor_name, &name_len);
154
155 if (err_code != MPI_SUCCESS) {
156 shambase::throw_with_loc<std::runtime_error>("failed getting the process name");
157 }
158
159 return {processor_name};
160 }
161} // namespace shamcomm
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:142
StateMPI_Aware mpi_rocm_aware
MPI ROCm aware capability.
Definition mpiInfo.cpp:42
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:113
i32 world_size()
Gives the size of the MPI communicator.
Definition worldInfo.cpp:38
i32 mpi_max_tag_value()
Gets the maximum value of the MPI tag.
Definition worldInfo.cpp:36
void fetch_mpi_capabilities(std::optional< StateMPI_Aware > forced_state)
Fetch the MPI capabilities.
Definition mpiInfo.cpp:70
StateMPI_Aware get_mpi_cuda_aware_status()
Get the MPI CUDA aware capability.
Definition mpiInfo.cpp:52
std::string get_process_name()
Get the process name.
Definition mpiInfo.cpp:147
StateMPI_Aware get_mpi_rocm_aware_status()
Get the MPI ROCM aware capability.
Definition mpiInfo.cpp:60
void print_mpi_capabilities()
Print the MPI capabilities.
Definition mpiInfo.cpp:115
bool fetched
Has the MPI capabilities been fetched?
Definition mpiInfo.cpp:50
StateMPI_Aware mpi_cuda_aware
MPI CUDA aware capability.
Definition mpiInfo.cpp:33
Functions related to the MPI communicator.