38 template<
class T,
unsigned Dim>
42 LocalSize =
new int[N];
44 MsgCount =
new int[N];
50 template<
class T,
unsigned Dim>
64 template<
class T,
unsigned Dim>
72 size_t TotalNum = PData.getTotalNum();
73 size_t LocalNum = PData.getLocalNum();
74 size_t DestroyNum = PData.getDestroyNum();
75 float Weight = 1.0 / (float)N;
86 PData.performDestroy();
89 LocalNum -= DestroyNum;
92 PData.setTotalNum(LocalNum);
93 PData.setLocalNum(LocalNum);
102 int node, sendnum, recnum;
110 nodedata[0] = LocalNum;
111 nodedata[1] = DestroyNum;
113 msg->
put(nodedata, nodedata + 2);
125 LocalSize[0] = LocalNum - DestroyNum;
126 TotalNum = LocalSize[0];
130 int notrecvd = N - 1;
131 while (notrecvd > 0) {
139 LocalSize[node] = nodedata[0] - nodedata[1];
140 TotalNum += LocalSize[node];
149 for (i = 0; i < N; i++) {
150 Change[i] = (int)((
float)TotalNum * Weight);
151 accounted += Change[i];
153 accounted -= TotalNum;
155 while (accounted != 0) {
156 Change[(-accounted) % N]++;
161 while (accounted != 0) {
162 if (Change[whichnode] > 0) {
166 whichnode = (whichnode + 1) % N;
169 for (i = 0; i < N; i++) {
170 Change[i] = Change[i] - LocalSize[i];
171 MsgCount[i] = Change[i];
174 for (i = 0; i < N; i++) {
175 Change[i] = MsgCount[i] = 0;
180 for (i = 0; i < N; i++) {
182 nodedata[0] = TotalNum;
183 if (Change[i] <= 0) {
184 nodedata[1] = -Change[i];
189 nodedata[2] = Change[i];
192 msg->
put(nodedata, nodedata + 3);
196 if (Change[i] <= 0) {
197 for (j = 0; j < N && MsgCount[i] < 0; j++) {
198 if (j != i && MsgCount[j] > 0) {
200 if ((-MsgCount[i]) > MsgCount[j])
201 nodedata[1] = MsgCount[j];
203 nodedata[1] = -MsgCount[i];
204 MsgCount[i] += nodedata[1];
205 MsgCount[j] -= nodedata[1];
206 msg->
put(nodedata, nodedata + 2);
220 TotalNum = nodedata[0];
221 sendnum = nodedata[1];
222 recnum = nodedata[2];
227 PData.performDestroy();
228 LocalNum -= DestroyNum;
234 while (sendnum > 0) {
237 LocalNum -= nodedata[1];
238 sendnum -= nodedata[1];
245 PData.putMessage(*sendmsg, nodedata[1], LocalNum);
249 PData.destroy(nodedata[1], LocalNum,
true);
253 while (sendnum > 0) {
259 int delpart = LocalNum-1;
260 for (
int ip=0; ip<nodedata[1]; ip++) {
261 while ( !(
bool((*canSwap)[delpart])) ) { --delpart; }
262 PData.putMessage(*sendmsg, 1, delpart);
264 PData.destroy(1, delpart,
true);
266 LocalNum -= nodedata[1];
267 sendnum -= nodedata[1];
285 int recvamt = PData.getMessage(*msg);
294 PData.setTotalNum(TotalNum);
295 PData.setLocalNum(LocalNum);
301 template<
class T,
unsigned Dim>
305 out <<
"ParticleUniformLayout" <<
std::endl;
312 template<
class T,
unsigned Dim>
315 o <<
"ParticleUniformLayout";
#define P_WEIGHTED_RETURN_TAG
#define P_WEIGHTED_LAYOUT_TAG
#define P_WEIGHTED_TRANSFER_TAG
std::ostream & operator<<(std::ostream &out, const ParticleUniformLayout< T, Dim > &)
Inform & endl(Inform &inf)
bool send(Message *, int node, int tag, bool delmsg=true)
Message * receive_block(int &node, int &tag)
Message & put(const T &val)
Message & get(const T &cval)
int next_tag(int t, int s=1000)
void printDebug(Inform &)
void update(IpplParticleBase< ParticleUniformLayout< T, Dim > > &p, const ParticleAttrib< char > *canSwap=0)
static Communicate * Comm