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 #ifdef TOOLS_MEM
0014 #include <tools/mem>
0015 #endif
0016 
0017 namespace toolx {
0018 namespace mpi {
0019 
0020 class world : public virtual tools::impi_world {
0021   typedef tools::impi_world parent;
0022 #ifdef TOOLS_MEM
0023 protected:
0024   static const std::string& s_class() {
0025     static const std::string s_v("toolx::mpi::world");
0026     return s_v;
0027   }
0028 #endif
0029 public:
0030   virtual bool init(int* a_argc,char*** a_argv) {
0031     if(::MPI_Init(a_argc,a_argv)!=MPI_SUCCESS) return false;
0032     return true;
0033   }
0034   virtual bool rank(int& a_rank) const {
0035     if(::MPI_Comm_rank(MPI_COMM_WORLD,&a_rank)!=MPI_SUCCESS) {a_rank=-1;return false;}
0036     return true;
0037   }
0038   virtual bool size(int& a_size) const {
0039     if(::MPI_Comm_size(MPI_COMM_WORLD,&a_size)!=MPI_SUCCESS) {a_size=0;return false;}
0040     return true;
0041   }
0042   virtual bool processor_name(std::string& a_s) const {
0043     char name[MPI_MAX_PROCESSOR_NAME];
0044     int lname;
0045     if(::MPI_Get_processor_name(name,&lname)!=MPI_SUCCESS) {a_s.clear();return false;}
0046     a_s = std::string(name);
0047     return true;
0048   }
0049 public:
0050   world() {
0051 #ifdef TOOLS_MEM
0052     tools::mem::increment(s_class().c_str());
0053 #endif
0054   }
0055   virtual ~world(){
0056 #ifdef TOOLS_MEM
0057     tools::mem::decrement(s_class().c_str());
0058 #endif
0059   }
0060 protected:
0061   world(const world& a_from):parent(a_from) {
0062 #ifdef TOOLS_MEM
0063     tools::mem::increment(s_class().c_str());
0064 #endif
0065   }
0066   world& operator=(const world&) {return *this;}
0067 };
0068 
0069 }}
0070 
0071 #endif