PstreamGlobals.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) 2013-2015 OpenFOAM Foundation
9  Copyright (C) 2022-2023 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Namespace
28  Foam::PstreamGlobals
29 
30 Description
31  Global functions and variables for working with parallel streams,
32  but principally for MPI.
33 
34 SourceFiles
35  PstreamGlobals.C
36 
37 \*---------------------------------------------------------------------------*/
38 
39 #ifndef Foam_PstreamGlobals_H
40 #define Foam_PstreamGlobals_H
41 
42 #include "DynamicList.H"
43 #include "UPstream.H" // for UPstream::Request
44 
45 // Include MPI without any C++ bindings
46 #ifndef MPICH_SKIP_MPICXX
47 #define MPICH_SKIP_MPICXX
48 #endif
49 #ifndef OMPI_SKIP_MPICXX
50 #define OMPI_SKIP_MPICXX
51 #endif
52 #include <mpi.h>
53 
54 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
55 
56 namespace Foam
57 {
58 namespace PstreamGlobals
59 {
60 
61 // Track if MPI_Comm_free is needed for communicator index in MPICommunicators_
62 extern DynamicList<bool> pendingMPIFree_;
63 
64 // Current communicators, which may be allocated or predefined
65 // (eg, MPI_COMM_SELF, MPI_COMM_WORLD)
66 extern DynamicList<MPI_Comm> MPICommunicators_;
67 
68 //- Outstanding non-blocking operations.
69 extern DynamicList<MPI_Request> outstandingRequests_;
70 
71 
72 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
73 
74 //- Fatal if comm is outside the allocated range
75 void checkCommunicator(const label comm, const label toProcNo);
76 
77 
78 //- Reset UPstream::Request to null and/or the index of the outstanding
79 //- request to -1.
80 // Does not affect the stack of outstanding requests.
81 inline void reset_request
82 (
83  UPstream::Request* requestPtr,
84  label* requestIdx = nullptr
85 )
86 {
87  if (requestPtr) *requestPtr = UPstream::Request(MPI_REQUEST_NULL);
88  if (requestIdx) *requestIdx = -1;
89 }
90 
91 
92 //- Transcribe MPI_Request to UPstream::Request
93 //- (does not affect the stack of outstanding requests)
94 //- or else push onto list of outstanding requests
95 //- and (optionally) record its location
96 inline void push_request
97 (
98  MPI_Request request,
99  UPstream::Request* requestPtr = nullptr,
100  label* requestIdx = nullptr
101 )
102 {
103  if (requestPtr)
104  {
105  // Transcribe as UPstream::Request
106  *requestPtr = UPstream::Request(request);
107 
108  // Not on stack of outstanding requests
109  if (requestIdx) *requestIdx = -1;
110  }
111  else
112  {
113  if (requestIdx)
114  {
115  // Its index into outstanding requests
116  *requestIdx = PstreamGlobals::outstandingRequests_.size();
117  }
118 
119  PstreamGlobals::outstandingRequests_.push_back(request);
120  }
121 }
122 
123 
124 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
125 
126 } // End namespace PstreamGlobals
127 } // End namespace Foam
128 
129 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
130 
131 #endif
132 
133 // ************************************************************************* //
DynamicList< MPI_Request > outstandingRequests_
Outstanding non-blocking operations.
DynamicList< MPI_Comm > MPICommunicators_
void reset_request(UPstream::Request *requestPtr, label *requestIdx=nullptr)
Reset UPstream::Request to null and/or the index of the outstanding request to -1.
void checkCommunicator(const label comm, const label toProcNo)
Fatal if comm is outside the allocated range.
DynamicList< bool > pendingMPIFree_
An opaque wrapper for MPI_Request with a vendor-independent representation independent of any <mpi...
Definition: UPstream.H:1573
void push_request(MPI_Request request, UPstream::Request *requestPtr=nullptr, label *requestIdx=nullptr)
Transcribe MPI_Request to UPstream::Request (does not affect the stack of outstanding requests) or el...
Namespace for OpenFOAM.