42 #ifndef THYRA_SPMD_MULTI_VECTOR_SERIALIZER_HPP
43 #define THYRA_SPMD_MULTI_VECTOR_SERIALIZER_HPP
45 #include "Thyra_SpmdMultiVectorSerializer_decl.hpp"
46 #include "Thyra_SpmdVectorSpaceDefaultBase.hpp"
47 #include "Thyra_MultiVectorBase.hpp"
48 #include "Thyra_DetachedMultiVectorView.hpp"
52 template<
class Scalar>
54 const bool my_binaryMode
56 :binaryMode_(my_binaryMode)
59 template<
class Scalar>
67 template<
class Scalar>
75 std::ios::fmtflags fmt(out.flags());
76 out.precision(std::numeric_limits<Scalar>::digits10+4);
77 if( mpi_vec_spc.
get() ) {
81 localOffset = mpi_vec_spc->localOffset(),
82 localSubDim = mpi_vec_spc->localSubDim();
83 const Range1D localRng( localOffset, localOffset+localSubDim-1 );
85 out << localSubDim <<
" " << local_mv.
numSubCols() << std::endl;
89 out.write( reinterpret_cast<const char*>(&local_mv(0,j)),
sizeof(Scalar)*localSubDim );
93 for(
Ordinal i = 0; i < localSubDim; ++i ) {
96 out <<
" " << local_mv(i,j);
110 template<
class Scalar>
117 if( mpi_vec_spc.
get() ) {
121 localOffset = mpi_vec_spc->localOffset(),
122 localSubDim = mpi_vec_spc->localSubDim();
123 const Range1D localRng( localOffset, localOffset+localSubDim-1 );
127 !in, std::logic_error
128 ,
"Error: The input stream given is empty before any reading has began!\n"
129 "If this stream came from a file, then the file may not exist!"
133 in >> localSubDim_in;
136 localSubDim != localSubDim_in, std::logic_error
137 ,
"Error, localSubDim = "<<localSubDim<<
" does not match the read in value of "
138 "localSubDim_in = "<<localSubDim_in<<
"!"
145 local_mv.
numSubCols() != numSubCols_in, std::logic_error
146 ,
"Error, numSubCols = "<<local_mv.
numSubCols()<<
" does not match the read in value of "
147 "numSubCols_in = "<<numSubCols_in<<
"!"
156 in.read( reinterpret_cast<char*>(&local_mv(0,j)),
sizeof(Scalar)*localSubDim );
160 for(
Ordinal i = 0; i < localSubDim; ++i ) {
168 i != i_in, std::logic_error
169 ,
"Error, i = "<<i<<
" does not match the read in value of "
176 !in, std::logic_error
177 ,
"Error: The input stream ran out at j="<<j<<
" before"
178 " reaching the promised " << local_mv.
numSubCols()
179 <<
" rows of the (multi)vector!"
196 #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.