00001
00005
00006 #ifndef LBCOMM_H
00007 #define LBCOMM_H
00008
00009 #include "converse.h"
00010 #include "lbdb.h"
00011
00012 class LBObj;
00013 template <class T> class CkVec;
00014
00015
00016 class LBCommData {
00017
00018 friend class LBCommTable;
00019
00020 public:
00021 LBCommData(int _src_proc, LDOMid _destOM, CmiUInt8 _destObj, int _destObjProc) {
00022 src_proc = _src_proc;
00023 destObj.init_objmsg(_destOM, _destObj, _destObjProc);
00024 n_messages = 0;
00025 n_bytes = 0;
00026 mykey = compute_key();
00027 };
00028
00029 LBCommData(LDObjHandle _srcObj, LDOMid _destOM, CmiUInt8 _destObj, int _destObjProc) {
00030 src_proc = -1;
00031 srcObj = _srcObj;
00032 destObj.init_objmsg(_destOM, _destObj, _destObjProc);
00033 n_messages = 0;
00034 n_bytes = 0;
00035 mykey = compute_key();
00036 };
00037
00038
00039 LBCommData(LDObjHandle _srcObj, LDOMid _destOM, CmiUInt8 *_destObjs, int _nobjs) {
00040 src_proc = -1;
00041 srcObj = _srcObj;
00042 destObj.init_mcastmsg(_destOM, _destObjs, _nobjs);
00043 n_messages = 0;
00044 n_bytes = 0;
00045 mykey = compute_key();
00046 };
00047
00048 LBCommData(const LBCommData& d) {
00049 src_proc = d.src_proc;
00050 if (!from_proc()) {
00051 srcObj = d.srcObj;
00052
00053 }
00054 destObj = d.destObj;
00055 n_messages = d.n_messages;
00056 n_bytes = d.n_bytes;
00057 mykey = d.mykey;
00058 };
00059
00060 ~LBCommData() { };
00061
00062 LBCommData& operator=(const LBCommData& d) {
00063 src_proc = d.src_proc;
00064 if (!from_proc()) {
00065 srcObj = d.srcObj;
00066
00067 }
00068 destObj = d.destObj;
00069 n_messages = d.n_messages;
00070 n_bytes = d.n_bytes;
00071 mykey = d.mykey;
00072 return *this;
00073 };
00074
00075 void addMessage(int bytes, int nMsgs=1) {
00076 n_messages += nMsgs;
00077 n_bytes += bytes;
00078 };
00079
00080 inline int key() const { return mykey; };
00081 bool equal(const LBCommData &_d2) const;
00082
00083 inline int from_proc() const { return (src_proc != -1); }
00084 private:
00085 LBCommData(): mykey(0), src_proc(0), n_messages(0), n_bytes(0) {};
00086
00087 int compute_key();
00088 int hash(const int i, const int m) const;
00089
00090 int mykey;
00091 int src_proc;
00092 LDObjHandle srcObj;
00093 LDCommDesc destObj;
00094 int n_messages;
00095 int n_bytes;
00096 };
00097
00098 class LBCommTable {
00099 public:
00100
00101 LBCommTable() {
00102 NewTable(initial_sz);
00103 };
00104
00105 ~LBCommTable() {
00106 delete [] set;
00107 delete [] state;
00108 };
00109
00110 LBCommData* HashInsert(const LBCommData &data);
00111 LBCommData* HashInsertUnique(const LBCommData &data);
00112 LBCommData* HashSearch(const LBCommData &data);
00113 int CommCount() { return in_use; };
00114 void GetCommData(LDCommData* data);
00115 void GetCommInfo(int& bytes, int& msgs, int& withinpebytes,
00116 int& outsidepebytes, int& num_nghbor, int& hops, int& hopbytes);
00117
00118 private:
00119 void NewTable(int _sz) {
00120 set = new LBCommData[_sz];
00121 state = new TableState[_sz];
00122 cur_sz = _sz;
00123 in_use = 0;
00124 for(int i=0; i < _sz; i++)
00125 state[i] = nil;
00126 };
00127
00128 void Resize();
00129
00130 #ifdef __BIGSIM__
00131 enum { initial_sz = 1 };
00132 #else
00133 enum { initial_sz = 500 };
00134 #endif
00135 enum TableState : uint8_t { nil, InUse } ;
00136 LBCommData* set;
00137 TableState* state;
00138 int cur_sz;
00139 int in_use;
00140 public:
00141 int useMem() { return cur_sz*(sizeof(LBCommData) + sizeof(TableState)) + sizeof(LBCommTable); }
00142 };
00143
00144
00145 #endif
00146