Bridge++  Ver. 2.0.2
communicator_mpi.h
Go to the documentation of this file.
1 
14 #ifndef COMMUNICATOR_MPI_INCLUDED
15 #define COMMUNICATOR_MPI_INCLUDED
16 
17 #include <cstdarg>
18 #include <cstring>
19 #include <exception>
20 
22 #include "channel.h"
23 
25 
32 class Communicator_impl {
33  public:
34  static int init(int *pargc, char ***pargv);
35  static int finalize();
36  static void abort();
37 
38  static int setup(int Ninstance = 1);
39 
40  static int setup(const std::vector<int>& lattice_size,
41  std::vector<int>& grid_size,
42  int Ninstance = 1);
43 
44  // info about rank
45  static bool is_primary();
46 
47 #ifdef ENABLE_MULTI_INSTANCE
48  static bool is_primary_master();
49 #endif
50 
51  static int self(); //< rank within small world.
52  static int size(); //< size of small world.
53 
54 #ifdef ENABLE_MULTI_INSTANCE
55  static int self_global();
56  static int world_id();
57 #endif
58 
59  // world
60  static MPI_Comm& world() { return m_comm; }
61 
62  // synchronize
63  static int sync(); //< synchronize within small world.
64 
65  // synchronize (uses usleep to avoid busy wait)
66  static int sync_usleep(); //< synchronize within small world. (w/o busy wait)
67 
68 #ifdef ENABLE_MULTI_INSTANCE
69  static int sync_global(); //< synchronize all processes.
70 #endif
71 
72  // info
73  static double get_time();
74 
75  // debug
76  static int status();
77 
78  // base case
79  class Base {
80  public:
81  static int reduce(int count, void *recv_buf, void *send_buf, MPI_Datatype type, MPI_Op op, int pattern);
82  static int broadcast(size_t size, void *data, int sender);
83  static int exchange(size_t size, void *recv_buf, void *send_buf, int idir, int ipm, int tag);
84 
85  static int send_1to1(size_t size, void *recv_buf, void *send_buf, int send_to, int recv_from, int tag);
86  };
87 
88  // for specific datatypes
89  static int broadcast_string(int count, string& data, int sender);
90 
91  // logical and physical layout
92  class Layout;
93 
94  private:
98 
100 
101 #ifdef ENABLE_MULTI_INSTANCE
102  static int m_Ninstance; // number of instances
103  static int m_instance_id; // id of present instance
104 
105  static int m_global_rank;
106  static int m_global_size;
107 #endif
108 
109  static int m_grid_rank;
110  static int m_grid_size;
111 
112  static MPI_Comm m_comm;
113 
114  static char default_grid_map[16];
115 };
116 #endif /* COMMUNICATOR_MPI_INCLUDED */
Communicator_impl::Base::reduce
static int reduce(int count, void *recv_buf, void *send_buf, MPI_Datatype type, MPI_Op op, int pattern)
Definition: communicator_mpi.cpp:323
Communicator_impl::m_grid_size
static int m_grid_size
Definition: communicator_mpi.h:110
Communicator_impl::Communicator_impl
Communicator_impl()
Definition: communicator_mpi.h:95
Communicator_impl::setup
static int setup(int Ninstance=1)
Definition: communicator_mpi.cpp:86
Communicator_impl::sync
static int sync()
Definition: communicator_mpi.cpp:216
Communicator_impl::Base::send_1to1
static int send_1to1(size_t size, void *recv_buf, void *send_buf, int send_to, int recv_from, int tag)
Definition: communicator_mpi.cpp:300
Communicator_impl
MPI-realisation of communicator class implementation.
Definition: communicator_mpi.h:32
Communicator_impl::~Communicator_impl
~Communicator_impl()
Definition: communicator_mpi.h:99
Communicator_impl::status
static int status()
Definition: communicator_mpi.cpp:376
Communicator_impl::abort
static void abort()
Definition: communicator_mpi.cpp:159
Communicator_impl::Base::broadcast
static int broadcast(size_t size, void *data, int sender)
Definition: communicator_mpi.cpp:259
Communicator_impl::init
static int init(int *pargc, char ***pargv)
Definition: communicator_mpi.cpp:38
Communicator_impl::operator=
Communicator_impl & operator=(const Communicator_impl &)
channel.h
Communicator_impl::m_comm
static MPI_Comm m_comm
Definition: communicator_mpi.h:112
Communicator_impl::m_grid_rank
static int m_grid_rank
Definition: communicator_mpi.h:109
Communicator_impl::get_time
static double get_time()
Definition: communicator_mpi.cpp:368
Communicator_impl::default_grid_map
static char default_grid_map[16]
Definition: communicator_mpi.h:114
Communicator_impl::Base::exchange
static int exchange(size_t size, void *recv_buf, void *send_buf, int idir, int ipm, int tag)
Definition: communicator_mpi.cpp:267
Communicator_impl::finalize
static int finalize()
Definition: communicator_mpi.cpp:78
Communicator_impl::Communicator_impl
Communicator_impl(const Communicator_impl &)
Definition: communicator_mpi.h:96
Communicator_impl::is_primary
static bool is_primary()
Definition: communicator_mpi.cpp:169
Communicator_impl::sync_usleep
static int sync_usleep()
Definition: communicator_mpi.cpp:225
communicator.h
Communicator_impl::size
static int size()
Definition: communicator_mpi.cpp:183
Communicator_impl::broadcast_string
static int broadcast_string(int count, string &data, int sender)
Definition: communicator_mpi.cpp:332
Element_type::type
type
Definition: bridge_defs.h:41