1 # ifndef _RHEOLEF_DISTSTREAM_H
2 # define _RHEOLEF_DISTSTREAM_H
118 #include "rheolef/distributed.h"
119 #include "rheolef/dis_macros.h"
120 #include "rheolef/catchmark.h"
133 odiststream (std::string filename, std::string suffix =
"",
144 void open (std::string filename, std::string suffix =
"",
146 void open (std::string filename,
148 void open (std::string filename, std::string suffix,
158 operator bool()
const {
return good(); }
184 : _ptr_os(0), _use_alloc(false), _comm()
189 : _ptr_os(0), _use_alloc(false), _comm()
191 open (filename, suffix, mode,
comm);
195 : _ptr_os(0), _use_alloc(false), _comm()
201 : _ptr_os(0), _use_alloc(false), _comm()
207 : _ptr_os(0), _use_alloc(false), _comm()
213 : _ptr_os(&os), _use_alloc(false), _comm(comm)
220 open (filename, std::string(
""), mode,
comm);
240 #ifndef _RHEOLEF_HAVE_MPI
249 # define define_sequential_odiststream_raw_macro(arg) \
252 operator << (odiststream& s, arg) { \
253 if (s.nop()) return s; s.os() << x; return s; \
255 # define define_sequential_odiststream_macro(T) \
256 define_sequential_odiststream_raw_macro(const T& x)
258 # define define_distributed_odiststream_macro(T) \
261 operator << (odiststream& s, const T& x) { \
262 s.os() << x; return s; \
270 if (s.
nop())
return s;
284 #ifdef _RHEOLEF_HAVE_FLOAT128
299 idiststream (std::istream& is,
const communicator& comm = communicator());
300 idiststream (std::string filename, std::string suffix =
"",
301 const communicator& comm = communicator());
306 void open (std::string filename, std::string suffix =
"",
307 const communicator& comm = communicator());
312 const communicator& comm()
const {
return _comm; }
314 operator bool()
const {
return good(); }
326 std::istream* _ptr_is;
330 idiststream(
const idiststream&);
331 idiststream& operator= (
const idiststream&);
339 idiststream::idiststream()
340 : _ptr_is(0), _use_alloc(false), _comm()
344 idiststream::idiststream (std::istream& is,
const communicator& comm)
345 : _ptr_is(&is), _use_alloc(false), _comm(comm)
349 idiststream::idiststream (std::string filename, std::string suffix,
const communicator& comm)
350 : _ptr_is(0), _use_alloc(false), _comm()
352 open (filename, suffix, comm);
358 check_macro (_ptr_is != 0,
"try to use an uninitialized idiststream");
361 #ifndef _RHEOLEF_HAVE_MPI
362 inline bool idiststream::nop() {
return false; }
363 inline bool idiststream::do_load() {
return true; }
365 inline bool idiststream::nop() {
return size_type(_comm.rank()) != io_proc(); }
366 inline bool idiststream::do_load() {
return size_type(_comm.rank()) == io_proc(); }
372 #ifdef _RHEOLEF_HAVE_MPI
373 # define define_sequential_idiststream_macro(T) \
376 operator >> (idiststream& s, T& x) \
378 if (s.do_load()) { (s.is()) >> x; } \
379 mpi::broadcast (mpi::communicator(), x, s.io_proc()); \
383 # define define_sequential_idiststream_macro(T) \
386 operator >> (idiststream& s, T& x) \
392 # define define_distributed_raw_idiststream_macro(T) \
395 operator >> (idiststream& s, T_x) \
400 # define define_distributed_idiststream_macro(T) \
401 define_distributed_raw_idiststream_macro(T& x)
412 #ifdef _RHEOLEF_HAVE_FLOAT128
418 operator >> (idiststream& s, std::istream& (*x)(std::istream&))
438 bool dis_scatch (idiststream& ips,
const communicator& comm, std::string ch);
449 if (ids.nop())
return ids;
450 ids.is() >> setmark(
m.mark());
451 std::string label =
"#" +
m.mark();
452 if (!
scatch(ids.is(),label)) {
453 bool verbose = iorheo::getverbose(ids.is());
454 if (
verbose) warning_macro (
"catchmark: label `"<< label <<
"' not found on input");
462 if (ods.
nop())
return ods;
463 ods.
os() << setmark(
m.mark())
464 <<
"#" <<
m.mark() << std::endl;
468 int dis_system (
const std::string&
command,
const communicator& comm = communicator());
469 bool dis_file_exists (
const std::string& filename,
const communicator& comm = communicator());
field::size_type size_type
see the catchmark page for the full documentation
odiststream: see the diststream page for the full documentation
void open(std::string filename, std::string suffix="", io::mode_type mode=io::out, const communicator &comm=communicator())
This routine opens a physical output file.
const communicator & comm() const
static size_type io_proc()
idiststream din
see the diststream page for the full documentation
#define define_sequential_odiststream_macro(T)
#define define_sequential_idiststream_macro(T)
#define define_sequential_odiststream_raw_macro(arg)
check_macro(expr1.have_homogeneous_space(Xh1), "dual(expr1,expr2); expr1 should have homogeneous space. HINT: use dual(interpolate(Xh, expr1),expr2)")
This file is part of Rheolef.
bool dis_scatch(idiststream &ips, std::string ch)
bool scatch(std::istream &in, const std::string &ch, bool full_match=true)
scatch: see the rheostream page for the full documentation
idiststream & operator>>(idiststream &ids, const catchmark &m)
int dis_system(const std::string &command, const communicator &comm)
bool dis_file_exists(const std::string &filename, const communicator &comm)
std::ostream & operator<<(std::ostream &os, const catchmark &m)
ostream & operator<<(ostream &os, const tiny_element &K)