1# ifndef _RHEOLEF_DISTSTREAM_H
2# define _RHEOLEF_DISTSTREAM_H
118#include "rheolef/communicator.h"
119#include "rheolef/dis_macros.h"
120#include "rheolef/catchmark.h"
126#include "rheolef/iorheo.h"
127#include "rheolef/point.h"
128#include "rheolef/tensor.h"
129#include "rheolef/tensor3.h"
130#include "rheolef/tensor4.h"
144 odiststream (std::string filename, std::string suffix =
"",
148 odiststream (std::string filename, std::string suffix,
const communicator&
comm);
155 void open (std::string filename, std::string suffix =
"",
157 void open (std::string filename,
159 void open (std::string filename, std::string suffix,
160 const communicator&
comm);
161 void open (std::string filename,
const communicator&
comm);
169 operator bool()
const {
return good(); }
195 : _ptr_os(0), _use_alloc(false), _comm()
200 : _ptr_os(0), _use_alloc(false), _comm()
202 open (filename, suffix, mode,
comm);
206 : _ptr_os(0), _use_alloc(false), _comm()
212 : _ptr_os(0), _use_alloc(false), _comm()
218 : _ptr_os(0), _use_alloc(false), _comm()
224 : _ptr_os(&os), _use_alloc(false), _comm(comm)
231 open (filename, std::string(
""), mode,
comm);
251#ifndef _RHEOLEF_HAVE_MPI
260# define _RHEOLEF_define_sequential_odiststream_raw_macro(arg) \
263 operator << (odiststream& s, arg) { \
264 if (s.nop()) return s; \
268# define _RHEOLEF_define_sequential_odiststream_macro(T) \
269 _RHEOLEF_define_sequential_odiststream_raw_macro(const T& x)
281#ifdef _RHEOLEF_HAVE_FLOAT128
286#undef _RHEOLEF_define_sequential_odiststream_macro
295template<
class T,
class Sfinae =
void>
296struct is_omanip : std::false_type {};
299struct is_omanip <
T,typename
std::enable_if<
300 std::is_pointer<decltype(static_cast<std::ostream& (*)(std::ostream&, const T&)>
301 (operator<<))>::value>::type>
307struct is_omanip <T,typename std::enable_if<
308 std::is_pointer<decltype(static_cast<std::ostream& (*)(std::ostream&, T)>
309 (operator<<))>::value>::type>
315struct is_omanip <typename std::function<decltype(std::setprecision)>::result_type>
321typename std::enable_if<
322 details::is_omanip<T>::value
325operator<< (odiststream& s, const T& x)
327 if (s.nop()) return s;
338 typedef std::size_t size_type;
343 idiststream (std::istream& is, const communicator& comm = communicator());
344 idiststream (std::string filename, std::string suffix = "",
345 const communicator& comm = communicator());
350 void open (std::string filename, std::string suffix = "",
351 const communicator& comm = communicator());
356 const communicator& comm() const { return _comm; }
358 operator bool() const { return good(); }
359 static size_type io_proc();
370 std::istream* _ptr_is;
374 idiststream(const idiststream&);
375 idiststream& operator= (const idiststream&);
383idiststream::idiststream()
384 : _ptr_is(0), _use_alloc(false), _comm()
388idiststream::idiststream (std::istream& is, const communicator& comm)
389 : _ptr_is(&is), _use_alloc(false), _comm(comm)
393idiststream::idiststream (std::string filename, std::string suffix, const communicator& comm)
394 : _ptr_is(0), _use_alloc(false), _comm()
396 open (filename, suffix, comm);
402 check_macro (_ptr_is != 0, "try to use an uninitialized idiststream");
405#ifndef _RHEOLEF_HAVE_MPI
406inline bool idiststream::nop() { return false; }
407inline bool idiststream::do_load() { return true; }
409inline bool idiststream::nop() { return size_type(_comm.rank()) != io_proc(); }
410inline bool idiststream::do_load() { return size_type(_comm.rank()) == io_proc(); }
416#ifdef _RHEOLEF_HAVE_MPI
417# define _RHEOLEF_define_sequential_idiststream_macro(T) \
420operator>> (idiststream& s, T& x) \
422 if (s.do_load()) { (s.is()) >> x; } \
423 mpi::broadcast (mpi::communicator(), x, s.io_proc()); \
427# define _RHEOLEF_define_sequential_idiststream_macro(T) \
430operator>> (idiststream& s, T& x) \
446#ifdef _RHEOLEF_HAVE_FLOAT128
450#undef _RHEOLEF_define_sequential_idiststream_macro
455operator>> (idiststream& s, std::istream& (*x)(std::istream&))
486 if (ids.
nop())
return ids;
487 ids.
is() >> setmark(m.mark());
488 std::string label =
"#" + m.mark();
490 bool verbose = iorheo::getverbose(ids.
is());
491 if (verbose)
warning_macro (
"catchmark: label `"<< label <<
"' not found on input");
499 if (ods.
nop())
return ods;
500 ods.
os() << setmark(m.mark())
501 <<
"#" << m.mark() << std::endl;
field::size_type size_type
see the communicator page for the full documentation
see the catchmark page for the full documentation
idiststream: see the diststream page for the full documentation
const communicator & comm() const
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.
static size_type io_proc()
const communicator & comm() const
#define warning_macro(message)
#define _RHEOLEF_define_sequential_odiststream_raw_macro(arg)
#define _RHEOLEF_define_sequential_idiststream_macro(T)
#define _RHEOLEF_define_sequential_odiststream_macro(T)
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.
std::ostream & operator<<(std::ostream &os, const catchmark &m)
bool scatch(std::istream &in, const std::string &ch, bool full_match=true)
scatch: see the rheostream page for the full documentation
bool dis_scatch(idiststream &ips, const communicator &comm, std::string ch)
distributed version of scatch(istream&,string)
int dis_system(const std::string &command, const communicator &comm)
bool dis_file_exists(const std::string &filename, const communicator &comm)
std::istream & operator>>(std::istream &is, const catchmark &m)