File cyclic_reduction.hxx

template<class T>
class CyclicReduce

Public Functions

CyclicReduce() = default
inline CyclicReduce(MPI_Comm c, int size)
inline void setup(MPI_Comm c, int size)

Set parameters

Parameters
  • c[in] The communicator of all processors involved in the solve

  • size[in] The number of rows on this processor

~CyclicReduce() = default
inline void setPeriodic(bool p = true)

Specify that the tridiagonal system is periodic By default not periodic

inline void setCoefs(const Array<T> &a, const Array<T> &b, const Array<T> &c)
inline void setCoefs(const Matrix<T> &a, const Matrix<T> &b, const Matrix<T> &c)

Set the entries in the matrix to be inverted

Parameters
  • a[in] Left diagonal. Should have size [nsys][N] where N is set in the constructor or setup

  • b[in] Diagonal values. Should have size [nsys][N]

  • c[in] Right diagonal. Should have size [nsys][N]

inline void solve(const Array<T> &rhs, Array<T> &x)

Solve a set of tridiagonal systems

Parameters
  • rhs[in] Array storing Values of the rhs for a single system

  • x[out] Array storing the result for a single system

inline void solve(const Matrix<T> &rhs, Matrix<T> &x)

Solve a set of tridiagonal systems

Parameters
  • rhs[in] Matrix storing Values of the rhs for each system

  • x[out] Matrix storing the result for each system

Private Functions

inline void allocMemory(int np, int nsys, int n)

Allocate memory arrays

Parameters
  • np[in] Number of processors

  • nsys[in] Number of independent systems to solve

  • n[in] Size of each system of equations

inline void reduce(int ns, int nloc, Matrix<T> &co, Matrix<T> &ifc)

Calculate interface equations

This reduces ns separate systems of equations, each consisting of nloc rows on this processor, to two interface rows for each system, which are stored in ifc.

(a1 b1 c1 ) ( a2 b2 c2 ) (A1 B1 C1 ) ( a3 b3 c3 ) => ( A2 B2 C2) ( … ) ( an bn cn)

inline void back_solve(int ns, int nloc, const Matrix<T> &co, const Array<T> &x1, const Array<T> &xn, Matrix<T> &xa)

Back-solve from x at ends (x1, xn) to obtain remaining values Coefficients ordered [ns, nloc*(a,b,c,r)]

Private Members

MPI_Comm comm

Communicator.

int nprocs = {0}
int myproc = {-1}

Number of processors and ID of my processor.

int N = {0}

Total size of the problem.

int Nsys = {0}

Number of independent systems to solve.

int myns

Number of systems for interface solve on this processor.

int sys0

Starting system index for interface solve.

bool periodic = {false}

Is the domain periodic?

Matrix<T> coefs

Starting coefficients, rhs [Nsys, {3*coef,rhs}*N].

Matrix<T> myif

Interface equations for this processor.

Matrix<T> recvbuffer

Buffer for receiving from other processors.

Matrix<T> ifcs

Coefficients for interface solve.

Matrix<T> if2x2

2x2 interface equations on this processor

Matrix<T> ifx

Solution of interface equations.

Array<T> ifp

Interface equations returned to processor p.

Array<T> x1
Array<T> xn

Interface solutions for back-solving.