QDP++
qdp_stdio.cc
Go to the documentation of this file.
1// -*- C++ -*-
2
9
10
11#include "qdp.h"
12
13namespace QDP {
14
15//-----------------------------------------
16// Make global (parallel) versions of stdin, stdout, stderr
17// Put this in a different namespace to avoid collisions
24
25
26//-----------------------------------------
29
30void StandardInputStream::init(std::istream* b)
31{
32 is = b;
33 open = true;
34}
35
36// Propagate status to all nodes
38{
39 bool s;
40
42 s = getIstream().fail();
43
45 return s;
46}
47
49
50
51// String reader
53{
54 // Only primary node can grab string
56 {
57 getIstream() >> input;
58 }
59
60 // broadcast string
62
63 return *this;
64}
65
66// Readers
115
116template< typename T>
118{
120 getIstream() >> input;
121
122 // Now broadcast back out to all nodes
124
125 return *this;
126}
127
128
129//-----------------------------------------
132
133void StandardOutputStream::init(std::ostream* b)
134{
135 os = b;
136 open = true;
137}
138
140{
141 if (is_open())
142 {
143 if (Layout::primaryNode())
144 getOstream().flush();
145 }
146}
147
148// Propagate status to all nodes
150{
151 bool s;
152
153 if (Layout::primaryNode())
154 s = getOstream().fail();
155
157 return s;
158}
159
161
162
163// Hook for manipulators
164StandardOutputStream& StandardOutputStream::operator<<(std::ostream& (*op)(std::ostream&))
165{
166 // Call the function passed as parameter with this stream as the argument.
167 // Hmm, for now do this on only the primary stream. This could potentially
168 // cause problems since somebody might set hex mode or something and it
169 // won't be done on all nodes.
171 (*op)(getOstream());
172
173 return *this;
174}
175
176
178{
180 getOstream() << output;
181
182 return *this;
183}
184
186{
188 getOstream() << output;
189
190 return *this;
191}
192
197
202
207
212
214{
216}
217
222
224{
226}
227
232
234{
236 {
237 std::streamsize initPrec = getOstream().precision();
238 getOstream().precision(7);
239 getOstream() << output;
240 getOstream().precision(initPrec);
241 }
242
243 return *this;
244}
245
247{
249 {
250 std::streamsize initPrec = getOstream().precision();
251 getOstream().precision(15);
252 getOstream() << output;
253 getOstream().precision(initPrec);
254 }
255
256 return *this;
257}
258
263
268
269template<typename T>
271{
273 getOstream() << output;
274
275 return *this;
276}
277
278
279} // namespace QDP;
StandardInputStream class.
Definition qdp_stdio.h:33
~StandardInputStream()
destructor
Definition qdp_stdio.cc:48
bool fail()
Return true if some failure occurred in previous IO operation.
Definition qdp_stdio.cc:37
StandardInputStream()
Constructor.
Definition qdp_stdio.cc:28
StandardInputStream & readPrimitive(T &output)
Definition qdp_stdio.cc:117
StandardInputStream & operator>>(std::string &input)
Definition qdp_stdio.cc:52
std::istream & getIstream()
Definition qdp_stdio.h:77
void init(std::istream *is)
Constructor from a stream.
Definition qdp_stdio.cc:30
StandardOutputStream class.
Definition qdp_stdio.h:106
StandardOutputStream & writePrimitive(T output)
Definition qdp_stdio.cc:270
StandardOutputStream()
Constructor.
Definition qdp_stdio.cc:131
bool fail()
Return true if some failure occurred in previous IO operation.
Definition qdp_stdio.cc:149
std::ostream & getOstream()
Definition qdp_stdio.h:156
bool is_open()
Is the stream open?
Definition qdp_stdio.h:159
void flush()
Flush the buffer.
Definition qdp_stdio.cc:139
StandardOutputStream & operator<<(std::ostream &(*op)(std::ostream &))
Hook for manipulators.
Definition qdp_stdio.cc:164
void init(std::ostream *os)
Constructor from a stream.
Definition qdp_stdio.cc:133
bool primaryNode()
Returns whether this is the primary node.
StandardOutputStream cout
Definition qdp_stdio.cc:21
StandardOutputStream cerr
Definition qdp_stdio.cc:22
StandardInputStream cin
Definition qdp_stdio.cc:20
void broadcast(T &dest)
Broadcast from primary node to all other nodes.
void broadcast_str(std::string &result)
Broadcast a string from primary node to all other nodes.
Yet another random number generator.
Primary include file for QDP.