OPAL (Object Oriented Parallel Accelerator Library) 2024.2
OPAL
IpplInfo.cpp
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#include "Utility/IpplInfo.h"
29#include "Utility/Inform.h"
30#include "Utility/IpplStats.h"
31#include "Utility/PAssert.h"
33#include "Utility/vmap.h"
35#include "Message/CommCreator.h"
36#include "Message/Communicate.h"
37
38#include "IpplVersions.h"
39
40#include <unistd.h>
41#include <cstdio>
42#include <csignal>
43#include <execinfo.h>
44
46// public static members of IpplInfo, initialized to default values
53
55 if (Comm == 0)
56 Comm = new Communicate();
57 if (Stats == 0)
58 Stats = new IpplStats();
59 if (Info == 0)
60 Info = new Inform("Ippl");
61 if (Warn == 0)
62 Warn = new Inform("Warning", std::cerr);
63 if (Error == 0)
64 Error = new Inform("Error", std::cerr, INFORM_ALL_NODES);
65 if (Debug == 0)
66 Debug = new Inform("**DEBUG**", std::cerr, INFORM_ALL_NODES);
67}
68
70 delete Comm;
71 delete Stats;
72 delete Info;
73 delete Warn;
74 delete Error;
75 delete Debug;
76
77 Comm = 0;
78 Stats = 0;
79 Info = 0;
80 Warn = 0;
81 Error = 0;
82 Debug = 0;
83}
84
85std::stack<StaticIpplInfo> IpplInfo::stashedStaticMembers;
86
87// should we use the optimization of deferring guard cell fills until
88// absolutely needed? Can be changed to true by specifying the
89// flag --defergcfill
91
92// should we use the compression capabilities in {[Bare]Field,LField}? Can be
93// changed to false by specifying the flag --nofieldcompression
95
96// private static members of IpplInfo, initialized to default values
97MPI_Comm IpplInfo::communicator_m = MPI_COMM_WORLD;
99bool IpplInfo::CommInitialized = false;
100bool IpplInfo::PrintStats = false;
101bool IpplInfo::NeedDeleteComm = false;
102int IpplInfo::MyArgc = 0;
103char **IpplInfo::MyArgv = 0;
104int IpplInfo::MyNode = 0;
106int IpplInfo::NumSMPs = 1;
107int* IpplInfo::SMPIDList = 0;
108int* IpplInfo::SMPNodeList = 0;
109bool IpplInfo::UseChecksums = false;
110bool IpplInfo::Retransmit = false;
112int IpplInfo::ChunkSize = 512*1024; // 512K == 64K doubles
113bool IpplInfo::PerSMPParallelIO = false;
114bool IpplInfo::offsetStorage = false;
116
118// print out current state to the given output stream
119std::ostream& operator<<(std::ostream& o, const IpplInfo&) {
120 o << "------------------------------------------\n";
121 o << "IPPL Framework Application Summary:\n";
122 o << " Running on node " << IpplInfo::myNode();
123 o << ", out of " << IpplInfo::getNodes() << " total.\n";
124 o << " Number of SMPs: " << IpplInfo::getSMPs() << "\n";
125 o << " Relative SMP node: " << IpplInfo::mySMPNode();
126 o << ", out of " << IpplInfo::getSMPNodes(IpplInfo::mySMP());
127 o << " nodes.\n";
128 o << " Communication method: " << IpplInfo::Comm->name() << "\n";
129 o << " Disc read chunk size: " << IpplInfo::chunkSize() << " bytes.\n";
130 o << " Deferring guard cell fills? ";
132 o << " Turning off Field compression? ";
133 o << IpplInfo::noFieldCompression << "\n";
134 o << " Offsetting storage? ";
135 o << IpplInfo::offsetStorage << "\n";
136 o << " Using extra compression checks in expressions? ";
138 o << " Use per-SMP parallel IO? ";
139 o << IpplInfo::perSMPParallelIO() << "\n";
140 o << " Computing message CRC checksums? ";
141 o << IpplInfo::useChecksums() << "\n";
142 o << " Retransmit messages on error (only if checkums on)? ";
143 o << IpplInfo::retransmit() << "\n";
144
145 o << " Elapsed wall-clock time (in seconds): ";
146 o << IpplInfo::Stats->getTime().clock_time() << "\n";
147 o << " Elapsed CPU-clock time (in seconds) : ";
148 o << IpplInfo::Stats->getTime().cpu_time() << "\n";
149 o << "------------------------------------------\n";
150 return o;
151}
152
153
155// Constructor 1: parse argc, argv, and create proper Communicate object
156// The second argument controls whether the IPPL-specific command line
157// arguments are stripped out (the default) or left in (if the setting
158// is IpplInfo::KEEP).
159IpplInfo::IpplInfo(int& argc, char**& argv, int removeargs, MPI_Comm mpicomm) {
160
161 int i; // loop variables
162 int connectoption = (-1); // for connection method option
163 int retargc; // number of args to return to caller
164 char **retargv; // arguments to return
165 bool printsummary = false; // print summary at end of constructor
166
167 //Inform dbgmsg("IpplInfo(argc,argv)", INFORM_ALL_NODES);
168
169 // determine whether we should strip out ippl-specific arguments, or keep
170 bool stripargs = (removeargs != KEEP);
171
172 communicator_m = mpicomm;
173
174 if (NumCreated == 0) {
175 Comm = new Communicate();
176 Stats = new IpplStats();
177 Info = new Inform("Ippl");
178 Warn = new Inform("Warning", std::cerr);
179 Error = new Inform("Error", std::cerr, INFORM_ALL_NODES);
180 Debug = new Inform("**DEBUG**", std::cerr, INFORM_ALL_NODES);
181 }
182 // You can only specify argc, argv once; if it is done again, print a warning
183 // and continue as if we had not given argc, argv.
184 if ( CommInitialized ) {
185 // ADA WARNMSG("Attempt to create IpplInfo with argc, argv again." << endl);
186 //WARNMSG("Using previous argc,argv settings." << endl);
187 } else {
188 // dbgmsg << "Starting initialization: argc = " << argc << ", " << endl;
189 // for (unsigned int dbgi=0; dbgi < argc; ++dbgi)
190 // dbgmsg << " argv[" << dbgi << "] = '" << argv[dbgi] << "'" << endl;
191
192 // first make a pass through the arguments, figure out whether we should
193 // run in parallel, and start up the parallel environment. After this,
194 // process all the other cmdline args
195 std::string commtype;
196 bool startcomm = false;
197 bool comminit = true; // do comm. system's init call
198 int nprocs = (-1); // num of processes to start; -1 means default
199
200
201 /*
202 if no argument is given, we assume mpi as
203 communication method
204 */
205 commtype = std::string("mpi");
206 startcomm = true;
207
208 for (i=1; i < argc; ++i) {
209 if ( ( strcmp(argv[i], "--processes") == 0 ) ||
210 ( strcmp(argv[i], "-procs") == 0 ) ) {
211 // The user specified how many processes to use. This may not be useful
212 // for all communication methods.
213 if ( (i + 1) < argc && argv[i+1][0] != '-' && atoi(argv[i+1]) > 0 )
214 nprocs = atoi(argv[++i]);
215 else
216 param_error(argv[i],
217 "Please specify a positive number of processes", 0);
218 } else if ( ( strcmp(argv[i], "--commlib") == 0 ) ||
219 ( strcmp(argv[i], "-comm") == 0 ) ) {
220 // The user specified what kind of comm library to use
221 if ( (i + 1) < argc && argv[i+1][0] != '-' ) {
222 commtype = argv[++i];
223 startcomm = true;
224 } else {
225 param_error(argv[i], "Please use one of: ",
227 startcomm = false;
228 }
229
230 } else if ( strcmp(argv[i], "--nocomminit") == 0 ) {
231 // The user requested that we do not let the run-time system call
232 // whatever initialization routine it might have (like MPI_Init).
233 // This is in case another agency has already done the initialization.
234 comminit = false;
235 }
236 }
237
238 // create Communicate object now.
239 // dbgmsg << "Setting up parallel environment ..." << endl;
240 if (startcomm && nprocs != 0 && nprocs != 1) {
241 // dbgmsg << " commlibarg=" << commtype << endl;
242 // dbgmsg << ", nprocs=" << nprocs << endl;
243 Communicate *newcomm = CommCreator::create(commtype.c_str(),
244 argc, argv,
245 nprocs, comminit, mpicomm);
246
247 if (newcomm == 0) {
248 if (CommCreator::supported(commtype.c_str()))
249 param_error("--commlib", "Could not initialize this ",
250 "communication library.", commtype.c_str());
251 else if (CommCreator::known(commtype.c_str()))
252 param_error("--commlib", "This communication library is not ",
253 "available.", commtype.c_str());
254 else
255 param_error("--commlib", "Please use one of: ",
257 } else {
258 // success, we have a new comm object
259 NeedDeleteComm = true;
260 delete Comm;
261 Comm = newcomm;
262
263 // cache our node number and node count
264 MyNode = Comm->myNode();
265 TotalNodes = Comm->getNodes();
267
268 // advance the default random number generator
269 IpplRandom.AdvanceSeed(Comm->myNode());
270
271 // dbgmsg << " Comm creation successful." << endl;
272 // dbgmsg << *this << endl;
273 }
274 }
275
276 // dbgmsg << "After comm init: argc = " << argc << ", " << endl;
277 // for (unsigned int dbgi=0; dbgi < argc; ++dbgi)
278 // dbgmsg << " argv[" << dbgi << "] = '" << argv[dbgi] << "'" << endl;
279
280 // keep track of which arguments we do no use; these are returned
281 retargc = 1;
282 retargv = new char*[argc];
283 retargv[0] = argv[0]; // we always return arg 0 (the exec. name)
284
285 // if we're not stripping out arguments, just save all the args
286 if (!stripargs)
287 for (i=1; i < argc; ++i)
288 retargv[retargc++] = argv[i];
289
290
291 // Parse command-line options, looking for ippl options. When found,
292 // save their suggested values and use them at the end to create data, etc.
293 for (i=1; i < argc; ++i) {
294 if ( ( strcmp(argv[i], "--processes") == 0 ) ||
295 ( strcmp(argv[i], "-procs") == 0 ) ) {
296 // handled above
297 if ( (i + 1) < argc && argv[i+1][0] != '-' && atoi(argv[i+1]) > 0 )
298 ++i;
299
300 } else if ( ( strcmp(argv[i], "--nocomminit") == 0 ) ) {
301 // handled above, nothing to do here but skip the arg
302
303 } else if ( ( strcmp(argv[i], "--summary") == 0 ) ) {
304 // set flag to print out summary of Ippl library settings at the
305 // end of this constructor
306 printsummary = true;
307
308 } else if ( ( strcmp(argv[i], "--ipplversion") == 0 ) ) {
309 printVersion();
310 std::string options = compileOptions();
311 std::string header("Compile-time options: ");
312 while (options.length() > 58) {
313 std::string line = options.substr(0, 58);
314 size_t n = line.find_last_of(' ');
315 INFOMSG(header << line.substr(0, n) << "\n");
316
317 header = std::string(22, ' ');
318 options = options.substr(n + 1);
319 }
320 INFOMSG(header << options << endl);
321 exit(0);
322
323 } else if ( ( strcmp(argv[i], "--checksums") == 0 ) ||
324 ( strcmp(argv[i], "--checksum") == 0 ) ) {
325 UseChecksums = true;
326
327 } else if ( ( strcmp(argv[i], "--retransmit") == 0 ) ) {
328 Retransmit = true;
329
330 } else if ( ( strcmp(argv[i], "--ipplversionall") == 0 ) ||
331 ( strcmp(argv[i], "-vall") == 0 ) ) {
332 printVersion();
333 std::string options = compileOptions();
334 std::string header("Compile-time options: ");
335 while (options.length() > 58) {
336 std::string line = options.substr(0, 58);
337 size_t n = line.find_last_of(' ');
338 INFOMSG(header << line.substr(0, n) << "\n");
339
340 header = std::string(22, ' ');
341 options = options.substr(n + 1);
342 }
343 INFOMSG(header << options << endl);
344 exit(0);
345
346 } else if ( ( strcmp(argv[i], "--time") == 0 ) ||
347 ( strcmp(argv[i], "-time") == 0 ) ||
348 ( strcmp(argv[i], "--statistics") == 0 ) ||
349 ( strcmp(argv[i], "-stats") == 0 ) ) {
350 // The user specified that the program stats be printed at
351 // the end of the program.
352 PrintStats = true;
353
354 } else if ( ( strcmp(argv[i], "--info") == 0 ) ) {
355 // Set the output level for informative messages.
356 if ( (i + 1) < argc && argv[i+1][0] != '-' && atoi(argv[i+1]) >= 0 )
357 Info->setOutputLevel(atoi(argv[++i]));
358 else
359 param_error(argv[i],
360 "Please specify an output level from 0 to 5", 0);
361
362 } else if ( ( strcmp(argv[i], "--warn") == 0 ) ) {
363 // Set the output level for warning messages.
364 if ( (i + 1) < argc && argv[i+1][0] != '-' && atoi(argv[i+1]) >= 0 )
365 Warn->setOutputLevel(atoi(argv[++i]));
366 else
367 param_error(argv[i],
368 "Please specify an output level from 0 to 5", 0);
369
370 } else if ( ( strcmp(argv[i], "--error") == 0 ) ) {
371 // Set the output level for error messages.
372 if ( (i + 1) < argc && argv[i+1][0] != '-' && atoi(argv[i+1]) >= 0 )
373 Error->setOutputLevel(atoi(argv[++i]));
374 else
375 param_error(argv[i],
376 "Please specify an output level from 0 to 5", 0);
377
378 } else if ( ( strcmp(argv[i], "--debug") == 0 ) ) {
379 // Set the output level for debug messages.
380 if ( (i + 1) < argc && argv[i+1][0] != '-' && atoi(argv[i+1]) >= 0 )
381 Debug->setOutputLevel(atoi(argv[++i]));
382 else
383 param_error(argv[i],
384 "Please specify an output level from 0 to 5", 0);
385
386 } else if ( ( strcmp(argv[i], "--connect") == 0 ) ) {
387 // Set the default external connection method
388 if ( (i + 1) < argc && argv[i+1][0] != '-' )
389 connectoption = ++i;
390 else
391 param_error(argv[i], "Please use one of: ",
393
394 } else if ( ( strcmp(argv[i], "--connectnodes") == 0 ) ) {
395 // Set the number of nodes that are used in connections, by default
396 if ( (i + 1) < argc && argv[i+1][0] != '-' && atoi(argv[i+1]) > 0 )
398 else
399 param_error(argv[i],
400 "Please specify a number of nodes for connections > 0",
401 0);
402
403 } else if ( ( strcmp(argv[i], "--commlib") == 0 ) ||
404 ( strcmp(argv[i], "-comm") == 0 ) ) {
405 // handled above
406 if ( (i + 1) < argc && argv[i+1][0] != '-' )
407 ++i;
408
409 } else if ( strcmp(argv[i], "--profile") == 0 ) {
410 // handled above in
411 if ( (i + 1) < argc && argv[i+1][0] != '-' )
412 ++i;
413
414 } else if ( ( strcmp(argv[i], "--persmppario") == 0 ) ) {
415 // Turn on the ability to use per-smp parallel IO
416 PerSMPParallelIO = true;
417
418 } else if ( ( strcmp(argv[i], "--nopersmppario") == 0 ) ) {
419 // Turn off the ability to use per-smp parallel IO
420 PerSMPParallelIO = false;
421
422 } else if ( ( strcmp(argv[i], "--chunksize") == 0 ) ) {
423 // Set the I/O chunk size, used to limit how many items
424 // are read in or written to disk at one time.
425 if ( (i + 1) < argc && argv[i+1][0] != '-' && atoi(argv[i+1]) >= 0 ) {
426 ChunkSize = atoi(argv[++i]);
427 char units = static_cast<char>(toupper(argv[i][strlen(argv[i])-1]));
428 if (units == 'K')
429 ChunkSize *= 1024;
430 else if (units == 'M')
431 ChunkSize *= 1024*1024;
432 else if (units == 'G')
433 ChunkSize *= 1024*1024*1024;
434 } else {
435 param_error(argv[i],
436 "Please specify a timeout value (in seconds)", 0);
437 }
438 } else if ( ( strcmp(argv[i], "--defergcfill") == 0 ) ) {
439 // Turn on the defer guard cell fill optimization
440 deferGuardCellFills = true;
441
442 } else if ( ( strcmp(argv[i], "--offsetstorage") == 0 ) ) {
443 // Turn on the offset-storage modification to LFields
444 offsetStorage = true;
445
446 } else if ( ( strcmp(argv[i], "--extracompcheck") == 0 ) ) {
447 // Turn on the extra compression checks in expressions
448 extraCompressChecks = true;
449
450 } else if ( ( strcmp(argv[i], "--nofieldcompression") == 0 ) ) {
451 // Turn off compression in the Field classes
452 noFieldCompression = true;
453
454 } else if ( ( strcmp(argv[i], "--directio") == 0 ) ) {
455 // Turn on the use of Direct-IO, if possible
456 param_error(argv[i],
457 "Direct-IO is not available in this build of IPPL", 0);
458 } else if ( ( strcmp(argv[i], "--maxfftnodes") == 0 ) ) {
459 // Limit the number of nodes that can participate in FFT operations
460 if ( (i + 1) < argc && argv[i+1][0] != '-' && atoi(argv[i+1]) > 0 )
461 MaxFFTNodes = atoi(argv[++i]);
462 else
463 param_error(argv[i],
464 "Please specify a maximum number of FFT nodes > 0", 0);
465
466 } else if ( ( strcmp(argv[i], "--ipplhelp") == 0 ) ||
467 ( strcmp(argv[i], "-h") == 0 ) ||
468 ( strcmp(argv[i], "-?") == 0 ) ) {
469 // print out summary of command line switches and exit
470 INFOMSG("Usage: " << argv[0] << " [<option> <option> ...]\n");
471 INFOMSG(" The possible values for <option> are:\n");
472 printHelp();
473 INFOMSG(" --ipplversion : Print a brief version summary.\n");
474 INFOMSG(" --ipplversionall : Print a detailed version summary.\n");
475 INFOMSG(" --ipplhelp : Display this command-line summary.\n");
476 INFOMSG(endl);
477 exit(0);
478
479 } else {
480 // Unknown option; just ignore it.
481 if (stripargs)
482 retargv[retargc++] = argv[i];
483 }
484 }
485
486 // We can get on with creating and initializing all globally-used objects.
487
488 // Select the default connection method
489 if ( connectoption >= 0 ) {
490 if ( ! DataConnectCreator::setDefaultMethod(argv[connectoption]) ) {
491 if (DataConnectCreator::supported(argv[connectoption]))
492 param_error(argv[connectoption - 1], "Could not initialize this ",
493 "connection.", argv[connectoption]);
494 else if (DataConnectCreator::known(argv[connectoption]))
495 param_error(argv[connectoption - 1],"This connection method is not ",
496 "available.", argv[connectoption]);
497 else
498 param_error(argv[connectoption - 1], "Please use one of: ",
500 }
501 }
502
503 // indicate back to the caller which arguments are left
504 MyArgc = retargc;
505 MyArgv = retargv;
506 if (stripargs) {
507 argc = retargc;
508 argv = retargv;
509 }
510
511 // Inform dbgmsg("IpplInfo::IpplInfo", INFORM_ALL_NODES);
512 // dbgmsg << "Created IpplInfo. node = " << MyNode << " out of ";
513 // dbgmsg << TotalNodes << ", commlib = " << Comm->name() << endl;
514
515 // now, at end, start the timer running, and print out a summary if asked
516 Stats->getTime().stop();
517 Stats->getTime().clear();
518 Stats->getTime().start();
519 }
520
521 // indicate we've created one more Ippl object
522 CommInitialized = true;
523 NumCreated++;
524
525 // At the very end, print out a summary if requested
526 if (printsummary)
527 INFOMSG(*this << endl);
528}
529
530
532// Constructor 2: default constructor.
534 if (NumCreated == 0) {
535 Comm = new Communicate();
536 Stats = new IpplStats();
537 Info = new Inform("Ippl");
538 Warn = new Inform("Warning", std::cerr);
539 Error = new Inform("Error", std::cerr, INFORM_ALL_NODES);
540 Debug = new Inform("**DEBUG**", std::cerr, INFORM_ALL_NODES);
541 }
542
543 // just indicate we've also been created
544 NumCreated++;
545}
546
547
549// Constructor 3: copy constructor.
551 if (NumCreated == 0) {
552 Comm = new Communicate();
553 Stats = new IpplStats();
554 Info = new Inform("Ippl");
555 Warn = new Inform("Warning", std::cerr);
556 Error = new Inform("Error", std::cerr, INFORM_ALL_NODES);
557 Debug = new Inform("**DEBUG**", std::cerr, INFORM_ALL_NODES);
558 }
559
560 // just indicate we've also been created
561 NumCreated++;
562}
563
564
566// Destructor: need to delete comm library if this is the last IpplInfo
568 // indicate we have one less instance; if this is the last one,
569 // close communication and clean up
570 // Inform dbgmsg("IpplInfo::~IpplInfo", INFORM_ALL_NODES);
571 // dbgmsg << "In destructor: Current NumCreated = " << NumCreated << endl;
572
573 if ((--NumCreated) == 0) {
574 // at end of program, print statistics if requested to do so
575 if (PrintStats) {
576 Inform statsmsg("Stats", INFORM_ALL_NODES);
577 statsmsg << *this;
578 printStatistics(statsmsg);
579 }
580
581 // Delete the communications object, if necessary, to shut down parallel
582 // environment
583 if (NeedDeleteComm) {
584 // dbgmsg << " Deleting comm object, since now NumCreated = ";
585 // dbgmsg << NumCreated << endl;
586 delete Comm;
587 Comm = 0;
588 NeedDeleteComm = false;
589 }
590 CommInitialized = false;
591
592 // delete other dynamically-allocated static objects
593 delete [] MyArgv;
594 if (SMPIDList != 0) {
595 delete [] SMPIDList;
596 }
597 if (SMPNodeList != 0) {
598 delete [] SMPNodeList;
599 }
600 delete Stats;
601
602 MyArgv = 0;
603 SMPIDList = 0;
604 SMPNodeList = 0;
605 Stats = 0;
606 }
607}
608
609
611// equal operator
613 // nothing to do, we don't even need to indicate we've made another
614 return *this;
615}
616
617void IpplInfo::abort(const char *msg) {
618 // print out message, if one was provided
619 if (msg != 0) {
620 ERRORMSG(msg << endl);
621 }
622
623 // Say where we are. This runs on the one node that hit the error. The
624 // frames print as <binary>(+0xoffset); resolve them against the same
625 // executable with addr2line -f -e <binary> <offset>, or with nm -n if
626 // the build carries no debug information.
627 {
628 void* frames[64];
629 int nframes = backtrace(frames, 64);
630 ERRORMSG("IpplInfo::abort on node " << MyNode << " of " << TotalNodes
631 << ", backtrace (" << nframes << " frames):" << endl);
632 backtrace_symbols_fd(frames, nframes, STDERR_FILENO);
633 }
634
635 // print out final stats, if necessary
636 if (PrintStats) {
637 Inform statsmsg("Stats", INFORM_ALL_NODES);
638 statsmsg << IpplInfo();
639 printStatistics(statsmsg);
640 }
641
642 // Do NOT delete the Communicate object here. CommMPI's destructor makes
643 // every node but 0 block in MPI_Recv for a "die" message that node 0 only
644 // sends from its own destructor - and node 0 is at this point sitting in a
645 // collective waiting for the node that is aborting. That deadlock turned
646 // every IPPL error into a 100% CPU spin that never returned, so the
647 // runtime_error below was never thrown and Main's MPI_Abort never ran.
648 // If we own the communicator (a standalone run), take the whole job down
649 // now. If we do not (e.g. the optimiser's nocomminit path), keep the old
650 // behaviour and let the caller handle the exception.
651 if (NeedDeleteComm) {
652 MPI_Abort(communicator_m, 1);
653 }
654
655 // that's it, folks this error will be propperly catched in the main
656 throw std::runtime_error("Error form IpplInfo::abort");
657}
658
659
661// Signal to ALL the nodes that we should exit or abort. If we abort,
662// a core file will be produced. If we exit, no core file will be made.
663// The node which calls abortAllNodes will print out the given message;
664// the other nodes will print out that they are aborting due to a message
665// from this node.
666void IpplInfo::abortAllNodes(const char *msg) {
667 // print out message, if one was provided
668 if (msg != 0) {
669 ERRORMSG(msg << endl);
670 }
671
672 // print out final stats, if necessary
673 if (PrintStats) {
674 Inform statsmsg("Stats", INFORM_ALL_NODES);
675 statsmsg << IpplInfo();
676 printStatistics(statsmsg);
677 }
678
679 // broadcast out the kill message, if necessary
680 if (getNodes() > 1)
681 Comm->broadcast_others(new Message, IPPL_ABORT_TAG);
682
683 throw std::runtime_error("Error form IpplInfo::abortAllNodes");
684
685}
686
688// getNodes: return the number of 'Nodes' in use for the computation
690 return TotalNodes;
691}
692
693
695// getContexts: return the number of 'Contexts' for the given node
696int IpplInfo::getContexts(const int n) {
697 return Comm->getContexts(n);
698}
699
700
702// getProcesses: return the number of 'Processes' for the given Node and Context
703int IpplInfo::getProcesses(const int n, const int c) {
704 return Comm->getProcesses(n, c);
705}
706
707
709// myNode: return which Node we are running on right now
711 return MyNode;
712}
713
714
716// getSMPs: return number of SMP's (each of which may be running
717// several processes)
719 return NumSMPs;
720}
721
722
724// getSMPNodes: return number of nodes on the SMP with the given index
725int IpplInfo::getSMPNodes(int smpindx) {
726 int num = 0;
727 if (SMPIDList == 0) {
728 num = 1;
729 } else {
730 for (int i=0; i < TotalNodes; ++i)
731 if (SMPIDList[i] == smpindx)
732 num++;
733 }
734 return num;
735}
736
737
739// mySMP: return ID of my SMP (numbered 0 ... getSMPs() - 1)
741 return (SMPIDList != 0 ? SMPIDList[MyNode] : 0);
742}
743
744
746// mySMPNode: return relative node number within the nodes on our SMP
748 return (SMPNodeList != 0 ? SMPNodeList[MyNode] : 0);
749}
750
751
753// printVersion: print out a version summary. If the argument is true,
754// print out a detailed listing, otherwise a summary.
756 INFOMSG("IPPL Framework version " << version() << endl);
757 INFOMSG("Last build date: " << compileDate() << " by user ");
759 INFOMSG("Built for machine: " << compileMachine() << endl);
760}
761
762
764 INFOMSG(" --summary : Print IPPL lib summary at start.\n");
765 INFOMSG(" --processes <n> : Number of parallel nodes to use.\n");
766 INFOMSG(" --commlib <x> : Selects a parallel comm. library.\n");
767 INFOMSG(" <x> = ");
769 INFOMSG(" --nocomminit : IPPL does not do communication\n");
770 INFOMSG(" initialization, assume already done.\n");
771 INFOMSG(" --connect <x> : Select external connection method.\n");
772 INFOMSG(" <x> = ");
774 INFOMSG(" --time : Show total time used in execution.\n");
775 INFOMSG(" --notime : Do not show timing info (default).\n");
776 INFOMSG(" --info <n> : Set info message level. 0 = off.\n");
777 INFOMSG(" --warn <n> : Set warning message level. 0 = off.\n");
778 INFOMSG(" --error <n> : Set error message level. 0 = off.\n");
779 INFOMSG(" --debug <n> : Set debug message level. 0 = off.\n");
780 /*#ifdef PROFILING_ON
781 INFOMSG(" --profile <gr> : Enable profiling for groups (e.g., M+P+io) \n");
782 INFOMSG(" M - Message, P - Pete, V - Viz, A - Assign, I - IO\n");
783 INFOMSG(" F - Field, L - Layout, S - Sparse, D - Domainmap \n");
784 INFOMSG(" Ut - Utility, R - Region, Ff - FFT \n");
785 INFOMSG(" U - User, 1 - User1, 2 - User2, 3 - User3, 4 - User4\n");
786
787 #endif*/ //PROFILING_ON
788 INFOMSG(" --defergcfill : Turn on deferred guard cell fills.\n");
789 INFOMSG(" --nofieldcompression : Turn off compression in the Field classes.\n");
790 INFOMSG(" --offsetstorage : Turn on random LField storage offsets.\n");
791 INFOMSG(" --extracompcheck : Turn on extra compression checks in evaluator.\n");
792 INFOMSG(" --checksums : Turn on CRC checksums for messages.\n");
793 INFOMSG(" --retransmit : Resent messages if a CRC error occurs.\n");
794 INFOMSG(" --maxfftnodes <n> : Limit the nodes that work on FFT's.\n");
795 INFOMSG(" --chunksize <n> : Set I/O chunk size. Can end w/K,M,G.\n");
796 INFOMSG(" --persmppario : Enable on-SMP parallel IO option.\n");
797 INFOMSG(" --nopersmppario : Disable on-SMP parallel IO option (default).\n");
798}
799
801// here: as in stop in IpplInfo::here (in the debugger)
803{
804}
805
807// print out statistics to the given Inform stream
809
810
812// version: return the name of this version of Ippl, as a string
813// (from Versions.h)
814const char *IpplInfo::version() {
815 return ippl_version_name;
816}
817
818
819
821// compileArch: return the architecture on which this library was built
822// (from IpplVersions.h)
824 return ippl_compile_arch;
825}
826
827
829// compileDate: return the date on which this library was prepared for
830// compilation (from IpplVersions.h)
832 return ippl_compile_date;
833}
834
835
837// compileLine: return the compiler command used to compile each source file
838// (from IpplVersions.h)
840 return ippl_compile_line;
841}
842
843
845// compileMachine: return the machine on which this library was
846// compiled (from IpplVersions.h)
848 return ippl_compile_machine;
849}
850
851
853// compileOptions: return the option list used to compile this library
854// (from IpplVersions.h)
856 return ippl_compile_options;
857}
858
859
861// compileUser: return the username of the user who compiled this
862// library (from IpplVersions.h)
864 return ippl_compile_user;
865}
866
867
869// param_error: print out an error message when an illegal cmd-line
870// parameter is encountered.
871// Arguments are: parameter, error message, bad value (if any)
872void IpplInfo::param_error(const char *param, const char *msg,
873 const char *bad) {
874 if ( param != 0 )
875 ERRORMSG(param << " ");
876 if ( bad != 0 )
877 ERRORMSG(bad << " ");
878 if ( msg != 0 )
879 ERRORMSG(": " << msg);
880 ERRORMSG(endl);
882}
883
884void IpplInfo::param_error(const char *param, const char *msg1,
885 const char *msg2, const char *bad) {
886 if ( param != 0 )
887 ERRORMSG(param << " ");
888 if ( bad != 0 )
889 ERRORMSG(bad << " ");
890 if ( msg1 != 0 )
891 ERRORMSG(": " << msg1);
892 if ( msg2 != 0 )
893 ERRORMSG(msg2);
894 ERRORMSG(endl);
896}
897
898
900// find out how many SMP's there are, and which processor we are on
901// our local SMP (e.g., if there are two SMP's with 4 nodes each,
902// the process will have a node number from 0 ... 7, and an SMP node
903// number from 0 ... 3
905 // Inform dbgmsg("IpplInfo::find_smp_nodes", INFORM_ALL_NODES);
906
907 // create a tag for use in sending info to/from other nodes
908 int tag = Comm->next_tag(IPPL_MAKE_HOST_MAP_TAG, IPPL_TAG_CYCLE);
909
910 // create arrays to store the Node -> SMP mapping, and the relative
911 // SMP node number
912 if (SMPIDList != 0)
913 delete [] SMPIDList;
914 if (SMPNodeList != 0)
915 delete [] SMPNodeList;
916 SMPIDList = new int[TotalNodes];
917 SMPNodeList = new int[TotalNodes];
918
919 // obtain the hostname and processor ID to send out
920 char name[1024];
921 if (gethostname(name, 1023) != 0) {
922 ERRORMSG("Could not get hostname ... using localhost." << endl);
923 strcpy(name, "localhost");
924 }
925 std::string NodeName(name,strlen(name));
926 // dbgmsg << "My hostname is " << NodeName << endl;
927
928 // all other nodes send their hostname to node 0; node 0 gets the names,
929 // maps pnode ID's -> SMP ID's, then broadcasts all the necessary info to
930 // all other nodes
931 if (MyNode != 0) {
932 // other nodes send their node name to node 0
933 Message *msg = new Message;
934 ::putMessage(*msg,NodeName);
935 // dbgmsg << "Sending my name to node 0." << endl;
936 Comm->send(msg, 0, tag);
937
938 // receive back the SMPIDList mapping
939 int node = 0;
940 msg = Comm->receive_block(node, tag);
941 PInsist(msg != 0 && node == 0,
942 "SPMDList map not received from master in IpplInfo::find_smp_nodes!!");
945 delete msg;
946 }
947 else {
948 // collect node names from everyone else, and then retransmit the collected
949 // list.
950 SMPIDList[0] = 0;
953 smpMap.insert(vmap<std::string,int>::value_type(NodeName, 0));
954 unsigned int unreceived = TotalNodes - 1;
955 while (unreceived-- > 0) {
956 // get the hostname from the remote node
957 int node = COMM_ANY_NODE;
958 Message *msg = Comm->receive_block(node, tag);
959 PInsist(msg != 0,
960 "Hostname not received by master in IpplInfo::find_smp_nodes!!");
961 std::string nodename;
962 ::getMessage(*msg,nodename);
963 delete msg;
964 // dbgmsg <<"Received name '"<< nodename <<"' from node "<< node<<endl;
965
966 // put it in the mapping from hostname -> SMP ID, if necessary
967 smpiter = smpMap.find(nodename);
968 if (smpiter == smpMap.end())
969 smpMap.insert(vmap<std::string,int>::value_type(nodename,smpMap.size()));
970
971 // from the hostname, get the SMP ID number and store it in SMPIDList
972 SMPIDList[node] = smpMap[nodename];
973 }
974
975 // convert from SMPID mapping -> relative node number
976 for (int smpindx = 0; (unsigned int) smpindx < smpMap.size(); ++smpindx) {
977 int smpnodes = 0;
978 for (int n=0; n < TotalNodes; ++n) {
979 if (SMPIDList[n] == smpindx)
980 SMPNodeList[n] = smpnodes++;
981 }
982 }
983
984 // broadcast SMP info to other nodes
985 if (TotalNodes > 1) {
986 Message *msg = new Message;
989 Comm->broadcast_others(msg, tag);
990 }
991 }
992
993 // compute number of SMP's ... necessary for all but node 0, but we'll do
994 // it for all
995 NumSMPs = 0;
996 for (int ns=0; ns < TotalNodes; ++ns)
997 if (SMPNodeList[ns] == 0)
998 NumSMPs++;
999
1000 // dbgmsg << "Results of SMP mapping: NumSMPs = " << NumSMPs << endl;
1001 // for (unsigned int n=0; n < TotalNodes; ++n) {
1002 // dbgmsg << " n=" << n << ", SMPID=" << SMPIDList[n] << ", SMPNode=";
1003 // dbgmsg << SMPNodeList[n] << endl;
1004 // }
1005}
1006
1009
1010 StaticIpplInfo obj;
1011
1012 obj.Comm = Comm;
1013 obj.Stats = Stats;
1014 obj.Info = Info;
1015 obj.Warn = Warn;
1016 obj.Error = Error;
1017 obj.Debug = Debug;
1023 obj.NumCreated = NumCreated;
1025 obj.PrintStats = PrintStats;
1028 obj.Retransmit = Retransmit;
1029 obj.MyArgc = MyArgc;
1030 obj.MyArgv = MyArgv;
1031 obj.MyNode = MyNode;
1032 obj.TotalNodes = TotalNodes;
1033 obj.NumSMPs = NumSMPs;
1034 obj.SMPIDList = SMPIDList;
1037 obj.ChunkSize = ChunkSize;
1039
1040 stashedStaticMembers.push(obj);
1041
1042 Comm = 0;
1043 Stats = 0;
1044 Info = 0;
1045 Warn = 0;
1046 Error = 0;
1047 Debug = 0;
1048
1049 deferGuardCellFills = false;
1050 noFieldCompression = false;
1051 offsetStorage = false;
1052 extraCompressChecks = false;
1053 communicator_m = MPI_COMM_WORLD;
1054 NumCreated = 0;
1055 CommInitialized = false;
1056 PrintStats = false;
1057 NeedDeleteComm = false;
1058 UseChecksums = false;
1059 Retransmit = false;
1060 MyArgc = 0;
1061 MyArgv = 0;
1062 MyNode = 0;
1063 TotalNodes = 1;
1064 NumSMPs = 1;
1065 SMPIDList = 0;
1066 SMPNodeList = 0;
1067 MaxFFTNodes = 0;
1068 ChunkSize = 512*1024; // 512K == 64K doubles
1069 PerSMPParallelIO = false;
1070}
1071
1074
1077 // Delete the communications object, if necessary, to shut down parallel
1078 // environment
1079 // Comm is deleted in destructor
1080 delete [] MyArgv;
1081 delete [] SMPIDList;
1082 delete [] SMPNodeList;
1083 delete Info;
1084 delete Warn;
1085 delete Error;
1086 delete Debug;
1087 delete Stats;
1088
1089 Comm = obj.Comm;
1090 Stats = obj.Stats;
1091 Info = obj.Info;
1092 Warn = obj.Warn;
1093 Error = obj.Error;
1094 Debug = obj.Debug;
1100 NumCreated = obj.NumCreated;
1102 PrintStats = obj.PrintStats;
1105 Retransmit = obj.Retransmit;
1106 MyArgc = obj.MyArgc;
1107 MyArgv = obj.MyArgv;
1108 MyNode = obj.MyNode;
1109 TotalNodes = obj.TotalNodes;
1110 NumSMPs = obj.NumSMPs;
1111 SMPIDList = obj.SMPIDList;
1114 ChunkSize = obj.ChunkSize;
1116}
#define IPPL_TAG_CYCLE
Definition Tags.h:90
#define IPPL_MAKE_HOST_MAP_TAG
Definition Tags.h:89
#define IPPL_ABORT_TAG
Definition Tags.h:25
const int COMM_ANY_NODE
Definition Communicate.h:40
void putMessage(Message &m, const T &t)
Definition Message.h:549
void getMessage_iter(Message &m, OutputIterator o)
Definition Message.h:595
void getMessage(Message &m, T &t)
Definition Message.h:572
std::ostream & operator<<(std::ostream &o, const IpplInfo &)
Definition IpplInfo.cpp:119
#define ERRORMSG(msg)
Definition IpplInfo.h:350
#define INFOMSG(msg)
Definition IpplInfo.h:348
Inform & endl(Inform &inf)
Definition Inform.cpp:42
#define INFORM_ALL_NODES
Definition Inform.h:39
RandomNumberGen IpplRandom
#define PInsist(c, m)
Definition PAssert.h:120
#define PAssert_EQ(a, b)
Definition PAssert.h:104
const std::string name
Definition types.h:26
static void setDefaultNodes(int)
static bool supported(int)
static const char * getAllMethodNames()
static bool setDefaultMethod(int)
static const char * getAllLibraryNames()
static bool supported(int)
static Communicate * create(int, int &, char **&, int=(-1), bool=true, MPI_Comm mpicomm=MPI_COMM_WORLD)
static bool known(const char *nm)
Definition CommCreator.h:69
virtual const char * name() const
Inform & setOutputLevel(const int)
Definition Inform.cpp:228
static bool NeedDeleteComm
Definition IpplInfo.h:298
static void deleteGlobals()
Definition IpplInfo.cpp:69
static bool noFieldCompression
Definition IpplInfo.h:262
static int NumCreated
Definition IpplInfo.h:287
static void printStatistics(Inform &)
Definition IpplInfo.cpp:808
static void instantiateGlobals()
Definition IpplInfo.cpp:54
static bool extraCompressChecks
Definition IpplInfo.h:270
static void printVersion(void)
Definition IpplInfo.cpp:755
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:763
static void pop()
static int NumSMPs
Definition IpplInfo.h:317
static const char * compileMachine()
Definition IpplInfo.cpp:847
static int * SMPNodeList
Definition IpplInfo.h:319
static int MyArgc
Definition IpplInfo.h:307
static void stash()
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 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:872
static void abort(const char *=0)
Definition IpplInfo.cpp:617
static int getProcesses(int, int)
Definition IpplInfo.cpp:703
static int getContexts(int)
Definition IpplInfo.cpp:696
static int getSMPNodes(int)
Definition IpplInfo.cpp:725
static const char * compileLine()
Definition IpplInfo.cpp:839
static const char * compileArch()
Definition IpplInfo.cpp:823
static bool retransmit()
Definition IpplInfo.h:195
static void find_smp_nodes()
Definition IpplInfo.cpp:904
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:718
static const char * version()
Definition IpplInfo.cpp:814
static void here()
Definition IpplInfo.cpp:802
static void abortAllNodes(const char *=0)
Definition IpplInfo.cpp:666
static int getNodes()
Definition IpplInfo.cpp:689
static bool PrintStats
Definition IpplInfo.h:295
static int mySMPNode()
Definition IpplInfo.cpp:747
static std::stack< StaticIpplInfo > stashedStaticMembers
Definition IpplInfo.h:333
static const char * compileUser()
Definition IpplInfo.cpp:863
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:710
static Communicate * Comm
Definition IpplInfo.h:84
static int mySMP()
Definition IpplInfo.cpp:740
static const char * compileDate()
Definition IpplInfo.cpp:831
IpplInfo & operator=(const IpplInfo &)
Definition IpplInfo.cpp:612
static const char * compileOptions()
Definition IpplInfo.cpp:855
static int ChunkSize
Definition IpplInfo.h:326
void print(Inform &)
Timer & getTime()
Definition IpplStats.h:82
void AdvanceSeed(int adv=0)
Definition RNGXDiv.h:147
Communicate * Comm
MPI_Comm communicator_m
IpplStats * Stats
void start()
Definition Timer.cpp:32
void stop()
Definition Timer.cpp:37
void clear()
Definition Timer.cpp:27
double clock_time()
Definition Timer.cpp:48
double cpu_time()
Definition Timer.cpp:52
Definition vmap.h:59
rep_type::iterator iterator
Definition vmap.h:98
size_type size() const
Definition vmap.h:120
iterator end()
Definition vmap.h:108
iterator find(const key_type &x)
Definition vmap.hpp:214
std::pair< Key, T > value_type
Definition vmap.h:64
std::pair< iterator, bool > insert(const value_type &x)
Definition vmap.hpp:73