OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
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
29 #include "Utility/ParticleDebug.h"
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 //----------------------------------------------------------------------
41 template<class T>
42 void pap(ParticleAttrib<T>& pattr, bool docomm) {
43 
44 
45  // Set Inform ptr if not set:
46  if (!PtclDbgInformIsSet) {
47  if (!FldDbgInformIsSet) {
49  }
50  else {
52  }
53  }
54 
55  if (docomm) {
56  int mype = IpplInfo::myNode();
57  int npes = IpplInfo::getNodes();
58  int myNumPtcles = pattr.size();
59  int numPtcles = pattr.size();
62  Message *msg, *msg2;
63  if (mype == 0) {
64  int otherNumPtcles;
65  for (int pe = 1; pe < npes; pe++) {
66  msg = IpplInfo::Comm->receive_block(pe, tag);
67  msg->get(otherNumPtcles);
68  delete msg;
69  numPtcles += otherNumPtcles;
70  }
71  msg2 = new Message;
72  msg2->put(numPtcles);
73  IpplInfo::Comm->broadcast_others(msg2, tag2);
74  }
75  else {
76  msg = new Message;
77  msg->put(myNumPtcles);
78  IpplInfo::Comm->send(msg, 0, tag);
79  int pe0 = 0;
80  msg2 = IpplInfo::Comm->receive_block(pe0, tag2);
81  msg2->get(numPtcles);
82  delete msg2;
83  }
85  spap(pattr, 0, numPtcles - 1, 1, docomm);
86 
87  }
88  else {
89 
90  spap(pattr, 0, pattr.size() - 1, 1, docomm);
91 
92  }
93 }
94 
95 //----------------------------------------------------------------------
96 // Print a single element of a ParticleAttrib
97 //----------------------------------------------------------------------
98 template<class T>
99 void epap(ParticleAttrib<T>& pattr, int i, bool docomm) {
100 
101 
102  // Set Inform ptr if not set:
103  if (!PtclDbgInformIsSet) {
104  if (!FldDbgInformIsSet) {
106  }
107  else {
109  }
110  }
111  spap(pattr, i, i, 1, docomm);
112 }
113 
114 //----------------------------------------------------------------------
115 // Print a strided subrange of a ParticleAttrib
116 //----------------------------------------------------------------------
117 template<class T>
118 void spap(ParticleAttrib<T>& pattr,
119  int ibase, int ibound, int istride, bool docomm) {
120 
121 
122 
123  // Set Inform ptr if not set:
124  if (!PtclDbgInformIsSet) {
125  if (!FldDbgInformIsSet) {
127  }
128  else {
130  }
131  }
132 
133  // Check input parameters for errors and unimplemented values:
134  bool okParameters = true;
135  if (ibase < -1) {
136  (*PtclDbgInform) << "spap() error: ibase (= " << ibase
137  << ") < lowest index value (= " << 0 << ")" << endl;
138  okParameters = false;
139  }
140  //tjw??? Can't check if i greater than total num ptcles, because this number
141  //isn't available in ParticleAttrib
142  if (istride < 0) {
143  (*PtclDbgInform) << "spap() error: istride < 0 not implemented yet."
144  << endl;
145  okParameters = false;
146  }
147  else {
148  if ((ibound < ibase) && !((ibase == 0) && (ibound == -1))) {
149  (*PtclDbgInform) << "spap() error: ibase (= " << ibase
150  << ") > ibound (= " << ibound
151  << ") not implemented yet." << endl;
152  okParameters = false;
153  }
154  }
155  if (istride == 0) {
156  if (((ibound - ibase) != 0) && !((ibase == 0) && (ibound == -1))) {
157  (*PtclDbgInform) << "spap() error: istride = 0 but (ibound - ibase) = "
158  << (ibound - ibase) << endl;
159  okParameters = false;
160  }
161  else {
162  istride = 1; // Allow specifying stride 0 for 1-element range; set=1
163  }
164  }
165 
166  if (!okParameters) return; // Exit if problem with input parameters
167 
168  if (docomm) {
169 
170  // With communication; assume a GLOBAL particle index range. Find which PEs
171  // own parts of it and have those PEs print out their values:
172  int myNumPtcles = pattr.size();
173  int npes = IpplInfo::getNodes();
174  int* numsPtcles = new int[npes];
175  int mype = IpplInfo::myNode();
176  for (int pe=0; pe<npes; pe++) {
177  numsPtcles[pe] = 0;
178  if (pe == mype) numsPtcles[pe] = myNumPtcles;
179  }
182  Message *msg, *msg2;
183  if (mype == 0) {
184  int otherNumPtcles;
185  for (int pe=1; pe<npes; pe++) {
186  msg = IpplInfo::Comm->receive_block(pe, tag);
187  msg->get(otherNumPtcles);
188  delete msg;
189  numsPtcles[pe] = numsPtcles[pe - 1] + otherNumPtcles;
190  }
191  msg2 = new Message;
192  msg2->putmsg((void *)numsPtcles, sizeof(int), npes);
193  IpplInfo::Comm->broadcast_others(msg2, tag2);
194  }
195  else {
196  msg = new Message;
197  msg->put(myNumPtcles);
198  IpplInfo::Comm->send(msg, 0, tag);
199  int pe0 = 0;
200  msg2 = IpplInfo::Comm->receive_block(pe0, tag2);
201  msg2->getmsg(numsPtcles);
202  delete msg2;
203  }
204  // Find out if I (pe) own part of the stated global particle index range:
205  int myPtcleIndexBegin, myPtcleIndexEnd;
206  if (mype == 0) {
207  myPtcleIndexBegin = 0;
208  myPtcleIndexEnd = myNumPtcles - 1;
209  }
210  else {
211  myPtcleIndexBegin = numsPtcles[mype - 1];
212  myPtcleIndexEnd = myPtcleIndexBegin + myNumPtcles - 1;
213  }
214  // Construct Index objects for convenience of using Index::touches, etc:
215  Index myRange(myPtcleIndexBegin, myPtcleIndexEnd, 1);
216  Index requestedRange(ibase, ibound, istride);
217  for (int pe=0; pe < npes; pe++) {
218  if (mype == pe) {
219  if (myNumPtcles > 0) {
220  if (myRange.touches(requestedRange)) {
221  Index myRequestedRange = requestedRange.intersect(myRange);
222  int mybase = myRequestedRange.first();
223  int mybound = myRequestedRange.last();
224  *PtclDbgInform << "....PE = " << mype
225  << " GLOBAL ptcle index subrange (" << mybase
226  << " : " << mybound << " : " << istride
227  << ")...." << endl;
228  for (int p = mybase; p <= mybound; p += istride*elementsPerLine) {
229  for (int item = 0; ((item < elementsPerLine) &&
230  ((p+item*istride) <= mybound)); item++) {
231 // (item < mylength)); item++) {
232  *PtclDbgInform << std::setprecision(digitsPastDecimal)
233  << std::setw(widthOfElements)
234  << pattr[p + item*istride] << " ";
235  }
236 
237  *PtclDbgInform << endl;
238  }
239  }
240  }
241  else {
242  //don't *PtclDbgInform << "....PE = " << mype
243  //don't << " has no particles ...." << endl;
244  }
245  }
247  }
248  if (mype == 0) *PtclDbgInform << endl;
249  delete [] numsPtcles;
250  }
251  else {
252 
253  // No communication; assume calling pe(s) print data for their particle
254  // data values having LOCAL index range (ibase,ibound,istride):
255  int mype = IpplInfo::myNode();
256  int myNumPtcles = pattr.size();
258  WARNMSG(endl << "spap(): Currently, if docomm=false you must specify "
259  << "an Inform object having INFORM_ALL_NODES as its "
260  << "printing-node specifier if you want to see output from "
261  << "any processor calling [e,s]pap(); the Inform object "
262  << "you're trying to use has "
263  << PtclDbgInform->getPrintNode() << " specified. "
264  << "N.B.: If you called setInform() and didn't also call "
265  << "setPtclDbgInform() you are getting the FldDbgInform object "
266  << "you set with setInform, which you may not have constructed "
267  << "with INFORM_ALL_NODES." << endl << endl);
268  }
269 
270  if (myNumPtcles > 0) {
271  *PtclDbgInform << "....PE = " << mype
272  << " LOCAL ptcle index range (" << ibase
273  << " : " << ibound << " : " << istride << ")...." << endl;
274  int length = (ibound - ibase)/istride + 1;
275  for (int p = ibase; p <= ibound; p += istride*elementsPerLine) {
276  for (int item = 0; ((item < elementsPerLine) &&
277  (item < length)); item++) {
278  *PtclDbgInform << std::setprecision(digitsPastDecimal)
279  << pattr[p + item*istride] << " ";
280  }
281  *PtclDbgInform << endl;
282  }
283  *PtclDbgInform << endl;
284  } else {
285  *PtclDbgInform << "....PE = " << mype
286  << " has no particles ...." << endl;
287  }
288 
289  }
290 
291 }
292 
293 // $Id: ParticleDebug.cpp,v 1.1.1.1 2003/01/23 07:40:33 adelmann Exp $
294 
295 /***************************************************************************
296  * $RCSfile: addheaderfooter,v $ $Author: adelmann $
297  * $Revision: 1.1.1.1 $ $Date: 2003/01/23 07:40:17 $
298  * IPPL_VERSION_ID: $Id: addheaderfooter,v 1.1.1.1 2003/01/23 07:40:17 adelmann Exp $
299  ***************************************************************************/
300 
static int getNodes()
Definition: IpplInfo.cpp:773
bool PtclDbgInformIsSet
void epap(ParticleAttrib< T > &pattr, int i, bool docomm=true)
Index intersect(const Index &) const
Definition: Index.cpp:108
#define INFORM_ALL_NODES
Definition: Inform.h:38
#define IPPL_APP_TAG0
Definition: Tags.h:103
size_t size(void) const
void pap(ParticleAttrib< T > &pattr, bool docomm=true)
void barrier(void)
static int myNode()
Definition: IpplInfo.cpp:794
int digitsPastDecimal
#define IPPL_APP_CYCLE
Definition: Tags.h:113
int next_tag(int t, int s=1000)
Definition: TagMaker.h:43
void spap(ParticleAttrib< T > &pattr, int ibase, int ibound, int istride, bool docomm=true)
int elementsPerLine
Definition: Index.h:236
int last() const
Definition: IndexInlines.h:136
void setPtclDbgInform(Inform &inform)
Message & putmsg(void *, int, int=0)
virtual int broadcast_others(Message *, int, bool delmsg=true)
#define WARNMSG(msg)
Definition: IpplInfo.h:398
int getPrintNode() const
Definition: Inform.h:84
Message & get(const T &cval)
Definition: Message.h:484
bool touches(const Index &a) const
Definition: IndexInlines.h:242
Message & put(const T &val)
Definition: Message.h:414
Inform * FldDbgInform
int widthOfElements
int first() const
Definition: IndexInlines.h:116
Message & getmsg(void *)
Message * receive_block(int &node, int &tag)
Definition: Inform.h:41
static Communicate * Comm
Definition: IpplInfo.h:93
bool send(Message *, int node, int tag, bool delmsg=true)
bool FldDbgInformIsSet
Inform & endl(Inform &inf)
Definition: Inform.cpp:42
Inform * PtclDbgInform