Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
MPIcout.h
Go to the documentation of this file.
1/* This file is part of MoDELib, the Mechanics Of Defects Evolution Library.
2 *
3 *
4 * MODEL is distributed without any warranty under the
5 * GNU General Public License (GPL) v2 <http://www.gnu.org/licenses/>.
6 */
7
8#ifndef model_MPIcout_h_
9#define model_MPIcout_h_
10
11#include <iostream>
12
13#ifdef _MODEL_MPI_
14#include <mpi.h>
15#include <ModelMPIbase.h>
16#endif
17
18namespace model
19{
20
21 struct MPIcout
22 {
23 typedef std::basic_ostream<char, std::char_traits<char> > StlEndl_IO;
24 // define StlEndl as a pointer-to-function taking and returning a reference to StlEndl_IO
25 typedef StlEndl_IO& (*StlEndl)(StlEndl_IO&);
26
27
28 /**********************************************************************/
29 MPIcout(const MPIcout&) :
30 /* base init*/ os(std::cout)
31 {
33 }
34
35 /**********************************************************************/
37 {
39 return *this;
40 }
41
42
43 std::ostream& os;
44
45 public:
46 /**********************************************************************/
48 /* base init*/ os(std::cout)
49 {
51 }
52
53 /**********************************************************************/
54 template<typename T>
55 MPIcout& operator<<(const T& t)
56 {
57#ifdef _MODEL_MPI_
58
59 if (ModelMPIbase::mpiRank()==0)
60 {
61 os<<t;
62 }
63#else
64 os<<t;
65#endif
66 return *this;
67 }
68
69 /**********************************************************************/
71 {
73#ifdef _MODEL_MPI_
75 {
76 manip(os);
77 }
78#else
79 manip(os);
80
81#endif
82 return *this;
83 }
84
85 };
86
87 // declare object cout
88 static MPIcout cout;
89
90} // end namespace
91#endif
static const int & mpiRank()
final point of the source segment t
static MPIcout cout
Definition MPIcout.h:88
StlEndl_IO &(* StlEndl)(StlEndl_IO &)
Definition MPIcout.h:25
MPIcout & operator<<(const T &t)
Definition MPIcout.h:55
MPIcout(const MPIcout &)
Definition MPIcout.h:29
std::basic_ostream< char, std::char_traits< char > > StlEndl_IO
Definition MPIcout.h:23
std::ostream & os
Definition MPIcout.h:43
MPIcout & operator=(const MPIcout &)
Definition MPIcout.h:36
MPIcout & operator<<(StlEndl manip)
Definition MPIcout.h:70