MPI_mgparc
Functions
header.h File Reference
#include <string>
#include <mpi.h>

Go to the source code of this file.

Functions

void Send_ProcD (const int to, const int nin, const double xin[], const MPI::Intracomm &icomm)
 
void Recv_ProcD (const int from, int &nout, double xout[], const int maxbuf, const MPI::Intracomm &icomm)
 
void ExchangeD (const int yourid, const int nin, const double xin[], int &nout, double xout[], const int maxbuf, const MPI::Intracomm &icomm)
 
int ReadIn ()
 
void DebugD (const int n, const double x[])
 
void DebugI (const int n, const int x[])
 
int CheckI (const int n, const int x[])
 
void PivotD (const int n, double x[])
 
void vdcopy (const int n, double xp[], const int ix, const double yp[], const int iy)
 
void vdplus (const int n, double x[], const int ix, const double y[], const int iy, const double z[], const int iz)
 
void vddiv (const int n, double x[], const int ix, const double y[], const int iy, const double z[], const int iz)
 
void vdmult (const int n, double x[], const int ix, const double y[], const int iy, const double z[], const int iz)
 
double dscapr (const int n, const double x[], const double y[])
 
void vdaxpy (const int n, double x[], const double y[], const double &a, const double z[])
 
void vicopy (const int n, int xp[], const int ix, const int yp[], const int iy)
 
void IniGeom (const int myid, const int procx, const int procy, int neigh[], int &color)
 
void IniCoord (const int myid, const int procx, const int procy, double &xl, double &xr, double &yb, double &yt)
 
void AddBound (const int ib, const int nx, const int ny, double w[], const double s[])
 
void GetBound (const int ib, const int nx, const int ny, const double w[], double s[])
 
void VecAccu (const int nx, const int ny, double w[], const int neigh[], const int color, const MPI::Intracomm &icomm)
 
void FreeVecAccu ()
 
double skalar (const int n, const double x[], const double y[], const MPI::Intracomm &icomm)
 
void SetU (const int nx, const int ny, double u[])
 
void SetF (const int nx, const int ny, double f[])
 
double FunctF (const double &x, const double &y)
 
double FunctU (const double &x, const double &y)
 
void SaveVectorP (const int myid, const string &name, const double u[], const int nx, const int ny, const double &xl, const double &xr, const double &yb, const double &yt)
 
void AccuDiag (const int nx, const int ny, const double sk[], const int id[], double d[], const int neigh[], const int color, const MPI::Intracomm &icomm)
 
void ApplyDirichletBC (const int nx, const int ny, const int neigh[], const double u[], double sk[], const int id[], const int *, double f[])
 
void CrsMult (const int iza, const int ize, double w[], const double u[], const int id[], const int ik[], const double sk[], const double &alfa)
 
void JacobiSolve (const int nx, const int ny, const int neigh[], const int color, const MPI::Intracomm &icomm, const double sk[], const int id[], const int ik[], const double f[], double u[])
 
void GetCoordsInRectangle (const int nx, const int ny, const double &xl, const double &xr, const double &yb, const double &yt, double xc[])
 
void GetConnectivityInRectangle (const int nx, const int ny, int ia[])
 
void GetMatrixpointersInRectangle (const int nx, const int ny, int id[], int ik[])
 
void CalcElem (const int ial[3], const double xc[], double ske[3][3], double fe[3])
 
void AddElem (const int ial[3], const double ske[3][3], const double fe[3], double sk[], const int id[], const int ik[], double f[])
 
void DebugMatrix (const int nnode, const double sk[], const int id[], const int ik[])
 
void GetMatrix (const int nx, const int ny, const double &xl, const double &xr, const double &yb, const double &yt, double sk[], int id[], int ik[], double f[])
 

Function Documentation

void AccuDiag ( const int  nx,
const int  ny,
const double  sk[],
const int  id[],
double  d[],
const int  neigh[],
const int  color,
const MPI::Intracomm &  icomm 
)

Copies the diagonal entries of a distributed symmetric CSR matrix (sk,id, ik) onto a vector and accumulates them.

Parameters
[in]nxnumber of discretization intervals in x-direction
[in]nynumber of discretization intervals in y-direction
[in]skvector non-zero entries of CSR matrix
[in]idindex vector containing the last entry in a CSR row
[out]daccumulated diagonal entries of CSR matrix
[in]neighvector of 4 elements containing the ranks of neighbouring processes, -1 indicates a boundary in this direction
[in]colorred/black coloring of subdomains (0/1)
[in]icommcommunicator
void AddBound ( const int  ib,
const int  nx,
const int  ny,
double  w[],
const double  s[] 
)

Computes w := w + s at the interface/boundary nodes on the boundary ib . South (ib==1), East (ib==2), North (ib==3), West (ib==4)

Parameters
[in]ibmy local boundary
[in]nxnumber of discretization intervals in x-direction
[in]nynumber of discretization intervals in y-direction
[in,out]wvector for all nodes of local discretization
[in]sshort vector with values on boundary ib
void AddElem ( const int  ial[3],
const double  ske[3][3],
const double  fe[3],
double  sk[],
const int  id[],
const int  ik[],
double  f[] 
)

Adds the element stiffness matrix ske and the element load vector fe of one triangular element with linear shape functions to the appropriate positions in the symmetric stiffness matrix, stored as CSR matrix K(sk,id, ik)

Parameters
[in]ianode indices of the three element vertices
[in]skeelement stiffness matrix
[in]feelement load vector
[out]skvector non-zero entries of CSR matrix
[in]idindex vector containing the last entry in a CSR row
[in]ikcolumn index vector of CSR matrix
[out]fdistributed local vector storing the right hand side
void ApplyDirichletBC ( const int  nx,
const int  ny,
const int  neigh[],
const double  u[],
double  sk[],
const int  id[],
const int *  ,
double  f[] 
)

Applies Dirichlet boundary conditions to symmetric CSR matrix (sk,id, ik) and right hand side f of a system of equations resulting from a FEM/FDM discretization

Parameters
[in]nxnumber of discretization intervals in x-direction
[in]nynumber of discretization intervals in y-direction
[in]neighvector of 4 elements containing the ranks of neighbouring processes, -1 indicates a boundary in this direction
[in]ulocal vector with appropriately initialized b.c.
[in,out]skvector non-zero entries of CSR matrix
[in]idindex vector containing the last entry in a CSR row
[in]ikcolumn index vector of CSR matrix
[in,out]fright hand side
void CalcElem ( const int  ial[3],
const double  xc[],
double  ske[3][3],
double  fe[3] 
)

Calculates the element stiffness matrix ske and the element load vector fe of one triangular element with linear shape functions.

Parameters
[in]ianode indices of the three element vertices
[in]xcvector of node coordinates with x(2*k,2*k+1) as coodinates of node k
[out]skeelement stiffness matrix
[out]feelement load vector
int CheckI ( const int  n,
const int  x[] 
)

Checks whether the entries of a global integer vector are consistent over all processors. If not then a message with the approprate indices and values is displayed.

Parameters
[in]nnumber of elements of vector x (of my process)
[in]xlocal vector (double) on my process
Returns
0/-1 consistent or not
void CrsMult ( const int  iza,
const int  ize,
double  w[],
const double  u[],
const int  id[],
const int  ik[],
const double  sk[],
const double &  alfa 
)

Multiplies vector u with a symmetric CSR matrix K(sk,id, ik). Operation can be performed for only a subset [iza, ize] of matrix rows. w := w + alpha*K*u

Parameters
[in]izafirst matrix row (starting at 0)
[in]izelast matrix row
[in,out]wdistributed local vector.
[in]uaccumulated local vector.
[in]idindex vector containing the last entry in a CSR row
[in]ikcolumn index vector of CSR matrix
[in]skvector non-zero entries of CSR matrix
[in]alfascaling factor
void DebugD ( const int  n,
const double  x[] 
)

Reads a integer number with the rank of a process from the terminal and writes the elements of vector x of this process onto the terminal. This will be repeated while rank number is valid, i.e., -1 stops the loop.

Parameters
[in]nnumber of elements of vector x (of my process)
[in]xlocal vector (double) on my process
void DebugI ( const int  n,
const int  x[] 
)
void DebugMatrix ( const int  nnode,
const double  sk[],
const int  id[],
const int  ik[] 
)

Print entries of the CSR matrix K(sk,id, ik).

Parameters
[in]nnodenumber of rows
[in]skvector non-zero entries of CSR matrix
[in]idindex vector containing the last entry in a CSR row
[in]ikcolumn index vector of CSR matrix
double dscapr ( const int  n,
const double  x[],
const double  y[] 
)
void ExchangeD ( const int  yourid,
const int  nin,
const double  xin[],
int &  nout,
double  xout[],
const int  maxbuf,
const MPI::Intracomm &  icomm 
)

Exchanges vectors between my process and the process with rank .

Parameters
[in]youridrank of process in communicator icomm to send the message
[in]ninnumber of elements in vector xin
[in]xinmy vector
[out]noutnumber of received elements stored in vector xout
[out]xoutvector
[in]maxbufmaximal number of elements of xout
[in]icommcommunicator to use
void FreeVecAccu ( )

Frees the dynamic memory allocated in the first call in VecAccu.

See also
VecAccu
double FunctF ( const double &  x,
const double &  y 
)

User function: f(x,y)

Parameters
[in]xx-coordinate of discretization point
[in]yy-coordinate of discretization point
Returns
value for right hand side f(x,y)
double FunctU ( const double &  x,
const double &  y 
)

User function: u(x,y)

Parameters
[in]xx-coordinate of discretization point
[in]yy-coordinate of discretization point
Returns
value for solution vector u(x,y)
void GetBound ( const int  ib,
const int  nx,
const int  ny,
const double  w[],
double  s[] 
)

Copies the values of w corresponding to boundary ib onto vector s. South (ib==1), East (ib==2), North (ib==3), West (ib==4). The vector s has to be long enough!!

Parameters
[in]ibmy local boundary
[in]nxnumber of discretization intervals in x-direction
[in]nynumber of discretization intervals in y-direction
[in]wvector for all nodes of local discretization
[out]sshort vector with values on boundary ib
void GetConnectivityInRectangle ( const int  nx,
const int  ny,
int  ia[] 
)

Determines the element connectivity of linear triangular elements of a FEM discretization of a rectangle using nx x ny equidistant intervals for discretization.

Parameters
[in]nxnumber of discretization intervals in x-direction
[in]nynumber of discretization intervals in y-direction
[out]iaelement connectivity matrix with ia(3*s,3*s+1,3*s+2) as node numbers od element s
void GetCoordsInRectangle ( const int  nx,
const int  ny,
const double &  xl,
const double &  xr,
const double &  yb,
const double &  yt,
double  xc[] 
)

Determines the coordinates of the dicretization nodes of the domain [xl, xr] x [yb, yt] which is discretized into nx x ny intervals.

Parameters
[in]nxnumber of discretization intervals in x-direction
[in]nynumber of discretization intervals in y-direction
[in]xlx-coordinate of left boundary
[in]xrx-coordinate of right boundary
[in]yby-coordinate of lower boundary
[in]yty-coordinate of upper boundary
[out]xccoordinate vector of length 2n with x(2*k,2*k+1) as coodinates of node k
void GetMatrix ( const int  nx,
const int  ny,
const double &  xl,
const double &  xr,
const double &  yb,
const double &  yt,
double  sk[],
int  id[],
int  ik[],
double  f[] 
)

Computes the stiffness matrix K(sk,id, ik) and load vector f for the Poisson problem without incorporating the boundary conditions in a domain [xl, xr] x [yb, yt] which is discretized into nx x ny intervals. The matrix pattern is generated and the matrix is stored as CSR matrix(sk,id, ik).

Parameters
[in]nxnumber of discretization intervals in x-direction
[in]nynumber of discretization intervals in y-direction
[in]xlx-coordinate of left boundary
[in]xrx-coordinate of right boundary
[in]yby-coordinate of lower boundary
[in]yty-coordinate of upper boundary
[out]skvector non-zero entries of CSR matrix
[out]idindex vector containing the last entry in a CSR row
[out]ikcolumn index vector of CSR matrix
[out]fdistributed local vector storing the right hand side
void GetMatrixpointersInRectangle ( const int  nx,
const int  ny,
int  id[],
int  ik[] 
)

Determines the sparsity pattern (id, ik) of a symmetric sparse CSR matrix assuming linear triangular elements in a rectangle using nx x ny equidistant intervals for discretization.

Parameters
[in]nxnumber of discretization intervals in x-direction
[in]nynumber of discretization intervals in y-direction
[out]idindex vector containing the last entry in a CSR row
[out]ikcolumn index vector of CSR matrix
void IniCoord ( const int  myid,
const int  procx,
const int  procy,
double &  xl,
double &  xr,
double &  yb,
double &  yt 
)

The quadratic domain [0,1] x [0,1] is divided into procx * procy subdomains numbered rowise. According to my process with rank number myid, the coordinates of the lower left corner (xl, yb) and of the upper right corner (xr, yt) are generated.

Parameters
[in]myidmy rank
[in]procxnumber of processes in x-direction
[in]procynumber of processes in y-direction
[out]xlx-coordinate of left boundary
[out]xrx-coordinate of right boundary
[out]yby-coordinate of lower boundary
[out]yty-coordinate of upper boundary
void IniGeom ( const int  myid,
const int  procx,
const int  procy,
int  neigh[],
int &  color 
)

The quadratic domain [0,1] x [0,1] is divided into procx * procy subdomains numbered rowise. According to my process with rank number myid, the vector neigh contains the ranks of the neighbours t the South, East, North, West.

Parameters
[in]myidmy rank
[in]procxnumber of processes in x-direction
[in]procynumber of processes in y-direction
[out]neighvector of 4 elements containing the ranks of neighbouring processes, -1 indicates a boundary in this direction
[out]colorred/black coloring of subdomains (0/1)
void JacobiSolve ( const int  nx,
const int  ny,
const int  neigh[],
const int  color,
const MPI::Intracomm &  icomm,
const double  sk[],
const int  id[],
const int  ik[],
const double  f[],
double  u[] 
)

Solves linear system of equations K u = f via the Jacobi iteration. We use a distributed symmetric CSR matrix K(sk,id, ik) and initial guess of the solution is set to 0.

Parameters
[in]nxnumber of discretization intervals in x-direction
[in]nynumber of discretization intervals in y-direction
[in]neighvector of 4 elements containing the ranks of neighbouring processes, -1 indicates a boundary in this direction
[in]colorred/black coloring of subdomains (0/1)
[in]icommcommunicator
[in]skvector non-zero entries of CSR matrix
[in]idindex vector containing the last entry in a CSR row
[in]ikcolumn index vector of CSR matrix
[in]fdistributed local vector storing the right hand side
[out]uaccumulated local vector storing the solution.
void PivotD ( const int  n,
double  x[] 
)

Exchanges global minimum and maximum of the global vector x .

Parameters
[in]nnumber of elements of vector x (of my process)
[in,out]xlocal vector (double) on my process
int ReadIn ( )

Reads one integer from the terminal and broadcasts it to all processes.

Returns
a number read by root process 0 which is broadcasted to all processes
void Recv_ProcD ( const int  from,
int &  nout,
double  xout[],
const int  maxbuf,
const MPI::Intracomm &  icomm 
)

Receives data from process with rank from into a double-vector xout .

Parameters
[in]fromrank of process in communicator icomm to receive the message from
[out]noutnumber of received elements stored in vector xout
[out]xoutvector
[in]maxbufmaximal number of elements of xout
[in]icommcommunicator to use
void SaveVectorP ( const int  myid,
const string &  name,
const double  u[],
const int  nx,
const int  ny,
const double &  xl,
const double &  xr,
const double &  yb,
const double &  yt 
)

Stores the values of vector u of subdomain myid into a file. The file stores rowise the x- and y- coordinates together with the value from u . The domain [xl, xr] x [yb, yt] is discretized into nx x ny intervals.

Parameters
[in]myidmy rank
[in]namebasename of file name (file name will be extended by the rank number)
[in]ulocal vector
[in]nxnumber of discretization intervals in x-direction
[in]nynumber of discretization intervals in y-direction
[in]xlx-coordinate of left boundary
[in]xrx-coordinate of right boundary
[in]yby-coordinate of lower boundary
[in]yty-coordinate of upper boundary
void Send_ProcD ( const int  to,
const int  nin,
const double  xin[],
const MPI::Intracomm &  icomm 
)

Sends data of double-vector xin to the process with rank to .

Parameters
[in]torank of process in communicator icomm to send the message
[in]ninnumber of elements in vector xin
[in]xinvector
[in]icommcommunicator to use
void SetF ( const int  nx,
const int  ny,
double  f[] 
)

User function: assignes values to right hand side vector f.

Parameters
[in]nxnumber of discretization intervals in x-direction
[in]nynumber of discretization intervals in y-direction
[out]fvector for all nodes of local discretization
void SetU ( const int  nx,
const int  ny,
double  u[] 
)

User function: assignes values to solution vector u.

Parameters
[in]nxnumber of discretization intervals in x-direction
[in]nynumber of discretization intervals in y-direction
[out]uvector for all nodes of local discretization
double skalar ( const int  n,
const double  x[],
const double  y[],
const MPI::Intracomm &  icomm 
)

Computes the parallel scalar product of two double vectors. One vecctor has to be accumulated the other one has to be distributed.

Parameters
[in]nlength of the vectors
[in]xvector
[in]yvector
See also
VecAccu
void vdaxpy ( const int  n,
double  x[],
const double  y[],
const double &  a,
const double  z[] 
)
void vdcopy ( const int  n,
double  xp[],
const int  ix,
const double  yp[],
const int  iy 
)
void vddiv ( const int  n,
double  x[],
const int  ix,
const double  y[],
const int  iy,
const double  z[],
const int  iz 
)
void vdmult ( const int  n,
double  x[],
const int  ix,
const double  y[],
const int  iy,
const double  z[],
const int  iz 
)
void vdplus ( const int  n,
double  x[],
const int  ix,
const double  y[],
const int  iy,
const double  z[],
const int  iz 
)
void VecAccu ( const int  nx,
const int  ny,
double  w[],
const int  neigh[],
const int  color,
const MPI::Intracomm &  icomm 
)

Accumulates vector w, i.e., a distributed vector is converted into an accumulated vector. Dynamic memory allocation in the first call of this function.

Parameters
[in]nxnumber of discretization intervals in x-direction
[in]nynumber of discretization intervals in y-direction
[in,out]wvector for all nodes of local discretization
[in]neighvector of 4 elements containing the ranks of neighbouring processes, -1 indicates a boundary in this direction
[in]colorred/black coloring of subdomains (0/1)
[in]icommcommunicator
void vicopy ( const int  n,
int  xp[],
const int  ix,
const int  yp[],
const int  iy 
)