FreeFOAM The Cross-Platform CFD Toolkit
PstreamImpl.H
Go to the documentation of this file.
1 /*----------------------------------------------------------------------------*\
2  ______ _ ____ __ __
3  | ____| _| |_ / __ \ /\ | \/ |
4  | |__ _ __ ___ ___ / \| | | | / \ | \ / |
5  | __| '__/ _ \/ _ ( (| |) ) | | |/ /\ \ | |\/| |
6  | | | | | __/ __/\_ _/| |__| / ____ \| | | |
7  |_| |_| \___|\___| |_| \____/_/ \_\_| |_|
8 
9  FreeFOAM: The Cross-Platform CFD Toolkit
10 
11  Copyright (C) 2008-2012 Michael Wild <themiwi@users.sf.net>
12  Gerber van der Graaf <gerber_graaf@users.sf.net>
13 --------------------------------------------------------------------------------
14 License
15  This file is part of FreeFOAM.
16 
17  FreeFOAM is free software: you can redistribute it and/or modify it
18  under the terms of the GNU General Public License as published by the
19  Free Software Foundation, either version 3 of the License, or (at your
20  option) any later version.
21 
22  FreeFOAM is distributed in the hope that it will be useful, but WITHOUT
23  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
24  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25  for more details.
26 
27  You should have received a copy of the GNU General Public License
28  along with FreeFOAM. If not, see <http://www.gnu.org/licenses/>.
29 
30 Class
31  Foam::PstreamImpl
32 
33 Description
34  Abstract base class for Pstream operations that depend on the parallel
35  library used. Foam::PstreamImpl::New will lookup the entry
36  "PstreamImplementation" in the global controlDict file (i.e. the one
37  found by Foam::dotFoam) and tries to first load a library named
38  lib<PstreamImplementation>Pstream.so, and then instantiate the class
39  <PstreamImplementation>PstreamImpl.
40 
41 SourceFiles
42  PstreamImplI.H
43  PstreamImpl.C
44 
45 
46 \*----------------------------------------------------------------------------*/
47 
48 #ifndef PstreamImpl_H
49 #define PstreamImpl_H
50 
51 #include <OpenFOAM/autoPtr.H>
52 #include <OpenFOAM/typeInfo.H>
54 #include <OpenFOAM/ops.H>
55 
56 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
57 
58 namespace Foam
59 {
60 
61 namespace helper_
62 {
63 //- Helper class
65 {
66  //- Types of communications
68  {
72  };
73 };
74 } // namespace helper_
75 
76 /*---------------------------------------------------------------------------*\
77  Class PstreamImpl Declaration
78 \*---------------------------------------------------------------------------*/
79 
81 : public helper_::PstreamBase
82 {
83  // Private data
84 
85  //- The singleton instance
86  static autoPtr<PstreamImpl> instance_;
87 
88  // Private Member Functions
89 
90  //- Disallow default bitwise copy construct
91  PstreamImpl(const PstreamImpl&);
92 
93  //- Disallow default bitwise assignment
94  void operator=(const PstreamImpl&);
95 
96 protected:
97 
98  // Protected Member Functions
99 
100  //- Set data for parallel running
101  static void setParRun(bool& isParallel);
102 
103  //- Initialize all communication schedules. Callback from
104  // PstreamImpl::init()
105  static void initCommunicationSchedule();
106 
107 public:
108 
109  //- Types of communications
111 
112  // Declare name of the class and its debug switch
113  TypeName("PstreamImpl");
114 
115  // Declare run-time constructor selection table
116 
118  (
119  autoPtr,
120  PstreamImpl,
121  dictionary,
122  (),
123  ()
124  );
125 
126  // Constructors
127 
128  //- Construct null
130 
131  // Destructor
132 
133  virtual ~PstreamImpl() {}
134 
135  // Selectors
136 
137  //- Return a reference to the selected PstreamImpl implementation
138  static autoPtr<PstreamImpl> New();
139 
140  // Member Functions
141 
142  //- Add the valid option this type of communications library
143  // adds/requires on the command line
144  virtual void addValidParOptions(HashTable<string>& validParOptions) = 0;
145 
146  //- Initialisation function called from main
147  // Spawns slave processes and initialises inter-communication
148  virtual bool init(int& argc, char**& argv, int& myProcNo, List<int>& procIDs, bool& isParallel) = 0;
149 
150  //- Exit program
151  virtual void exit(int errnum) = 0;
152 
153  //- Abort program
154  virtual void abort() = 0;
155 
156  //- Reduce implementation for scalars (@sa PstreamReduceOps.H)
157  virtual void reduce(scalar& Value, const sumOp<scalar>& bop) = 0;
158 
159  //- Loads the Pstream implementation library
160  static void loadPstreamLibrary();
161 
162  //- Loads the given type from the Pstream implementation library
163  template<class T, class CTable>
165  (
166  const word& dictEntry,
167  const word& envName,
168  CTable* ctable
169  );
170 
171 
172  // Friends
173 
174  friend class Pstream;
175 
176 };
177 
178 
179 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
180 
181 } // End namespace Foam
182 
183 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
184 
185 #include <OpenFOAM/PstreamImplI.H>
186 
187 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
188 
189 #endif
190 
191 // ************************ vim: set sw=4 sts=4 et: ************************ //