00001
00002
00003
00004
00005
00006
00007 #ifndef BALL_SYSTEM_MPISUPPORT_H
00008 #define BALL_SYSTEM_MPISUPPORT_H
00009
00010 #ifndef BALL_COMMON_H
00011 # include <BALL/common.h>
00012 #endif
00013
00014 #ifndef BALL_DATATYPE_STRING_H
00015 # include <BALL/DATATYPE/string.h>
00016 #endif
00017
00018 #ifndef BALL_MATHS_VECTOR3_H
00019 # include <BALL/MATHS/vector3.h>
00020 #endif
00021
00022 #ifndef BALL_COMMON_EXCEPTION_H
00023 # include <BALL/COMMON/exception.h>
00024 #endif
00025
00026 #include <iostream>
00027
00028 #include <mpi.h>
00029
00030 #if MPI_VERSION >= 2
00031 # define BALL_HAS_MPI2_SUPPORT TRUE
00032 #else
00033 # undef BALL_HAS_MPI2_SUPPORT
00034 #endif
00035
00036 namespace BALL
00037 {
00038 class System;
00039 class Options;
00040
00044 class BALL_EXPORT MPISupport
00045 {
00046 public:
00047
00050 enum TAGS
00051 {
00052 TAG_SYSTEM,
00053 TAG_OPTIONS
00054 };
00055
00059
00065 MPISupport(MPI_Comm default_communicator = MPI_COMM_WORLD);
00066
00081 MPISupport(int argc, char** argv,
00082 MPI_Comm default_communicator = MPI_COMM_WORLD,
00083 bool accept_communicator = true);
00084
00089 ~MPISupport();
00091
00095
00097 Index getRank();
00098
00100 Index getSize();
00101
00103 MPI_Comm getDefaultCommunicator();
00104
00106 void setDefaultCommunicator(MPI_Comm default_communicator);
00107
00111 bool getFinalizeOnDestruct();
00112
00114 void setFinalizeOnDestruct(bool new_value);
00115
00120 void setMpiInfo(const MPI_Info &mpi_info);
00121
00123 bool isMaster();
00124
00134 void init(int argc, char** argv, bool accept_communicator = true);
00135
00141 void setBarrier();
00142
00149 void sendSystem(const System& system, bool broadcast = true, int receiver = 0);
00150
00156 System* receiveSystem(bool broadcast = true, int source = MPI_ANY_SOURCE);
00157
00164 void sendOptions(const Options& options, bool broadcast = true, int receiver = 0);
00165
00171 Options* receiveOptions(bool broadcast = true, int source = MPI_ANY_SOURCE);
00172
00178 template <typename valuetype>
00179 void distributeDatapoints(const std::vector<valuetype>& input, std::vector<valuetype>& our_share);
00180
00184 template <typename valuetype>
00185 void acceptDatapoints(std::vector<valuetype>& our_share);
00186
00191 template <typename valuetype>
00192 void combineDatapoints(const std::vector<valuetype>& our_share)
00193 throw(Exception::OutOfMemory);
00194
00198 template <typename valuetype>
00199 void acceptCombinedDatapoints(std::vector<valuetype>& combined_set, std::vector<valuetype>& our_share)
00200 throw(Exception::OutOfMemory);
00201
00210 void* distributeDatapoints(const void* input, int size, Size& numpoints, MPI_Datatype datatype);
00211
00217 void* acceptDatapoints(Size& numpoints, MPI_Datatype datatype);
00218
00224 void combineDatapoints(const void* input, int size, MPI_Datatype datatype);
00225
00234 void* acceptCombinedDatapoints(const void* input, int size, Size& numpoints, MPI_Datatype datatype);
00235
00268 #ifdef BALL_HAS_MPI2_SUPPORT
00269 Size spawn(const String& command, char *argv[], Size wanted_number_of_processes = 0, bool merge_communicator = true);
00270 #endif
00271
00278 template <typename valuetype>
00279 valuetype getSum(valuetype& local_value);
00280
00287 template <typename valuetype>
00288 valuetype getProduct(valuetype& local_value);
00289
00297 template <typename valuetype>
00298 valuetype getMaximum(valuetype& local_value);
00299
00307 template <typename valuetype>
00308 valuetype getMinimum(valuetype& local_value);
00310
00311 protected:
00314 void registerTypes_();
00315
00319 void sendPersistenceStream_(const std::ostringstream& stream,
00320 int tag = MPI_ANY_TAG, bool broadcast = true, int receiver = 0);
00321
00326 void receivePersistenceStream_(std::istringstream& in, int tag = MPI_ANY_TAG,
00327 bool broadcast = true, int source = 0);
00328
00329 Index rank_;
00330 Index comm_size_;
00331 bool finalize_on_destruct_;
00332 MPI_Comm default_communicator_;
00333 MPI_Info mpi_info_object_;
00334 MPI_Datatype mpi_Vector3_float_type_;
00335 MPI_Datatype mpi_Vector3_double_type_;
00336 };
00337 }
00338 #endif
00339
00340