Bridge++  Version 1.5.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
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  // async communication
92  static Channel *send_init(int count, int idir, int ipm);
93  static Channel *recv_init(int count, int idir, int ipm);
94 
95  // logical and physical layout
96  class Layout;
97 
98  private:
102 
104 
105 #ifdef ENABLE_MULTI_INSTANCE
106  static int m_n_instance; // number of instances
107  static int m_instance_id; // id of present instance
108 
109  static int m_global_rank;
110  static int m_global_size;
111 #endif
112 
113  static int m_grid_rank;
114  static int m_grid_size;
115 
116  static MPI_Comm m_comm;
117 
118  static char default_grid_map[16];
119 };
120 #endif /* COMMUNICATOR_MPI_INCLUDED */
static int send_1to1(size_t size, void *recv_buf, void *send_buf, int send_to, int recv_from, int tag)
static int broadcast(size_t size, void *data, int sender)
static char default_grid_map[16]
static int setup(int ninstance=1)
static bool is_primary()
Channel class for asynchronous communication.
Definition: channel.h:48
static int init(int *pargc, char ***pargv)
Layout class for logical organisation of parallel nodes.
Definition: layout.h:28
static MPI_Comm m_comm
static MPI_Comm & world()
retrieves current communicator.
static int broadcast_string(int count, string &data, int sender)
Communicator_impl & operator=(const Communicator_impl &)
static double get_time()
static int sync_usleep()
static int reduce(int count, void *recv_buf, void *send_buf, MPI_Datatype type, MPI_Op op, int pattern)
static Channel * recv_init(int count, int idir, int ipm)
Definition: channel.cpp:65
static Channel * send_init(int count, int idir, int ipm)
Definition: channel.cpp:28
Communicator_impl(const Communicator_impl &)
MPI-realisation of communicator class implementation.
static int exchange(size_t size, void *recv_buf, void *send_buf, int idir, int ipm, int tag)