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 
BALL::MPISupport::getRank
Index getRank()
Return the rank of this process.
BALL_EXPORT
#define BALL_EXPORT
Definition: COMMON/global.h:50
BALL::MPISupport::registerTypes_
void registerTypes_()
BALL::MPISupport::sendSystem
void sendSystem(const System &system, bool broadcast=true, int receiver=0)
BALL::MPISupport::TAG_SYSTEM
@ TAG_SYSTEM
Definition: MPISupport.h:52
BALL::MPISupport::isMaster
bool isMaster()
Returns true if this process is the master, false otherwise.
BALL::MPISupport::sendOptions
void sendOptions(const Options &options, bool broadcast=true, int receiver=0)
BALL::MPISupport::mpi_Vector3_double_type_
MPI_Datatype mpi_Vector3_double_type_
Definition: MPISupport.h:335
BALL::Options
Definition: options.h:48
BALL::MPISupport::getFinalizeOnDestruct
bool getFinalizeOnDestruct()
BALL::MPISupport::acceptCombinedDatapoints
void acceptCombinedDatapoints(std::vector< valuetype > &combined_set, std::vector< valuetype > &our_share)
BALL::MPISupport::sendPersistenceStream_
void sendPersistenceStream_(const std::ostringstream &stream, int tag=MPI_ANY_TAG, bool broadcast=true, int receiver=0)
BALL::MPISupport::init
void init(int argc, char **argv, bool accept_communicator=true)
BALL::MPISupport::acceptCombinedDatapoints
void * acceptCombinedDatapoints(const void *input, int size, Size &numpoints, MPI_Datatype datatype)
BALL::System
Definition: KERNEL/system.h:40
BALL::MPISupport::getMinimum
valuetype getMinimum(valuetype &local_value)
vector3.h
BALL::MPISupport::getProduct
valuetype getProduct(valuetype &local_value)
BALL::MPISupport::~MPISupport
~MPISupport()
BALL::MPISupport::mpi_Vector3_float_type_
MPI_Datatype mpi_Vector3_float_type_
Definition: MPISupport.h:334
BALL::MPISupport::distributeDatapoints
void distributeDatapoints(const std::vector< valuetype > &input, std::vector< valuetype > &our_share)
BALL::MPISupport::getSize
Index getSize()
Return the number of processes in MPI_COMM_WORLD.
BALL::MPISupport::distributeDatapoints
void * distributeDatapoints(const void *input, int size, Size &numpoints, MPI_Datatype datatype)
BALL::String
Definition: string.h:57
BALL::MPISupport::receiveSystem
System * receiveSystem(bool broadcast=true, int source=MPI_ANY_SOURCE)
BALL::MPISupport::getSum
valuetype getSum(valuetype &local_value)
BALL::MPISupport::acceptDatapoints
void acceptDatapoints(std::vector< valuetype > &our_share)
BALL::MPISupport::setFinalizeOnDestruct
void setFinalizeOnDestruct(bool new_value)
Decides whether MPI_Finalize will be called in the destructor.
BALL
Definition: constants.h:13
BALL::MPISupport
Definition: MPISupport.h:45
BALL_INDEX_TYPE
BALL_SIZE_TYPE
BALL::MPISupport::receiveOptions
Options * receiveOptions(bool broadcast=true, int source=MPI_ANY_SOURCE)
BALL::MPISupport::acceptDatapoints
void * acceptDatapoints(Size &numpoints, MPI_Datatype datatype)
BALL::MPISupport::mpi_info_object_
MPI_Info mpi_info_object_
Definition: MPISupport.h:333
string.h
BALL::MPISupport::MPISupport
MPISupport(MPI_Comm default_communicator=MPI_COMM_WORLD)
BALL::MPISupport::combineDatapoints
void combineDatapoints(const void *input, int size, MPI_Datatype datatype)
BALL::MPISupport::finalize_on_destruct_
bool finalize_on_destruct_
Definition: MPISupport.h:331
exception.h
BALL::MPISupport::setBarrier
void setBarrier()
BALL::MPISupport::getDefaultCommunicator
MPI_Comm getDefaultCommunicator()
Return the default communicator used for MPI calls.
BALL::MPISupport::receivePersistenceStream_
void receivePersistenceStream_(std::istringstream &in, int tag=MPI_ANY_TAG, bool broadcast=true, int source=0)
BALL::MPISupport::combineDatapoints
void combineDatapoints(const std::vector< valuetype > &our_share)
common.h
BALL::MPISupport::setMpiInfo
void setMpiInfo(const MPI_Info &mpi_info)
BALL::MPISupport::rank_
Index rank_
Definition: MPISupport.h:329
BALL::MPISupport::getMaximum
valuetype getMaximum(valuetype &local_value)
BALL::MPISupport::default_communicator_
MPI_Comm default_communicator_
Definition: MPISupport.h:332
BALL::MPISupport::comm_size_
Index comm_size_
Definition: MPISupport.h:330
BALL::MPISupport::setDefaultCommunicator
void setDefaultCommunicator(MPI_Comm default_communicator)
Set the default communicator used for MPI calls.
BALL::MPISupport::MPISupport
MPISupport(int argc, char **argv, MPI_Comm default_communicator=MPI_COMM_WORLD, bool accept_communicator=true)
BALL::MPISupport::TAGS
TAGS
Definition: MPISupport.h:51