PaStiX Handbook  6.2.1
cpucblk_cpack.c
Go to the documentation of this file.
1 /**
2  *
3  * @file cpucblk_cpack.c
4  *
5  * Precision dependent routines to pack and unpack cblks.
6  *
7  * @copyright 2021-2021 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria,
8  * Univ. Bordeaux. All rights reserved.
9  *
10  * @version 6.2.1
11  * @author Nolan Bredel
12  * @date 2021-07-20
13  *
14  * @generated from /builds/solverstack/pastix/kernels/cpucblk_zpack.c, normal z -> c, Tue Apr 12 09:38:41 2022
15  *
16  **/
17 #include "common/common.h"
18 #include "blend/solver.h"
19 #include "cpucblk_cpack.h"
20 #include "pastix_ccores.h"
21 #include "pastix_clrcores.h"
22 
23 /**
24  *******************************************************************************
25  *
26  * @brief Compute the size of a block to send in LR.
27  *
28  *******************************************************************************
29  *
30  * @param[in] side
31  * Define which side of the cblk must be tested.
32  * @arg PastixLCoef if lower part only
33  * @arg PastixUCoef if upper part only
34  * @arg PastixLUCoef if both sides.
35  *
36  * @param[in] N
37  * The number of columns of the block.
38  *
39  * @param[in] blok
40  * The block for which the size is computed.
41  *
42  *******************************************************************************
43  *
44  * @return size of the LR block to send in bytes
45  *
46  *******************************************************************************/
47 size_t
48 cpublok_ccompute_size_lr( pastix_coefside_t side, pastix_int_t N, const SolverBlok *blok )
49 {
50  pastix_int_t M = blok_rownbr( blok );
51  pastix_int_t suv = 0;
52  pastix_int_t coef = 0;
53 
54  /* Add lower part size */
55  if ( side != PastixUCoef ) {
56  suv += core_clrgetsize( M, N, blok->LRblock[0] );
57  coef++;
58  }
59 
60  /* Add upper part size */
61  if ( side != PastixLCoef ) {
62  suv += core_clrgetsize( M, N, blok->LRblock[1] );
63  coef++;
64  }
65 
66  /* size of rk(int) + size of u + size of v */
67  return coef * sizeof( int ) + suv * sizeof( pastix_complex32_t );
68 }
69 
70 /**
71  *******************************************************************************
72  *
73  * @brief Compute the size of a column block to send in LR.
74  *
75  *******************************************************************************
76  *
77  * @param[in] side
78  * Define which side of the cblk must be tested.
79  * @arg PastixLCoef if lower part only
80  * @arg PastixUCoef if upper part only
81  * @arg PastixLUCoef if both sides.
82  *
83  * @param[in] cblk
84  * The low-rank column block for which the size is computed.
85  *
86  *******************************************************************************
87  *
88  * @return size of the LR column block to send in bytes.
89  *
90  *******************************************************************************/
91 pastix_uint_t
93 {
94  assert( cblk->cblktype & CBLK_COMPRESSED );
95 
96  pastix_uint_t N = cblk_colnbr( cblk );
97  pastix_uint_t size = 0;
98  const SolverBlok *blok = cblk->fblokptr;
99  const SolverBlok *lblok = cblk[1].fblokptr;
100 
101  for ( ; blok < lblok; blok++ ) {
102  size += cpublok_ccompute_size_lr( side, N, blok );
103  }
104 
105  /* size of all blocks */
106  return size;
107 }
108 
109 /**
110  *******************************************************************************
111  *
112  * @brief Compute the size of the buffer to send.
113  *
114  *******************************************************************************
115  *
116  * @param[in] side
117  * Define which side of the cblk must be tested.
118  * @arg PastixLCoef if lower part only
119  * @arg PastixUCoef if upper part only
120  * @arg PastixLUCoef if both sides.
121  *
122  * @param[in] cblk
123  * The column block for which the size is computed.
124  *
125  *******************************************************************************
126  *
127  * @return Size of the buffer to send.
128  *
129  *******************************************************************************/
130 size_t
132 {
133  if ( cblk->cblktype & CBLK_COMPRESSED ) {
134  return cpucblk_ccompute_size_lr( side, cblk );
135  }
136  else {
137  size_t cblksize = cblk->stride * cblk_colnbr( cblk );
138  if ( side == PastixLUCoef ) {
139  cblksize *= 2;
140  }
141  return cblksize * sizeof( pastix_complex32_t );
142  }
143 }
144 
145 /**
146  *******************************************************************************
147  *
148  * @brief Pack low-rank data for a block.
149  *
150  *******************************************************************************
151  *
152  * @param[in] side
153  * Define which side of the cblk must be tested.
154  * @arg PastixLCoef if lower part only
155  * @arg PastixUCoef if upper part only
156  * @arg PastixLUCoef if both sides.
157  *
158  * @param[in] N
159  * Number of columns of the block.
160  *
161  * @param[in] blok
162  * The solver block to pack.
163  *
164  * @param[inout] buffer
165  * Pointer to the buffer where to pack the data.
166  *
167  *******************************************************************************
168  *
169  * @return Pointer to the end of the packed data.
170  *
171  *******************************************************************************/
172 char *
173 cpublok_cpack_lr( pastix_coefside_t side, pastix_uint_t N, const SolverBlok *blok, char *buffer )
174 {
175  pastix_int_t M = blok_rownbr( blok );
176 
177  if ( side != PastixUCoef ) {
178  buffer = core_clrpack( M, N, blok->LRblock[0], buffer );
179  }
180 
181  if ( side != PastixLCoef ) {
182  buffer = core_clrpack( M, N, blok->LRblock[1], buffer );
183  }
184 
185  return buffer;
186 }
187 
188 /**
189  *******************************************************************************
190  *
191  * @brief Pack low-rank data for column block.
192  *
193  *******************************************************************************
194  *
195  * @param[in] side
196  * Define which side of the cblk must be tested.
197  * @arg PastixLCoef if lower part only
198  * @arg PastixUCoef if upper part only
199  * @arg PastixLUCoef if both sides.
200  *
201  * @param[in] cblk
202  * The column block to pack.
203  *
204  * @param[in] size
205  * Size to allocate the buffer.
206  *
207  *******************************************************************************
208  *
209  * @return Pointer to the packed data.
210  *
211  *******************************************************************************/
212 void *
213 cpucblk_cpack_lr( pastix_coefside_t side, SolverCblk *cblk, size_t size )
214 {
215  assert( cblk->cblktype & CBLK_COMPRESSED );
216 
217  char *buffer = malloc(size);
218  char *tmp = buffer;
219 
220  const SolverBlok *blok = cblk->fblokptr;
221  const SolverBlok *lblok = cblk[1].fblokptr;
222 
223  pastix_int_t N = cblk_colnbr( cblk );
224 
225  for ( ; blok < lblok; blok++ ) {
226  tmp = cpublok_cpack_lr( side, N, blok, tmp );
227  }
228 
229  assert( (side == PastixUCoef) || (cblk->lcoeftab == (void*)-1) );
230  assert( (side == PastixLCoef) || (cblk->ucoeftab == (void*)-1) );
231 
232  return buffer;
233 }
234 
235 /**
236  *******************************************************************************
237  *
238  * @brief Unpack low rank data and fill the block concerned by the computation.
239  *
240  *******************************************************************************
241  *
242  * @param[in] side
243  * Define which side of the cblk must be tested.
244  * @arg PastixLCoef if lower part only
245  * @arg PastixUCoef if upper part only
246  * @arg PastixLUCoef if both sides.
247  *
248  * @param[in] N
249  * Number of columns of the block.
250  *
251  * @param[inout] blok
252  * The block concerned by the computation.
253  *
254  * @param[inout] buffer
255  * Pointer on the packed data.
256  *
257  *******************************************************************************
258  *
259  * @return Pointer to the next block to unpack.
260  *
261  *******************************************************************************/
262 char *
263 cpublok_cunpack_lr( pastix_coefside_t side, pastix_int_t N, SolverBlok *blok, char *buffer )
264 {
265  pastix_int_t M = blok_rownbr( blok );
266 
267  if ( side != PastixUCoef ) {
268  buffer = core_clrunpack( M, N, blok->LRblock[0], buffer );
269  }
270 
271  if ( side != PastixLCoef ) {
272  buffer = core_clrunpack( M, N, blok->LRblock[1], buffer );
273  }
274 
275  return buffer;
276 }
277 
278 /**
279  *******************************************************************************
280  *
281  * @brief Unpack low rank data and fill the column block concerned by the computation.
282  *
283  *******************************************************************************
284  *
285  * @param[in] side
286  * Define which side of the cblk must be tested.
287  * @arg PastixLCoef if lower part only
288  * @arg PastixUCoef if upper part only
289  * @arg PastixLUCoef if both sides.
290  *
291  * @param[inout] cblk
292  * The column block to fill.
293  *
294  * @param[inout] buffer
295  * Pointer on packed data.
296  *
297  *******************************************************************************/
298 void
299 cpucblk_cunpack_lr( pastix_coefside_t side, SolverCblk *cblk, void *buffer )
300 {
301  assert( cblk->cblktype & CBLK_COMPRESSED );
302 
303  SolverBlok *blok = cblk->fblokptr;
304  SolverBlok *lblok = cblk[1].fblokptr;
305  pastix_int_t N = cblk_colnbr( cblk );
306 
307  cpucblk_calloc_lr( side, cblk, 0 );
308 
309  for ( ; blok < lblok; blok++ ) {
310  buffer = cpublok_cunpack_lr( side, N, blok, buffer );
311  }
312 }
313 
314 /**
315  *******************************************************************************
316  *
317  * @brief Pack data in full rank.
318  *
319  *******************************************************************************
320  *
321  * @param[in] side
322  * Define which side of the cblk must be tested.
323  * @arg PastixLCoef if lower part only
324  * @arg PastixUCoef if upper part only
325  * @arg PastixLUCoef if both sides.
326  *
327  * @param[in] cblk
328  * The column block that will be sent.
329  *
330  *******************************************************************************
331  *
332  * @return Pointer to the data buffer. Note that in full-rank, the data pointer is directly returned
333  * without data copy.
334  *
335  *******************************************************************************/
336 void *
338 {
339  assert( !( cblk->cblktype & CBLK_COMPRESSED ) );
340 
341  return side == PastixUCoef ? cblk->ucoeftab : cblk->lcoeftab;
342 }
343 
344 /**
345  *******************************************************************************
346  *
347  * @brief Unpack data in full rank and fill the column block concerned by the computation.
348  *
349  *******************************************************************************
350  *
351  * @param[in] side
352  * Define which side of the cblk must be tested.
353  * @arg PastixLCoef if lower part only
354  * @arg PastixUCoef if upper part only
355  * @arg PastixLUCoef if both sides.
356  *
357  * @param[in] cblk
358  * The column block to unpack.
359  *
360  * @param[in] buffer
361  * Pointer on packed data.
362  *
363  *******************************************************************************/
364 void
365 cpucblk_cunpack_fr( pastix_coefside_t side, SolverCblk *cblk, pastix_complex32_t *buffer )
366 {
367  assert( !( cblk->cblktype & CBLK_COMPRESSED ) );
368 
369  cblk->lcoeftab = buffer;
370  if ( side != PastixLCoef ) {
371  cblk->ucoeftab = buffer + ( cblk_colnbr( cblk ) * cblk->stride );
372  }
373 }
374 
375 /**
376  *******************************************************************************
377  *
378  * @brief Pack a column block (Full rank or low rank).
379  *
380  *******************************************************************************
381  *
382  * @param[in] side
383  * Define which side of the cblk must be tested.
384  * @arg PastixLCoef if lower part only
385  * @arg PastixUCoef if upper part only
386  * @arg PastixLUCoef if both sides.
387  *
388  * @param[in] cblk
389  * The column block that will be sent.
390  *
391  * @param[inout] buffer
392  * Pointer on packed data.
393  *
394  *******************************************************************************
395  *
396  * @return Pointer to the data buffer.
397  *
398  *******************************************************************************/
399 void *
400 cpucblk_cpack( pastix_coefside_t side, SolverCblk *cblk, size_t size )
401 {
402  if ( cblk->cblktype & CBLK_COMPRESSED ) {
403  return cpucblk_cpack_lr( side, cblk, size );
404  }
405  else {
406  return cpucblk_cpack_fr( side, cblk );
407  }
408 }
409 
410 /**
411  *******************************************************************************
412  *
413  * @brief Unpack data and fill the column block concerned by the computation.
414  *
415  *******************************************************************************
416  *
417  * @param[in] side
418  * Define which side of the cblk must be tested.
419  * @arg PastixLCoef if lower part only
420  * @arg PastixUCoef if upper part only
421  * @arg PastixLUCoef if both sides.
422  *
423  * @param[inout] cblk
424  * The cblk to unpack.
425  *
426  * @param[in] buffer
427  * Pointer on packed data.
428  *
429  *******************************************************************************/
430 void
431 cpucblk_cunpack( pastix_coefside_t side, SolverCblk *cblk, void *buffer )
432 {
433  if ( cblk->cblktype & CBLK_COMPRESSED ) {
434  cpucblk_cunpack_lr( side, cblk, buffer );
435 
436  /*
437  * In low-rank, we created a copy so we need to directly free the
438  * reception buffer
439  */
440  free( buffer );
441  }
442  else {
443  cpucblk_cunpack_fr( side, cblk, buffer );
444  }
445 }
solver.h
blok_rownbr
static pastix_int_t blok_rownbr(const SolverBlok *blok)
Compute the number of rows of a block.
Definition: solver.h:313
cblk_colnbr
static pastix_int_t cblk_colnbr(const SolverCblk *cblk)
Compute the number of columns in a column block.
Definition: solver.h:247
solver_cblk_s::fblokptr
SolverBlok * fblokptr
Definition: solver.h:134
cpucblk_ccompute_size
size_t cpucblk_ccompute_size(pastix_coefside_t side, const SolverCblk *cblk)
Compute the size of the buffer to send.
Definition: cpucblk_cpack.c:131
solver_cblk_s::stride
pastix_int_t stride
Definition: solver.h:135
solver_cblk_s
Solver column block structure.
Definition: solver.h:127
pastix_coefside_t
enum pastix_coefside_e pastix_coefside_t
Data blocks used in the kernel.
cpucblk_cunpack
void cpucblk_cunpack(pastix_coefside_t side, SolverCblk *cblk, void *buffer)
Unpack data and fill the column block concerned by the computation.
Definition: cpucblk_cpack.c:431
solver_blok_s
Solver block structure.
Definition: solver.h:107
solver_cblk_s::ucoeftab
void * ucoeftab
Definition: solver.h:143
cpublok_cpack_lr
char * cpublok_cpack_lr(pastix_coefside_t side, pastix_uint_t N, const SolverBlok *blok, char *buffer)
Pack low-rank data for a block.
Definition: cpucblk_cpack.c:173
core_clrgetsize
size_t core_clrgetsize(pastix_int_t M, pastix_int_t N, pastix_lrblock_t *A)
Compute the size of a block to send in LR.
Definition: core_cgelrops.c:1570
core_clrpack
char * core_clrpack(pastix_int_t M, pastix_int_t N, const pastix_lrblock_t *A, char *buffer)
Pack low-rank data by side.
Definition: core_cgelrops.c:1605
cpucblk_cpack
void * cpucblk_cpack(pastix_coefside_t side, SolverCblk *cblk, size_t size)
Pack a column block (Full rank or low rank).
Definition: cpucblk_cpack.c:400
solver_cblk_s::lcoeftab
void * lcoeftab
Definition: solver.h:142
pastix_ccores.h
cpucblk_cpack_fr
void * cpucblk_cpack_fr(pastix_coefside_t side, const SolverCblk *cblk)
Pack data in full rank.
Definition: cpucblk_cpack.c:337
PastixUCoef
@ PastixUCoef
Definition: api.h:457
cpublok_ccompute_size_lr
size_t cpublok_ccompute_size_lr(pastix_coefside_t side, pastix_int_t N, const SolverBlok *blok)
Compute the size of a block to send in LR.
Definition: cpucblk_cpack.c:48
cpucblk_ccompute_size_lr
pastix_uint_t cpucblk_ccompute_size_lr(pastix_coefside_t side, const SolverCblk *cblk)
Compute the size of a column block to send in LR.
Definition: cpucblk_cpack.c:92
PastixLCoef
@ PastixLCoef
Definition: api.h:456
cpucblk_cpack.h
cpublok_cunpack_lr
char * cpublok_cunpack_lr(pastix_coefside_t side, pastix_int_t N, SolverBlok *blok, char *buffer)
Unpack low rank data and fill the block concerned by the computation.
Definition: cpucblk_cpack.c:263
cpucblk_calloc_lr
void cpucblk_calloc_lr(pastix_coefside_t side, SolverCblk *cblk, int rkmax)
Allocate the cblk structure to store the coefficient.
Definition: cpucblk_cinit.c:143
cpucblk_cunpack_fr
void cpucblk_cunpack_fr(pastix_coefside_t side, SolverCblk *cblk, pastix_complex32_t *buffer)
Unpack data in full rank and fill the column block concerned by the computation.
Definition: cpucblk_cpack.c:365
solver_cblk_s::cblktype
int8_t cblktype
Definition: solver.h:130
PastixLUCoef
@ PastixLUCoef
Definition: api.h:458
cpucblk_cpack_lr
void * cpucblk_cpack_lr(pastix_coefside_t side, SolverCblk *cblk, size_t size)
Pack low-rank data for column block.
Definition: cpucblk_cpack.c:213
solver_blok_s::LRblock
pastix_lrblock_t * LRblock[2]
Definition: solver.h:121
cpucblk_cunpack_lr
void cpucblk_cunpack_lr(pastix_coefside_t side, SolverCblk *cblk, void *buffer)
Unpack low rank data and fill the column block concerned by the computation.
Definition: cpucblk_cpack.c:299
pastix_clrcores.h
core_clrunpack
char * core_clrunpack(pastix_int_t M, pastix_int_t N, pastix_lrblock_t *A, char *buffer)
Unpack low rank data and fill the cblk concerned by the computation.
Definition: core_cgelrops.c:1665