10 #ifndef THYRA_DEFAULT_SPMD_MULTI_VECTOR_FILE_IO_HPP
11 #define THYRA_DEFAULT_SPMD_MULTI_VECTOR_FILE_IO_HPP
13 #include "Thyra_MultiVectorFileIOBase.hpp"
14 #include "Thyra_SpmdMultiVectorSerializer.hpp"
15 #include "Teuchos_Utils.hpp"
35 template<
class Scalar>
48 const std::string &extensionTagName =
""
49 ,
const int numProcs = -1
50 ,
const int procRank = -1
70 const std::string &extensionTagName =
""
71 ,
const int numProcs = -1
72 ,
const int procRank = -1
86 const std::string &fileNameBase
92 ,
const std::string &fileNameBase
98 std::string localFileNameExtension_;
108 template<
class Scalar>
110 const std::string &extensionTagName
114 :useBinaryMode_(false)
115 ,mvSerializer_(useBinaryMode_)
120 template<
class Scalar>
122 const std::string &extensionTagName
129 if(extensionTagName.length())
130 localFileNameExtension_ = extensionTagName+
"."+endExtension;
132 localFileNameExtension_ = endExtension;
135 template<
class Scalar>
138 const std::string &fileNameBase
141 std::ostringstream parallelFileName;
142 parallelFileName << fileNameBase;
143 if(localFileNameExtension_.length())
144 parallelFileName <<
"." << localFileNameExtension_;
145 return parallelFileName.str();
148 template<
class Scalar>
153 return mvSerializer_.isCompatible(mv);
156 template<
class Scalar>
158 const std::string &fileNameBase
163 const std::string fileName = getLocalFileName(fileNameBase);
164 std::ifstream in_file(fileName.c_str());
166 in_file.eof(), std::logic_error
167 ,
"Error, the file \""<<fileName<<
"\" could not be opened for input!"
169 mvSerializer_.binaryMode(useBinaryMode_);
170 mvSerializer_.deserialize(in_file,mv);
173 template<
class Scalar>
176 ,
const std::string &fileNameBase
179 const std::string fileName = getLocalFileName(fileNameBase);
180 std::ofstream out_file(fileName.c_str());
181 mvSerializer_.binaryMode(useBinaryMode_);
182 mvSerializer_.serialize(mv,out_file);
187 #endif // THYRA_DEFAULT_SPMD_MULTI_VECTOR_FILE_IO_HPP
DefaultSpmdMultiVectorFileIO(const std::string &extensionTagName="", const int numProcs=-1, const int procRank=-1)
Construct with file extension information (calls setFileNameExtension()).
Concrete utility class for reading and writing SPMD-based MultiVectorBase objects to and from standar...
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
void readMultiVectorFromFile(const std::string &fileNameBase, Thyra::MultiVectorBase< Scalar > *mv) const
void writeMultiVectorToFile(const Thyra::MultiVectorBase< Scalar > &mv, const std::string &fileNameBase) const
bool isCompatible(const MultiVectorBase< Scalar > &mv) const
Interface for a collection of column vectors called a multi-vector.
Abstract strategy interface for reading and writing (multi)vector objects to and from files...
void setFileNameExtension(const std::string &extensionTagName="", const int numProcs=-1, const int procRank=-1)
Set file name extension information to disambiguate files on different processes and from other files...
static std::string getParallelExtension(int procRank=-1, int numProcs=-1)
std::string getLocalFileName(const std::string &fileNameBase) const
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
Concrete implementation of MultiVectorFileIO that reads and writes SPMD-based (multi)vectors to and f...