OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
ParticleDebug.hpp
Go to the documentation of this file.
1// -*- C++ -*-
2/***************************************************************************
3 *
4 * The IPPL Framework
5 *
6 * This program was prepared by PSI.
7 * All rights in the program are reserved by PSI.
8 * Neither PSI nor the author(s)
9 * makes any warranty, express or implied, or assumes any liability or
10 * responsibility for the use of this software
11 *
12 * Visit www.amas.web.psi for more details
13 *
14 ***************************************************************************/
15
16// -*- C++ -*-
17//-----------------------------------------------------------------------------
18// The IPPL Framework - Visit http://people.web.psi.ch/adelmann/ for more details
19//
20// This program was prepared by the Regents of the University of California at
21// ParticleDebug.cpp , Tim Williams 8/6/1998
22// Helper functions to print out (formatted ASCII) ParticleAttrib elements.
23// Intended mainly for use from within a debugger, called interactively, but
24// also callable as template functions from source code. To call from many
25// debuggers, the user has to provide nontemplate wrapper functions, as
26// described in ParticleDebugFunctions.cpp.
27
28// include files
30#include "Utility/Inform.h"
31
33
34#include <iostream>
35#include <iomanip> // need format fcns setf() and setprecision() from here
36
37
38//----------------------------------------------------------------------
39// Print a ParticleAttrib
40//----------------------------------------------------------------------
41template<class T>
42void pap(ParticleAttrib<T>& pattr, bool docomm) {
43
44 // Set Inform ptr if not set:
45 if (!PtclDbgInformIsSet) {
46 if (!FldDbgInformIsSet) {
48 }
49 else {
51 }
52 }
53
54 if (docomm) {
55 int mype = IpplInfo::myNode();
56 int npes = IpplInfo::getNodes();
57 int myNumPtcles = pattr.size();
58 int numPtcles = pattr.size();
61 Message *msg, *msg2;
62 if (mype == 0) {
63 int otherNumPtcles = 0;
64 for (int pe = 1; pe < npes; pe++) {
65 msg = IpplInfo::Comm->receive_block(pe, tag);
66 msg->get(otherNumPtcles);
67 delete msg;
68 numPtcles += otherNumPtcles;
69 }
70 msg2 = new Message;
71 msg2->put(numPtcles);
73 }
74 else {
75 msg = new Message;
76 msg->put(myNumPtcles);
77 IpplInfo::Comm->send(msg, 0, tag);
78 int pe0 = 0;
79 msg2 = IpplInfo::Comm->receive_block(pe0, tag2);
80 msg2->get(numPtcles);
81 delete msg2;
82 }
84 spap(pattr, 0, numPtcles - 1, 1, docomm);
85
86 }
87 else {
88
89 spap(pattr, 0, pattr.size() - 1, 1, docomm);
90
91 }
92}
93
94//----------------------------------------------------------------------
95// Print a single element of a ParticleAttrib
96//----------------------------------------------------------------------
97template<class T>
98void epap(ParticleAttrib<T>& pattr, int i, bool docomm) {
99
100
101 // Set Inform ptr if not set:
102 if (!PtclDbgInformIsSet) {
103 if (!FldDbgInformIsSet) {
105 }
106 else {
108 }
109 }
110 spap(pattr, i, i, 1, docomm);
111}
112
113//----------------------------------------------------------------------
114// Print a strided subrange of a ParticleAttrib
115//----------------------------------------------------------------------
116template<class T>
118 int ibase, int ibound, int istride, bool docomm) {
119
120
121
122 // Set Inform ptr if not set:
123 if (!PtclDbgInformIsSet) {
124 if (!FldDbgInformIsSet) {
126 }
127 else {
129 }
130 }
131
132 // Check input parameters for errors and unimplemented values:
133 bool okParameters = true;
134 if (ibase < -1) {
135 (*PtclDbgInform) << "spap() error: ibase (= " << ibase
136 << ") < lowest index value (= " << 0 << ")" << endl;
137 okParameters = false;
138 }
139 //tjw??? Can't check if i greater than total num ptcles, because this number
140 //isn't available in ParticleAttrib
141 if (istride < 0) {
142 (*PtclDbgInform) << "spap() error: istride < 0 not implemented yet."
143 << endl;
144 okParameters = false;
145 }
146 else {
147 if ((ibound < ibase) && !((ibase == 0) && (ibound == -1))) {
148 (*PtclDbgInform) << "spap() error: ibase (= " << ibase
149 << ") > ibound (= " << ibound
150 << ") not implemented yet." << endl;
151 okParameters = false;
152 }
153 }
154 if (istride == 0) {
155 if (((ibound - ibase) != 0) && !((ibase == 0) && (ibound == -1))) {
156 (*PtclDbgInform) << "spap() error: istride = 0 but (ibound - ibase) = "
157 << (ibound - ibase) << endl;
158 okParameters = false;
159 }
160 else {
161 istride = 1; // Allow specifying stride 0 for 1-element range; set=1
162 }
163 }
164
165 if (!okParameters) return; // Exit if problem with input parameters
166
167 if (docomm) {
168
169 // With communication; assume a GLOBAL particle index range. Find which PEs
170 // own parts of it and have those PEs print out their values:
171 int myNumPtcles = pattr.size();
172 int npes = IpplInfo::getNodes();
173 int* numsPtcles = new int[npes];
174 int mype = IpplInfo::myNode();
175 for (int pe=0; pe<npes; pe++) {
176 numsPtcles[pe] = 0;
177 if (pe == mype) numsPtcles[pe] = myNumPtcles;
178 }
181 Message *msg, *msg2;
182 if (mype == 0) {
183 int otherNumPtcles = 0;
184 for (int pe=1; pe<npes; pe++) {
185 msg = IpplInfo::Comm->receive_block(pe, tag);
186 msg->get(otherNumPtcles);
187 delete msg;
188 numsPtcles[pe] = numsPtcles[pe - 1] + otherNumPtcles;
189 }
190 msg2 = new Message;
191 msg2->putmsg((void *)numsPtcles, sizeof(int), npes);
192 IpplInfo::Comm->broadcast_others(msg2, tag2);
193 }
194 else {
195 msg = new Message;
196 msg->put(myNumPtcles);
197 IpplInfo::Comm->send(msg, 0, tag);
198 int pe0 = 0;
199 msg2 = IpplInfo::Comm->receive_block(pe0, tag2);
200 msg2->getmsg(numsPtcles);
201 delete msg2;
202 }
203 // Find out if I (pe) own part of the stated global particle index range:
204 int myPtcleIndexBegin, myPtcleIndexEnd;
205 if (mype == 0) {
206 myPtcleIndexBegin = 0;
207 myPtcleIndexEnd = myNumPtcles - 1;
208 }
209 else {
210 myPtcleIndexBegin = numsPtcles[mype - 1];
211 myPtcleIndexEnd = myPtcleIndexBegin + myNumPtcles - 1;
212 }
213 // Construct Index objects for convenience of using Index::touches, etc:
214 Index myRange(myPtcleIndexBegin, myPtcleIndexEnd, 1);
215 Index requestedRange(ibase, ibound, istride);
216 for (int pe=0; pe < npes; pe++) {
217 if (mype == pe) {
218 if (myNumPtcles > 0) {
219 if (myRange.touches(requestedRange)) {
220 Index myRequestedRange = requestedRange.intersect(myRange);
221 int mybase = myRequestedRange.first();
222 int mybound = myRequestedRange.last();
223 *PtclDbgInform << "....PE = " << mype
224 << " GLOBAL ptcle index subrange (" << mybase
225 << " : " << mybound << " : " << istride
226 << ")...." << endl;
227 for (int p = mybase; p <= mybound; p += istride*elementsPerLine) {
228 for (int item = 0; ((item < elementsPerLine) &&
229 ((p+item*istride) <= mybound)); item++) {
230// (item < mylength)); item++) {
231 *PtclDbgInform << std::setprecision(digitsPastDecimal)
232 << std::setw(widthOfElements)
233 << pattr[p + item*istride] << " ";
234 }
235
237 }
238 }
239 }
240 else {
241 //don't *PtclDbgInform << "....PE = " << mype
242 //don't << " has no particles ...." << endl;
243 }
244 }
246 }
247 if (mype == 0) *PtclDbgInform << endl;
248 delete [] numsPtcles;
249 }
250 else {
251
252 // No communication; assume calling pe(s) print data for their particle
253 // data values having LOCAL index range (ibase,ibound,istride):
254 int mype = IpplInfo::myNode();
255 int myNumPtcles = pattr.size();
257 WARNMSG(endl << "spap(): Currently, if docomm=false you must specify "
258 << "an Inform object having INFORM_ALL_NODES as its "
259 << "printing-node specifier if you want to see output from "
260 << "any processor calling [e,s]pap(); the Inform object "
261 << "you're trying to use has "
262 << PtclDbgInform->getPrintNode() << " specified. "
263 << "N.B.: If you called setInform() and didn't also call "
264 << "setPtclDbgInform() you are getting the FldDbgInform object "
265 << "you set with setInform, which you may not have constructed "
266 << "with INFORM_ALL_NODES." << endl << endl);
267 }
268
269 if (myNumPtcles > 0) {
270 *PtclDbgInform << "....PE = " << mype
271 << " LOCAL ptcle index range (" << ibase
272 << " : " << ibound << " : " << istride << ")...." << endl;
273 int length = (ibound - ibase)/istride + 1;
274 for (int p = ibase; p <= ibound; p += istride*elementsPerLine) {
275 for (int item = 0; ((item < elementsPerLine) &&
276 (item < length)); item++) {
277 *PtclDbgInform << std::setprecision(digitsPastDecimal)
278 << pattr[p + item*istride] << " ";
279 }
281 }
283 } else {
284 *PtclDbgInform << "....PE = " << mype
285 << " has no particles ...." << endl;
286 }
287
288 }
289}
#define IPPL_APP_TAG0
Definition: Tags.h:93
#define IPPL_APP_CYCLE
Definition: Tags.h:103
void setPtclDbgInform(Inform &inform)
Inform * FldDbgInform
bool FldDbgInformIsSet
int widthOfElements
int digitsPastDecimal
int elementsPerLine
Inform & endl(Inform &inf)
Definition: Inform.cpp:42
#define INFORM_ALL_NODES
Definition: Inform.h:39
void spap(ParticleAttrib< T > &pattr, int ibase, int ibound, int istride, bool docomm)
void pap(ParticleAttrib< T > &pattr, bool docomm)
void epap(ParticleAttrib< T > &pattr, int i, bool docomm)
bool PtclDbgInformIsSet
Inform * PtclDbgInform
#define WARNMSG(msg)
Definition: IpplInfo.h:349
size_t size(void) const
Definition: Index.h:237
int last() const
Definition: IndexInlines.h:136
Index intersect(const Index &) const
Definition: Index.cpp:108
bool touches(const Index &a) const
Definition: IndexInlines.h:242
int first() const
Definition: IndexInlines.h:116
bool send(Message *, int node, int tag, bool delmsg=true)
virtual int broadcast_others(Message *, int, bool delmsg=true)
Message * receive_block(int &node, int &tag)
void barrier(void)
Message & putmsg(void *, int, int=0)
Message & getmsg(void *)
Message & put(const T &val)
Definition: Message.h:406
Message & get(const T &cval)
Definition: Message.h:476
int next_tag(int t, int s=1000)
Definition: TagMaker.h:39
Definition: Inform.h:42
int getPrintNode() const
Definition: Inform.h:85
static int getNodes()
Definition: IpplInfo.cpp:670
static int myNode()
Definition: IpplInfo.cpp:691
static Communicate * Comm
Definition: IpplInfo.h:84