PaStiX Handbook  6.3.2
cpucblk_zcompress.c
Go to the documentation of this file.
1 /**
2  *
3  * @file cpucblk_zcompress.c
4  *
5  * Precision dependent function to compress/uncompress the coefficients
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 Gregoire Pichon
12  * @author Mathieu Faverge
13  * @author Esragul Korkmaz
14  * @date 2023-07-21
15  *
16  * @generated from /builds/solverstack/pastix/kernels/cpucblk_zcompress.c, normal z -> z, Wed Dec 13 12:09:17 2023
17  *
18  **/
19 #include "common/common.h"
20 #include "blend/solver.h"
21 #include <lapacke.h>
22 #include "kernels_trace.h"
23 #include "pastix_zcores.h"
24 #include "pastix_zlrcores.h"
25 
26 /**
27  *******************************************************************************
28  *
29  * @brief Compress a single block from full-rank to low-rank format
30  *
31  * The compression to low-rank format is parameterized by the input information
32  * stored in the low-rank structure.
33  *
34  *******************************************************************************
35  *
36  * @param[in] lowrank
37  * The pointer to the low-rank structure describing the lo-rank
38  * compression parameters.
39  *
40  * @param[in] M
41  * The number of rows in the block
42  *
43  * @param[in] N
44  * The number of columns in the block
45  *
46  * @param[inout] lrA
47  * The block to compress. On input, it points to a full-rank matrix. On
48  * output, if possible the matrix is compressed in block low-rank
49  * format.
50  *
51  *******************************************************************************
52  *
53  * @return The number of flops used to compress the block.
54  *
55  *******************************************************************************/
58  pastix_int_t M,
59  pastix_int_t N,
60  pastix_lrblock_t *lrA )
61 {
62  pastix_fixdbl_t flops;
63  pastix_complex64_t *A = lrA->u;
64 
65  if ( lrA->rk != -1 ) {
66  return 0.;
67  }
68  assert( lrA->u != NULL );
69  assert( lrA->v == NULL );
70 
71  kernel_trace_start_lvl2( PastixKernelLvl2_LR_init_compress );
72  flops = lowrank->core_ge2lr( lowrank->use_reltol, lowrank->tolerance, -1,
73  M, N, A, M, lrA );
74  kernel_trace_stop_lvl2_rank( flops, lrA->rk );
75 
76  assert( A != lrA->u );
77  free( A );
78 
79  return flops;
80 }
81 
82 /**
83  *******************************************************************************
84  *
85  * @brief Compress a single column block from full-rank to low-rank format
86  *
87  * The compression to low-rank format is parameterized by the input information
88  * stored in the low-rank structure.
89  *
90  *******************************************************************************
91  *
92  * @param[in] solvmtx
93  * The pointer to the solver structure.
94  *
95  * @param[in] side
96  * Define which side of the matrix must be initialized.
97  * @arg PastixLCoef if lower part only
98  * @arg PastixUCoef if upper part only
99  * @arg PastixLUCoef if both sides.
100  *
101  * @param[in] max_ilulvl
102  * TODO
103  *
104  * @param[inout] cblk
105  * The column block to compress.
106  *
107  *******************************************************************************
108  *
109  * @return The memory gain resulting from the compression to low-rank format in
110  * number of elements.
111  *
112  *******************************************************************************/
115  pastix_coefside_t side,
116  int max_ilulvl,
117  SolverCblk *cblk )
118 {
119  pastix_lrblock_t *lrA;
120  SolverBlok *blok = cblk[0].fblokptr + 1;
121  SolverBlok *lblok = cblk[1].fblokptr;
122  pastix_int_t ncols = cblk_colnbr( cblk );
123  pastix_int_t gain;
124  pastix_int_t gainL = 0;
125  pastix_int_t gainU = 0;
126  const pastix_lr_t *lowrank = &(solvmtx->lowrank);
127 
128  assert( cblk->cblktype & CBLK_LAYOUT_2D );
129  assert( cblk->cblktype & CBLK_COMPRESSED );
130 
131  if ( ncols < lowrank->compress_min_width ) {
132  return 0;
133  }
134 
135  for (; blok<lblok; blok++)
136  {
137  pastix_int_t nrows = blok_rownbr( blok );
138  int is_preselected = ( blok->iluklvl <= max_ilulvl );
139 
140  /* Skip uncompressible blocks */
141  if ( nrows < lowrank->compress_min_height ) {
142  continue;
143  }
144 
145  if ( is_preselected ) {
146  continue;
147  }
148 
149  gain = nrows * ncols;
150 
151  /* Lower part */
152  if ( side != PastixUCoef ) {
153  lrA = blok->LRblock[0];
154 
155  /* Try to compress non selected blocks */
156  if ( lrA->rk == -1 ) {
157  cpublok_zcompress( lowrank, nrows, ncols, lrA );
158  }
159 
160  if ( lrA->rk != -1 ) {
161  gainL += gain - ((nrows+ncols) * lrA->rk);
162  }
163  }
164 
165  /* Upper part */
166  if ( side != PastixLCoef ) {
167  lrA = blok->LRblock[1];
168 
169  if ( lrA->rk == -1 ) {
170  cpublok_zcompress( lowrank, nrows, ncols, lrA );
171  }
172 
173  if ( lrA->rk != -1 ) {
174  gainU += gain - ((nrows+ncols) * lrA->rk);
175  }
176  }
177  }
178 
179  return gainL + gainU;
180 }
181 
182 /**
183  *******************************************************************************
184  *
185  * @brief Uncompress a single column block from low-rank format to full-rank
186  * format.
187  *
188  *******************************************************************************
189  *
190  * @param[in] side
191  * Define which side of the matrix must be initialized.
192  * @arg PastixLCoef if lower part only
193  * @arg PastixUCoef if upper part only
194  * @arg PastixLUCoef if both sides.
195  *
196  * @param[inout] cblk
197  * The column block to uncompress.
198  *
199  *******************************************************************************/
200 void
202  SolverCblk *cblk )
203 {
204  SolverBlok *blok, *lblok;
205  pastix_int_t ncols = cblk_colnbr( cblk );
206  int ret;
207 
208  if ( side != PastixUCoef ) {
209  blok = cblk[0].fblokptr;
210  lblok = cblk[1].fblokptr;
211  for (; blok<lblok; blok++)
212  {
213  pastix_lrblock_t lrtmp;
214  pastix_int_t nrows = blok_rownbr( blok );
215 
216  memcpy( &lrtmp, blok->LRblock[0], sizeof(pastix_lrblock_t) );
217 
218  core_zlralloc( nrows, ncols, -1, blok->LRblock[0] );
219  ret = core_zlr2ge( PastixNoTrans, nrows, ncols,
220  &lrtmp,
221  blok->LRblock[0]->u, nrows );
222  assert( ret == 0 );
223  core_zlrfree( &lrtmp );
224  }
225  }
226 
227  if ( side != PastixLCoef ) {
228  blok = cblk[0].fblokptr;
229  lblok = cblk[1].fblokptr;
230  for (; blok<lblok; blok++)
231  {
232  pastix_lrblock_t lrtmp;
233  pastix_int_t nrows = blok_rownbr( blok );
234 
235  memcpy( &lrtmp, blok->LRblock[1], sizeof(pastix_lrblock_t) );
236 
237  core_zlralloc( nrows, ncols, -1, blok->LRblock[1] );
238  ret = core_zlr2ge( PastixNoTrans, nrows, ncols,
239  &lrtmp,
240  blok->LRblock[1]->u, nrows );
241  assert( ret == 0 );
242  core_zlrfree( &lrtmp );
243  }
244  }
245 
246  (void)ret;
247 }
248 
249 /**
250  *******************************************************************************
251  *
252  * @brief Return the memory gain of the low-rank form over the full-rank form
253  * for a single column-block.
254  *
255  * This function returns the memory gain in number of elements for a single
256  * column block when it is stored in low-rank format compared to a full rank
257  * storage.
258  *
259  *******************************************************************************
260  *
261  * @param[in] side
262  * Define which side of the matrix must be initialized.
263  * @arg PastixLCoef if lower part only
264  * @arg PastixUCoef if upper part only
265  * @arg PastixLUCoef if both sides.
266  *
267  * @param[in] solvmtx
268  * The pointer to the solver structure.
269  *
270  * @param[in] cblk
271  * The column block to study.
272  *
273  * @param[in,out] orig
274  * The structure that counts the original cost of the blocks.
275  *
276  * @param[in,out] gain
277  * The structure that counts gain on each type of the blocks.
278  *
279  *******************************************************************************/
280 void
282  const SolverMatrix *solvmtx,
283  SolverCblk *cblk,
284  pastix_int_t *orig,
285  pastix_int_t *gain )
286 {
287  SolverBlok *blok = cblk[0].fblokptr + 1;
288  SolverBlok *lblok = cblk[1].fblokptr;
289 
290  pastix_int_t ncols = cblk_colnbr( cblk );
291  pastix_int_t size;
292  pastix_int_t origblok;
293  pastix_int_t gainblok, gaintmp;
294 
295  assert( cblk->ownerid == solvmtx->clustnum );
296 
297  /* Compute potential gains if blocks where not compressed */
298  if ( cblk->cblktype & CBLK_COMPRESSED ) {
299  int ilu_lvl = solvmtx->lowrank.compress_preselect ? -1 : solvmtx->lowrank.ilu_lvl;
300  cpucblk_zcompress( solvmtx, side, ilu_lvl, cblk );
301  }
302 
303  for (; blok<lblok; blok++)
304  {
305  const SolverCblk *fcblk = solvmtx->cblktab + blok->fcblknm;
306  pastix_int_t nrows = blok_rownbr( blok );
307  size = nrows * ncols;
308  gainblok = 0;
309  origblok = size;
310 
311  /* Lower part */
312  if ( (side != PastixUCoef) &&
313  (blok->LRblock[0]->rk >= 0) )
314  {
315  gaintmp = (size - ((nrows+ncols) * blok->LRblock[0]->rkmax));
316  assert( gaintmp >= 0 );
317  gainblok += gaintmp;
318  }
319 
320  /* Upper part */
321  if ( (side != PastixLCoef) &&
322  (blok->LRblock[1]->rk >= 0) )
323  {
324  gaintmp = (size - ((nrows+ncols) * blok->LRblock[1]->rkmax));
325  assert( gaintmp >= 0 );
326  gainblok += gaintmp;
327  }
328 
329  if ( blok_is_preselected( cblk, blok, fcblk ) )
330  {
331  /* Selected block should always be inside supernode diagonal blocks */
332  assert( fcblk->sndeidx == cblk->sndeidx );
333  gain[LR_InSele] += gainblok;
334  orig[LR_InSele] += origblok;
335  }
336  else{
337  if ( fcblk->sndeidx == cblk->sndeidx ) {
338  gain[LR_InDiag] += gainblok;
339  orig[LR_InDiag] += origblok;
340  }
341  else {
342  gain[LR_OffDiag] += gainblok;
343  orig[LR_OffDiag] += origblok;
344  }
345  }
346  }
347  return;
348 }
BEGIN_C_DECLS typedef int pastix_int_t
Definition: datatypes.h:51
double pastix_fixdbl_t
Definition: datatypes.h:65
void cpucblk_zuncompress(pastix_coefside_t side, SolverCblk *cblk)
Uncompress a single column block from low-rank format to full-rank format.
pastix_fixdbl_t cpublok_zcompress(const pastix_lr_t *lowrank, pastix_int_t M, pastix_int_t N, pastix_lrblock_t *lrA)
Compress a single block from full-rank to low-rank format.
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_zmemory(pastix_coefside_t side, const SolverMatrix *solvmtx, SolverCblk *cblk, pastix_int_t *orig, pastix_int_t *gain)
Return the memory gain of the low-rank form over the full-rank form for a single column-block.
int compress_preselect
double tolerance
fct_ge2lr_t core_ge2lr
@ LR_InSele
@ LR_InDiag
@ LR_OffDiag
Structure to define the type of function to use for the low-rank kernels and their parameters.
The block low-rank structure to hold a matrix in low-rank form.
int core_zlr2ge(pastix_trans_t trans, pastix_int_t m, pastix_int_t n, const pastix_lrblock_t *Alr, pastix_complex64_t *A, pastix_int_t lda)
Convert a low rank matrix into a dense matrix.
void core_zlrfree(pastix_lrblock_t *A)
Free a low-rank matrix.
void core_zlralloc(pastix_int_t M, pastix_int_t N, pastix_int_t rkmax, pastix_lrblock_t *A)
Allocate a low-rank matrix.
Definition: core_zgelrops.c:56
enum pastix_coefside_e pastix_coefside_t
Data blocks used in the kernel.
@ PastixLCoef
Definition: api.h:478
@ PastixUCoef
Definition: api.h:479
@ PastixNoTrans
Definition: api.h:445
static pastix_int_t blok_rownbr(const SolverBlok *blok)
Compute the number of rows of a block.
Definition: solver.h:390
pastix_lr_t lowrank
Definition: solver.h:230
static pastix_int_t cblk_colnbr(const SolverCblk *cblk)
Compute the number of columns in a column block.
Definition: solver.h:324
int iluklvl
Definition: solver.h:147
pastix_int_t fcblknm
Definition: solver.h:140
pastix_int_t sndeidx
Definition: solver.h:168
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
SolverBlok * fblokptr
Definition: solver.h:163
pastix_lrblock_t * LRblock[2]
Definition: solver.h:150
SolverCblk *restrict cblktab
Definition: solver.h:222
int8_t cblktype
Definition: solver.h:159
int ownerid
Definition: solver.h:175
Solver block structure.
Definition: solver.h:137
Solver column block structure.
Definition: solver.h:156
Solver column block structure.
Definition: solver.h:200