OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
IpplInfo.h
Go to the documentation of this file.
1 //
2 // IpplInfo has the following capabilities:
3 // 1) It initializes all globally-used Ippl variables, such as the
4 // Communicate class and other manager classes;
5 // 2) It parses command-line arguments to determine how to configure the
6 // global state of the Ippl application;
7 // 3) It properly selects and configures the Communicate class, generally
8 // resulting in initialization of the parallel machine;
9 // 4) It offers to the user a single class with access member functions to
10 // query for information about the Ippl application (such as what is
11 // the Communicate class instance to use, how many processors are there
12 // in the current run, etc.)
13 //
14 // Copyright (c) 2008 - 2020, Paul Scherrer Institut, Villigen PSI, Switzerland
15 //
16 // All rights reserved
17 //
18 // This file is part of OPAL.
19 //
20 // OPAL is free software: you can redistribute it and/or modify
21 // it under the terms of the GNU General Public License as published by
22 // the Free Software Foundation, either version 3 of the License, or
23 // (at your option) any later version.
24 //
25 // You should have received a copy of the GNU General Public License
26 // along with OPAL. If not, see <https://www.gnu.org/licenses/>.
27 //
28 #ifndef IPPL_INFO_H
29 #define IPPL_INFO_H
30 
31 /*
32  * The globally-available Ippl objects are (available via IpplInfo::variable)
33  * Communicate *Comm ....... parallel communication object
34  * Inform *Info ............ used to print out informative messages
35  * Inform *Warn ............ used to print out warning messages
36  * Inform *Error ........... used to print out error messages
37  * Inform *Debug ........... used to print out debugging messages
38  *
39  * Note that you should use the following macros to access the Inform objects,
40  * so that these messages may be left out at compile time:
41  * INFOMSG("This is some information " << 34 << endl);
42  * WARNMSG("This is a warning " << 34 << endl);
43  * ERRORMSG("This is an error message " << 34 << endl);
44  *
45  * There is also a 'typedef IpplInfo Ippl' here, so you can simply use
46  * the name 'Ippl' instead of the longer 'IpplInfo' to access this class.
47  * 'Ippl' is in fact preferred, as it is shorter.
48  */
49 
50 // include files
51 #include "Utility/StaticIpplInfo.h"
52 #include "Utility/Inform.h"
53 
54 #include <iostream>
55 #include <stack>
56 
57 //FIXME: Including this header here (regardless of the used commlib) here is
58 //necessary to enable IPPL to work on a user define communicator group
59 //(without further increasing the number of defines).
60 #include <mpi.h>
61 
62 // forward declarations
63 class Communicate;
64 class IpplStats;
65 class IpplInfo;
66 std::ostream& operator<<(std::ostream&, const IpplInfo&);
67 
68 
69 class IpplInfo {
70 
71 public:
72  // an enumeration used to indicate whether to KEEP command-line arguments
73  // or REMOVE them
74  enum { KEEP = 0, REMOVE = 1 };
75 
76  // Inform object to use to print messages to the console (or even to a
77  // file if requested)
78  static Inform *Info;
79  static Inform *Warn;
80  static Inform *Error;
81  static Inform *Debug;
82 
83  // the parallel communication object
84  static Communicate *Comm;
85 
86  // the statistics collection object
87  static IpplStats *Stats;
88 
89 
90  // Constructor 1: specify the argc, argv values from the cmd line.
91  // The second argument controls whether the IPPL-specific command line
92  // arguments are stripped out (the default) or left in (if the setting
93  // is IpplInfo::KEEP).
94  IpplInfo(int&, char** &, int removeargs = REMOVE, MPI_Comm mpicomm = MPI_COMM_WORLD);
95 
96  // Constructor 2: default constructor. This will not change anything in
97  // how the static data members are set up. This is useful for declaring
98  // automatic IpplInfo instances in functions after IpplInfo.has been
99  // initially created in the main() routine.
100  IpplInfo();
101 
102  // Constructor 3: copy constructor. This will only copy non-static members
103  // (obviously), if any exist.
104  IpplInfo(const IpplInfo&);
105 
106  // Destructor.
107  ~IpplInfo();
108 
109  // Overload the = operator; does the same thing as the copy constructor.
110  IpplInfo& operator=(const IpplInfo&);
111 
112 
113  /* NOTE: The following initialize/finalize methods have not yet been
114  implemented. Add them to IpplInfo.cpp if they are needed (bfh).
115  //
116  // Initialize and finalize routines ... initialize can be used if you
117  // created IpplInfo with the default constructor, and finalize() can
118  // be used to shut down IPPL and possibly exit the program
119  //
120 
121  // initialize ourselves, if we have not yet done so, by parsing the
122  // command-line args and creating the Communication object. This should
123  // be called by all the currently-running nodes.
124  void initialize(int &, char ** &);
125 
126  // shut down the communication, and possibly exit. This should be called
127  // by all the nodes, it will not work if it is called by just one node
128  // and you are running in parallel (in that case, the Communicate subclass
129  // destructor will hang).
130  void finalize();
131 
132  // a version of finalize that will also shut down all the machines via
133  // a call to exit()
134  void finalize(int exitcode);
135  */
136 
137 
138  //
139  // Standard IPPL action methods (such as abort, etc)
140  //
141 
142  // Kill the communication and throw runtime error exception.
143  static void abort(const char * = 0);
144 
145  // Signal to ALL the nodes to abort and throw runtime error exception
146  static void abortAllNodes(const char * = 0);
147 
148  //
149  // Functions which return information about the current Ippl application.
150  //
151 
152  static MPI_Comm getComm() {return communicator_m;}
153 
154  // Return the number of the 'current' node.
155  static int myNode();
156 
157  // Return the current number of nodes working in parallel, where
158  // each node may have more than one processor. A 'Node' is basically
159  // considered as an entity which has a single IP address.
160  static int getNodes();
161 
162  // Return the number of contexts on a given node N. A 'Context' is
163  // considered to be a single addressable memory space; for shared memory
164  // machines, this could be the whole machine or one of many separate sections
165  // each being treated as distinct from the others.
166  static int getContexts(int);
167 
168  // Return the number of processes which are actively working on node N in
169  // context C. A 'Process' is not necessarily one in the strict Unix sense; it
170  // could be a lightweight thread or indeed a full process. These numbers
171  // may dynamically change.
172  static int getProcesses(int, int);
173 
174  // getSMPs: return number of SMP's (each of which may be running
175  // several processes)
176  static int getSMPs();
177 
178  // getSMPNodes: return number of nodes on the SMP with the given index
179  static int getSMPNodes(int);
180 
181  // mySMP: return ID of my SMP (numbered 0 ... getSMPs() - 1)
182  static int mySMP();
183 
184  // mySMPNode: return relative node number within the nodes on our SMP
185  static int mySMPNode();
186 
187  // Return argc or argv as provided in the initialization
188  static int getArgc() { return MyArgc; }
189  static char **getArgv() { return MyArgv; }
190 
191  // return true if we should use checksums on messages
192  static bool useChecksums() { return UseChecksums; }
193 
194  // return true if we should try to retransmit messages on error
195  static bool retransmit() { return (UseChecksums && Retransmit); }
196 
197  // Static data about a limit to the number of nodes that should be used
198  // in FFT operations. If this is <= 0 or > number of nodes, it is ignored.
199  static int maxFFTNodes() { return MaxFFTNodes; }
200 
201  // Return the "read chunk size", the number of bytes that will be
202  // read in, at max, for most Disc read operations. If the final
203  // character is 'K', 'M', or 'G', the number will mean the number
204  // of kilobytes, megabytes, or gigabytes. The default is one MB. If
205  // this is <= 0, then no limit should be used.
206  static int chunkSize() { return ChunkSize; }
207 
208  // Return boolean setting for whether we should attempt to use parallel
209  // I/O within a single SMP, for example by having multipple processors
210  // try to read from a single file (vs just having one node do it).
211  static bool perSMPParallelIO() { return PerSMPParallelIO; }
212 
213  //
214  // Functions which return information about the Ippl library
215  //
216 
217  // printVersion: print out a version summary. If the argument is true,
218  // print out a detailed listing, otherwise a summary.
219  static void printVersion(void);
220 
221  static void printHelp();
222 
223  // version: return the name of this version of Ippl, as a string
224  // (from IpplVersions.h)
225  static const char *version();
226 
227  // compileArch: return the architecture on which this library was built
228  // (from IpplVersions.h)
229  static const char *compileArch();
230 
231  // compileDate: return the date on which this library was prepared for
232  // compilation (from IpplVersions.h)
233  static const char *compileDate();
234 
235  // compileLine: return the compiler command used to compile each source file
236  // (from IpplVersions.h)
237  static const char *compileLine();
238 
239  // compileMachine: return the machine on which this library was
240  // compiled (from IpplVersions.h)
241  static const char *compileMachine();
242 
243  // compileOptions: return the option list used to compile this library
244  // (from IpplVersions.h)
245  static const char *compileOptions();
246 
247  // compileUser: return the username of the user who compiled this
248  // library (from IpplVersions.h)
249  static const char *compileUser();
250 
251  // stash all static members
252  static void stash();
253 
254  // restore all static members
255  static void pop();
256 
257  // Static flag telling whether to use optimization for reducing
258  // communication by deferring guard cell fills.
259  static bool deferGuardCellFills;
260 
261  // Static flag telling whether to turn off compression in the Field classes.
262  static bool noFieldCompression;
263 
264  // Static flag telling whether to try to (pseudo-)randomly offset the
265  // LField blocks to try to avoid cache conflicts.
266  static bool offsetStorage;
267 
268  // Static flag telling whether to try to do a TryCompress after each
269  // individual LField has been processed in an expression.
270  static bool extraCompressChecks;
271 
272  // Static routine giving one a place to stop at with #$%$%#1 stupid
273  // debuggers.
274  static void here();
275 
276  // print out statistics to the given Inform stream
277  static void printStatistics(Inform&);
278 
279  static void instantiateGlobals();
280  static void deleteGlobals();
281 private:
282 
283  static MPI_Comm communicator_m;
284 
285  // Static counter indicating how many IpplInit objects have been created.
286  // When this gets back to zero, it's time to delete the Comm and quit.
287  static int NumCreated;
288 
289  // Static flag indicating whether this class has been created with
290  // argc,argv specified ever. This should only be done once.
291  static bool CommInitialized;
292 
293  // Static flag indicating whether we should print out stats info at the
294  // end of the program.
295  static bool PrintStats;
296 
297  // Static flag indicating if we need to delete the comm object at the end.
298  static bool NeedDeleteComm;
299 
300  // Static flag indicating whether to use checksums on messages
301  static bool UseChecksums;
302 
303  // Static flag indicating whether to retransmit messages when errors occur
304  static bool Retransmit;
305 
306  // Static data with argc and argv
307  static int MyArgc;
308  static char **MyArgv;
309 
310  // Static data with my node number and total number of nodes. These are
311  // only changed when a new Communicate object is created.
312  static int MyNode;
313  static int TotalNodes;
314 
315  // Static data with SMP information. These are changed after a new
316  // Communicate object is created.
317  static int NumSMPs;
318  static int *SMPIDList;
319  static int *SMPNodeList;
320 
321  // Static data about a limit to the number of nodes that should be used
322  // in FFT operations. If this is <= 0 or > number of nodes, it is ignored.
323  static int MaxFFTNodes;
324 
325  // Maximum read chunk size
326  static int ChunkSize;
327 
328  // A boolean setting for whether we should attempt to use parallel
329  // I/O within a single SMP, for example by having multipple processors
330  // try to read from a single file (vs just having one node do it).
331  static bool PerSMPParallelIO;
332 
333  static std::stack<StaticIpplInfo> stashedStaticMembers;
334 
335  // Indicate an error occurred while trying to parse the given command-line
336  // option, and quit. Arguments are: parameter, error message, bad value
337  static void param_error(const char *, const char *, const char *);
338  static void param_error(const char *, const char *, const char *, const char *);
339 
340  // find out how many SMP's there are, and which processor we are on
341  // our local SMP (e.g., if there are two SMP's with 4 nodes each,
342  // the process will have a node number from 0 ... 7, and an SMP node
343  // number from 0 ... 3
344  static void find_smp_nodes();
345 };
346 
347 // macros used to print out messages to the console or a directed file
348 #define INFOMSG(msg) { *IpplInfo::Info << msg; }
349 #define WARNMSG(msg) { *IpplInfo::Warn << msg; }
350 #define ERRORMSG(msg) { *IpplInfo::Error << msg; }
351 
352 // typedef so that we can have a 'Ippl' class that's easier to manipulate
353 typedef IpplInfo Ippl;
354 
355 
356 #endif // IPPL_INFO_H
std::ostream & operator<<(std::ostream &, const IpplInfo &)
Definition: IpplInfo.cpp:118
IpplInfo Ippl
Definition: IpplInfo.h:353
Definition: Inform.h:42
static bool NeedDeleteComm
Definition: IpplInfo.h:298
static void deleteGlobals()
Definition: IpplInfo.cpp:68
@ REMOVE
Definition: IpplInfo.h:74
@ KEEP
Definition: IpplInfo.h:74
static bool noFieldCompression
Definition: IpplInfo.h:262
static int NumCreated
Definition: IpplInfo.h:287
static void printStatistics(Inform &)
Definition: IpplInfo.cpp:789
static void instantiateGlobals()
Definition: IpplInfo.cpp:53
static bool extraCompressChecks
Definition: IpplInfo.h:270
static void printVersion(void)
Definition: IpplInfo.cpp:736
static IpplStats * Stats
Definition: IpplInfo.h:87
static int * SMPIDList
Definition: IpplInfo.h:318
static MPI_Comm communicator_m
Definition: IpplInfo.h:283
static bool offsetStorage
Definition: IpplInfo.h:266
static Inform * Warn
Definition: IpplInfo.h:79
static bool perSMPParallelIO()
Definition: IpplInfo.h:211
static int chunkSize()
Definition: IpplInfo.h:206
static int TotalNodes
Definition: IpplInfo.h:313
static void printHelp()
Definition: IpplInfo.cpp:744
static void pop()
Definition: IpplInfo.cpp:1053
static int NumSMPs
Definition: IpplInfo.h:317
static const char * compileMachine()
Definition: IpplInfo.cpp:828
static int * SMPNodeList
Definition: IpplInfo.h:319
static int MyArgc
Definition: IpplInfo.h:307
static int maxFFTNodes()
Definition: IpplInfo.h:199
static void stash()
Definition: IpplInfo.cpp:988
static int MyNode
Definition: IpplInfo.h:312
static Inform * Info
Definition: IpplInfo.h:78
static char ** MyArgv
Definition: IpplInfo.h:308
static bool Retransmit
Definition: IpplInfo.h:304
static char ** getArgv()
Definition: IpplInfo.h:189
static Inform * Error
Definition: IpplInfo.h:80
static bool PerSMPParallelIO
Definition: IpplInfo.h:331
static void param_error(const char *, const char *, const char *)
Definition: IpplInfo.cpp:853
static void abort(const char *=0)
Definition: IpplInfo.cpp:616
static int getProcesses(int, int)
Definition: IpplInfo.cpp:684
static MPI_Comm getComm()
Definition: IpplInfo.h:152
static int getContexts(int)
Definition: IpplInfo.cpp:677
static int getSMPNodes(int)
Definition: IpplInfo.cpp:706
static const char * compileLine()
Definition: IpplInfo.cpp:820
static int getArgc()
Definition: IpplInfo.h:188
static const char * compileArch()
Definition: IpplInfo.cpp:804
static bool retransmit()
Definition: IpplInfo.h:195
static void find_smp_nodes()
Definition: IpplInfo.cpp:885
static bool useChecksums()
Definition: IpplInfo.h:192
static int MaxFFTNodes
Definition: IpplInfo.h:323
static bool CommInitialized
Definition: IpplInfo.h:291
static int getSMPs()
Definition: IpplInfo.cpp:699
static const char * version()
Definition: IpplInfo.cpp:795
static void here()
Definition: IpplInfo.cpp:783
static void abortAllNodes(const char *=0)
Definition: IpplInfo.cpp:647
static int getNodes()
Definition: IpplInfo.cpp:670
static bool PrintStats
Definition: IpplInfo.h:295
static int mySMPNode()
Definition: IpplInfo.cpp:728
static std::stack< StaticIpplInfo > stashedStaticMembers
Definition: IpplInfo.h:333
static const char * compileUser()
Definition: IpplInfo.cpp:844
static bool deferGuardCellFills
Definition: IpplInfo.h:259
static bool UseChecksums
Definition: IpplInfo.h:301
static Inform * Debug
Definition: IpplInfo.h:81
static int myNode()
Definition: IpplInfo.cpp:691
static Communicate * Comm
Definition: IpplInfo.h:84
static int mySMP()
Definition: IpplInfo.cpp:721
static const char * compileDate()
Definition: IpplInfo.cpp:812
IpplInfo & operator=(const IpplInfo &)
Definition: IpplInfo.cpp:611
static const char * compileOptions()
Definition: IpplInfo.cpp:836
static int ChunkSize
Definition: IpplInfo.h:326