dubfi.linalg.mpi_parent¶
MPI linear algebra parent module.
This module instructs multiple MPI processes (workers) to do linear algebra computations.
Added in version 0.1.0: (initial release)
Classes¶
Singleton class keeping information about MPI setup. |
|
Base class for all MPI parent objects. |
|
MPI distributed vector. |
|
MPI parent of approximately diagonal or block-diagonal matrix. |
|
MPI distributed linear parametrized vector. |
|
MPI distributed R matrix for flux inversion. |
Functions¶
|
Construct MPI segments along one linear, equally spaced coordinate. |
|
Broadcast array to all child processes. |
Module Contents¶
- class dubfi.linalg.mpi_parent.MpiContext¶
Singleton class keeping information about MPI setup.
Return singleton when trying to create new instance.
- setup(workers=-1)¶
Create MPI setup, create child process if necessary.
- Parameters:
workers (int)
- Return type:
None
- is_initialized()¶
Check whether self has been initialized.
- Return type:
bool
- init(workers=-1)¶
Initialize self if it is not initialized yet.
- Parameters:
workers (int)
- Return type:
None
- property workers: int¶
Number of MPI workers.
- Return type:
int
- property root: int¶
Number (id) of MPI root (or parent) process.
- Return type:
int
- property iter¶
Iterator over ids of worker processes.
- property comm¶
MPI communicator.
- gen_name(prefix='')¶
Generate a new, unique name.
- Parameters:
prefix (str)
- Return type:
str
- send_cmd(command)¶
Send command to worker processes.
- Parameters:
command (str)
- Return type:
None
- quit()¶
Send termination signal to MPI child processes.
- Return type:
None
- __del__()¶
Destructor: quit child processes.
- Return type:
None
- Reduce(recvbuf, op)¶
Wrap
mpi4py.MPI.Comm.Reduce()to receive data in root.- Parameters:
recvbuf (numpy.ndarray)
op (mpi4py.MPI.Op)
- Return type:
None
- dubfi.linalg.mpi_parent.simple_segments(size, overlap, number=-1)¶
Construct MPI segments along one linear, equally spaced coordinate.
- Parameters:
size (int)
overlap (int)
number (int)
- Return type:
- dubfi.linalg.mpi_parent._send_array(array)¶
Broadcast array to all child processes.
- Parameters:
array (numpy.ndarray | float | int)
- Return type:
None
- class dubfi.linalg.mpi_parent.MpiObj¶
Base class for all MPI parent objects.
Initialization generates self._name and destruction deletes the associated objects on worker processes.
- __del__()¶
Destructor: Delete associated objects on worker processes.
- class dubfi.linalg.mpi_parent.MpiVector(seg, shape)¶
Bases:
dubfi.linalg.types.AbstractVector,MpiObjMPI distributed vector.
- Parameters:
shape (tuple[int, Ellipsis])
- property shape¶
Shape of array representation of self, last dimension is the vector dimension.
- property data¶
Numpy array representation of self, collects data from worker processes.
- classmethod fromdata(data, other=None)¶
Construct distributed vector from dense array, borrowing segment information from other.
- Parameters:
data (numpy.ndarray)
- classmethod fromarray(segments, data)¶
Construct distributed vector from dense array and given segments.
- Parameters:
segments (dubfi.linalg.segments.Segments)
data (numpy.ndarray)
- apply(other)¶
Compute scalar product with other vector.
- dot(other)¶
Compute scalar product along some non-vector dimension.
- Parameters:
other (numpy.ndarray)
- Return type:
- __add__(other)¶
Add two vectors, applying broadcasting rules.
- __iadd__(other)¶
Add vector in-place.
- __sub__(other)¶
Subtract vector from self, applying broadcasting rules.
- __isub__(other)¶
Subtract vector in-place.
- __mul__(other)¶
Multiply by scalar or numpy array treated as scalar along vector space dimension.
- iszero()¶
Check if all elements are zero.
- tonumpy()¶
Numpy array representation of self, collects data from worker processes.
- class dubfi.linalg.mpi_parent.MpiDenseBdMatrix(seg, shape)¶
Bases:
dubfi.linalg.types.AbstractOperator,MpiObjMPI parent of approximately diagonal or block-diagonal matrix.
- Parameters:
shape (tuple[int, Ellipsis])
- property shape¶
Shape of array (matrix) representation of self.
- classmethod fromarray(data, seg)¶
Construct distributed operator from dense array and given segments.
- Parameters:
data (numpy.ndarray)
- apply(vec)¶
Apply operator on vector: self @ vec.
- rapply(vec)¶
Apply transpose operator on vector: self.T @ vec.
- inv()¶
Compute (multiplicative) inverse operator.
- solve(vec)¶
Solve linear equation self @ x = vec for x.
- chain(other)¶
Combine operators: self @ other.
- diagonal()¶
Return diagonal of self as MPI vector.
- __mul__(other)¶
Multiply element-wise.
- __add__(other)¶
Add to other linear operator.
- __iadd__(other)¶
Add other linear operator in-place.
- __sub__(other)¶
Subtract other linear operator.
- __isub__(other)¶
Subtract other linear operator in-place.
- dot(other)¶
Inner product along non-vector dimensions.
- trace()¶
Compute trace of self.
- trace_product(other)¶
Compute trace of (self @ other).
- logdet()¶
Compute log(det(self)) assuming that self is a positive definite, real-symmetric matrix.
- tonumpy()¶
Numpy array representation of self, collects data from worker processes.
- sandwich(vec)¶
Compute vec @ self @ vec.
- class dubfi.linalg.mpi_parent.MpiLinParamVector(seg, shape)¶
Bases:
dubfi.linalg.generic.ParametrizedVector,MpiObjMPI distributed linear parametrized vector.
- Parameters:
shape (tuple[int, Ellipsis])
- classmethod fromarray(seg, array)¶
Construct distributed parametrized vector from dense array and given segments.
- __call__(s)¶
Compute vector at given parameters.
- grad(s)¶
Compute gradient of vector at given parameters.
- hess(s)¶
Compute Hesse matrix of vector at given parameters.
- class dubfi.linalg.mpi_parent.MpiDensePostR(seg)¶
Bases:
dubfi.linalg.generic.ParametrizedOperator,MpiObjMPI distributed R matrix for flux inversion.
- classmethod fromarray(seg, h_ens, localization_length, regularization)¶
Construct distributed object from dense vectors and given segments.
- __call__(s)¶
Compute R at given parameters.
- grad(s)¶
Compute gradient of R at given parameters.
- hess(s)¶
Compute Hesse matrix of R at given parameters.