MPI_mgparc
|
#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[]) |
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.
[in] | nx | number of discretization intervals in x-direction |
[in] | ny | number of discretization intervals in y-direction |
[in] | sk | vector non-zero entries of CSR matrix |
[in] | id | index vector containing the last entry in a CSR row |
[out] | d | accumulated diagonal entries of CSR matrix |
[in] | neigh | vector of 4 elements containing the ranks of neighbouring processes, -1 indicates a boundary in this direction |
[in] | color | red/black coloring of subdomains (0/1) |
[in] | icomm | communicator |
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)
[in] | ib | my local boundary |
[in] | nx | number of discretization intervals in x-direction |
[in] | ny | number of discretization intervals in y-direction |
[in,out] | w | vector for all nodes of local discretization |
[in] | s | short 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
)
[in] | ia | node indices of the three element vertices |
[in] | ske | element stiffness matrix |
[in] | fe | element load vector |
[out] | sk | vector non-zero entries of CSR matrix |
[in] | id | index vector containing the last entry in a CSR row |
[in] | ik | column index vector of CSR matrix |
[out] | f | distributed 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
[in] | nx | number of discretization intervals in x-direction |
[in] | ny | number of discretization intervals in y-direction |
[in] | neigh | vector of 4 elements containing the ranks of neighbouring processes, -1 indicates a boundary in this direction |
[in] | u | local vector with appropriately initialized b.c. |
[in,out] | sk | vector non-zero entries of CSR matrix |
[in] | id | index vector containing the last entry in a CSR row |
[in] | ik | column index vector of CSR matrix |
[in,out] | f | right 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.
[in] | ia | node indices of the three element vertices |
[in] | xc | vector of node coordinates with x(2*k,2*k+1) as coodinates of node k |
[out] | ske | element stiffness matrix |
[out] | fe | element 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.
[in] | n | number of elements of vector x (of my process) |
[in] | x | local vector (double) on my process |
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
[in] | iza | first matrix row (starting at 0) |
[in] | ize | last matrix row |
[in,out] | w | distributed local vector. |
[in] | u | accumulated local vector. |
[in] | id | index vector containing the last entry in a CSR row |
[in] | ik | column index vector of CSR matrix |
[in] | sk | vector non-zero entries of CSR matrix |
[in] | alfa | scaling 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.
[in] | n | number of elements of vector x (of my process) |
[in] | x | local 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
).
[in] | nnode | number of rows |
[in] | sk | vector non-zero entries of CSR matrix |
[in] | id | index vector containing the last entry in a CSR row |
[in] | ik | column 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 .
[in] | yourid | rank of process in communicator icomm to send the message |
[in] | nin | number of elements in vector xin |
[in] | xin | my vector |
[out] | nout | number of received elements stored in vector xout |
[out] | xout | vector |
[in] | maxbuf | maximal number of elements of xout |
[in] | icomm | communicator to use |
void FreeVecAccu | ( | ) |
Frees the dynamic memory allocated in the first call in VecAccu.
double FunctF | ( | const double & | x, |
const double & | y | ||
) |
User function: f(x
,y
)
[in] | x | x-coordinate of discretization point |
[in] | y | y-coordinate of discretization point |
x
,y
) double FunctU | ( | const double & | x, |
const double & | y | ||
) |
User function: u(x
,y
)
[in] | x | x-coordinate of discretization point |
[in] | y | y-coordinate of discretization point |
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!!
[in] | ib | my local boundary |
[in] | nx | number of discretization intervals in x-direction |
[in] | ny | number of discretization intervals in y-direction |
[in] | w | vector for all nodes of local discretization |
[out] | s | short 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.
[in] | nx | number of discretization intervals in x-direction |
[in] | ny | number of discretization intervals in y-direction |
[out] | ia | element 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.
[in] | nx | number of discretization intervals in x-direction |
[in] | ny | number of discretization intervals in y-direction |
[in] | xl | x-coordinate of left boundary |
[in] | xr | x-coordinate of right boundary |
[in] | yb | y-coordinate of lower boundary |
[in] | yt | y-coordinate of upper boundary |
[out] | xc | coordinate 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
).
[in] | nx | number of discretization intervals in x-direction |
[in] | ny | number of discretization intervals in y-direction |
[in] | xl | x-coordinate of left boundary |
[in] | xr | x-coordinate of right boundary |
[in] | yb | y-coordinate of lower boundary |
[in] | yt | y-coordinate of upper boundary |
[out] | sk | vector non-zero entries of CSR matrix |
[out] | id | index vector containing the last entry in a CSR row |
[out] | ik | column index vector of CSR matrix |
[out] | f | distributed 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.
[in] | nx | number of discretization intervals in x-direction |
[in] | ny | number of discretization intervals in y-direction |
[out] | id | index vector containing the last entry in a CSR row |
[out] | ik | column 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.
[in] | myid | my rank |
[in] | procx | number of processes in x-direction |
[in] | procy | number of processes in y-direction |
[out] | xl | x-coordinate of left boundary |
[out] | xr | x-coordinate of right boundary |
[out] | yb | y-coordinate of lower boundary |
[out] | yt | y-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.
[in] | myid | my rank |
[in] | procx | number of processes in x-direction |
[in] | procy | number of processes in y-direction |
[out] | neigh | vector of 4 elements containing the ranks of neighbouring processes, -1 indicates a boundary in this direction |
[out] | color | red/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.
[in] | nx | number of discretization intervals in x-direction |
[in] | ny | number of discretization intervals in y-direction |
[in] | neigh | vector of 4 elements containing the ranks of neighbouring processes, -1 indicates a boundary in this direction |
[in] | color | red/black coloring of subdomains (0/1) |
[in] | icomm | communicator |
[in] | sk | vector non-zero entries of CSR matrix |
[in] | id | index vector containing the last entry in a CSR row |
[in] | ik | column index vector of CSR matrix |
[in] | f | distributed local vector storing the right hand side |
[out] | u | accumulated local vector storing the solution. |
void PivotD | ( | const int | n, |
double | x[] | ||
) |
Exchanges global minimum and maximum of the global vector x
.
[in] | n | number of elements of vector x (of my process) |
[in,out] | x | local vector (double) on my process |
int ReadIn | ( | ) |
Reads one integer from the terminal and broadcasts it 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
.
[in] | from | rank of process in communicator icomm to receive the message from |
[out] | nout | number of received elements stored in vector xout |
[out] | xout | vector |
[in] | maxbuf | maximal number of elements of xout |
[in] | icomm | communicator 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.
[in] | myid | my rank |
[in] | name | basename of file name (file name will be extended by the rank number) |
[in] | u | local vector |
[in] | nx | number of discretization intervals in x-direction |
[in] | ny | number of discretization intervals in y-direction |
[in] | xl | x-coordinate of left boundary |
[in] | xr | x-coordinate of right boundary |
[in] | yb | y-coordinate of lower boundary |
[in] | yt | y-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
.
[in] | to | rank of process in communicator icomm to send the message |
[in] | nin | number of elements in vector xin |
[in] | xin | vector |
[in] | icomm | communicator to use |
void SetF | ( | const int | nx, |
const int | ny, | ||
double | f[] | ||
) |
User function: assignes values to right hand side vector f
.
[in] | nx | number of discretization intervals in x-direction |
[in] | ny | number of discretization intervals in y-direction |
[out] | f | vector for all nodes of local discretization |
void SetU | ( | const int | nx, |
const int | ny, | ||
double | u[] | ||
) |
User function: assignes values to solution vector u
.
[in] | nx | number of discretization intervals in x-direction |
[in] | ny | number of discretization intervals in y-direction |
[out] | u | vector 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.
[in] | n | length of the vectors |
[in] | x | vector |
[in] | y | vector |
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.
[in] | nx | number of discretization intervals in x-direction |
[in] | ny | number of discretization intervals in y-direction |
[in,out] | w | vector for all nodes of local discretization |
[in] | neigh | vector of 4 elements containing the ranks of neighbouring processes, -1 indicates a boundary in this direction |
[in] | color | red/black coloring of subdomains (0/1) |
[in] | icomm | communicator |
void vicopy | ( | const int | n, |
int | xp[], | ||
const int | ix, | ||
const int | yp[], | ||
const int | iy | ||
) |