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"
22 const bool my_binaryMode
24 :binaryMode_(my_binaryMode)
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);
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!"
Create an explicit non-mutable (const) view of a MultiVectorBase object.
Ordinal numSubCols() const
Create an explicit mutable (non-const) view of a MultiVectorBase object.
Ordinal numSubCols() const
virtual RCP< const VectorSpaceBase< Scalar > > range() const =0
Return a smart pointer for the range space for this operator.
Interface for a collection of column vectors called a multi-vector.
bool isCompatible(const MultiVectorBase< Scalar > &mv) const
Determine if the multi-vector is compatible or not.
void serialize(const MultiVectorBase< Scalar > &mv, std::ostream &out) const
Write to a stream.
SpmdMultiVectorSerializer(const bool binaryMode=false)
void deserialize(std::istream &in, MultiVectorBase< Scalar > *mv) const
Read from a stream.
Base abstract VectorSpaceBase class for all SPMD-based vector spaces.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Teuchos::Ordinal Ordinal
Type for the dimension of a vector space. `*.
T_To & dyn_cast(T_From &from)