// BLMPI.hh -- MPI interface for parallelization /* This source file is part of G4beamline, http://g4beamline.muonsinc.com Copyright (C) 2003,2004,2005,2006 by Tom Roberts, all rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. http://www.gnu.org/copyleft/gpl.html */ #ifndef BLMPI_HH #define BLMPI_HH /** class BLMPI implements MPI interface for parallelization. * * BLMPI handles G4beamline-specific MPI stuff. * * NOTE: No other class should call any MPI functions directly. This * implies that the only #include should be in BLMPI.cc. * * NOTE: When running in MPI mode, threads are not permitted. * * When running under MPI, all BLNTuples are physically written * only by the rank-0 instance; MPI is used by all other instances to * send messages to rank-0 to create BLNTuple-s and to append rows to * BLNTuple-s. * * This entire class is static. **/ class BLMPI { static int rank; static int nodes; static void mainRankZero(); static void mainRankNonZero(); static int nComplete; static double startupTime; static double startupWaitTime; static double computeTime; static double computeWaitTime; public: /// init() will check whether or not we are running under MPI, /// and will initialize MPI if so. /// MUST be called before any other BLMPI routine. /// NOTE: for all but rank-0, sets stdout to /dev/null (stderr /// remains connected for all ranks, so G4Exception will be seen). static void init(int *argc, char ***argv); /// isMPI() returns true if in MPI mode. static bool isMPI(); /// isRank0() returns false in non-MPI mode, and returns true if /// this node is rank 0 in MPI. static bool isRank0(); /// isRank1() returns true in non-MPI mode, and returns true if /// this node is rank 1 in MPI. Used for Traces and other things /// that should happen once per simulation, not once per node. static bool isRank1(); /// main will perform the computation in MPI mode. /// In non-MPI mode this is a no-op that returns immediately. /// In MPI mode this determines the collective/serial mode and then /// performs the computation, never returning. static void main(); }; #endif // BLMPI_HH