OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
IpplInfo.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 /***************************************************************************
3  *
4  * The IPPL Framework
5  *
6  *
7  * Visit http://people.web.psi.ch/adelmann/ for more details
8  *
9  ***************************************************************************/
10 
11 #ifndef IPPL_INFO_H
12 #define IPPL_INFO_H
13 
14 /*
15  * IpplInfo.has the following capabilities:
16  * 1) It initializes all globally-used Ippl variables, such as the
17  * Communicate class and other manager classes;
18  * 2) It parses command-line arguments to determine how to configure the
19  * global state of the Ippl application;
20  * 3) It properly selects and configures the Communicate class, generally
21  * resulting in initialization of the parallel machine;
22  * 4) It offers to the user a single class with access member functions to
23  * query for information about the Ippl application (such as what is
24  * the Communicate class instance to use, how many processors are there
25  * in the current run, etc.)
26  *
27  * The globally-available Ippl objects are (available via IpplInfo::variable)
28  * Communicate *Comm ....... parallel communication object
29  * Inform *Info ............ used to print out informative messages
30  * Inform *Warn ............ used to print out warning messages
31  * Inform *Error ........... used to print out error messages
32  * Inform *Debug ........... used to print out debugging messages
33  *
34  * Note that you should use the following macros to access the Inform objects,
35  * so that these messages may be left out at compile time:
36  * INFOMSG("This is some information " << 34 << endl);
37  * WARNMSG("This is a warning " << 34 << endl);
38  * ERRORMSG("This is an error message " << 34 << endl);
39  * DEBUGMSG("This is some debugging info " << 34 << endl);
40  *
41  * There is also a 'typedef IpplInfo Ippl' here, so you can simply use
42  * the name 'Ippl' instead of the longer 'IpplInfo' to access this class.
43  * 'Ippl' is in fact preferred, as it is shorter.
44  */
45 
46 // include files
47 #include "Utility/Inform.h"
48 #include "Message/Communicate.h"
49 #include "Utility/StaticIpplInfo.h"
50 
51 #include <iostream>
52 #include <stack>
53 
54 //FIXME: Including this header here (regardless of the used commlib) here is
55 //necessary to enable IPPL to work on a user define communicator group
56 //(without further increasing the number of defines).
57 #include <mpi.h>
58 
59 //DKS include
60 #ifdef IPPL_DKS
61 #include "DKSOPAL.h"
62 #endif
63 
64 // forward declarations
65 class IpplStats;
66 class IpplInfo;
67 std::ostream& operator<<(std::ostream&, const IpplInfo&);
68 
69 
70 #ifdef IPPL_RUNTIME_ERRCHECK
71 // special routine used in runtime debugging error detection
72 extern "C" {
73 void __C_runtime_error (int trap_code, char *name, int line_no, ...);
74 };
75 #endif
76 
77 
78 class IpplInfo {
79 
80 public:
81  // an enumeration used to indicate whether to KEEP command-line arguments
82  // or REMOVE them
83  enum { KEEP = 0, REMOVE = 1 };
84 
85  // Inform object to use to print messages to the console (or even to a
86  // file if requested)
87  static Inform *Info;
88  static Inform *Warn;
89  static Inform *Error;
90  static Inform *Debug;
91 
92  // the parallel communication object
93  static Communicate *Comm;
94 
95  // the statistics collection object
96  static IpplStats *Stats;
97 
98 
99 #ifdef IPPL_DKS
100  static DKSOPAL *DKS;
101 #endif
102 
103  // Constructor 1: specify the argc, argv values from the cmd line.
104  // The second argument controls whether the IPPL-specific command line
105  // arguments are stripped out (the default) or left in (if the setting
106  // is IpplInfo::KEEP).
107  IpplInfo(int&, char** &, int removeargs = REMOVE, MPI_Comm mpicomm = MPI_COMM_WORLD);
108 
109  // Constructor 2: default constructor. This will not change anything in
110  // how the static data members are set up. This is useful for declaring
111  // automatic IpplInfo instances in functions after IpplInfo.has been
112  // initially created in the main() routine.
113  IpplInfo();
114 
115  // Constructor 3: copy constructor. This will only copy non-static members
116  // (obviously), if any exist.
117  IpplInfo(const IpplInfo&);
118 
119  // Destructor.
120  ~IpplInfo();
121 
122  // Overload the = operator; does the same thing as the copy constructor.
123  IpplInfo& operator=(const IpplInfo&);
124 
125 
126  /* NOTE: The following initialize/finalize methods have not yet been
127  implemented. Add them to IpplInfo.cpp if they are needed (bfh).
128  //
129  // Initialize and finalize routines ... initialize can be used if you
130  // created IpplInfo with the default constructor, and finalize() can
131  // be used to shut down IPPL and possibly exit the program
132  //
133 
134  // initialize ourselves, if we have not yet done so, by parsing the
135  // command-line args and creating the Communication object. This should
136  // be called by all the currently-running nodes.
137  void initialize(int &, char ** &);
138 
139  // shut down the communication, and possibly exit. This should be called
140  // by all the nodes, it will not work if it is called by just one node
141  // and you are running in parallel (in that case, the Communicate subclass
142  // destructor will hang).
143  void finalize();
144 
145  // a version of finalize that will also shut down all the machines via
146  // a call to exit()
147  void finalize(int exitcode);
148  */
149 
150 
151  //
152  // Standard IPPL action methods (such as abort, etc)
153  //
154 
155  // Kill the communication and exit the program, in an emergency. This
156  // will exit with an error code. If the given exit code is < 0, the
157  // program will call the system abort(). If the exit code is >= 0,
158  // the program will call the system exit() with the given error code.
159  static void abort(const char * = 0, int exitcode = (-1));
160 
161  // Signal to ALL the nodes that we should exit or abort. If we abort,
162  // a core file will be produced. If we exit, no core file will be made.
163  // The node which calls abortAllNodes will print out the given message;
164  // the other nodes will print out that they are aborting due to a message
165  // from this node. The final boolean argument indicates whether the
166  // calling node should abort or exit just as the other nodes are being
167  // asked to do; if this is false, then only the other nodes will be
168  // instructed to quit, and it will be up to the caller to abort or exit
169  // the current node. This makes it possible to ask all other nodes to
170  // exit, but have your own node abort.
171  static void abortAllNodes(const char * = 0, bool thisnode = true);
172  static void exitAllNodes(const char * = 0, bool thisnode = true);
173 
174  //
175  // Functions which return information about the current Ippl application.
176  //
177 
178  static MPI_Comm getComm() {return communicator_m;}
179 
180  // Return the number of the 'current' node.
181  static int myNode();
182 
183  // Return the current number of nodes working in parallel, where
184  // each node may have more than one processor. A 'Node' is basically
185  // considered as an entity which has a single IP address.
186  static int getNodes();
187 
188  // Return the number of contexts on a given node N. A 'Context' is
189  // considered to be a single addressable memory space; for shared memory
190  // machines, this could be the whole machine or one of many separate sections
191  // each being treated as distinct from the others.
192  static int getContexts(int);
193 
194  // Return the number of processes which are actively working on node N in
195  // context C. A 'Process' is not necessarily one in the strict Unix sense; it
196  // could be a lightweight thread or indeed a full process. These numbers
197  // may dynamically change.
198  static int getProcesses(int, int);
199 
200  // getSMPs: return number of SMP's (each of which may be running
201  // several processes)
202  static int getSMPs();
203 
204  // getSMPNodes: return number of nodes on the SMP with the given index
205  static int getSMPNodes(int);
206 
207  // mySMP: return ID of my SMP (numbered 0 ... getSMPs() - 1)
208  static int mySMP();
209 
210  // mySMPNode: return relative node number within the nodes on our SMP
211  static int mySMPNode();
212 
213  // Return argc or argv as provided in the initialization
214  static int getArgc() { return MyArgc; }
215  static char **getArgv() { return MyArgv; }
216 
217  // return true if we should use checksums on messages
218  static bool useChecksums() { return UseChecksums; }
219 
220  // return true if we should try to retransmit messages on error
221  static bool retransmit() { return (UseChecksums && Retransmit); }
222 
223 #ifdef IPPL_COMM_ALARMS
224  // A timeout quantity, in seconds, to allow us to wait a certain number
225  // of seconds before we signal a timeout when we're trying to receive
226  // a message.
227  static unsigned int getCommTimeout() { return CommTimeoutSeconds; }
228 #endif
229 
230  // Static data about a limit to the number of nodes that should be used
231  // in FFT operations. If this is <= 0 or > number of nodes, it is ignored.
232  static int maxFFTNodes() { return MaxFFTNodes; }
233 
234  // Return the "read chunk size", the number of bytes that will be
235  // read in, at max, for most Disc read operations. If the final
236  // character is 'K', 'M', or 'G', the number will mean the number
237  // of kilobytes, megabytes, or gigabytes. The default is one MB. If
238  // this is <= 0, then no limit should be used.
239  static int chunkSize() { return ChunkSize; }
240 
241  // Return boolean setting for whether we should attempt to use parallel
242  // I/O within a single SMP, for example by having multipple processors
243  // try to read from a single file (vs just having one node do it).
244  static bool perSMPParallelIO() { return PerSMPParallelIO; }
245 
246  //
247  // Functions which return information about the Ippl library
248  //
249 
250  // printVersion: print out a version summary. If the argument is true,
251  // print out a detailed listing, otherwise a summary.
252  static void printVersion(bool = false);
253 
254  static void printHelp(char** argv);
255 
256  // version: return the name of this version of Ippl, as a string
257  // (from IpplVersions.h)
258  static const char *version();
259 
260  // compileArch: return the architecture on which this library was built
261  // (from IpplVersions.h)
262  static const char *compileArch();
263 
264  // compileDate: return the date on which this library was prepared for
265  // compilation (from IpplVersions.h)
266  static const char *compileDate();
267 
268  // compileLine: return the compiler command used to compile each source file
269  // (from IpplVersions.h)
270  static const char *compileLine();
271 
272  // compileMachine: return the machine on which this library was
273  // compiled (from IpplVersions.h)
274  static const char *compileMachine();
275 
276  // compileOptions: return the option list used to compile this library
277  // (from IpplVersions.h)
278  static const char *compileOptions();
279 
280  // compileUser: return the username of the user who compiled this
281  // library (from IpplVersions.h)
282  static const char *compileUser();
283 
284  //Static flag telling wheteher to use DKS when runnign OPAL
285  static bool DKSEnabled;
286 
287  // stash all static members
288  static void stash();
289 
290  // restore all static members
291  static void pop();
292 
293  // Static flag telling whether to use optimization for reducing
294  // communication by deferring guard cell fills.
295  static bool deferGuardCellFills;
296 
297  // Static flag telling whether to turn off compression in the Field classes.
298  static bool noFieldCompression;
299 
300  // Static flag telling whether to try to (pseudo-)randomly offset the
301  // LField blocks to try to avoid cache conflicts.
302  static bool offsetStorage;
303 
304  // Static flag telling whether to try to do a TryCompress after each
305  // individual LField has been processed in an expression.
306  static bool extraCompressChecks;
307 
308  // Static flag telling whether to try to use direct-io. This is only
309  // possible if the library is compiled with the IPPL_DIRECTIO option,
310  // and you are on a system that provides this capablity.
311  static bool useDirectIO;
312 
313  // Static routine giving one a place to stop at with #$%$%#1 stupid
314  // debuggers.
315  static void here();
316 
317  // print out statistics to the given Inform stream
318  static void printStatistics(Inform&);
319 
320  static void instantiateGlobals();
321  static void deleteGlobals();
322 private:
323 
324  static MPI_Comm communicator_m;
325 
326  // Static counter indicating how many IpplInit objects have been created.
327  // When this gets back to zero, it's time to delete the Comm and quit.
328  static int NumCreated;
329 
330  // Static flag indicating whether this class has been created with
331  // argc,argv specified ever. This should only be done once.
332  static bool CommInitialized;
333 
334  // Static flag indicating whether we should print out stats info at the
335  // end of the program.
336  static bool PrintStats;
337 
338  // Static flag indicating if we need to delete the comm object at the end.
339  static bool NeedDeleteComm;
340 
341  // Static flag indicating whether to use checksums on messages
342  static bool UseChecksums;
343 
344  // Static flag indicating whether to retransmit messages when errors occur
345  static bool Retransmit;
346 
347  // Static data with argc and argv
348  static int MyArgc;
349  static char **MyArgv;
350 
351  // Static data with my node number and total number of nodes. These are
352  // only changed when a new Communicate object is created.
353  static int MyNode;
354  static int TotalNodes;
355 
356  // Static data with SMP information. These are changed after a new
357  // Communicate object is created.
358  static int NumSMPs;
359  static int *SMPIDList;
360  static int *SMPNodeList;
361 
362  // Static data about a limit to the number of nodes that should be used
363  // in FFT operations. If this is <= 0 or > number of nodes, it is ignored.
364  static int MaxFFTNodes;
365 
366  // Maximum read chunk size
367  static int ChunkSize;
368 
369  // A boolean setting for whether we should attempt to use parallel
370  // I/O within a single SMP, for example by having multipple processors
371  // try to read from a single file (vs just having one node do it).
372  static bool PerSMPParallelIO;
373 
374 #ifdef IPPL_COMM_ALARMS
375  // A timeout quantity, in seconds, to allow us to wait a certain number
376  // of seconds before we signal a timeout when we're trying to receive
377  // a message. By default, this will be zero; change it with the
378  // --msgtimeout <seconds> flag
379  static unsigned int CommTimeoutSeconds;
380 #endif
381 
382  static std::stack<StaticIpplInfo> stashedStaticMembers;
383 
384  // Indicate an error occurred while trying to parse the given command-line
385  // option, and quit. Arguments are: parameter, error message, bad value
386  static void param_error(const char *, const char *, const char *);
387  static void param_error(const char *, const char *, const char *, const char *);
388 
389  // find out how many SMP's there are, and which processor we are on
390  // our local SMP (e.g., if there are two SMP's with 4 nodes each,
391  // the process will have a node number from 0 ... 7, and an SMP node
392  // number from 0 ... 3
393  static void find_smp_nodes();
394 };
395 
396 // macros used to print out messages to the console or a directed file
397 #define INFOMSG(msg) { *IpplInfo::Info << msg; }
398 #define WARNMSG(msg) { *IpplInfo::Warn << msg; }
399 #define ERRORMSG(msg) { *IpplInfo::Error << msg; }
400 
401 // special macro to print debugging messages
402 #ifdef IPPL_PRINTDEBUG
403 #define DEBUGMSG(msg) { *IpplInfo::Debug << msg; }
404 #else
405 #define DEBUGMSG(msg)
406 #endif
407 
408 
409 // typedef so that we can have a 'Ippl' class that's easier to manipulate
410 typedef IpplInfo Ippl;
411 
412 
413 #endif // IPPL_INFO_H
414 
415 /***************************************************************************
416  * $RCSfile: IpplInfo.h,v $ $Author: adelmann $
417  * $Revision: 1.1.1.1 $ $Date: 2003/01/23 07:40:33 $
418  * IPPL_VERSION_ID: $Id: IpplInfo.h,v 1.1.1.1 2003/01/23 07:40:33 adelmann Exp $
419  ***************************************************************************/
static int getProcesses(int, int)
Definition: IpplInfo.cpp:787
static bool extraCompressChecks
Definition: IpplInfo.h:306
static int getNodes()
Definition: IpplInfo.cpp:773
static bool Retransmit
Definition: IpplInfo.h:345
std::ostream & operator<<(std::ostream &os, const Attribute &attr)
Definition: Attribute.cpp:167
IpplInfo Ippl
Definition: IpplInfo.h:410
static void abort(const char *=0, int exitcode=(-1))
Definition: IpplInfo.cpp:696
static int NumCreated
Definition: IpplInfo.h:328
static char ** getArgv()
Definition: IpplInfo.h:215
static void param_error(const char *, const char *, const char *)
Definition: IpplInfo.cpp:967
static bool PerSMPParallelIO
Definition: IpplInfo.h:372
static void deleteGlobals()
Definition: IpplInfo.cpp:66
static char ** MyArgv
Definition: IpplInfo.h:349
static int NumSMPs
Definition: IpplInfo.h:358
static bool useDirectIO
Definition: IpplInfo.h:311
static int ChunkSize
Definition: IpplInfo.h:367
static bool retransmit()
Definition: IpplInfo.h:221
static void stash()
Definition: IpplInfo.cpp:1102
static bool DKSEnabled
Definition: IpplInfo.h:285
static Inform * Warn
Definition: IpplInfo.h:88
IpplInfo & operator=(const IpplInfo &)
Definition: IpplInfo.cpp:685
static int myNode()
Definition: IpplInfo.cpp:794
static int getArgc()
Definition: IpplInfo.h:214
static std::stack< StaticIpplInfo > stashedStaticMembers
Definition: IpplInfo.h:382
static int MaxFFTNodes
Definition: IpplInfo.h:364
static int * SMPIDList
Definition: IpplInfo.h:359
static bool deferGuardCellFills
Definition: IpplInfo.h:295
static bool offsetStorage
Definition: IpplInfo.h:302
static bool noFieldCompression
Definition: IpplInfo.h:298
static Inform * Debug
Definition: IpplInfo.h:90
static bool CommInitialized
Definition: IpplInfo.h:332
static const char * version()
Definition: IpplInfo.cpp:909
static int mySMP()
Definition: IpplInfo.cpp:824
static const char * compileUser()
Definition: IpplInfo.cpp:958
static int MyNode
Definition: IpplInfo.h:353
static void printVersion(bool=false)
Definition: IpplInfo.cpp:839
static bool useChecksums()
Definition: IpplInfo.h:218
static void instantiateGlobals()
Definition: IpplInfo.cpp:51
static int TotalNodes
Definition: IpplInfo.h:354
static const char * compileArch()
Definition: IpplInfo.cpp:918
static int mySMPNode()
Definition: IpplInfo.cpp:831
static const char * compileLine()
Definition: IpplInfo.cpp:934
static int getSMPs()
Definition: IpplInfo.cpp:802
static void abortAllNodes(const char *=0, bool thisnode=true)
Definition: IpplInfo.cpp:727
static int maxFFTNodes()
Definition: IpplInfo.h:232
static MPI_Comm getComm()
Definition: IpplInfo.h:178
static bool PrintStats
Definition: IpplInfo.h:336
static void here()
Definition: IpplInfo.cpp:897
static bool UseChecksums
Definition: IpplInfo.h:342
static void printHelp(char **argv)
Definition: IpplInfo.cpp:850
static IpplStats * Stats
Definition: IpplInfo.h:96
static Inform * Error
Definition: IpplInfo.h:89
static const char * compileOptions()
Definition: IpplInfo.cpp:950
static const char * compileMachine()
Definition: IpplInfo.cpp:942
static Inform * Info
Definition: IpplInfo.h:87
const std::string name
static void find_smp_nodes()
Definition: IpplInfo.cpp:999
static void printStatistics(Inform &)
Definition: IpplInfo.cpp:903
static int * SMPNodeList
Definition: IpplInfo.h:360
static int chunkSize()
Definition: IpplInfo.h:239
static bool NeedDeleteComm
Definition: IpplInfo.h:339
static int getSMPNodes(int)
Definition: IpplInfo.cpp:809
Definition: Inform.h:41
static Communicate * Comm
Definition: IpplInfo.h:93
static void pop()
Definition: IpplInfo.cpp:1173
static void exitAllNodes(const char *=0, bool thisnode=true)
Definition: IpplInfo.cpp:748
static const char * compileDate()
Definition: IpplInfo.cpp:926
static MPI_Comm communicator_m
Definition: IpplInfo.h:324
static int getContexts(int)
Definition: IpplInfo.cpp:780
static int MyArgc
Definition: IpplInfo.h:348
static bool perSMPParallelIO()
Definition: IpplInfo.h:244