4 These classes implement array (or group) sections which are a subset of a
6 Supported operations include section multicast and reduction.
7 It is currently implemented using delegation.
9 Extracted from charm++.h into separate file on 6/22/2003 by
18 #include "ckarrayindex.h"
20 // ----------- CkSectionInfo -----------
23 * Contains array/group ID for a section, and state information for CkMulticast
24 * to manage the section. This object is also referred to as the section "cookie".
30 * For now we still need to encapsulate CkSectionInfo's data
31 * in a separate CkSectionInfoStruct because it is used in ckcallback
32 * inside a union, and C++03 doesn't support placing objects with non-trivial
33 * constructors in unions.
34 * TODO When all our supported compilers have C++11 we might want to modify callbackData
35 * union to allow objects with non-trivial constructors.
37 class CkSectionInfoStruct
{
39 /// Pointer to mCastEntry (used by CkMulticast)
41 /// Array/group ID of the array/group that has been sectioned
43 /// The pe on which this object has been created
45 /// Counter tracking the last reduction that has traversed this section (used by CkMulticast)
48 bool operator==(CkSectionInfoStruct
&other
) {
49 return (val
== other
.val
&& aid
== other
.aid
&& pe
== other
.pe
&& redNo
== other
.redNo
);
53 CkSectionInfoStruct info
;
61 CkSectionInfo(const CkSectionInfoStruct
&i
): info(i
) {}
63 CkSectionInfo(CkArrayID _aid
, void *p
= NULL
) {
70 CkSectionInfo(int e
, void *p
, int r
, CkArrayID _aid
) {
77 inline int &get_pe() { return info
.pe
; }
78 inline int &get_redNo() { return info
.redNo
; }
79 inline void set_redNo(int redNo
) { info
.redNo
= redNo
; }
80 inline void* &get_val() { return info
.val
; }
81 inline CkGroupID
&get_aid() { return info
.aid
; }
82 inline CkGroupID
get_aid() const { return info
.aid
; }
86 PUPbytes(CkSectionInfo
)
87 PUPmarshall(CkSectionInfo
)
89 // ----------- CkMcastBaseMsg -----------
91 #define _SECTION_MAGIC 88 /* multicast magic number for error checking */
93 /// CkMcastBaseMsg is the base class for all multicast messages
94 class CkMcastBaseMsg
{
96 /// Current info about the state of this section
97 CkSectionInfo _cookie
;
99 #if CMK_ERROR_CHECKING
101 /// A magic number to detect msg corruption
102 char magic
= _SECTION_MAGIC
;
106 CkMcastBaseMsg() = default;
107 static inline bool checkMagic(CkMcastBaseMsg
*m
) {
108 #if CMK_ERROR_CHECKING
109 return m
->magic
== _SECTION_MAGIC
;
114 inline int &gpe(void) { return _cookie
.get_pe(); }
115 inline int &redno(void) { return _cookie
.get_redNo(); }
116 inline void *&entry(void) { return _cookie
.get_val(); }
119 // ----------- CkSectionID -----------
121 class CkArrayIndex1D
;
122 class CkArrayIndex2D
;
123 class CkArrayIndex3D
;
124 class CkArrayIndex4D
;
125 class CkArrayIndex5D
;
126 class CkArrayIndex6D
;
128 #define CKSECTIONID_CONSTRUCTOR(index) \
129 CkSectionID(const CkArrayID &aid, const CkArrayIndex##index *elems, const int nElems, int factor=USE_DEFAULT_BRANCH_FACTOR); \
130 CkSectionID(const CkArrayID &aid, const std::vector<CkArrayIndex##index> &elems, int factor=USE_DEFAULT_BRANCH_FACTOR);
132 #define USE_DEFAULT_BRANCH_FACTOR 0
134 /** A class that holds complete info about an array/group section.
136 * Describes section members, host PEs, current section status etc.
140 /// Minimal section info (cookie)
141 CkSectionInfo _cookie
;
142 /// The list of array indices that are section members (array sections)
143 std::vector
<CkArrayIndex
> _elems
;
145 * \brief A list of PEs that host section members.
146 * - For group sections these point to the PEs in the section
147 * - For array sections these point to the processors the array elements are on
148 * @note For array sections, currently not saved when pupped across processors
150 std::vector
<int> pelist
;
151 /// Branching factor in the spanning tree, can be negative
154 CkSectionID(): bfactor(USE_DEFAULT_BRANCH_FACTOR
) {}
155 CkSectionID(const CkSectionID
&sid
);
156 CkSectionID(CkSectionInfo
&c
, const CkArrayIndex
*e
, int n
, const int *_pelist
, int _npes
,
157 int factor
=USE_DEFAULT_BRANCH_FACTOR
): _cookie(c
), bfactor(factor
)
159 _elems
.assign(e
, e
+n
);
160 pelist
.assign(_pelist
, _pelist
+_npes
);
162 CkSectionID(CkSectionInfo
&c
, const std::vector
<CkArrayIndex
>& e
, const std::vector
<int>& _pelist
,
163 int factor
=USE_DEFAULT_BRANCH_FACTOR
): _cookie(c
), _elems(e
),
164 pelist(_pelist
), bfactor(factor
) {}
165 CkSectionID(const CkGroupID
&gid
, const int *_pelist
, const int _npes
,
166 int factor
=USE_DEFAULT_BRANCH_FACTOR
);
167 CkSectionID(const CkGroupID
&gid
, const std::vector
<int>& _pelist
,
168 int factor
=USE_DEFAULT_BRANCH_FACTOR
);
169 CKSECTIONID_CONSTRUCTOR(1D
)
170 CKSECTIONID_CONSTRUCTOR(2D
)
171 CKSECTIONID_CONSTRUCTOR(3D
)
172 CKSECTIONID_CONSTRUCTOR(4D
)
173 CKSECTIONID_CONSTRUCTOR(5D
)
174 CKSECTIONID_CONSTRUCTOR(6D
)
175 CKSECTIONID_CONSTRUCTOR(Max
)
177 inline CkGroupID
get_aid() const { return _cookie
.get_aid(); }
178 inline int nElems() const { return _elems
.size(); }
179 inline int nPes() const { return pelist
.size(); }
180 void operator=(const CkSectionID
&);
181 ~CkSectionID() = default;
182 void pup(PUP::er
&p
);
184 PUPmarshall(CkSectionID
)