BALL  1.4.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
MPISupport.h
Go to the documentation of this file.
1 // -*- Mode: C++; tab-width: 2; -*-
2 // vi: set ts=2:
3 //
4 // $Id: MPISupport.h,v 1.1.2.4 2006/03/02 18:52:57 anhi Exp $
5 //
6 
7 #ifndef BALL_SYSTEM_MPISUPPORT_H
8 #define BALL_SYSTEM_MPISUPPORT_H
9 
10 #ifndef BALL_COMMON_H
11 # include <BALL/common.h>
12 #endif
13 
14 #ifndef BALL_DATATYPE_STRING_H
15 # include <BALL/DATATYPE/string.h>
16 #endif
17 
18 #ifndef BALL_MATHS_VECTOR3_H
19 # include <BALL/MATHS/vector3.h>
20 #endif
21 
22 #ifndef BALL_COMMON_EXCEPTION_H
23 # include <BALL/COMMON/exception.h>
24 #endif
25 
26 #include <iostream>
27 
28 #include <mpi.h>
29 
30 #if MPI_VERSION >= 2
31 # define BALL_HAS_MPI2_SUPPORT TRUE
32 #else
33 # undef BALL_HAS_MPI2_SUPPORT
34 #endif
35 
36 namespace BALL
37 {
38  class System;
39  class Options;
40 
45  {
46  public:
47 
50  enum TAGS
51  {
53  TAG_OPTIONS
54  };
55 
59 
65  MPISupport(MPI_Comm default_communicator = MPI_COMM_WORLD);
66 
81  MPISupport(int argc, char** argv,
82  MPI_Comm default_communicator = MPI_COMM_WORLD,
83  bool accept_communicator = true);
84 
89  ~MPISupport();
91 
95 
97  Index getRank();
98 
100  Index getSize();
101 
103  MPI_Comm getDefaultCommunicator();
104 
106  void setDefaultCommunicator(MPI_Comm default_communicator);
107 
111  bool getFinalizeOnDestruct();
112 
114  void setFinalizeOnDestruct(bool new_value);
115 
120  void setMpiInfo(const MPI_Info &mpi_info);
121 
123  bool isMaster();
124 
134  void init(int argc, char** argv, bool accept_communicator = true);
135 
141  void setBarrier();
142 
149  void sendSystem(const System& system, bool broadcast = true, int receiver = 0);
150 
156  System* receiveSystem(bool broadcast = true, int source = MPI_ANY_SOURCE);
157 
164  void sendOptions(const Options& options, bool broadcast = true, int receiver = 0);
165 
171  Options* receiveOptions(bool broadcast = true, int source = MPI_ANY_SOURCE);
172 
178  template <typename valuetype>
179  void distributeDatapoints(const std::vector<valuetype>& input, std::vector<valuetype>& our_share);
180 
184  template <typename valuetype>
185  void acceptDatapoints(std::vector<valuetype>& our_share);
186 
191  template <typename valuetype>
192  void combineDatapoints(const std::vector<valuetype>& our_share)
193  throw(Exception::OutOfMemory);
194 
198  template <typename valuetype>
199  void acceptCombinedDatapoints(std::vector<valuetype>& combined_set, std::vector<valuetype>& our_share)
200  throw(Exception::OutOfMemory);
201 
210  void* distributeDatapoints(const void* input, int size, Size& numpoints, MPI_Datatype datatype);
211 
217  void* acceptDatapoints(Size& numpoints, MPI_Datatype datatype);
218 
224  void combineDatapoints(const void* input, int size, MPI_Datatype datatype);
225 
234  void* acceptCombinedDatapoints(const void* input, int size, Size& numpoints, MPI_Datatype datatype);
235 
268 #ifdef BALL_HAS_MPI2_SUPPORT
269  Size spawn(const String& command, char *argv[], Size wanted_number_of_processes = 0, bool merge_communicator = true);
270 #endif
271 
278  template <typename valuetype>
279  valuetype getSum(valuetype& local_value);
280 
287  template <typename valuetype>
288  valuetype getProduct(valuetype& local_value);
289 
297  template <typename valuetype>
298  valuetype getMaximum(valuetype& local_value);
299 
307  template <typename valuetype>
308  valuetype getMinimum(valuetype& local_value);
310 
311  protected:
314  void registerTypes_();
315 
319  void sendPersistenceStream_(const std::ostringstream& stream,
320  int tag = MPI_ANY_TAG, bool broadcast = true, int receiver = 0);
321 
326  void receivePersistenceStream_(std::istringstream& in, int tag = MPI_ANY_TAG,
327  bool broadcast = true, int source = 0);
328 
336  };
337 }
338 #endif
339 
340