Tpetra Matrix/Vector Services Version of the Day
Public Types | Static Public Member Functions
Tpetra::MatrixMarket::Writer< SparseMatrixType > Class Template Reference

Matrix Market file writer for CrsMatrix and MultiVector. More...

#include <MatrixMarket_Tpetra.hpp>

List of all members.

Public Types

typedef
SparseMatrixType::scalar_type 
scalar_type
 Type of the entries of the sparse matrix.
typedef
SparseMatrixType::local_ordinal_type 
local_ordinal_type
 Only used to define map_type.
typedef
SparseMatrixType::global_ordinal_type 
global_ordinal_type
 Type of indices as read from the Matrix Market file.
typedef SparseMatrixType::node_type node_type
 The Kokkos Node type.
typedef MultiVector
< scalar_type,
local_ordinal_type,
global_ordinal_type, node_type
multivector_type
 The MultiVector type associated with SparseMatrixType.
typedef Map
< local_ordinal_type,
global_ordinal_type, node_type
map_type
 Tpetra::Map specialization associated with SparseMatrixType.

Static Public Member Functions

static void writeSparseFile (const std::string &filename, const RCP< const sparse_matrix_type > &pMatrix, const std::string &matrixName, const std::string &matrixDescription, const bool debug=false)
 Print the sparse matrix in Matrix Market format, with comments.
static void writeSparseFile (const std::string &filename, const RCP< const sparse_matrix_type > &pMatrix, const bool debug=false)
 Print the sparse matrix in Matrix Market format.
static void writeSparse (std::ostream &out, const RCP< const sparse_matrix_type > &pMatrix, const std::string &matrixName, const std::string &matrixDescription, const bool debug=false)
 Print the sparse matrix in Matrix Market format, with comments.
static void writeSparse (std::ostream &out, const RCP< const sparse_matrix_type > &pMatrix, const bool debug=false)
 Print the sparse matrix in Matrix Market format.
static void writeDenseFile (const std::string &filename, const multivector_type &X, const std::string &matrixName, const std::string &matrixDescription, const Teuchos::RCP< Teuchos::FancyOStream > &err=Teuchos::null, const Teuchos::RCP< Teuchos::FancyOStream > &dbg=Teuchos::null)
 Print the multivector in Matrix Market format, with matrix name and description.
static void writeDenseFile (const std::string &filename, const Teuchos::RCP< const multivector_type > &X, const std::string &matrixName, const std::string &matrixDescription, const Teuchos::RCP< Teuchos::FancyOStream > &err=Teuchos::null, const Teuchos::RCP< Teuchos::FancyOStream > &dbg=Teuchos::null)
 Print the multivector in Matrix Market format, with matrix name and description.
static void writeDenseFile (const std::string &filename, const multivector_type &X, const Teuchos::RCP< Teuchos::FancyOStream > &err=Teuchos::null, const Teuchos::RCP< Teuchos::FancyOStream > &dbg=Teuchos::null)
 Print the multivector in Matrix Market format, with no matrix name or description.
static void writeDenseFile (const std::string &filename, const RCP< const multivector_type > &X, const Teuchos::RCP< Teuchos::FancyOStream > &err=Teuchos::null, const Teuchos::RCP< Teuchos::FancyOStream > &dbg=Teuchos::null)
 Print the multivector in Matrix Market format, with no matrix name or description.
static void writeDense (std::ostream &out, const multivector_type &X, const std::string &matrixName, const std::string &matrixDescription, const Teuchos::RCP< Teuchos::FancyOStream > &err=Teuchos::null, const Teuchos::RCP< Teuchos::FancyOStream > &dbg=Teuchos::null)
 Print the multivector in Matrix Market format, with matrix name and description.
static void writeDense (std::ostream &out, const RCP< const multivector_type > &X, const std::string &matrixName, const std::string &matrixDescription, const Teuchos::RCP< Teuchos::FancyOStream > &err=Teuchos::null, const Teuchos::RCP< Teuchos::FancyOStream > &dbg=Teuchos::null)
 Print the multivector in Matrix Market format, with matrix name and or description.
static void writeDense (std::ostream &out, const multivector_type &X, const Teuchos::RCP< Teuchos::FancyOStream > &err=Teuchos::null, const Teuchos::RCP< Teuchos::FancyOStream > &dbg=Teuchos::null)
 Print the multivector in Matrix Market format, with no matrix name or description.
static void writeDense (std::ostream &out, const RCP< const multivector_type > &X, const Teuchos::RCP< Teuchos::FancyOStream > &err=Teuchos::null, const Teuchos::RCP< Teuchos::FancyOStream > &dbg=Teuchos::null)
 Print the multivector in Matrix Market format, with no matrix name or description.
static void writeMap (std::ostream &out, const map_type &map, const bool debug=false)
 Print the Map to the given output stream.
static void writeMap (std::ostream &out, const map_type &map, const Teuchos::RCP< Teuchos::FancyOStream > &err, const bool debug=false)
 Print the Map to the given output stream out.
static void writeMapFile (const std::string &filename, const map_type &map)
 Write the Map to the given file.

Detailed Description

template<class SparseMatrixType>
class Tpetra::MatrixMarket::Writer< SparseMatrixType >

Matrix Market file writer for CrsMatrix and MultiVector.

Author:
Mark Hoemmen

The Matrix Market (see their web site for details) defines a human-readable ASCII text file format for interchange of sparse and dense matrices. This class defines methods for writing sparse and dense matrices to a Matrix Market file or input stream.

All methods of this class assume that the file is only openable resp. the input stream is only writeable, on the MPI process with Rank 0 (with respect to the MPI communicator over which the given CrsMatrix or MultiVector is to be distributed).

We define the MultiVector type accepted by writeDense() and writeDenseFile() using the scalar_type, local_ordinal_type, global_ordinal_type, and node_type typedefs in SparseMatrixType. This ensures that the multivectors returned by those methods have a type compatible with the CrsMatrix sparse matrices accepted by writeSparse() and writeSparseFile(). We do this because the typical use case of Matrix Market files in Trilinos is to test sparse matrix methods, which usually involves reading a sparse matrix A and perhaps also a dense right-hand side b. Also, this lets you use CrsMatrix objects with non-default LocalMatOps template parameters. (If we templated on Scalar, LocalOrdinal, GlobalOrdinal, and Node, we would also have to template on LocalMatOps in order to deal with CrsMatrix types with nondefault LocalMatOps. That would tie Writer to CrsMatrix anyway, since MultiVector is not templated on LocalMatOps. As a result, we might as well just template on the CrsMatrix type, in order to use arbitrary LocalMatOps types without additional code.)

Template Parameters:
SparseMatrixTypeA specialization of Tpetra::CrsMatrix.

Definition at line 4871 of file MatrixMarket_Tpetra.hpp.


Member Typedef Documentation

template<class SparseMatrixType >
Tpetra::MatrixMarket::Writer< SparseMatrixType >::scalar_type

Type of the entries of the sparse matrix.

Definition at line 4878 of file MatrixMarket_Tpetra.hpp.

template<class SparseMatrixType >
Tpetra::MatrixMarket::Writer< SparseMatrixType >::local_ordinal_type

Only used to define map_type.

Definition at line 4881 of file MatrixMarket_Tpetra.hpp.

template<class SparseMatrixType >
Tpetra::MatrixMarket::Writer< SparseMatrixType >::global_ordinal_type

Type of indices as read from the Matrix Market file.

Indices of the sparse matrix are stored as global ordinals, since Matrix Market files represent the whole matrix and don't have a notion of distribution.

Definition at line 4888 of file MatrixMarket_Tpetra.hpp.

template<class SparseMatrixType >
Tpetra::MatrixMarket::Writer< SparseMatrixType >::node_type

The Kokkos Node type.

Definition at line 4891 of file MatrixMarket_Tpetra.hpp.

template<class SparseMatrixType >
Tpetra::MatrixMarket::Writer< SparseMatrixType >::multivector_type

The MultiVector type associated with SparseMatrixType.

Definition at line 4898 of file MatrixMarket_Tpetra.hpp.

template<class SparseMatrixType >
Tpetra::MatrixMarket::Writer< SparseMatrixType >::map_type

Tpetra::Map specialization associated with SparseMatrixType.

Definition at line 4901 of file MatrixMarket_Tpetra.hpp.


Member Function Documentation

template<class SparseMatrixType >
static void Tpetra::MatrixMarket::Writer< SparseMatrixType >::writeSparseFile ( const std::string &  filename,
const RCP< const sparse_matrix_type > &  pMatrix,
const std::string &  matrixName,
const std::string &  matrixDescription,
const bool  debug = false 
) [inline, static]

Print the sparse matrix in Matrix Market format, with comments.

Write the given Tpetra::CrsMatrix sparse matrix to the given file, using the Matrix Market "coordinate" format. MPI Proc 0 is the only MPI process that opens or writes to the file. Include the matrix name and description in the comments section of the file (after the initial banner line, but before the matrix metadata and data).

Parameters:
filename[in] Name of the file to which to write the given sparse matrix. The matrix is distributed, but only Proc 0 opens the file and writes to it.
pMatrix[in] The sparse matrix to write to the file.
matrixName[in] Name of the matrix, to print in the comments section of the output file. If empty, we don't print anything (not even an empty line).
matrixDescription[in] Matrix description, to print in the comments section of the output file. If empty, we don't print anything (not even an empty line).
debug[in] Whether to print possibly copious debugging output to stderr on Proc 0.
Warning:
The current implementation gathers the whole matrix onto MPI Proc 0. This will cause out-of-memory errors if the matrix is too big to fit on one process. This will be fixed in the future.

Definition at line 4935 of file MatrixMarket_Tpetra.hpp.

template<class SparseMatrixType >
static void Tpetra::MatrixMarket::Writer< SparseMatrixType >::writeSparseFile ( const std::string &  filename,
const RCP< const sparse_matrix_type > &  pMatrix,
const bool  debug = false 
) [inline, static]

Print the sparse matrix in Matrix Market format.

Write the given Tpetra::CrsMatrix sparse matrix to the given file, using the Matrix Market "coordinate" format. MPI Proc 0 is the only MPI process that opens or writes to the file.

Parameters:
filename[in] Name of the file to which to write the given sparse matrix. The matrix is distributed, but only Proc 0 opens the file and writes to it.
pMatrix[in] The sparse matrix to write to the file.
debug[in] Whether to print possibly copious debugging output to stderr on Proc 0.
Warning:
The current implementation gathers the whole matrix onto MPI Proc 0. This will cause out-of-memory errors if the matrix is too big to fit on one process. This will be fixed in the future.

Definition at line 4973 of file MatrixMarket_Tpetra.hpp.

template<class SparseMatrixType >
static void Tpetra::MatrixMarket::Writer< SparseMatrixType >::writeSparse ( std::ostream &  out,
const RCP< const sparse_matrix_type > &  pMatrix,
const std::string &  matrixName,
const std::string &  matrixDescription,
const bool  debug = false 
) [inline, static]

Print the sparse matrix in Matrix Market format, with comments.

Write the given Tpetra::CrsMatrix sparse matrix to an output stream, using the Matrix Market "coordinate" format. MPI Proc 0 is the only MPI process that writes to the output stream.

Parameters:
out[out] Name of the output stream to which to write the given sparse matrix. The matrix is distributed, but only Proc 0 writes to the output stream.
pMatrix[in] The sparse matrix to write to the given output stream.
matrixName[in] Name of the matrix, to print in the comments section of the output stream. If empty, we don't print anything (not even an empty line).
matrixDescription[in] Matrix description, to print in the comments section of the output stream. If empty, we don't print anything (not even an empty line).
debug[in] Whether to print possibly copious debugging output to stderr on Proc 0.
Warning:
The current implementation gathers the whole matrix onto MPI Proc 0. This will cause out-of-memory errors if the matrix is too big to fit on one process. This will be fixed in the future.

Definition at line 5013 of file MatrixMarket_Tpetra.hpp.

template<class SparseMatrixType >
static void Tpetra::MatrixMarket::Writer< SparseMatrixType >::writeSparse ( std::ostream &  out,
const RCP< const sparse_matrix_type > &  pMatrix,
const bool  debug = false 
) [inline, static]

Print the sparse matrix in Matrix Market format.

Write the given Tpetra::CrsMatrix sparse matrix to an output stream, using the Matrix Market "coordinate" format. MPI Proc 0 is the only MPI process that writes to the output stream.

Parameters:
out[out] Name of the output stream to which to write the given sparse matrix. The matrix is distributed, but only Proc 0 writes to the output stream.
pMatrix[in] The sparse matrix to write to the given output stream.
debug[in] Whether to print possibly copious debugging output to stderr on Proc 0.
Warning:
The current implementation gathers the whole matrix onto MPI Proc 0. This will cause out-of-memory errors if the matrix is too big to fit on one process. This will be fixed in the future.

Definition at line 5293 of file MatrixMarket_Tpetra.hpp.

template<class SparseMatrixType >
static void Tpetra::MatrixMarket::Writer< SparseMatrixType >::writeDenseFile ( const std::string &  filename,
const multivector_type X,
const std::string &  matrixName,
const std::string &  matrixDescription,
const Teuchos::RCP< Teuchos::FancyOStream > &  err = Teuchos::null,
const Teuchos::RCP< Teuchos::FancyOStream > &  dbg = Teuchos::null 
) [inline, static]

Print the multivector in Matrix Market format, with matrix name and description.

Write the given Tpetra::MultiVector matrix to the given file, using the Matrix Market "array" format for dense matrices. MPI Process 0 is the only MPI process that opens or writes to the file.

This is the preferred overload of writeDenseFile. It is used to implement all other overloads of writeDenseFile.

Parameters:
filename[in] Name of the output file to create (on MPI Proc 0 only).
X[in] The dense matrix (stored as a multivector) to write to the output file.
matrixName[in] Name of the matrix, to print in the comments section of the output file. If empty, we don't print anything (not even an empty line).
matrixDescription[in] Matrix description, to print in the comments section of the output file. If empty, we don't print anything (not even an empty line).
err[out] If nonnull, print any error messages to it.
dbg[out] If nonnull, print copious debugging output to it.

Definition at line 5329 of file MatrixMarket_Tpetra.hpp.

template<class SparseMatrixType >
static void Tpetra::MatrixMarket::Writer< SparseMatrixType >::writeDenseFile ( const std::string &  filename,
const Teuchos::RCP< const multivector_type > &  X,
const std::string &  matrixName,
const std::string &  matrixDescription,
const Teuchos::RCP< Teuchos::FancyOStream > &  err = Teuchos::null,
const Teuchos::RCP< Teuchos::FancyOStream > &  dbg = Teuchos::null 
) [inline, static]

Print the multivector in Matrix Market format, with matrix name and description.

See the documentation of the above six-argument version of writeDenseFile().

Definition at line 5355 of file MatrixMarket_Tpetra.hpp.

template<class SparseMatrixType >
static void Tpetra::MatrixMarket::Writer< SparseMatrixType >::writeDenseFile ( const std::string &  filename,
const multivector_type X,
const Teuchos::RCP< Teuchos::FancyOStream > &  err = Teuchos::null,
const Teuchos::RCP< Teuchos::FancyOStream > &  dbg = Teuchos::null 
) [inline, static]

Print the multivector in Matrix Market format, with no matrix name or description.

See the documentation of the above six-argument version of writeDenseFile().

Definition at line 5374 of file MatrixMarket_Tpetra.hpp.

template<class SparseMatrixType >
static void Tpetra::MatrixMarket::Writer< SparseMatrixType >::writeDenseFile ( const std::string &  filename,
const RCP< const multivector_type > &  X,
const Teuchos::RCP< Teuchos::FancyOStream > &  err = Teuchos::null,
const Teuchos::RCP< Teuchos::FancyOStream > &  dbg = Teuchos::null 
) [inline, static]

Print the multivector in Matrix Market format, with no matrix name or description.

See the documentation of the above six-argument version of writeDenseFile().

Definition at line 5388 of file MatrixMarket_Tpetra.hpp.

template<class SparseMatrixType >
static void Tpetra::MatrixMarket::Writer< SparseMatrixType >::writeDense ( std::ostream &  out,
const multivector_type X,
const std::string &  matrixName,
const std::string &  matrixDescription,
const Teuchos::RCP< Teuchos::FancyOStream > &  err = Teuchos::null,
const Teuchos::RCP< Teuchos::FancyOStream > &  dbg = Teuchos::null 
) [inline, static]

Print the multivector in Matrix Market format, with matrix name and description.

Write the given Tpetra::MultiVector matrix to an output stream, using the Matrix Market "array" format for dense matrices. MPI Process 0 is the only MPI process that writes to the output stream.

This is the preferred overload of writeDense(). It is used to implement all other overloads of writeDense(), and is also used to implement all overloads of writeDenseFile.

Parameters:
out[out] The output stream to which to write (on MPI Process 0 only).
X[in] The dense matrix (stored as a multivector) to write to the output file.
matrixName[in] Name of the matrix, to print in the comments section of the output stream. If empty, we don't print anything (not even an empty line).
matrixDescription[in] Matrix description, to print in the comments section of the output stream. If empty, we don't print anything (not even an empty line).
err[out] If nonnull, print any error messages to it.
dbg[out] If nonnull, print copious debugging output to it.

Definition at line 5430 of file MatrixMarket_Tpetra.hpp.

template<class SparseMatrixType >
static void Tpetra::MatrixMarket::Writer< SparseMatrixType >::writeDense ( std::ostream &  out,
const RCP< const multivector_type > &  X,
const std::string &  matrixName,
const std::string &  matrixDescription,
const Teuchos::RCP< Teuchos::FancyOStream > &  err = Teuchos::null,
const Teuchos::RCP< Teuchos::FancyOStream > &  dbg = Teuchos::null 
) [inline, static]

Print the multivector in Matrix Market format, with matrix name and or description.

See the documentation of the above six-argument version of writeDense().

Definition at line 6007 of file MatrixMarket_Tpetra.hpp.

template<class SparseMatrixType >
static void Tpetra::MatrixMarket::Writer< SparseMatrixType >::writeDense ( std::ostream &  out,
const multivector_type X,
const Teuchos::RCP< Teuchos::FancyOStream > &  err = Teuchos::null,
const Teuchos::RCP< Teuchos::FancyOStream > &  dbg = Teuchos::null 
) [inline, static]

Print the multivector in Matrix Market format, with no matrix name or description.

See the documentation of the above six-argument version of writeDense().

Definition at line 6026 of file MatrixMarket_Tpetra.hpp.

template<class SparseMatrixType >
static void Tpetra::MatrixMarket::Writer< SparseMatrixType >::writeDense ( std::ostream &  out,
const RCP< const multivector_type > &  X,
const Teuchos::RCP< Teuchos::FancyOStream > &  err = Teuchos::null,
const Teuchos::RCP< Teuchos::FancyOStream > &  dbg = Teuchos::null 
) [inline, static]

Print the multivector in Matrix Market format, with no matrix name or description.

See the documentation of the above six-argument version of writeDense().

Definition at line 6040 of file MatrixMarket_Tpetra.hpp.

template<class SparseMatrixType >
static void Tpetra::MatrixMarket::Writer< SparseMatrixType >::writeMap ( std::ostream &  out,
const map_type map,
const bool  debug = false 
) [inline, static]

Print the Map to the given output stream.

Parameters:
out[out] Output stream to which to print. This only needs to be accessible on Process 0 in the Map's communicator; no other process will do anything with it.
map[in] The Map to print.
debug[in] Whether to print copious debugging output to stderr on all processes in the Map's communicator.

We print the Map in Matrix Market format as a dense nonsymmetric integer matrix with two columns. The first column holds global indices (GIDs), and the second column holds process ranks (PIDs). In any row of the matrix, the first entry is a GID, and the second is a PID that owns the GID. Multiple PIDs may own the same GID, and the order of rows with respect to a given PID is significant.

Definition at line 6071 of file MatrixMarket_Tpetra.hpp.

template<class SparseMatrixType >
static void Tpetra::MatrixMarket::Writer< SparseMatrixType >::writeMap ( std::ostream &  out,
const map_type map,
const Teuchos::RCP< Teuchos::FancyOStream > &  err,
const bool  debug = false 
) [inline, static]

Print the Map to the given output stream out.

This version of writeMap() comes with an extra debug output stream err, that is only used if debug is true.

Warning:
We make no promises of backwards compatibility with this method. It may go away or its interface may change at any time.

Definition at line 6087 of file MatrixMarket_Tpetra.hpp.

template<class SparseMatrixType >
static void Tpetra::MatrixMarket::Writer< SparseMatrixType >::writeMapFile ( const std::string &  filename,
const map_type map 
) [inline, static]

Write the Map to the given file.

Definition at line 6586 of file MatrixMarket_Tpetra.hpp.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines