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>
72 Teuchos::RCP<const SpmdVectorSpaceBase<Scalar> >
75 std::ios::fmtflags fmt(out.flags());
76 out.precision(std::numeric_limits<Scalar>::digits10+4);
77 if( mpi_vec_spc.get() ) {
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);
105 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
"Does not handle non-SPMD spaces yet" );
110 template<
class Scalar>
115 Teuchos::RCP<const SpmdVectorSpaceBase<Scalar> >
117 if( mpi_vec_spc.get() ) {
122 localSubDim = mpi_vec_spc->localSubDim();
123 const Range1D localRng( localOffset, localOffset+localSubDim-1 );
126 TEUCHOS_TEST_FOR_EXCEPTION(
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;
135 TEUCHOS_TEST_FOR_EXCEPTION(
136 localSubDim != localSubDim_in, std::logic_error
137 ,
"Error, localSubDim = "<<localSubDim<<
" does not match the read in value of " 138 "localSubDim_in = "<<localSubDim_in<<
"!" 144 TEUCHOS_TEST_FOR_EXCEPTION(
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 ) {
162 TEUCHOS_TEST_FOR_EXCEPTION( !in, std::logic_error,
"Error, premature end of input!" );
167 TEUCHOS_TEST_FOR_EXCEPTION(
168 i != i_in, std::logic_error
169 ,
"Error, i = "<<i<<
" does not match the read in value of " 175 TEUCHOS_TEST_FOR_EXCEPTION(
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!" 190 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
"Does not handle non-SPMD spaces yet" );
196 #endif // THYRA_SPMD_MULTI_VECTOR_SERIALIZER_HPP 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.
void deserialize(std::istream &in, MultiVectorBase< Scalar > *mv) const
Read from a stream.
Create an explicit mutable (non-const) view of a MultiVectorBase object.
Teuchos::Ordinal Ordinal
Type for the dimension of a vector space. `*.
Ordinal numSubCols() const
Interface for a collection of column vectors called a multi-vector.
Ordinal numSubCols() const
virtual Ordinal localOffset() const =0
Returns the offset for the local sub-vector stored on this process.
SpmdMultiVectorSerializer(const bool binaryMode=false)
void serialize(const MultiVectorBase< Scalar > &mv, std::ostream &out) const
Write to a stream.
bool isCompatible(const MultiVectorBase< Scalar > &mv) const
Determine if the multi-vector is compatible or not.
Base abstract VectorSpaceBase class for all SPMD-based vector spaces.