Actual source code: blas_cyclic.h

  1: #pragma once

  3: #include <petscvec.h>
  4: #include <petscmat.h>

  6: /*
  7:   Dense linear algebra for vectors and matrices that are _cyclically indexed_.

  9:   For a Vec, this means that it has a fixed size m, but it is for storing data from a sliding window of _history
 10:   indices_.  Rather than rearranging the vector as the window slides, we insert the value v_i for history index i in the
 11:   location v[i % m].

 13:   This has the following effects on linear algebra:

 15:   - Sometimes we are dealing with a window that is smaller than m, e.g. doing y[i % m] <- alpha x[i % m], but not all
 16:     values in [0, m) are active.  We want the linear algebra routines to leave the inactive indices
 17:     untouched.

 19:   - We sometimes need operations that work on the upper triangle of a matrix _with respect to history indices_, i.e.
 20:     operating on the values

 22:       A[i % m, j % m], i <= j

 24:   The functions defined here dispatch linear algebra operations, described by the range of history indices [oldest, next) that
 25:   they act on, to the appropriate backend blas-like (BLAS, cuBLAS, hipBLAS) libraries.
 26:  */

 28: PETSC_INTERN PetscLogEvent AXPBY_Cyc;
 29: PETSC_INTERN PetscLogEvent DMV_Cyc;
 30: PETSC_INTERN PetscLogEvent DSV_Cyc;
 31: PETSC_INTERN PetscLogEvent TRSV_Cyc;
 32: PETSC_INTERN PetscLogEvent GEMV_Cyc;
 33: PETSC_INTERN PetscLogEvent HEMV_Cyc;

 35: /* These methods are intended for small vectors / dense matrices that are either sequential or have all of their entries on the first rank */
 36: // y <- alpha * x + beta * y
 37: PETSC_INTERN PetscErrorCode VecAXPBYCyclic(PetscInt, PetscInt, PetscScalar, Vec, PetscScalar, Vec);
 38: // y <- alpha * (A .* x) + beta * y
 39: PETSC_INTERN PetscErrorCode VecDMVCyclic(PetscBool, PetscInt, PetscInt, PetscScalar, Vec, Vec, PetscScalar, Vec);
 40: // y <- (x ./ A)
 41: PETSC_INTERN PetscErrorCode VecDSVCyclic(PetscBool, PetscInt, PetscInt, Vec, Vec, Vec);
 42: // y <- (triu(A) \ x)
 43: PETSC_INTERN PetscErrorCode MatSeqDenseTRSVCyclic(PetscBool, PetscInt, PetscInt, Mat, Vec, Vec);
 44: // y <- alpha * A * x + beta * y
 45: PETSC_INTERN PetscErrorCode MatSeqDenseGEMVCyclic(PetscBool, PetscInt, PetscInt, PetscScalar, Mat, Vec, PetscScalar, Vec);
 46: // y <- alpha * symm(A) * x + beta * y   [sym(A) = triu(A) + striu(A)^H]
 47: PETSC_INTERN PetscErrorCode MatSeqDenseHEMVCyclic(PetscInt, PetscInt, PetscScalar, Mat, Vec, PetscScalar, Vec);
 48: // A[i,:] <- alpha * x + beta * A[i,:]
 49: PETSC_INTERN PetscErrorCode MatSeqDenseRowAXPBYCyclic(PetscInt, PetscInt, PetscScalar, Vec, PetscScalar, Mat, PetscInt);

 51: /* These methods are intended for for tall matrices of column vectors where we would like to compute products with ranges of the
 52:    vectors.  The column layout should place all columns on the first rank.  Because they may involve MPI communication,
 53:    they rely on implementations from the dense matrix backends */
 54: PETSC_INTERN PetscErrorCode MatMultColumnRange(Mat, Vec, Vec, PetscInt, PetscInt);
 55: PETSC_INTERN PetscErrorCode MatMultAddColumnRange(Mat, Vec, Vec, Vec, PetscInt, PetscInt);
 56: PETSC_INTERN PetscErrorCode MatMultHermitianTransposeColumnRange(Mat, Vec, Vec, PetscInt, PetscInt);
 57: PETSC_INTERN PetscErrorCode MatMultHermitianTransposeAddColumnRange(Mat, Vec, Vec, Vec, PetscInt, PetscInt);