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 #ifdef __GNUC__
00029 #pragma interface
00030 #endif
00031
00032 #ifndef _util_group_memamsg_h
00033 #define _util_group_memamsg_h
00034
00035 #include <iostream>
00036
00037 #include <util/group/memmsg.h>
00038
00039 class MemoryDataRequest {
00040 public:
00041 enum { NData = 6 };
00042 enum Request { Deactivate, Sync, Retrieve, Replace, DoubleSum };
00043 private:
00044 int data_[NData];
00045 public:
00046 MemoryDataRequest() {}
00047 MemoryDataRequest(Request r, int node = 0, int offset = 0, int size = 0,
00048 int lock = 0, int serial = 0);
00049 void assign(Request r, int node, int offset, int size,
00050 int lock, int serial);
00051 void *data() const { return (void *) data_; }
00052 int nbytes() const { return sizeof(int)*NData; }
00053
00054 const char *request_string() const;
00055
00056 MemoryDataRequest::Request request() const { return (Request) data_[0]; }
00057 int node() const { return data_[1]; }
00058 int offset() const { return data_[2]; }
00059 int size() const { return data_[3]; }
00060 int serial_number() const { return data_[4]; }
00061 int lock() const { return data_[5]; }
00062
00063 int touches_data() const {return request()!=Deactivate&&request()!=Sync;}
00064
00065
00066 int reactivate() const { return data_[2]; }
00067
00068 void operator =(const MemoryDataRequest &r);
00069
00070 void print(const char* msg = 0, std::ostream & o = ExEnv::out()) const;
00071 };
00072
00073 class MemoryDataRequestQueue {
00074 public:
00075 enum { MaxDepth = 1024 };
00076 private:
00077 MemoryDataRequest q_[MaxDepth];
00078 int n_;
00079 public:
00080 MemoryDataRequestQueue(): n_(0) {}
00081 int n() const { return n_; }
00082 void push(MemoryDataRequest&);
00083 void pop(MemoryDataRequest&);
00084
00085 MemoryDataRequest& operator[](int i) { return q_[i]; }
00086 void clear() { n_ = 0; }
00087 };
00088
00091 class ActiveMsgMemoryGrp : public MsgMemoryGrp {
00092 protected:
00093 char *data_;
00094
00095 virtual void retrieve_data(void *, int node, int offset, int size,
00096 int lock) = 0;
00097 virtual void replace_data(void *, int node, int offset, int size,
00098 int unlock) = 0;
00099 virtual void sum_data(double *data, int node, int doffset, int dsize) = 0;
00100 public:
00101 ActiveMsgMemoryGrp(const Ref<MessageGrp>& msg);
00102 ActiveMsgMemoryGrp(const Ref<KeyVal>&);
00103 ~ActiveMsgMemoryGrp();
00104
00105 void set_localsize(int);
00106 void *localdata();
00107
00108 void *obtain_writeonly(distsize_t offset, int size);
00109 void *obtain_readwrite(distsize_t offset, int size);
00110 void *obtain_readonly(distsize_t offset, int size);
00111 void release_readonly(void *data, distsize_t offset, int size);
00112 void release_writeonly(void *data, distsize_t offset, int size);
00113 void release_readwrite(void *data, distsize_t offset, int size);
00114
00115 void sum_reduction(double *data, distsize_t doffset, int dsize);
00116 void sum_reduction_on_node(double *data, int doffset, int dsize,
00117 int node = -1);
00118
00119 void print(std::ostream &o = ExEnv::out()) const;
00120 };
00121
00122 #endif
00123
00124
00125
00126
00127