42 #ifndef THYRA_DEFAULT_SPMD_MULTI_VECTOR_FILE_IO_HPP
43 #define THYRA_DEFAULT_SPMD_MULTI_VECTOR_FILE_IO_HPP
45 #include "Thyra_MultiVectorFileIOBase.hpp"
46 #include "Thyra_SpmdMultiVectorSerializer.hpp"
47 #include "Teuchos_Utils.hpp"
67 template<
class Scalar>
80 const std::string &extensionTagName =
""
81 ,
const int numProcs = -1
82 ,
const int procRank = -1
102 const std::string &extensionTagName =
""
103 ,
const int numProcs = -1
104 ,
const int procRank = -1
118 const std::string &fileNameBase
124 ,
const std::string &fileNameBase
130 std::string localFileNameExtension_;
140 template<
class Scalar>
142 const std::string &extensionTagName
146 :useBinaryMode_(false)
147 ,mvSerializer_(useBinaryMode_)
152 template<
class Scalar>
154 const std::string &extensionTagName
161 if(extensionTagName.length())
162 localFileNameExtension_ = extensionTagName+
"."+endExtension;
164 localFileNameExtension_ = endExtension;
167 template<
class Scalar>
170 const std::string &fileNameBase
173 std::ostringstream parallelFileName;
174 parallelFileName << fileNameBase;
175 if(localFileNameExtension_.length())
176 parallelFileName <<
"." << localFileNameExtension_;
177 return parallelFileName.str();
180 template<
class Scalar>
185 return mvSerializer_.isCompatible(mv);
188 template<
class Scalar>
190 const std::string &fileNameBase
195 const std::string fileName = getLocalFileName(fileNameBase);
196 std::ifstream in_file(fileName.c_str());
198 in_file.eof(), std::logic_error
199 ,
"Error, the file \""<<fileName<<
"\" could not be opened for input!"
201 mvSerializer_.binaryMode(useBinaryMode_);
202 mvSerializer_.deserialize(in_file,mv);
205 template<
class Scalar>
208 ,
const std::string &fileNameBase
211 const std::string fileName = getLocalFileName(fileNameBase);
212 std::ofstream out_file(fileName.c_str());
213 mvSerializer_.binaryMode(useBinaryMode_);
214 mvSerializer_.serialize(mv,out_file);
219 #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...