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 #include <mpi.h>
45 
46 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 
48 namespace Foam
49 {
50 namespace PstreamGlobals
51 {
52 
53 // Track if MPI_Comm_free is needed for communicator index in MPICommunicators_
54 extern DynamicList<bool> pendingMPIFree_;
55 
56 // Current communicators, which may be allocated or predefined
57 // (eg, MPI_COMM_SELF, MPI_COMM_WORLD)
58 extern DynamicList<MPI_Comm> MPICommunicators_;
59 
60 //- Outstanding non-blocking operations.
61 extern DynamicList<MPI_Request> outstandingRequests_;
62 
63 
64 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
65 
66 //- Fatal if comm is outside the allocated range
67 void checkCommunicator(const label comm, const label toProcNo);
68 
69 
70 //- Reset UPstream::Request to null and/or the index of the outstanding
71 //- request to -1.
72 // Does not affect the stack of outstanding requests.
73 inline void reset_request
74 (
75  UPstream::Request* requestPtr,
76  label* requestIdx = nullptr
77 )
78 {
79  if (requestPtr) *requestPtr = UPstream::Request(MPI_REQUEST_NULL);
80  if (requestIdx) *requestIdx = -1;
81 }
82 
83 
84 //- Transcribe MPI_Request to UPstream::Request
85 //- (does not affect the stack of outstanding requests)
86 //- or else push onto list of outstanding requests
87 //- and (optionally) record its location
88 inline void push_request
89 (
90  MPI_Request request,
91  UPstream::Request* requestPtr = nullptr,
92  label* requestIdx = nullptr
93 )
94 {
95  if (requestPtr)
96  {
97  // Transcribe as UPstream::Request
98  *requestPtr = UPstream::Request(request);
99 
100  // Not on stack of outstanding requests
101  if (requestIdx) *requestIdx = -1;
102  }
103  else
104  {
105  if (requestIdx)
106  {
107  // Its index into outstanding requests
108  *requestIdx = PstreamGlobals::outstandingRequests_.size();
109  }
110 
111  PstreamGlobals::outstandingRequests_.push_back(request);
112  }
113 }
114 
115 
116 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
117 
118 } // End namespace PstreamGlobals
119 } // End namespace Foam
120 
121 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
122 
123 #endif
124 
125 // ************************************************************************* //
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:1571
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.