Geant4 Cross Reference |
1 // Copyright (C) 2010, Guy Barrand. All rights reserved. 2 // See the file tools.license for terms. 3 4 #ifndef toolx_mpi_world 5 #define toolx_mpi_world 6 7 // code to wrap MPI global things by having an interface (toolx::mpi). 8 9 #include <tools/impi_world> 10 11 #include <mpi.h> 12 13 #ifdef TOOLS_MEM 14 #include <tools/mem> 15 #endif 16 17 namespace toolx { 18 namespace mpi { 19 20 class world : public virtual tools::impi_world { 21 typedef tools::impi_world parent; 22 #ifdef TOOLS_MEM 23 protected: 24 static const std::string& s_class() { 25 static const std::string s_v("toolx::mpi::world"); 26 return s_v; 27 } 28 #endif 29 public: 30 virtual bool init(int* a_argc,char*** a_argv) { 31 if(::MPI_Init(a_argc,a_argv)!=MPI_SUCCESS) return false; 32 return true; 33 } 34 virtual bool rank(int& a_rank) const { 35 if(::MPI_Comm_rank(MPI_COMM_WORLD,&a_rank)!=MPI_SUCCESS) {a_rank=-1;return false;} 36 return true; 37 } 38 virtual bool size(int& a_size) const { 39 if(::MPI_Comm_size(MPI_COMM_WORLD,&a_size)!=MPI_SUCCESS) {a_size=0;return false;} 40 return true; 41 } 42 virtual bool processor_name(std::string& a_s) const { 43 char name[MPI_MAX_PROCESSOR_NAME]; 44 int lname; 45 if(::MPI_Get_processor_name(name,&lname)!=MPI_SUCCESS) {a_s.clear();return false;} 46 a_s = std::string(name); 47 return true; 48 } 49 public: 50 world() { 51 #ifdef TOOLS_MEM 52 tools::mem::increment(s_class().c_str()); 53 #endif 54 } 55 virtual ~world(){ 56 #ifdef TOOLS_MEM 57 tools::mem::decrement(s_class().c_str()); 58 #endif 59 } 60 protected: 61 world(const world& a_from):parent(a_from) { 62 #ifdef TOOLS_MEM 63 tools::mem::increment(s_class().c_str()); 64 #endif 65 } 66 world& operator=(const world&) {return *this;} 67 }; 68 69 }} 70 71 #endif