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 -------------------------------------------------------------------------------
10 License
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 
26 Description
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
34 
35 #include "UPstream.H"
36 
37 // Include MPI without any C++ bindings
38 #ifndef MPICH_SKIP_MPICXX
39 #define MPICH_SKIP_MPICXX
40 #endif
41 #ifndef OMPI_SKIP_MPICXX
42 #define OMPI_SKIP_MPICXX
43 #endif
44 #include <mpi.h>
45 
46 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 
48 namespace Foam
49 {
50 namespace PstreamUtils
51 {
52 
53 // Casting helpers
54 struct Cast
55 {
56  //- Cast UPstream::Communicator to MPI_Comm
57  template<typename Type = MPI_Comm>
58  static Type to_mpi(UPstream::Communicator arg) noexcept
59  {
60  if constexpr (std::is_pointer_v<Type>)
61  {
62  return reinterpret_cast<Type>(arg.value());
63  }
64  else // std::is_integral_v<Type>
65  {
66  return static_cast<Type>(arg.value());
67  }
68  }
69 
70  //- Cast UPstream::Request to MPI_Request
71  template<typename Type = MPI_Request>
72  static Type to_mpi(UPstream::Request arg) noexcept
73  {
74  if constexpr (std::is_pointer_v<Type>)
75  {
76  return reinterpret_cast<Type>(arg.value());
77  }
78  else // std::is_integral_v<Type>
79  {
80  return static_cast<Type>(arg.value());
81  }
82  }
83 
84  //- Cast UPstream::Window to MPI_Win
85  template<typename Type = MPI_Win>
86  static Type to_mpi(UPstream::Window arg) noexcept
87  {
88  if constexpr (std::is_pointer_v<Type>)
89  {
90  return reinterpret_cast<Type>(arg.value());
91  }
92  else // std::is_integral_v<Type>
93  {
94  return static_cast<Type>(arg.value());
95  }
96  }
97 };
98 
99 
100 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
101 
102 } // End namespace PstreamUtils
103 } // End namespace Foam
104 
105 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
106 
107 #endif
108 
109 // ************************************************************************* //
An opaque wrapper for MPI_Comm with a vendor-independent representation without any <mpi...
Definition: UPstream.H:2451
An opaque wrapper for MPI_Win with a vendor-independent representation and without any <mpi...
static Type to_mpi(UPstream::Communicator arg) noexcept
Cast UPstream::Communicator to MPI_Comm.
Definition: openfoam_mpi.H:54
static Type to_mpi(UPstream::Window arg) noexcept
Cast UPstream::Window to MPI_Win.
Definition: openfoam_mpi.H:86
An opaque wrapper for MPI_Request with a vendor-independent representation without any <mpi...
Definition: UPstream.H:2599
value_type value() const noexcept
Return raw value.
Definition: UPstream.H:2561
const direction noexcept
Definition: scalarImpl.H:255
Namespace for OpenFOAM.