BLMPI.hh

Go to the documentation of this file.
00001 //      BLMPI.hh -- MPI interface for parallelization
00002 /*
00003 This source file is part of G4beamline, http://g4beamline.muonsinc.com
00004 Copyright (C) 2003,2004,2005,2006 by Tom Roberts, all rights reserved.
00005 
00006 This program is free software; you can redistribute it and/or
00007 modify it under the terms of the GNU General Public License
00008 as published by the Free Software Foundation; either version 2
00009 of the License, or (at your option) any later version.
00010 
00011 This program is distributed in the hope that it will be useful,
00012 but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 GNU General Public License for more details.
00015 
00016 http://www.gnu.org/copyleft/gpl.html
00017 */
00018 
00019 #ifndef BLMPI_HH
00020 #define BLMPI_HH
00021 
00022 /**     class BLMPI implements MPI interface for parallelization.
00023  *
00024  *      BLMPI handles G4beamline-specific MPI stuff.
00025  *
00026  *      NOTE: No other class should call any MPI functions directly. This
00027  *      implies that the only #include <mpi.h> should be in BLMPI.cc.
00028  *
00029  *      NOTE: When running in MPI mode, threads are not permitted.
00030  *
00031  *      When running under MPI, all BLNTuples are physically written
00032  *      only by the rank-0 instance; MPI is used by all other instances to
00033  *      send messages to rank-0 to create BLNTuple-s and to append rows to
00034  *      BLNTuple-s.
00035  *
00036  *      This entire class is static.
00037  **/
00038 class BLMPI {
00039         static int rank;
00040         static int nodes;
00041         static void mainRankZero();
00042         static void mainRankNonZero();
00043         static int nComplete;
00044         static double startupTime;
00045         static double startupWaitTime;
00046         static double computeTime;
00047         static double computeWaitTime;
00048 public:
00049         /// init() will check whether or not we are running under MPI,
00050         /// and will initialize MPI if so. 
00051         /// MUST be called before any other BLMPI routine.
00052         /// NOTE: for all but rank-0, sets stdout to /dev/null (stderr
00053         /// remains connected for all ranks, so G4Exception will be seen).
00054         static void init(int *argc, char ***argv);
00055 
00056         /// isMPI() returns true if in MPI mode.
00057         static bool isMPI();
00058 
00059         /// isRank0() returns false in non-MPI mode, and returns true if
00060         /// this node is rank 0 in MPI.
00061         static bool isRank0();
00062 
00063         /// isRank1() returns true in non-MPI mode, and returns true if
00064         /// this node is rank 1 in MPI. Used for Traces and other things
00065         /// that should happen once per simulation, not once per node.
00066         static bool isRank1();
00067 
00068         /// main will perform the computation in MPI mode.
00069         /// In non-MPI mode this is a no-op that returns immediately.
00070         /// In MPI mode this determines the collective/serial mode and then
00071         /// performs the computation, never returning.
00072         static void main();
00073 };
00074 
00075 #endif // BLMPI_HH
g4beamline