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 
44 #ifdef NEKTAR_USE_MPI
46 #endif
47 
48 namespace Xxt
49 {
50 using namespace Nektar;
51 #ifdef NEKTAR_USE_MPI
52 typedef MPI_Comm comm_ext;
53 typedef MPI_Request comm_req;
54 #else
55 typedef int comm_ext;
56 typedef int comm_req;
57 #endif
58 
59 struct comm
60 {
61  unsigned int id;
62  unsigned int np;
64 };
65 
67 {
68  unsigned int n, *Lrp, *Lj;
69  double *L, *D;
70 };
71 
72 struct csr_mat
73 {
74  unsigned int n, *Arp, *Aj;
75  double *A;
76 };
77 
78 struct crs_data
79 {
80 
81  /* communication */
82  struct comm comm;
83  unsigned int pcoord; /* coordinate in communication tree */
84  unsigned plevels; /* # of stages of communication */
85  signed int *pother; /* let p = pother[i], then during stage i of fan-in,
86  if p>=0, receive from p
87  if p< 0, send to (-p-1)
88  fan-out is just the reverse ...
89  on proc 0, pother is never negative
90  on others, pother is negative for the last stage only */
92 
93  /* separators */
94  unsigned nsep; /* number of separators */
95  unsigned int *sep_size; /* # of dofs on each separator,
96  ordered from the bottom to the top of the tree:
97  separator 0 is the bottom-most one (dofs not shared)
98  separator nsep-1 is the root of the tree */
99 
100  unsigned null_space;
101  double *share_weight;
102 
103  /* vector sizes */
104  unsigned int un; /* user's vector size */
105 
106  /* xxt_solve works with "condensed" vectors;
107  same dofs as in user's vectors, but no duplicates and no Dirichlet
108  nodes, and also ordered topologically (children before parents)
109  according to the separator tree */
110 
111  unsigned int cn; /* size of condensed vectors */
112  signed int *perm_u2c; /* permutation from user vector to condensed
113  vector, p=perm_u2c[i]; xu[i] = p=-1 ? 0 : xc[p];*/
114  unsigned int ln, sn; /* xc[0 ... ln-1] are not shared
115  (ln=sep_size[0])
116  xc[ln ... ln+sn-1] are shared
117  ln+sn = cn */
118 
119  unsigned int xn; /* # of columns of x = sum_i(sep_size[i]) -
120  sep_size[0] */
121 
122  /* data */
123  struct sparse_cholesky fac_A_ll;
124  struct csr_mat A_sl;
125  unsigned int *Xp;
126  double *X; /* column i of X starts at X[Xp[i]] */
127 
128  /* execution buffers */
129  double *vl, *vc, *vx, *combuf;
130 };
131 
132 extern "C"
133 {
134  struct crs_data *nektar_crs_setup(unsigned int n, const unsigned long *id,
135  unsigned int nz, const unsigned int *Ai,
136  const unsigned int *Aj, const double *A,
137  unsigned int null_space,
138  const struct comm *comm);
139  void nektar_crs_solve(double *x, struct crs_data *data, double *b);
140  void nektar_crs_stats(struct crs_data *data);
141  void nektar_crs_free(struct crs_data *data);
142 }
143 
144 /**
145  * @brief Initialise the matrix-solve.
146  *
147  * On each process an array of IDs for each global degree of freedom is
148  * supplied which corresponds to a unique numbering of universal degrees of
149  * freedom. Three vectors describing the matrix are also provided. The
150  * parallel matrix solve is then set up.
151  *
152  * @param pId Array of integers providing universal IDs for each
153  * global DOF on the process.
154  * @param pAi Row indices of matrix entries
155  * @param pAj Column indices of matrix entries
156  * @param pAr Values of matrix entries
157  * @param pComm Communication object used for inter-process
158  * communication.
159  * @returns crs_data structure
160  */
161 static inline struct crs_data *Init(
162  unsigned int pRank, const Nektar::Array<OneD, unsigned long> pId,
166  const LibUtilities::CommSharedPtr &pComm)
167 {
168 #ifdef NEKTAR_USE_MPI
169  unsigned int nz = pAr.size();
171  std::dynamic_pointer_cast<LibUtilities::CommMpi>(pComm);
172  ASSERTL1(vCommMpi, "Failed to cast MPI Comm object.");
173  comm vComm;
174  MPI_Comm_dup(vCommMpi->GetComm(), &vComm.c);
175  vComm.id = vCommMpi->GetRank();
176  vComm.np = vCommMpi->GetSize();
177  crs_data *result = nektar_crs_setup(pRank, &pId[0], nz, &pAi[0], &pAj[0],
178  &pAr[0], 0, &vComm);
179  MPI_Comm_free(&vComm.c);
180  return result;
181 #else
182  return 0;
183 #endif
184 }
185 
186 /**
187  * @brief Solve the matrix system for a given input vector b.
188  */
189 static inline void Solve(Nektar::Array<OneD, NekDouble> pX,
190  struct crs_data *pCrs,
192 {
193 #ifdef NEKTAR_USE_MPI
194  if (!pCrs)
195  {
196  return;
197  }
198  nektar_crs_solve(&pX[0], pCrs, &pB[0]);
199 #endif
200 }
201 
202 /**
203  * @brief Deallocates the crs mapping data.
204  */
205 static inline void Finalise(crs_data *pCrs)
206 {
207 #ifdef NEKTAR_USE_MPI
208  int finalized;
209  MPI_Finalized(&finalized);
210  if (pCrs && !finalized)
211  {
212  nektar_crs_free(pCrs);
213  }
214 #endif
215 }
216 } // namespace Xxt
217 
218 #endif
NekDouble L
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....
Definition: ErrorUtil.hpp:249
std::shared_ptr< CommMpi > CommMpiSharedPtr
Pointer to a Communicator object.
Definition: CommMpi.h:55
std::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
Definition: Comm.h:54
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:2
Definition: Xxt.hpp:49
void nektar_crs_stats(struct crs_data *data)
int comm_req
Definition: Xxt.hpp:56
static void Finalise(crs_data *pCrs)
Deallocates the crs mapping data.
Definition: Xxt.hpp:205
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:189
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:161
void nektar_crs_solve(double *x, struct crs_data *data, double *b)
int comm_ext
Definition: Xxt.hpp:55
unsigned int id
Definition: Xxt.hpp:61
unsigned int np
Definition: Xxt.hpp:62
comm_ext c
Definition: Xxt.hpp:63
double * share_weight
Definition: Xxt.hpp:101
unsigned int * sep_size
Definition: Xxt.hpp:95
signed int * pother
Definition: Xxt.hpp:85
unsigned int cn
Definition: Xxt.hpp:111
unsigned null_space
Definition: Xxt.hpp:100
unsigned int pcoord
Definition: Xxt.hpp:83
double * combuf
Definition: Xxt.hpp:129
unsigned nsep
Definition: Xxt.hpp:94
unsigned int un
Definition: Xxt.hpp:104
unsigned int ln
Definition: Xxt.hpp:114
double * X
Definition: Xxt.hpp:126
signed int * perm_u2c
Definition: Xxt.hpp:112
unsigned int * Xp
Definition: Xxt.hpp:125
unsigned plevels
Definition: Xxt.hpp:84
comm_req * req
Definition: Xxt.hpp:91
double * A
Definition: Xxt.hpp:75
unsigned int * Aj
Definition: Xxt.hpp:74
unsigned int * Lj
Definition: Xxt.hpp:68
double * D
Definition: Xxt.hpp:69