escript  Revision_
RipleySystemMatrix.h
Go to the documentation of this file.
1 
2 /*****************************************************************************
3 *
4 * Copyright (c) 2014-2018 by The University of Queensland
5 * http://www.uq.edu.au
6 *
7 * Primary Business: Queensland, Australia
8 * Licensed under the Apache License, version 2.0
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 * Development 2012-2013 by School of Earth Sciences
13 * Development from 2014 by Centre for Geoscience Computing (GeoComp)
14 *
15 *****************************************************************************/
16 
17 #ifndef __RIPLEY_SYSTEMMATRIX_H__
18 #define __RIPLEY_SYSTEMMATRIX_H__
19 
20 #include <escript/AbstractSystemMatrix.h>
21 #include <escript/FunctionSpace.h>
22 
23 #include <ripley/Ripley.h>
24 
25 namespace escript {
26 class SolverBuddy;
27 }
28 
29 #include <cusp/cds_matrix.h>
30 
31 namespace ripley {
32 
33 typedef cusp::cds_matrix<int, double, cusp::host_memory> HostMatrixType;
34 typedef cusp::cds_matrix<int, double, cusp::device_memory> DeviceMatrixType;
35 typedef cusp::array1d<double, cusp::host_memory> HostVectorType;
36 typedef cusp::array1d<double, cusp::device_memory> DeviceVectorType;
37 
39 {
40 public:
41  SystemMatrix(escript::JMPI mpiInfo, int blocksize,
42  const escript::FunctionSpace& fs, int nRows,
43  const IndexVector& diagonalOffsets, bool symmetric);
44 
45  virtual ~SystemMatrix() {}
46 
47  virtual void nullifyRowsAndCols(escript::Data& row_q,
48  escript::Data& col_q,
49  double mdv);
50 
51  virtual void saveMM(const std::string& filename) const;
52 
53  virtual void saveHB(const std::string& filename) const;
54 
55  virtual void resetValues(bool preserveSolverData = false);
56 
57  void add(const IndexVector& rowIndex, const std::vector<double>& array);
58 
59  inline int getBlockSize() const { return getRowBlockSize(); }
60 
61 private:
62  template<class LinearOperator, class Vector, class Preconditioner>
63  void runSolver(LinearOperator& A, Vector& x, Vector& b, Preconditioner& M,
64  escript::SolverBuddy& sb) const;
65 
67  void copyMatrixToDevice(bool verbose=false) const;
68 
69  virtual void setToSolution(escript::Data& out, escript::Data& in,
70  boost::python::object& options) const;
71 
72  virtual void ypAx(escript::Data& y, escript::Data& x) const;
73 
74  static void checkCUDA();
75 
77  static std::vector<int> cudaDevices;
78 
82  mutable bool matrixAltered;
83  bool symmetric;
84 };
85 
86 } // namespace ripley
87 
88 #endif // __RIPLEY_SYSTEMMATRIX_H__
89 
ripley::SystemMatrix::dmat
DeviceMatrixType dmat
Definition: RipleySystemMatrix.h:80
escript::SolverBuddy
Definition: SolverOptions.h:168
ripley
Definition: ripley/src/AbstractAssembler.h:24
ripley::SystemMatrix::runSolver
void runSolver(LinearOperator &A, Vector &x, Vector &b, Preconditioner &M, escript::SolverBuddy &sb) const
ripley::SystemMatrix::resetValues
virtual void resetValues(bool preserveSolverData=false)
resets the matrix entries
ripley::SystemMatrix::symmetric
bool symmetric
Definition: RipleySystemMatrix.h:82
ripley::SystemMatrix::checkCUDA
static void checkCUDA()
ripley::SystemMatrix::ypAx
virtual void ypAx(escript::Data &y, escript::Data &x) const
performs y+=this*x
ripley::SystemMatrix::~SystemMatrix
virtual ~SystemMatrix()
Definition: RipleySystemMatrix.h:44
ripley::SystemMatrix::saveMM
virtual void saveMM(const std::string &filename) const
writes the matrix to a file using the Matrix Market file format
ripley::SystemMatrix::cudaDevices
static std::vector< int > cudaDevices
GPU device IDs supporting CUDA.
Definition: RipleySystemMatrix.h:76
ripley::SystemMatrix::copyMatrixToDevice
void copyMatrixToDevice(bool verbose=false) const
copies the current matrix stored on host to device if required
escript::FunctionSpace
Definition: FunctionSpace.h:45
ripley::SystemMatrix::m_mpiInfo
escript::JMPI m_mpiInfo
Definition: RipleySystemMatrix.h:78
ripley::SystemMatrix::matrixAltered
bool matrixAltered
Definition: RipleySystemMatrix.h:81
ripley::SystemMatrix::getBlockSize
int getBlockSize() const
Definition: RipleySystemMatrix.h:58
ripley::DeviceVectorType
cusp::array1d< double, cusp::device_memory > DeviceVectorType
Definition: RipleySystemMatrix.h:35
escript::Data
Data represents a collection of datapoints.
Definition: Data.h:62
escript::JMPI
boost::shared_ptr< JMPI_ > JMPI
Definition: EsysMPI.h:70
escript::AbstractSystemMatrix
Base class for escript system matrices.
Definition: AbstractSystemMatrix.h:53
ripley::SystemMatrix::nullifyRowsAndCols
virtual void nullifyRowsAndCols(escript::Data &row_q, escript::Data &col_q, double mdv)
sets matrix entries to zero in specified rows and columns. The rows and columns are marked by positiv...
ripley::SystemMatrix::setToSolution
virtual void setToSolution(escript::Data &out, escript::Data &in, boost::python::object &options) const
solves the linear system this*out=in
ripley::IndexVector
std::vector< index_t > IndexVector
Definition: Ripley.h:55
ripley::SystemMatrix::saveHB
virtual void saveHB(const std::string &filename) const
writes the matrix to a file using the Harwell-Boeing file format
ripley::HostMatrixType
cusp::cds_matrix< int, double, cusp::host_memory > HostMatrixType
Definition: RipleySystemMatrix.h:32
escript
Definition: AbstractContinuousDomain.cpp:22
ripley::HostVectorType
cusp::array1d< double, cusp::host_memory > HostVectorType
Definition: RipleySystemMatrix.h:34
escript::Vector
Data Vector(double value, const FunctionSpace &what, bool expanded)
Return a Data object containing vector data-points. ie: rank 1 data-points.
Definition: DataFactory.cpp:96
paso::M
static dim_t M
Definition: SparseMatrix_saveHB.cpp:48
ripley::SystemMatrix::SystemMatrix
SystemMatrix(escript::JMPI mpiInfo, int blocksize, const escript::FunctionSpace &fs, int nRows, const IndexVector &diagonalOffsets, bool symmetric)
ripley::SystemMatrix::mat
HostMatrixType mat
Definition: RipleySystemMatrix.h:79
ripley::DeviceMatrixType
cusp::cds_matrix< int, double, cusp::device_memory > DeviceMatrixType
Definition: RipleySystemMatrix.h:33
escript::AbstractSystemMatrix::getRowBlockSize
int getRowBlockSize() const
returns the row block size
Definition: AbstractSystemMatrix.h:124
ripley::SystemMatrix
Definition: RipleySystemMatrix.h:37
ripley::SystemMatrix::add
void add(const IndexVector &rowIndex, const std::vector< double > &array)