00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifdef __GNUC__
00030 #pragma interface
00031 #endif
00032
00033 #ifndef _util_group_memmtmpi_h
00034 #define _util_group_memmtmpi_h
00035
00036 #include <fstream>
00037 #include <vector>
00038
00039 #define MPICH_SKIP_MPICXX
00040 #include <mpi.h>
00041
00042 #include <util/group/message.h>
00043 #include <util/group/memamsg.h>
00044 #include <util/group/thread.h>
00045 #include <util/misc/regtime.h>
00046
00047 namespace sc {
00048
00049 class MTMPIThread;
00050
00055 class MTMPIMemoryGrp: public ActiveMsgMemoryGrp {
00056 private:
00057 Ref<ThreadGrp> th_;
00058
00059 Ref<ThreadLock> serial_lock_;
00060 int serial_;
00061 int serial(int node);
00062
00063 MPI_Comm comp_comm_;
00064 MPI_Comm comm_comm_;
00065 int req_tag_;
00066
00067 int active_;
00068
00069 unsigned int *nreq_sent_;
00070 unsigned int *nreq_sent_buf_;
00071
00072 MTMPIThread **thread_;
00073 Ref<ThreadLock> print_lock_;
00074 std::ofstream hout;
00075 std::ofstream mout;
00076
00077 void init_mtmpimg(MPI_Comm comm, int nthreads);
00078
00079 Ref<RegionTimer> timer_;
00080
00081
00082 int nbuffer_;
00083
00084 int current_datareq_index_;
00085 std::vector<MemoryDataRequest> datareqs_;
00086 std::vector<MPI_Request> datareqs_mpireq_;
00087
00088 int current_data_index_;
00089 std::vector<double*> databufs_;
00090 std::vector<MPI_Request> databufs_mpireq_;
00091
00092 Ref<ThreadLock> buffer_lock_;
00093
00094 int next_buffer(int &counter);
00095 void init_buffer();
00096 int next_buffer(int &counter,
00097 std::vector<MPI_Request> &reqs);
00098 int get_buffer();
00099 int get_request();
00100 void done_buffers();
00101
00102
00103 void retrieve_data(void *, int node, long offset, long size, int lock);
00104 void replace_data(void *, int node, long offset, long size, int unlock);
00105 void sum_data(double *data, int node, long doffset, long dsize);
00106
00107 friend class MTMPIThread;
00108 public:
00113 MTMPIMemoryGrp(const Ref<MessageGrp>& msg, const Ref<ThreadGrp> &th,
00114 MPI_Comm comm = MPI_COMM_WORLD);
00117 MTMPIMemoryGrp(const Ref<KeyVal> &);
00118 ~MTMPIMemoryGrp();
00119
00120 void activate();
00121 void deactivate();
00122
00123 void sync();
00124
00125 Ref<MemoryGrp> clone();
00126 };
00127
00128 }
00129
00130 #endif
00131
00132
00133
00134
00135