22 #include "rheolef/diststream.h"
23 #include "rheolef/environment.h"
24 #include "rheolef/rheostream.h"
32 idiststream din (cin);
34 odiststream dout (cout);
36 odiststream dlog (clog);
38 odiststream derr (cerr);
48 size_type io_proc = idiststream::io_proc();
51 if (my_proc == io_proc) {
54 #ifdef _RHEOLEF_HAVE_MPI
55 mpi::broadcast (comm,
status, io_proc);
64 idiststream::io_proc() {
65 #ifndef _RHEOLEF_HAVE_MPI
68 boost::optional<int> opt_io_proc = environment::io_rank();
69 check_macro (opt_io_proc,
"no process can perform i/o");
70 int io_proc = opt_io_proc.get();
71 if (io_proc == mpi::any_source) {
79 odiststream::io_proc()
81 return idiststream::io_proc();
88 const communicator& comm)
91 if (_use_alloc && _ptr_is != 0) {
92 delete_macro (_ptr_is);
96 if (
size_type(comm.rank()) == idiststream::io_proc()) {
97 _ptr_is = new_macro (
irheostream(filename, suffix));
105 idiststream::close ()
107 if (_use_alloc && _ptr_is != 0) {
108 if (
size_type(_comm.rank()) == idiststream::io_proc()) {
114 idiststream::~idiststream ()
117 if (_use_alloc && _ptr_is != 0) {
118 delete_macro (_ptr_is);
124 idiststream::good()
const
127 if (
size_type(comm().rank()) != idiststream::io_proc()) {
129 }
else if (_ptr_is == 0) {
132 status = (*_ptr_is).good();
134 #ifdef _RHEOLEF_HAVE_MPI
135 mpi::broadcast(comm(),
status, 0);
145 std::string filename,
148 const communicator& comm)
151 if (_use_alloc && _ptr_os != 0) {
152 delete_macro (_ptr_os);
156 if (
size_type(comm.rank()) == odiststream::io_proc()) {
157 _ptr_os = new_macro (
orheostream(filename, suffix, mode));
165 odiststream::close ()
167 if (_use_alloc && _ptr_os != 0) {
168 if (
size_type(_comm.rank()) == odiststream::io_proc()) {
177 if (
size_type(_comm.rank()) != odiststream::io_proc())
return;
178 if (_use_alloc && _ptr_os != 0) {
181 }
else if (_ptr_os != 0) {
185 odiststream::~odiststream ()
188 if (_use_alloc && _ptr_os != 0) {
189 delete_macro (_ptr_os);
195 odiststream::good()
const
198 if (
size_type(comm().rank()) != idiststream::io_proc()) {
200 }
else if (_ptr_os == 0) {
203 status = (*_ptr_os).good();
205 #ifdef _RHEOLEF_HAVE_MPI
206 mpi::broadcast(comm(),
status, 0);
217 size_type io_proc = odiststream::io_proc();
220 #ifdef _RHEOLEF_HAVE_MPI
221 mpi::communicator().barrier();
223 if (my_proc == io_proc) {
226 #ifdef _RHEOLEF_HAVE_MPI
227 mpi::communicator().barrier();
228 mpi::broadcast (mpi::communicator(),
status, io_proc);
236 size_type io_proc = odiststream::io_proc();
239 if (my_proc == io_proc) {
242 #ifdef _RHEOLEF_HAVE_MPI
243 mpi::broadcast (mpi::communicator(),
status, io_proc);
field::size_type size_type
idiststream: see the diststream page for the full documentation
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 scatch(std::istream &in, const std::string &ch, bool full_match=true)
scatch: see the rheostream page for the full documentation
int dis_system(const std::string &command, const communicator &comm)
bool dis_scatch(idiststream &ips, const communicator &comm, std::string ch)
distributed version of scatch(istream&,string)
bool dis_file_exists(const std::string &filename, const communicator &comm)
bool file_exists(const std::string &filename)
file_exists: see the rheostream page for the full documentation