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