Loading...
Searching...
No Matches
openfoam_mpi.H
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2022-2025 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26Description
27 Header for low-level interfaces between MPI and OpenFOAM.
28 The detail interfaces are subject to change.
29
30\*---------------------------------------------------------------------------*/
31
32#ifndef Foam_UPstreamMPI_H
33#define Foam_UPstreamMPI_H
35#include "UPstream.H"
36#include "UPstreamWindow.H"
38// Include MPI without any C++ bindings
39#ifndef MPICH_SKIP_MPICXX
40#define MPICH_SKIP_MPICXX
41#endif
42#ifndef OMPI_SKIP_MPICXX
43#define OMPI_SKIP_MPICXX
44#endif
45#include <mpi.h>
46
47// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48
49namespace Foam
50{
51namespace PstreamUtils
52{
53
54// Casting helpers
55struct Cast
56{
57 //- Cast UPstream::Communicator to MPI_Comm
58 template<typename Type = MPI_Comm>
59 static Type to_mpi(UPstream::Communicator arg) noexcept
60 {
61 if constexpr (std::is_pointer_v<Type>)
62 {
63 return reinterpret_cast<Type>(arg.value());
64 }
65 else // std::is_integral_v<Type>
66 {
67 return static_cast<Type>(arg.value());
68 }
69 }
70
71 //- Cast UPstream::Request to MPI_Request
72 template<typename Type = MPI_Request>
73 static Type to_mpi(UPstream::Request arg) noexcept
74 {
75 if constexpr (std::is_pointer_v<Type>)
76 {
77 return reinterpret_cast<Type>(arg.value());
78 }
79 else // std::is_integral_v<Type>
80 {
81 return static_cast<Type>(arg.value());
82 }
83 }
84
85 //- Cast UPstream::Window to MPI_Win
86 template<typename Type = MPI_Win>
87 static Type to_mpi(UPstream::Window arg) noexcept
88 {
89 if constexpr (std::is_pointer_v<Type>)
90 {
91 return reinterpret_cast<Type>(arg.value());
92 }
93 else // std::is_integral_v<Type>
94 {
95 return static_cast<Type>(arg.value());
96 }
97 }
98};
99
100
101// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
102
103} // End namespace PstreamUtils
104} // End namespace Foam
105
106// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
107
108#endif
109
110// ************************************************************************* //
An opaque wrapper for MPI_Comm with a vendor-independent representation without any <mpi....
Definition UPstream.H:2760
value_type value() const noexcept
Return raw value.
Definition UPstream.H:2877
An opaque wrapper for MPI_Request with a vendor-independent representation without any <mpi....
Definition UPstream.H:2919
An opaque wrapper for MPI_Win with a vendor-independent representation and without any <mpi....
Interface handling for UPstream/Pstream/MPI etc.
Definition UPstream.H:62
Namespace for OpenFOAM.
static Type to_mpi(UPstream::Communicator arg) noexcept
Cast UPstream::Communicator to MPI_Comm.
static Type to_mpi(UPstream::Request arg) noexcept
Cast UPstream::Request to MPI_Request.
static Type to_mpi(UPstream::Window arg) noexcept
Cast UPstream::Window to MPI_Win.