PaStiX Handbook  6.3.2
coeftab_zinit.c
Go to the documentation of this file.
1 /**
2  *
3  * @file coeftab_zinit.c
4  *
5  * Precision dependent coeficient array initialization routines.
6  *
7  * @copyright 2015-2023 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria,
8  * Univ. Bordeaux. All rights reserved.
9  *
10  * @version 6.3.2
11  * @author Xavier Lacoste
12  * @author Pierre Ramet
13  * @author Mathieu Faverge
14  * @author Esragul Korkmaz
15  * @date 2023-07-21
16  *
17  * @generated from /builds/solverstack/pastix/sopalin/coeftab_zinit.c, normal z -> z, Wed Dec 13 12:09:47 2023
18  *
19  **/
20 #ifndef DOXYGEN_SHOULD_SKIP_THIS
21 #define _GNU_SOURCE 1
22 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
23 #include "common.h"
24 #include "blend/solver.h"
25 #include "bcsc/bcsc.h"
26 #include "sopalin/coeftab.h"
27 #include "sopalin/coeftab_z.h"
28 #include "pastix_zcores.h"
29 
30 /**
31  *******************************************************************************
32  *
33  * @brief Dump a single column block into a FILE in a human readale format.
34  *
35  * All non-zeroes coefficients are dumped in the format:
36  * i j val
37  * with one value per row.
38  *
39  *******************************************************************************
40  *
41  * @param[in] side
42  * Define which side of the cblk must be printed.
43  * @arg PastixLCoef if lower part only
44  * @arg PastixUCoef if upper part only
45  *
46  * @param[in] cblk
47  * The column block to dump into the file.
48  *
49  * @param[inout] stream
50  * The FILE structure opened in write mode.
51  *
52  *******************************************************************************/
53 void
55  const SolverCblk *cblk,
56  FILE *stream )
57 {
58  const pastix_complex64_t *coeftab = side == PastixUCoef ? cblk->ucoeftab : cblk->lcoeftab;
59  SolverBlok *blok;
60  pastix_int_t itercol;
61  pastix_int_t iterrow;
62  pastix_int_t coefindx;
63 
64  /* We don't know how to dump the compressed block for now */
65  if ( cblk->cblktype & CBLK_COMPRESSED ) {
66  fprintf(stderr, "coeftab_zcblkdump: Can't dump a compressed cblk\n");
67  return;
68  }
69 
70  for (itercol = cblk->fcolnum;
71  itercol <= cblk->lcolnum;
72  itercol++)
73  {
74  /* Diagonal Block */
75  blok = cblk->fblokptr;
76  coefindx = blok->coefind;
77  if (cblk->cblktype & CBLK_LAYOUT_2D) {
78  coefindx += (itercol - cblk->fcolnum) * blok_rownbr( blok );
79  }
80  else {
81  coefindx += (itercol - cblk->fcolnum) * cblk->stride;
82  }
83 
84  for (iterrow = blok->frownum;
85  iterrow <= blok->lrownum;
86  iterrow++, coefindx++)
87  {
88  if ((cabs( coeftab[coefindx] ) > 0.) &&
89  (itercol <= iterrow))
90  {
91  if ( side == PastixUCoef ) {
92 #if defined(PRECISION_z) || defined(PRECISION_c)
93  fprintf(stream, "%ld %ld (%13e,%13e) [U]\n",
94  (long)itercol, (long)iterrow,
95  creal(coeftab[coefindx]), cimag(coeftab[coefindx]));
96 #else
97  fprintf(stream, "%ld %ld %13e [U]\n",
98  (long)itercol, (long)iterrow,
99  coeftab[coefindx]);
100 #endif
101  }
102  else {
103 #if defined(PRECISION_z) || defined(PRECISION_c)
104  fprintf(stream, "%ld %ld (%13e,%13e) [L]\n",
105  (long)iterrow, (long)itercol,
106  creal(coeftab[coefindx]), cimag(coeftab[coefindx]));
107 #else
108  fprintf(stream, "%ld %ld %13e [L]\n",
109  (long)iterrow, (long)itercol,
110  coeftab[coefindx]);
111 #endif
112  }
113  }
114  }
115 
116  /* Off diagonal blocks */
117  blok++;
118  while( blok < (cblk+1)->fblokptr )
119  {
120  coefindx = blok->coefind;
121  if (cblk->cblktype & CBLK_LAYOUT_2D) {
122  coefindx += (itercol - cblk->fcolnum) * blok_rownbr( blok );
123  }
124  else {
125  coefindx += (itercol - cblk->fcolnum) * cblk->stride;
126  }
127 
128  for (iterrow = blok->frownum;
129  iterrow <= blok->lrownum;
130  iterrow++, coefindx++)
131  {
132  if (cabs( coeftab[coefindx]) > 0.)
133  {
134  if ( side == PastixUCoef ) {
135 #if defined(PRECISION_z) || defined(PRECISION_c)
136  fprintf(stream, "%ld %ld (%13e,%13e) [U]\n",
137  (long)itercol, (long)iterrow,
138  creal(coeftab[coefindx]), cimag(coeftab[coefindx]));
139 #else
140  fprintf(stream, "%ld %ld %13e [U]\n",
141  (long)itercol, (long)iterrow,
142  coeftab[coefindx]);
143 #endif
144  }
145  else {
146 #if defined(PRECISION_z) || defined(PRECISION_c)
147  fprintf(stream, "%ld %ld (%13e,%13e) [L]\n",
148  (long)iterrow, (long)itercol,
149  creal(coeftab[coefindx]), cimag(coeftab[coefindx]));
150 #else
151  fprintf(stream, "%ld %ld %13e [L]\n",
152  (long)iterrow, (long)itercol,
153  coeftab[coefindx]);
154 #endif
155  }
156  }
157  }
158  blok++;
159  }
160  }
161 }
162 
163 /**
164  *******************************************************************************
165  *
166  * @brief TODO
167  *
168  *******************************************************************************
169  *
170  * @param[in] solvmtx
171  * TODO
172  *
173  * @param[in] cblk
174  * TODO
175  *
176  *******************************************************************************/
178 {
179  /* If there are off diagonal supernodes in the column */
180  SolverBlok *blok = cblk->fblokptr + 1; /* this diagonal block */
181  SolverBlok *lblk = cblk[1].fblokptr; /* the next diagonal block */
182 
183  for (; blok<lblk; blok++) {
184  SolverCblk *fcblk = solvmtx->cblktab + blok->fcblknm;
185  int is_preselected = blok_is_preselected( cblk, blok, fcblk );
186 
187  if ( is_preselected ) {
188  blok->iluklvl = -1;
189  }
190  else {
191  blok->iluklvl = INT_MAX;
192  }
193  }
194 }
195 
196 /**
197  *******************************************************************************
198  *
199  * @brief Fully initialize a single cblk.
200  *
201  * The cblk is allocated, intialized from the bcsc, and compressed if necessary.
202  *
203  *******************************************************************************
204  *
205  * @param[in] side
206  * Define which side of the matrix must be initialized.
207  * @arg PastixLCoef if lower part only
208  * @arg PastixUCoef if upper part only
209  * @arg PastixLUCoef if both sides.
210  *
211  * @param[in] solvmtx
212  * The solver matrix data structure.
213  *
214  * @param[in] bcsc
215  * The internal block CSC structure to fill-in the matrix.
216  *
217  * @param[in] itercblk
218  * The index of the cblk to initialize.
219  *
220  * @param[inout] directory
221  * The pointer to the temporary directory where to store the output
222  * files. Used only if PASTIX_DEBUG_DUMP_COEFTAB is defined.
223  *
224  *******************************************************************************/
225 void
227  const SolverMatrix *solvmtx,
228  const pastix_bcsc_t *bcsc,
229  pastix_int_t itercblk,
230  const char *directory )
231 {
232  SolverCblk *cblk = solvmtx->cblktab + itercblk;
233  int ilukmax = solvmtx->lowrank.ilu_lvl;
234 
235  /* Do not allocate if already allocated */
236  if ( !solvmtx->globalalloc ) {
237  cpucblk_zalloc( side, cblk );
238  }
239 
240  cpucblk_zfillin( side, solvmtx, bcsc, itercblk );
241 
242 #if defined(PASTIX_DEBUG_DUMP_COEFTAB)
243  /*
244  * Rk: This function is not in the kernel directory to avoid the double
245  * dependency with the pastix library due to pastix_fopenw()
246  */
247  {
248  cpucblk_zdumpfile(side, cblk, itercblk, directory);
249  }
250 #endif /* defined(PASTIX_DEBUG_DUMP_COEFTAB) */
251 
252  /* Update ILU levels if needed */
253  if ( (ilukmax > 0) && (ilukmax < INT_MAX) ) {
254 #if defined(PASTIX_WITH_MPI)
255  /* For now, we can't compute ILU(k) levels in distributed */
256  if ( solvmtx->clustnbr == 1 )
257 #endif
258  {
259  do { pastix_yield(); } while( cblk->ctrbcnt > 0 );
260  coeftabComputeCblkILULevels( solvmtx, cblk );
261  }
262  }
263 
264  /**
265  * Try to compress the cblk if needs to be compressed
266  */
267  if ( (cblk->cblktype & CBLK_COMPRESSED) &&
268  (ilukmax < INT_MAX) )
269  {
270  cpucblk_zcompress( solvmtx, side, ilukmax, cblk );
271  }
272 
273  (void)directory;
274 }
void coeftab_zcblkComputePreselect(const SolverMatrix *solvmtx, SolverCblk *cblk)
TODO.
BEGIN_C_DECLS typedef int pastix_int_t
Definition: datatypes.h:51
void coeftabComputeCblkILULevels(const SolverMatrix *solvmtx, SolverCblk *cblk)
Compute the ILU levels of a cblk.
Definition: coeftab.c:456
void cpucblk_zdumpfile(pastix_coefside_t side, SolverCblk *cblk, pastix_int_t itercblk, const char *directory)
Dump a single column block into a FILE in a human readale format.
Definition: coeftab_z.c:125
void cpucblk_zinit(pastix_coefside_t side, const SolverMatrix *solvmtx, const pastix_bcsc_t *bcsc, pastix_int_t itercblk, const char *directory)
Fully initialize a single cblk.
void cpucblk_zalloc(pastix_coefside_t side, SolverCblk *cblk)
Allocate the cblk structure to store the coefficient.
void cpucblk_zdump(pastix_coefside_t side, const SolverCblk *cblk, FILE *stream)
Dump a single column block into a FILE in a human readale format.
Definition: coeftab_zinit.c:54
pastix_int_t cpucblk_zcompress(const SolverMatrix *solvmtx, pastix_coefside_t side, int max_ilulvl, SolverCblk *cblk)
Compress a single column block from full-rank to low-rank format.
void cpucblk_zfillin(pastix_coefside_t side, const SolverMatrix *solvmtx, const pastix_bcsc_t *bcsc, pastix_int_t itercblk)
Initialize the coeftab structure from the internal bcsc.
enum pastix_coefside_e pastix_coefside_t
Data blocks used in the kernel.
@ PastixUCoef
Definition: api.h:479
static pastix_int_t blok_rownbr(const SolverBlok *blok)
Compute the number of rows of a block.
Definition: solver.h:390
void * ucoeftab
Definition: solver.h:172
pastix_lr_t lowrank
Definition: solver.h:230
int iluklvl
Definition: solver.h:147
pastix_int_t fcblknm
Definition: solver.h:140
int globalalloc
Definition: solver.h:226
pastix_int_t frownum
Definition: solver.h:142
static int blok_is_preselected(const SolverCblk *cblk, const SolverBlok *blok, const SolverCblk *fcbk)
Return if a block is preselected as either part of the projection, or as a sub-diagonal block.
Definition: solver.h:427
pastix_int_t coefind
Definition: solver.h:144
volatile int32_t ctrbcnt
Definition: solver.h:158
SolverBlok * fblokptr
Definition: solver.h:163
SolverCblk *restrict cblktab
Definition: solver.h:222
pastix_int_t stride
Definition: solver.h:164
int8_t cblktype
Definition: solver.h:159
void * lcoeftab
Definition: solver.h:171
pastix_int_t fcolnum
Definition: solver.h:161
Solver block structure.
Definition: solver.h:137
Solver column block structure.
Definition: solver.h:156
Solver column block structure.
Definition: solver.h:200