OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
FieldPrint.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 *
19 * The IPPL Framework
20 *
21 *
22 * Visit http://people.web.psi.ch/adelmann/ for more details
23 *
24 ***************************************************************************/
25
26// include files
27#include "Utility/FieldPrint.h"
28#include "Utility/IpplInfo.h"
29#include "Utility/PAssert.h"
31
32
33#include <iomanip>
34
35
36//------------------------------------------------------------------
37template<class T, unsigned Dim >
38void
40
41 // check that the view is contained inside of the Field's domain
42 NDIndex<Dim>& domain = (NDIndex<Dim>&) MyField.getDomain();
43 if( ! domain.contains(view) ) {
44 ERRORMSG("FieldPrint::print - the domain of the field: " << domain<<endl);
45 ERRORMSG(" must contain the selected view: " << view << endl);
46 return;
47 }
48
49 // Loop over all the local nodes and send the intersecting data to the
50 // parent node
52 typedef typename LField<T,Dim>::iterator LFI;
53 typename BareField<T,Dim>::iterator_if local;
54 if (Ippl::Comm->myNode() != Parent) {
55 // prepare a message to send to parent node
56 Message *mess = new Message();
57 int datahere;
58
59 // put data for each local LField in the message
60 for (local = MyField.begin_if(); local != MyField.end_if(); ++local) {
61 // find the intersection of this lfield with the view, and put data in
62 // message.
63 LField<T,Dim> &l = *(*local).second;
65 if (view.touches(lo)) {
66 datahere = 1;
67 NDIndex<Dim> intersection = lo.intersect(view);
68 T compressed_data;
69 LFI rhs = l.begin(intersection, compressed_data);
70 rhs.TryCompress();
71 ::putMessage(*mess, datahere);
72 intersection.putMessage(*mess);
73 rhs.putMessage(*mess);
74 }
75 }
76
77 // Send the message.
78 datahere = 0;
79 ::putMessage(*mess, datahere);
80 Ippl::Comm->send(mess, Parent, tag);
81 } else {
82 // on parent, first copy all local blocks into a single LField
83 LField<T,Dim> myLField(view,view);
84 myLField.Uncompress();
85
86 for (local = MyField.begin_if(); local != MyField.end_if(); ++local) {
87 // find the intersection of this lfield with the view
88 LField<T,Dim> &l = *(*local).second;
90 if (view.touches(lo)) {
91 NDIndex<Dim> intersection = lo.intersect(view);
92 LFI lhs = myLField.begin(intersection);
93 LFI rhs = l.begin(intersection);
95 }
96 }
97
98 // Receive all the messages, one from each node.
99 for (int remaining = Ippl::getNodes() - 1; remaining > 0; --remaining) {
100 // Receive the generic message.
101 int any_node = COMM_ANY_NODE;
102 Message *mess = Ippl::Comm->receive_block(any_node, tag);
103 PAssert(mess);
104
105 // keep getting blocks until we're done with the message
106 int datahere;
107 ::getMessage(*mess, datahere);
108 while (datahere != 0) {
109 // Extract the intersection domain from the message.
110 NDIndex<Dim> localBlock;
111 localBlock.getMessage(*mess);
112
113 // Extract the rhs iterator from it.
114 T compressed_value;
115 LFI rhs(compressed_value);
116 rhs.getMessage(*mess);
117
118 // copy the data into our local LField
119 LFI lhs = myLField.begin(localBlock);
121
122 // see if there is another block
123 ::getMessage(*mess, datahere);
124 }
125
126 // done with the message now
127 delete mess;
128 }
129
130 // now that we have populated the localfield with the view, we print
131 Inform out("");
132
133 int f0, f1, f2, n0, n1, n2, i0, i1, i2;
134 LFI liter = myLField.begin();
135 switch(Dim) {
136 case 1:
137 f0 = view[0].first();
138 n0 = view[0].length();
139 for (i0=0; i0<n0; ++i0) {
140 out << "["<<f0+i0<<"]= "<< liter.offset(i0) << endl;
141 }
142 break;
143
144 case 2:
145 f0 = view[0].first();
146 f1 = view[1].first();
147 n0 = view[0].length();
148 n1 = view[1].length();
149 for (i0=0; i0<n0; ++i0) {
150 for (i1=0; i1<n1; ++i1) {
151 out << "["<<f0+i0<<"]["<<f1+i1<<"]= "<< liter.offset(i0,i1)<< endl;
152 }
153 }
154 break;
155
156 case 3:
157 f0 = view[0].first();
158 f1 = view[1].first();
159 f2 = view[2].first();
160 n0 = view[0].length();
161 n1 = view[1].length();
162 n2 = view[2].length();
163 if(Scientific) {
164 out.setf(std::ios::scientific);
165 }
166 for (i0=0; i0<n0; ++i0) {
167 for (i1=0; i1<n1; ++i1) {
168 out << "[" << std::setw(IndexWidth) << f0+i0 << "]"
169 << "[" << std::setw(IndexWidth) << f1+i1 << "]"
170 << "[" << std::setw(IndexWidth) << f2 << ":" << std::setw(IndexWidth) << f2+n2-1 << "] ";
171 for (i2=0; i2<n2; ++i2) {
172 out << std::setprecision(DataPrecision) << std::setw(DataWidth)
173 << liter.offset(i0,i1,i2)<<" ";
174 if( CarReturn > 0 ) {
175 if( i2 != 0 && i2 != ( n2-1) && !( (i2+1) % CarReturn) ) {
176 out << endl << " ";
177 }
178 }
179 }
180 out << endl;
181 }
182 }
183 break;
184
185 default:
186 ERRORMSG("bad Dimension \""<<Dim<<"\" in FieldPrint::print()"<< endl);
187 return;
188 }
189 }
190}
191
192
193/***************************************************************************
194 * $RCSfile: FieldPrint.cpp,v $ $Author: adelmann $
195 * $Revision: 1.1.1.1 $ $Date: 2003/01/23 07:40:33 $
196 * IPPL_VERSION_ID: $Id: FieldPrint.cpp,v 1.1.1.1 2003/01/23 07:40:33 adelmann Exp $
197 ***************************************************************************/
const unsigned Dim
void putMessage(Message &m, const T &t)
Definition: Message.h:549
void getMessage(Message &m, T &t)
Definition: Message.h:572
const int COMM_ANY_NODE
Definition: Communicate.h:40
#define FP_TAG_CYCLE
Definition: Tags.h:65
#define FP_GATHER_TAG
Definition: Tags.h:64
Inform & endl(Inform &inf)
Definition: Inform.cpp:42
#define PAssert(c)
Definition: PAssert.h:102
#define ERRORMSG(msg)
Definition: IpplInfo.h:350
bool touches(const NDIndex< Dim > &) const
Message & putMessage(Message &m) const
Definition: NDIndex.h:130
bool contains(const NDIndex< Dim > &a) const
Message & getMessage(Message &m)
Definition: NDIndex.h:138
NDIndex< Dim > intersect(const NDIndex< Dim > &) const
iterator_if begin_if()
Definition: BareField.h:100
ac_id_larray::iterator iterator_if
Definition: BareField.h:92
iterator_if end_if()
Definition: BareField.h:101
Definition: LField.h:58
const NDIndex< Dim > & getOwned() const
Definition: LField.h:99
void Uncompress(bool fill_domain=true)
Definition: LField.h:172
const iterator & begin() const
Definition: LField.h:110
virtual void apply()
bool send(Message *, int node, int tag, bool delmsg=true)
Message * receive_block(int &node, int &tag)
int next_tag(int t, int s=1000)
Definition: TagMaker.h:39
void print(NDIndex< Dim > &view)
Definition: FieldPrint.hpp:39
Definition: Inform.h:42
FmtFlags_t setf(FmtFlags_t setbits, FmtFlags_t field)
Definition: Inform.h:101
static int getNodes()
Definition: IpplInfo.cpp:670
static Communicate * Comm
Definition: IpplInfo.h:84