00001
00014 #ifndef _CKSECTION_H
00015 #define _CKSECTION_H
00016
00017 #include "charm.h"
00018 #include "ckarrayindex.h"
00019
00020
00021
00026 class CkSectionInfo {
00027 public:
00028
00037 class CkSectionInfoStruct {
00038 public:
00040 void *val;
00042 CkGroupID aid;
00044 int pe;
00046 int redNo;
00047
00048 bool operator==(CkSectionInfoStruct &other) {
00049 return (val == other.val && aid == other.aid && pe == other.pe && redNo == other.redNo);
00050 }
00051 };
00052
00053 CkSectionInfoStruct info;
00054
00055 CkSectionInfo() {
00056 info.pe = -1;
00057 info.redNo = 0;
00058 info.val = NULL;
00059 }
00060
00061 CkSectionInfo(const CkSectionInfoStruct &i): info(i) {}
00062
00063 CkSectionInfo(CkArrayID _aid, void *p = NULL) {
00064 info.pe = CkMyPe();
00065 info.aid = _aid;
00066 info.val = p;
00067 info.redNo = 0;
00068 }
00069
00070 CkSectionInfo(int e, void *p, int r, CkArrayID _aid) {
00071 info.pe = e;
00072 info.aid = _aid;
00073 info.val = p;
00074 info.redNo = r;
00075 }
00076
00077 inline int &get_pe() { return info.pe; }
00078 inline int &get_redNo() { return info.redNo; }
00079 inline void set_redNo(int redNo) { info.redNo = redNo; }
00080 inline void* &get_val() { return info.val; }
00081 inline CkGroupID &get_aid() { return info.aid; }
00082 inline CkGroupID get_aid() const { return info.aid; }
00083
00084 };
00085
00086 PUPbytes(CkSectionInfo)
00087 PUPmarshall(CkSectionInfo)
00088
00089
00090
00091 #define _SECTION_MAGIC 88
00092
00094 class CkMcastBaseMsg {
00095 public:
00097 CkSectionInfo _cookie;
00098 unsigned short ep;
00099 #if CMK_ERROR_CHECKING
00100 private:
00102 char magic = _SECTION_MAGIC;
00103 #endif
00104
00105 public:
00106 CkMcastBaseMsg() = default;
00107 static inline bool checkMagic(CkMcastBaseMsg *m) {
00108 #if CMK_ERROR_CHECKING
00109 return m->magic == _SECTION_MAGIC;
00110 #else
00111 return true;
00112 #endif
00113 }
00114 inline int &gpe(void) { return _cookie.get_pe(); }
00115 inline int &redno(void) { return _cookie.get_redNo(); }
00116 inline void *&entry(void) { return _cookie.get_val(); }
00117 };
00118
00119
00120
00121 class CkArrayIndex1D;
00122 class CkArrayIndex2D;
00123 class CkArrayIndex3D;
00124 class CkArrayIndex4D;
00125 class CkArrayIndex5D;
00126 class CkArrayIndex6D;
00127
00128 #define CKSECTIONID_CONSTRUCTOR(index) \
00129 CkSectionID(const CkArrayID &aid, const CkArrayIndex##index *elems, const int nElems, int factor=USE_DEFAULT_BRANCH_FACTOR); \
00130 CkSectionID(const CkArrayID &aid, const std::vector<CkArrayIndex##index> &elems, int factor=USE_DEFAULT_BRANCH_FACTOR);
00131
00132 #define USE_DEFAULT_BRANCH_FACTOR 0
00133
00138 class CkSectionID {
00139 public:
00141 CkSectionInfo _cookie;
00143 std::vector<CkArrayIndex> _elems;
00150 std::vector<int> pelist;
00152 int bfactor;
00153
00154 CkSectionID(): bfactor(USE_DEFAULT_BRANCH_FACTOR) {}
00155 CkSectionID(const CkSectionID &sid);
00156 CkSectionID(CkSectionInfo &c, const CkArrayIndex *e, int n, const int *_pelist, int _npes,
00157 int factor=USE_DEFAULT_BRANCH_FACTOR): _cookie(c), bfactor(factor)
00158 {
00159 _elems.assign(e, e+n);
00160 pelist.assign(_pelist, _pelist+_npes);
00161 }
00162 CkSectionID(CkSectionInfo &c, const std::vector<CkArrayIndex>& e, const std::vector<int>& _pelist,
00163 int factor=USE_DEFAULT_BRANCH_FACTOR): _cookie(c), _elems(e),
00164 pelist(_pelist), bfactor(factor) {}
00165 CkSectionID(const CkGroupID &gid, const int *_pelist, const int _npes,
00166 int factor=USE_DEFAULT_BRANCH_FACTOR);
00167 CkSectionID(const CkGroupID &gid, const std::vector<int>& _pelist,
00168 int factor=USE_DEFAULT_BRANCH_FACTOR);
00169 CKSECTIONID_CONSTRUCTOR(1D)
00170 CKSECTIONID_CONSTRUCTOR(2D)
00171 CKSECTIONID_CONSTRUCTOR(3D)
00172 CKSECTIONID_CONSTRUCTOR(4D)
00173 CKSECTIONID_CONSTRUCTOR(5D)
00174 CKSECTIONID_CONSTRUCTOR(6D)
00175 CKSECTIONID_CONSTRUCTOR(Max)
00176
00177 inline CkGroupID get_aid() const { return _cookie.get_aid(); }
00178 inline int nElems() const { return _elems.size(); }
00179 inline int nPes() const { return pelist.size(); }
00180 void operator=(const CkSectionID &);
00181 ~CkSectionID() = default;
00182 void pup(PUP::er &p);
00183 };
00184 PUPmarshall(CkSectionID)
00185
00186 #endif