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