Nektar++
Xxt.hpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: Xxt.hpp
4//
5// For more information, please see: http://www.nektar.info
6//
7// The MIT License
8//
9// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10// Department of Aeronautics, Imperial College London (UK), and Scientific
11// Computing and Imaging Institute, University of Utah (USA).
12//
13// Permission is hereby granted, free of charge, to any person obtaining a
14// copy of this software and associated documentation files (the "Software"),
15// to deal in the Software without restriction, including without limitation
16// the rights to use, copy, modify, merge, publish, distribute, sublicense,
17// and/or sell copies of the Software, and to permit persons to whom the
18// Software is furnished to do so, subject to the following conditions:
19//
20// The above copyright notice and this permission notice shall be included
21// in all copies or substantial portions of the Software.
22//
23// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29// DEALINGS IN THE SOFTWARE.
30//
31// Description: wrapper of functions around XXT routines
32//
33///////////////////////////////////////////////////////////////////////////////
34
35#ifndef NEKTAR_LIB_UTILITIES_COMMUNICATION_XXT_HPP
36#define NEKTAR_LIB_UTILITIES_COMMUNICATION_XXT_HPP
37
38#include <iostream>
39
41#ifdef NEKTAR_USE_MPI
43#endif
44
45namespace Xxt
46{
47using namespace Nektar;
48#ifdef NEKTAR_USE_MPI
49typedef MPI_Comm comm_ext;
50typedef MPI_Request comm_req;
51#else
52typedef int comm_ext;
53typedef int comm_req;
54#endif
55
56struct comm
57{
58 unsigned int id;
59 unsigned int np;
61};
62
64{
65 unsigned int n, *Lrp, *Lj;
66 double *L, *D;
67};
68
69struct csr_mat
70{
71 unsigned int n, *Arp, *Aj;
72 double *A;
73};
74
76{
77
78 /* communication */
79 struct comm comm;
80 unsigned int pcoord; /* coordinate in communication tree */
81 unsigned plevels; /* # of stages of communication */
82 signed int *pother; /* let p = pother[i], then during stage i of fan-in,
83 if p>=0, receive from p
84 if p< 0, send to (-p-1)
85 fan-out is just the reverse ...
86 on proc 0, pother is never negative
87 on others, pother is negative for the last stage only */
89
90 /* separators */
91 unsigned nsep; /* number of separators */
92 unsigned int *sep_size; /* # of dofs on each separator,
93 ordered from the bottom to the top of the tree:
94 separator 0 is the bottom-most one (dofs not shared)
95 separator nsep-1 is the root of the tree */
96
97 unsigned null_space;
98 double *share_weight;
99
100 /* vector sizes */
101 unsigned int un; /* user's vector size */
102
103 /* xxt_solve works with "condensed" vectors;
104 same dofs as in user's vectors, but no duplicates and no Dirichlet
105 nodes, and also ordered topologically (children before parents)
106 according to the separator tree */
107
108 unsigned int cn; /* size of condensed vectors */
109 signed int *perm_u2c; /* permutation from user vector to condensed
110 vector, p=perm_u2c[i]; xu[i] = p=-1 ? 0 : xc[p];*/
111 unsigned int ln, sn; /* xc[0 ... ln-1] are not shared
112 (ln=sep_size[0])
113 xc[ln ... ln+sn-1] are shared
114 ln+sn = cn */
115
116 unsigned int xn; /* # of columns of x = sum_i(sep_size[i]) -
117 sep_size[0] */
118
119 /* data */
121 struct csr_mat A_sl;
122 unsigned int *Xp;
123 double *X; /* column i of X starts at X[Xp[i]] */
124
125 /* execution buffers */
126 double *vl, *vc, *vx, *combuf;
127};
128
129extern "C"
130{
131 struct crs_data *nektar_crs_setup(unsigned int n, const unsigned long *id,
132 unsigned int nz, const unsigned int *Ai,
133 const unsigned int *Aj, const double *A,
134 unsigned int null_space,
135 const struct comm *comm);
136 void nektar_crs_solve(double *x, struct crs_data *data, double *b);
137 void nektar_crs_stats(struct crs_data *data);
138 void nektar_crs_free(struct crs_data *data);
139}
140
141/**
142 * @brief Initialise the matrix-solve.
143 *
144 * On each process an array of IDs for each global degree of freedom is
145 * supplied which corresponds to a unique numbering of universal degrees of
146 * freedom. Three vectors describing the matrix are also provided. The
147 * parallel matrix solve is then set up.
148 *
149 * @param pId Array of integers providing universal IDs for each
150 * global DOF on the process.
151 * @param pAi Row indices of matrix entries
152 * @param pAj Column indices of matrix entries
153 * @param pAr Values of matrix entries
154 * @param pComm Communication object used for inter-process
155 * communication.
156 * @returns crs_data structure
157 */
158static inline struct crs_data *Init(
159 unsigned int pRank, const Nektar::Array<OneD, unsigned long> pId,
163 const LibUtilities::CommSharedPtr &pComm)
164{
165#ifdef NEKTAR_USE_MPI
166 unsigned int nz = pAr.size();
168 std::dynamic_pointer_cast<LibUtilities::CommMpi>(pComm);
169 ASSERTL1(vCommMpi, "Failed to cast MPI Comm object.");
170 comm vComm;
171 MPI_Comm_dup(vCommMpi->GetComm(), &vComm.c);
172 vComm.id = vCommMpi->GetRank();
173 vComm.np = vCommMpi->GetSize();
174 crs_data *result = nektar_crs_setup(pRank, &pId[0], nz, &pAi[0], &pAj[0],
175 &pAr[0], 0, &vComm);
176 MPI_Comm_free(&vComm.c);
177 return result;
178#else
179 return 0;
180#endif
181}
182
183/**
184 * @brief Solve the matrix system for a given input vector b.
185 */
187 struct crs_data *pCrs,
189{
190#ifdef NEKTAR_USE_MPI
191 if (!pCrs)
192 {
193 return;
194 }
195 nektar_crs_solve(&pX[0], pCrs, &pB[0]);
196#endif
197}
198
199/**
200 * @brief Deallocates the crs mapping data.
201 */
202static inline void Finalise(crs_data *pCrs)
203{
204#ifdef NEKTAR_USE_MPI
205 int finalized;
206 MPI_Finalized(&finalized);
207 if (pCrs && !finalized)
208 {
209 nektar_crs_free(pCrs);
210 }
211#endif
212}
213} // namespace Xxt
214
215#endif
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....
Definition: ErrorUtil.hpp:242
std::shared_ptr< CommMpi > CommMpiSharedPtr
Pointer to a Communicator object.
Definition: CommMpi.h:56
std::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
Definition: Comm.h:55
Definition: Xxt.hpp:46
void nektar_crs_stats(struct crs_data *data)
int comm_req
Definition: Xxt.hpp:53
static struct crs_data * Init(unsigned int pRank, const Nektar::Array< OneD, unsigned long > pId, const Nektar::Array< OneD, unsigned int > pAi, const Nektar::Array< OneD, unsigned int > pAj, const Nektar::Array< OneD, NekDouble > pAr, const LibUtilities::CommSharedPtr &pComm)
Initialise the matrix-solve.
Definition: Xxt.hpp:158
static void Finalise(crs_data *pCrs)
Deallocates the crs mapping data.
Definition: Xxt.hpp:202
void nektar_crs_free(struct crs_data *data)
struct crs_data * nektar_crs_setup(unsigned int n, const unsigned long *id, unsigned int nz, const unsigned int *Ai, const unsigned int *Aj, const double *A, unsigned int null_space, const struct comm *comm)
static void Solve(Nektar::Array< OneD, NekDouble > pX, struct crs_data *pCrs, Nektar::Array< OneD, NekDouble > pB)
Solve the matrix system for a given input vector b.
Definition: Xxt.hpp:186
void nektar_crs_solve(double *x, struct crs_data *data, double *b)
int comm_ext
Definition: Xxt.hpp:52
unsigned int id
Definition: Xxt.hpp:58
unsigned int np
Definition: Xxt.hpp:59
comm_ext c
Definition: Xxt.hpp:60
double * share_weight
Definition: Xxt.hpp:98
unsigned int * sep_size
Definition: Xxt.hpp:92
signed int * pother
Definition: Xxt.hpp:82
unsigned int cn
Definition: Xxt.hpp:108
unsigned int xn
Definition: Xxt.hpp:116
unsigned null_space
Definition: Xxt.hpp:97
double * vc
Definition: Xxt.hpp:126
unsigned int pcoord
Definition: Xxt.hpp:80
double * vl
Definition: Xxt.hpp:126
unsigned int sn
Definition: Xxt.hpp:111
double * combuf
Definition: Xxt.hpp:126
unsigned nsep
Definition: Xxt.hpp:91
unsigned int un
Definition: Xxt.hpp:101
unsigned int ln
Definition: Xxt.hpp:111
double * X
Definition: Xxt.hpp:123
signed int * perm_u2c
Definition: Xxt.hpp:109
struct csr_mat A_sl
Definition: Xxt.hpp:121
double * vx
Definition: Xxt.hpp:126
unsigned int * Xp
Definition: Xxt.hpp:122
unsigned plevels
Definition: Xxt.hpp:81
comm_req * req
Definition: Xxt.hpp:88
struct sparse_cholesky fac_A_ll
Definition: Xxt.hpp:120
unsigned int n
Definition: Xxt.hpp:71
unsigned int * Arp
Definition: Xxt.hpp:71
double * A
Definition: Xxt.hpp:72
unsigned int * Aj
Definition: Xxt.hpp:71
unsigned int n
Definition: Xxt.hpp:65
unsigned int * Lj
Definition: Xxt.hpp:65
unsigned int * Lrp
Definition: Xxt.hpp:65
double * L
Definition: Xxt.hpp:66
double * D
Definition: Xxt.hpp:66