BALL  1.5.0
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 
91 
95 
98 
101 
104 
106  void setDefaultCommunicator(MPI_Comm default_communicator);
107 
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 
192  template <typename valuetype>
193  void combineDatapoints(const std::vector<valuetype>& our_share);
194 
199  template <typename valuetype>
200  void acceptCombinedDatapoints(std::vector<valuetype>& combined_set, std::vector<valuetype>& our_share);
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:
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 
Definition: constants.h:13
BALL_INDEX_TYPE Index
MPI_Datatype mpi_Vector3_float_type_
Definition: MPISupport.h:334
Index getSize()
Return the number of processes in MPI_COMM_WORLD.
MPI_Info mpi_info_object_
Definition: MPISupport.h:333
valuetype getSum(valuetype &local_value)
void acceptCombinedDatapoints(std::vector< valuetype > &combined_set, std::vector< valuetype > &our_share)
void * acceptDatapoints(Size &numpoints, MPI_Datatype datatype)
void combineDatapoints(const std::vector< valuetype > &our_share)
bool getFinalizeOnDestruct()
Index getRank()
Return the rank of this process.
void * distributeDatapoints(const void *input, int size, Size &numpoints, MPI_Datatype datatype)
void setMpiInfo(const MPI_Info &mpi_info)
valuetype getMaximum(valuetype &local_value)
MPISupport(MPI_Comm default_communicator=MPI_COMM_WORLD)
MPI_Comm getDefaultCommunicator()
Return the default communicator used for MPI calls.
valuetype getMinimum(valuetype &local_value)
void setFinalizeOnDestruct(bool new_value)
Decides whether MPI_Finalize will be called in the destructor.
bool finalize_on_destruct_
Definition: MPISupport.h:331
void combineDatapoints(const void *input, int size, MPI_Datatype datatype)
void * acceptCombinedDatapoints(const void *input, int size, Size &numpoints, MPI_Datatype datatype)
void acceptDatapoints(std::vector< valuetype > &our_share)
Options * receiveOptions(bool broadcast=true, int source=MPI_ANY_SOURCE)
void receivePersistenceStream_(std::istringstream &in, int tag=MPI_ANY_TAG, bool broadcast=true, int source=0)
void setDefaultCommunicator(MPI_Comm default_communicator)
Set the default communicator used for MPI calls.
MPI_Datatype mpi_Vector3_double_type_
Definition: MPISupport.h:335
void sendSystem(const System &system, bool broadcast=true, int receiver=0)
bool isMaster()
Returns true if this process is the master, false otherwise.
MPI_Comm default_communicator_
Definition: MPISupport.h:332
valuetype getProduct(valuetype &local_value)
System * receiveSystem(bool broadcast=true, int source=MPI_ANY_SOURCE)
void sendPersistenceStream_(const std::ostringstream &stream, int tag=MPI_ANY_TAG, bool broadcast=true, int receiver=0)
MPISupport(int argc, char **argv, MPI_Comm default_communicator=MPI_COMM_WORLD, bool accept_communicator=true)
void sendOptions(const Options &options, bool broadcast=true, int receiver=0)
void distributeDatapoints(const std::vector< valuetype > &input, std::vector< valuetype > &our_share)
void init(int argc, char **argv, bool accept_communicator=true)
#define BALL_EXPORT
Definition: COMMON/global.h:50