Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/Geant4/toolx/mpi/world is written in an unsupported language. File is not indexed.

0001 // Copyright (C) 2010, Guy Barrand. All rights reserved.
0002 // See the file tools.license for terms.
0003 
0004 #ifndef toolx_mpi_world
0005 #define toolx_mpi_world
0006 
0007 // code to wrap MPI global things by having an interface (toolx::mpi).
0008 
0009 #include <tools/impi_world>
0010 
0011 #include <mpi.h>
0012 
0013 namespace toolx {
0014 namespace mpi {
0015 
0016 class world : public virtual tools::impi_world {
0017   typedef tools::impi_world parent;
0018 public:
0019   virtual bool init(int* a_argc,char*** a_argv) {
0020     if(::MPI_Init(a_argc,a_argv)!=MPI_SUCCESS) return false;
0021     return true;
0022   }
0023   virtual bool rank(int& a_rank) const {
0024     if(::MPI_Comm_rank(MPI_COMM_WORLD,&a_rank)!=MPI_SUCCESS) {a_rank=-1;return false;}
0025     return true;
0026   }
0027   virtual bool size(int& a_size) const {
0028     if(::MPI_Comm_size(MPI_COMM_WORLD,&a_size)!=MPI_SUCCESS) {a_size=0;return false;}
0029     return true;
0030   }
0031   virtual bool processor_name(std::string& a_s) const {
0032     char name[MPI_MAX_PROCESSOR_NAME];
0033     int lname;
0034     if(::MPI_Get_processor_name(name,&lname)!=MPI_SUCCESS) {a_s.clear();return false;}
0035     a_s = std::string(name);
0036     return true;
0037   }
0038 public:
0039   world() {
0040   }
0041   virtual ~world(){
0042   }
0043 protected:
0044   world(const world& a_from):parent(a_from) {
0045   }
0046   world& operator=(const world&) {return *this;}
0047 };
0048 
0049 }}
0050 
0051 #endif