Linear Algebra Layer
The Linear Algebra layer provides the main abstractions for linear algebra codes. The two top level interfaces are MultiVector
, for groups of vectors, and Operator
, for operations on MultiVector
s.
MultiVectors
MutliVectors support many basic array functions, including broadcasting. Additionally, [dot
] and [norm
] are supported, however they return arrays since [MultiVector
]s may have multiple dot products and norms.
JuliaPetra.MultiVector
— Type.MultiVector
s represent a group of vectors to be processed together. They are a subtype of [AbstractArray{Data, 2}
] and support the [DistObject
], and [SrcDistObject
] for transfering between any two MultiVectors
. Required methods:
getMap(::MultiVector)
numVectors(::MultiVector)
getLocalArray(::MultiVector{Data})::AbstractMatrix{Data}
similar(::MultiVector{Data})
commReduce(::MultiVector)
may need to be overridden if getLocallArray(multiVector)
doesn't return a type useable by sumAll
.
See [DenseMultiVector
] for a concrete implementation.
JuliaPetra.DenseMultiVector
— Type.DenseMultiVector represents a dense multi-vector. Note that all the vectors in a single DenseMultiVector are the same size
JuliaPetra.localLength
— Function.localLength(::MultiVector{Data, GID, PID, LID})::LID
Returns the local length of the vectors in the MultiVector
JuliaPetra.globalLength
— Function.globalLength(::MultiVector{Data, GID, PID, LID})::GID
Returns the global length of the vectors in the mutlivector
JuliaPetra.numVectors
— Function.numVectors(::MultiVector{Data, GID, PID, LID})::LID
Returns the number of vectors in this MultiVector
JuliaPetra.getVectorView
— Function.getVectorView(::DenseMultiVector{Data}, columns)::AbstractArray{Data}
Gets a view of the requested column vector(s) in this DenseMultiVector
JuliaPetra.getVectorCopy
— Function.getVectorCopy(::MultiVector{Data}, columns)::Array{Data}
Gets a copy of the requested column vector(s) in this MultiVector
JuliaPetra.getLocalArray
— Function.getLocalArray(::MultiVector{Data})::AbstractMatrix{Data}
Returns the array holding the MultiVector
's local elements. Changes to the array content are be reflected in the MultiVector
JuliaPetra.commReduce
— Function.commReduce(::MultiVector)
Elementwise reduces the content of the MultiVector across all processes. Note that the MultiVector cannot be distributed globally.
Operators
Operator
s represent an operation on a MultiVector
, such as a matrix which applies a matrix-vector product.
JuliaPetra.Operator
— Type.Operator is a description of all types that have a specific set of methods.
All Operator types must implement the following methods (with Op standing in for the Operator):
apply!(Y::MultiVector{Data, GID, PID, LID}, operator::Op{Data, GID, PID, LID}, X::MultiVector{Data, GID, PID, LID}, mode::TransposeMode, alpha::Data, beta::Data)
Computes $Y = α\cdot A^{mode}\cdot X + β\cdot Y$, with the following exceptions
- If beta == 0, apply MUST overwrite Y, so that any values in Y (including NaNs) are ignored.
- If alpha == 0, apply MAY short-circuit the operator, so that any values in X (including NaNs) are ignored
getDomainMap(operator::Op{Data, GID, PID, LID})::BlockMap{GID, PID, LID}
Returns the BlockMap associated with the domain of this operation
getRangeMap(operator::Op{Data, GID, PID, LID})::BlockMap{GID, PID, LID}
Returns the BlockMap associated with the range of this operation
JuliaPetra.getRangeMap
— Function.getRangeMap(::RowGraph{GID, PID, LID})::BlockMap{GID, PID, LID}
Gets the range map for the graph
JuliaPetra.getDomainMap
— Function.getDomainMap(::RowGraph{GID, PID, LID})::BlockMap{GID, PID, LID}
Gets the domain map for the graph
JuliaPetra.apply!
— Function.apply!(Y::MultiVector, operator, X::MultiVector, mode::TransposeMode=NO_TRANS, alpha=1, beta=0)
apply!(Y::MultiVector, operator, X::MultiVector, alpha=1, beta=0)
Computes $Y = α\cdot A^{mode}\cdot X + β\cdot Y$, with the following exceptions:
- If beta == 0, apply MUST overwrite Y, so that any values in Y (including NaNs) are ignored.
- If alpha == 0, apply MAY short-circuit the operator, so that any values in X (including NaNs) are ignored
JuliaPetra.apply
— Function.apply(Y::MultiVector,operator, X::MultiVector, mode::TransposeMode=NO_TRANS, alpha=1, beta=0)
apply(Y::MultiVector, operator, X::MultiVector, alpha=1, beta=0)
As apply!
except returns a new array for the results
JuliaPetra.TransposeMode
— Type.Tells JuliaPetra to use the transpose or conjugate transpose of the matrix
JuliaPetra.isTransposed
— Function.isTransposed(mode::TransposeMode)::Bool
Checks whether the given TransposeMode is transposed
JuliaPetra.applyConjugation
— Function.applyConjugation(mode::TraseposeMode, val)
If mode is CONJ_TRANS
, the take the conjugate. Otherwise, just return the value.
Matrices
Sparse matrices are the primary Operator
in JuliaPetra.
JuliaPetra.RowMatrix
— Type.RowMatrix is the base type for all row oriented Petra matrices. RowMatrix fufils both the Operator and DistObject interfaces.
getGraph(mat::RowMatrix)::RowGraph
Returns the graph that represents the structure of the row matrix
getLocalRowCopy!(copy::Tuple{<:AbstractVector{<:Integer}, <:AbstractVector{Data}}, matrix::RowMatrix{Data, GID, PID, LID}, localRow::LID)::Integer
Copies the given row into the provided arrays and returns the number of elements in that row using local indices
getGlobalRowCopy!(copy::Tuple{<:AbstractVector{<:Integer}, <:AbstractVector{Data}}, matrix::RowMatrix{Data, GID, PID, LID}, globalRow::GID)::Integer
Copies the given row into the provided arrays and returns the number of elements in that row using global indices
getGlobalRowView(matrix::RowMatrix{Data, GID, PID, LID}, globalRow::Integer)::Tuple{AbstractArray{GID, 1}, AbstractArray{Data, 1}}
Returns a view to the given row using global indices
getLocalRowView(matrix::RowMatrix{Data, GID, PID, LID},localRow::Integer)::Tuple{AbstractArray{GID, 1}, AbstractArray{Data, 1}}
Returns a view to the given row using local indices
getLocalDiagCopy!(copy::MultiVector{Data, GID, PID, LID}, matrix::RowMatrix{Data, GID, PID, LID})::MultiVector{Data, GID, PID, LID}
Copies the local diagonal into the given MultiVector
then returns the MultiVector
leftScale!(matrix::RowMatrix{Data, GID, PID, LID}, X::AbstractArray{Data, 1})
Scales matrix on the left with X
rightScale!(matrix::RowMatrix{Data, GID, PID, LID}, X::AbstractArray{Data, 1})
Scales matrix on the right with X
getMap(...)
, as required by SrcDistObject, is implemented by calling getRowMap(...)
apply!(...)
, as required by Operator, is implemented, but can be optimized by overrideing the following method localApply(Y::MultiVector, A::RowMatrix, X::MultiVector, ::TransposeMode, α::Data, β::Data) Does the computations for Y = β⋅Y + α⋅A⋅X
, X
and Y
match the row map and column map, depending on the transpose mode
The following methods are currently implemented as no-ops, but can be overridden to improve performance.
setColumnMapMultiVector(::RowMatrix{Data, GID, PID, LID}, ::Union{MultiVector{Data, GID, PID, LID}, Nothing})
Caches a MultiVector
that uses the matrix's column map.
getColumnMapMultiVector(::RowMatrix{Data, GID, PID, LID})::Union{MultiVector{Data, GID, PID, LID}, Nothing}
Fetches any cached MultiVector
that uses the matrix's column map.
setRowMapMultiVector(::RowMatrix{Data, GID, PID, LID}, ::Union{MultiVector{Data, GID, PID, LID}, Nothing})
Caches a MultiVector
that uses the matrix's row map.
getRowMapMultiVector(::RowMatrix{Data, GID, PID, LID})::Union{MultiVector{Data, GID, PID, LID}, Nothing}
Fetches any cached MultiVector
that uses the matrix's row map.
Some pre-implemented methods can be optimized by providing specialized implementations apply!
, as mentioned above All RowMatrix
methods that are also implemented by RowGraph
are implemented using getGraph
. pack
is implemented using getLocalRowCopy
getGlobalRowCopy!
is implemented by calling getLocalRowCopy!
and remapping the values using gid(::BlockMap, ::Integer)
Additionally, Julia's mul!
and *
functions are implemented for RowMatrix
-MultiVector
products
JuliaPetra.CSRMatrix
— Type.An implementation of RowMatrix
that uses CSR format