10 #ifndef THYRA_SPMD_MULTI_VECTOR_SERIALIZER_HPP
11 #define THYRA_SPMD_MULTI_VECTOR_SERIALIZER_HPP
13 #include "Thyra_SpmdMultiVectorSerializer_decl.hpp"
14 #include "Thyra_SpmdVectorSpaceDefaultBase.hpp"
15 #include "Thyra_MultiVectorBase.hpp"
16 #include "Thyra_DetachedMultiVectorView.hpp"
20 template<
class Scalar>
22 const bool my_binaryMode
24 :binaryMode_(my_binaryMode)
27 template<
class Scalar>
35 template<
class Scalar>
43 std::ios::fmtflags fmt(out.flags());
44 out.precision(std::numeric_limits<Scalar>::digits10+4);
45 if( mpi_vec_spc.
get() ) {
49 localOffset = mpi_vec_spc->localOffset(),
50 localSubDim = mpi_vec_spc->localSubDim();
51 const Range1D localRng( localOffset, localOffset+localSubDim-1 );
53 out << localSubDim <<
" " << local_mv.
numSubCols() << std::endl;
57 out.write( reinterpret_cast<const char*>(&local_mv(0,j)),
sizeof(Scalar)*localSubDim );
61 for(
Ordinal i = 0; i < localSubDim; ++i ) {
64 out <<
" " << local_mv(i,j);
78 template<
class Scalar>
85 if( mpi_vec_spc.
get() ) {
89 localOffset = mpi_vec_spc->localOffset(),
90 localSubDim = mpi_vec_spc->localSubDim();
91 const Range1D localRng( localOffset, localOffset+localSubDim-1 );
96 ,
"Error: The input stream given is empty before any reading has began!\n"
97 "If this stream came from a file, then the file may not exist!"
101 in >> localSubDim_in;
104 localSubDim != localSubDim_in, std::logic_error
105 ,
"Error, localSubDim = "<<localSubDim<<
" does not match the read in value of "
106 "localSubDim_in = "<<localSubDim_in<<
"!"
113 local_mv.
numSubCols() != numSubCols_in, std::logic_error
114 ,
"Error, numSubCols = "<<local_mv.
numSubCols()<<
" does not match the read in value of "
115 "numSubCols_in = "<<numSubCols_in<<
"!"
124 in.read( reinterpret_cast<char*>(&local_mv(0,j)),
sizeof(Scalar)*localSubDim );
128 for(
Ordinal i = 0; i < localSubDim; ++i ) {
136 i != i_in, std::logic_error
137 ,
"Error, i = "<<i<<
" does not match the read in value of "
144 !in, std::logic_error
145 ,
"Error: The input stream ran out at j="<<j<<
" before"
146 " reaching the promised " << local_mv.
numSubCols()
147 <<
" rows of the (multi)vector!"
164 #endif // THYRA_SPMD_MULTI_VECTOR_SERIALIZER_HPP
void deserialize(std::istream &in, MultiVectorBase< Scalar > *mv) const
Read from a stream.
Create an explicit non-mutable (const) view of a MultiVectorBase object.
virtual RCP< const VectorSpaceBase< Scalar > > range() const =0
Return a smart pointer for the range space for this operator.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Ordinal numSubCols() const
bool isCompatible(const MultiVectorBase< Scalar > &mv) const
Determine if the multi-vector is compatible or not.
Create an explicit mutable (non-const) view of a MultiVectorBase object.
Teuchos::Ordinal Ordinal
Type for the dimension of a vector space. `*.
Interface for a collection of column vectors called a multi-vector.
Ordinal numSubCols() const
void serialize(const MultiVectorBase< Scalar > &mv, std::ostream &out) const
Write to a stream.
SpmdMultiVectorSerializer(const bool binaryMode=false)
Base abstract VectorSpaceBase class for all SPMD-based vector spaces.