PaStiX Handbook  6.3.2
parsec_zhetrf.c
Go to the documentation of this file.
1 /**
2  *
3  * @file parsec_zhetrf.c
4  *
5  * PaStiX zhetrf PaRSEC wrapper.
6  *
7  * @copyright 2016-2023 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria,
8  * Univ. Bordeaux. All rights reserved.
9  *
10  * @version 6.3.2
11  * @author Mathieu Faverge
12  * @author Esragul Korkmaz
13  * @date 2023-07-21
14  * @generated from /builds/solverstack/pastix/sopalin/parsec/parsec_zhetrf.c, normal z -> z, Wed Dec 13 12:09:27 2023
15  *
16  * @addtogroup parsec_hetrf
17  * @{
18  *
19  **/
20 #include <parsec.h>
21 #include <parsec/data_distribution.h>
22 #include <parsec/private_mempool.h>
23 #include <parsec/arena.h>
24 #include <parsec/data_dist/matrix/matrix.h>
25 #include "common.h"
26 #include "blend/solver.h"
27 #include "sopalin/sopalin_data.h"
28 #include "zhetrf_sp1dplus.h"
29 #include "zhetrf_sp2d.h"
30 #include "pastix_parsec.h"
31 
32 /**
33  *******************************************************************************
34  *
35  * @brief Generate the PaRSEC taskpool object for the LDL^h factorization with
36  * 1D kernels.
37  *
38  * The function only return the object that describes the LDL^h factorization
39  * of a sparse hermitian matrix A.
40  * The factorization has the form
41  *
42  * \f[ A = L \times D \times L^h \f]
43  *
44  * where L is a sparse lower triangular matrix unitary on the diagonal, and D a
45  * diagonal matrix.
46  *
47  * In this object, all operations are panel based operation which might result in
48  * lower parallelism for large problems.
49  *
50  * @warning The computations are not done by this call.
51  *
52  *******************************************************************************
53  *
54  * @param[inout] A
55  * Descriptor of the sparse matrix A.
56  * On exit, A is overwritten with the factorized matrix.
57  *
58  * @param[inout] sopalin_data
59  * Solver matrix information structure that will guide the algorithm.
60  *
61  *******************************************************************************
62  *
63  * @retval NULL if incorrect parameters are given.
64  * @retval The parsec taskpool describing the operation that can be
65  * enqueued in the runtime with parsec_enqueue(). It, then, needs to be
66  * destroy with parsec_zhetrf_sp1dplus_Destruct().
67  *
68  *******************************************************************************
69  *
70  * @sa parsec_zhetrf_sp1dplus
71  * @sa parsec_zhetrf_sp1dplus_Destruct
72  * @sa parsec_zhetrf_sp1dplus
73  * @sa parsec_chetrf_sp1dplus_New
74  * @sa parsec_dhetrf_sp1dplus_New
75  * @sa parsec_shetrf_sp1dplus_New
76  *
77  ******************************************************************************/
78 parsec_taskpool_t*
80  sopalin_data_t *sopalin_data )
81 {
82  parsec_zhetrf_sp1dplus_taskpool_t *parsec_zhetrf_sp1dplus = NULL;
83  unsigned int gemmmax = sopalin_data->solvmtx->gemmmax;
84  unsigned int offdmax = sopalin_data->solvmtx->offdmax;
85  unsigned int blokmax = sopalin_data->solvmtx->blokmax;
86  pastix_int_t lwork;
87 
88  lwork = pastix_imax( gemmmax, blokmax );
89  if ( (sopalin_data->solvmtx->lowrank.compress_when != PastixCompressNever) &&
90  (sopalin_data->solvmtx->lowrank.ilu_lvl < INT_MAX) )
91  {
92  lwork = pastix_imax( lwork, 2 * blokmax );
93  }
94 
95  parsec_zhetrf_sp1dplus = parsec_zhetrf_sp1dplus_new( A, sopalin_data, NULL, lwork );
96 
97  parsec_zhetrf_sp1dplus->_g_p_work = (parsec_memory_pool_t*)malloc(sizeof(parsec_memory_pool_t));
98  parsec_private_memory_init( parsec_zhetrf_sp1dplus->_g_p_work,
99  lwork * sizeof(pastix_complex64_t) );
100 
101  parsec_arena_construct( parsec_zhetrf_sp1dplus->arenas[PARSEC_zhetrf_sp1dplus_DEFAULT_ARENA],
102  sizeof(pastix_complex64_t), PARSEC_ARENA_ALIGNMENT_SSE,
103  parsec_datatype_double_complex_t );
104 
105  parsec_matrix_add2arena_rect( parsec_zhetrf_sp1dplus->arenas[PARSEC_zhetrf_sp1dplus_CBLK_WS_ARENA],
106  parsec_datatype_double_complex_t, offdmax, 1, offdmax );
107 
108 #if defined(PASTIX_GENERATE_MODEL)
109  parsec_zhetrf_sp1dplus->_g_forced_pushout = 1;
110 #endif
111  return (parsec_taskpool_t*)parsec_zhetrf_sp1dplus;
112 }
113 
114 /**
115  *******************************************************************************
116  *
117  * @brief Free the data structure associated to a taskpool created with
118  * parsec_zhetrf_sp1dplus_New().
119  *
120  *******************************************************************************
121  *
122  * @param[inout] taskpool
123  * On entry, the taskpool to destroy.
124  * On exit, the taskpool cannot be used anymore.
125  *
126  ******************************************************************************/
127 void
128 parsec_zhetrf_sp1dplus_Destruct( parsec_taskpool_t *taskpool )
129 {
130  parsec_zhetrf_sp1dplus_taskpool_t *parsec_zhetrf_sp1dplus = NULL;
131  parsec_zhetrf_sp1dplus = (parsec_zhetrf_sp1dplus_taskpool_t *)taskpool;
132 
133  parsec_matrix_del2arena( parsec_zhetrf_sp1dplus->arenas[PARSEC_zhetrf_sp1dplus_CBLK_WS_ARENA] );
134 
135  parsec_private_memory_fini( parsec_zhetrf_sp1dplus->_g_p_work );
136  free( parsec_zhetrf_sp1dplus->_g_p_work );
137 
138  parsec_taskpool_free( taskpool );
139 }
140 
141 /**
142  *******************************************************************************
143  *
144  * @brief Perform a sparse LDL^h factorization with 1D kernels.
145  *
146  * The function performs the LDL^h factorization of a sparse hermitian matrix A.
147  * The factorization has the form
148  *
149  * \f[ A = L \times D \times L^h \f]
150  *
151  * where L is a sparse lower triangular matrix unitary on the diagonal, and D a
152  * diagonal matrix.
153  *
154  *******************************************************************************
155  *
156  * @param[inout] parsec
157  * The parsec context of the application that will run the operation.
158  *
159  * @param[inout] A
160  * Descriptor of the sparse matrix A.
161  * On exit, A is overwritten with the factorized matrix.
162  *
163  * @param[inout] sopalin_data
164  * Solver matrix information structure that will guide the algorithm.
165  *
166  *******************************************************************************
167  *
168  * @retval NULL if incorrect parameters are given.
169  * @retval The parsec taskpool describing the operation that can be
170  * enqueued in the runtime with parsec_enqueue(). It, then, needs to be
171  * destroy with parsec_zhetrf_sp1dplus_Destruct().
172  *
173  *******************************************************************************
174  *
175  * @sa parsec_zhetrf_sp1dplus_New
176  * @sa parsec_zhetrf_sp1dplus_Destruct
177  *
178  ******************************************************************************/
179 int
180 parsec_zhetrf_sp1dplus( parsec_context_t *parsec,
182  sopalin_data_t *sopalin_data )
183 {
184  parsec_taskpool_t *parsec_zhetrf_sp1dplus = NULL;
185  int info = 0;
186 
188 
189  if ( parsec_zhetrf_sp1dplus == NULL ) {
190  return -1;
191  }
192 
193  parsec_context_add_taskpool( parsec, (parsec_taskpool_t*)parsec_zhetrf_sp1dplus );
194  parsec_context_start( parsec );
195  parsec_context_wait( parsec );
197 
198  return info;
199 }
200 
201 /**
202  *******************************************************************************
203  *
204  * @brief Generate the PaRSEC taskpool object for the LDL^h factorization with
205  * 1D and 2D kernels.
206  *
207  * The function only returns the object that describes the LDL^h factorization
208  * of a sparse hermitian matrix A.
209  * The factorization has the form
210  *
211  * \f[ A = L \times D \times L^h \f]
212  *
213  * where L is a sparse lower triangular matrix unitary on the diagonal, and D a
214  * diagonal matrix.
215  *
216  * In this object, operations are panel based operations for the lower levels of
217  * the elimination tree, and the higher levels are taskpool by 2D tasks scheme to
218  * create more parallelism and adapt to large architectures.
219  *
220  * @warning The computations are not done by this call.
221  *
222  *******************************************************************************
223  *
224  * @param[inout] A
225  * Descriptor of the sparse matrix A.
226  * On exit, A is overwritten with the factorized matrix.
227  *
228  * @param[inout] sopalin_data
229  * Solver matrix information structure that will guide the algorithm.
230  *
231  *******************************************************************************
232  *
233  * @retval NULL if incorrect parameters are given.
234  * @retval The parsec taskpool describing the operation that can be
235  * enqueued in the runtime with parsec_enqueue(). It, then, needs to be
236  * destroy with parsec_zhetrf_sp2d_Destruct().
237  *
238  *******************************************************************************
239  *
240  * @sa parsec_zhetrf_sp2d
241  * @sa parsec_zhetrf_sp2d_Destruct
242  * @sa parsec_zhetrf_sp2d
243  * @sa parsec_chetrf_sp2d_New
244  * @sa parsec_dhetrf_sp2d_New
245  * @sa parsec_shetrf_sp2d_New
246  *
247  ******************************************************************************/
248 parsec_taskpool_t*
250  sopalin_data_t *sopalin_data )
251 {
252  parsec_zhetrf_sp2d_taskpool_t *parsec_zhetrf_sp2d = NULL;
253  unsigned int gemmmax = sopalin_data->solvmtx->gemmmax;
254  unsigned int offdmax = sopalin_data->solvmtx->offdmax;
255  unsigned int blokmax = sopalin_data->solvmtx->blokmax;
256  pastix_int_t lwork;
257 
258  lwork = pastix_imax( gemmmax, blokmax );
259  if ( (sopalin_data->solvmtx->lowrank.compress_when != PastixCompressNever) &&
260  (sopalin_data->solvmtx->lowrank.ilu_lvl < INT_MAX) )
261  {
262  lwork = pastix_imax( lwork, 2 * blokmax );
263  }
264 
265  parsec_zhetrf_sp2d = parsec_zhetrf_sp2d_new( A, sopalin_data, NULL, lwork );
266 
267  parsec_zhetrf_sp2d->_g_p_work = (parsec_memory_pool_t*)malloc(sizeof(parsec_memory_pool_t));
268  parsec_private_memory_init( parsec_zhetrf_sp2d->_g_p_work,
269  lwork * sizeof(pastix_complex64_t) );
270 
271  parsec_arena_construct( parsec_zhetrf_sp2d->arenas[PARSEC_zhetrf_sp2d_DEFAULT_ARENA],
272  sizeof(pastix_complex64_t), PARSEC_ARENA_ALIGNMENT_SSE,
273  parsec_datatype_double_complex_t );
274 
275  parsec_matrix_add2arena_rect( parsec_zhetrf_sp2d->arenas[PARSEC_zhetrf_sp2d_CBLK_WS_ARENA],
276  parsec_datatype_double_complex_t,
277  offdmax, 1, offdmax );
278 
279  parsec_matrix_add2arena_rect( parsec_zhetrf_sp2d->arenas[PARSEC_zhetrf_sp2d_BLOK_WS_ARENA],
280  parsec_datatype_double_complex_t,
281  blokmax, 1, blokmax );
282 
283 #if defined(PASTIX_GENERATE_MODEL)
284  parsec_zhetrf_sp2d->_g_forced_pushout = 1;
285 #endif
286  return (parsec_taskpool_t*)parsec_zhetrf_sp2d;
287 }
288 
289 /**
290  *******************************************************************************
291  *
292  * @brief Free the data structure associated to a taskpool created with
293  * parsec_zhetrf_sp2d_New().
294  *
295  *******************************************************************************
296  *
297  * @param[inout] taskpool
298  * On entry, the taskpool to destroy.
299  * On exit, the taskpool cannot be used anymore.
300  *
301  ******************************************************************************/
302 void
303 parsec_zhetrf_sp2d_Destruct( parsec_taskpool_t *taskpool )
304 {
305  parsec_zhetrf_sp2d_taskpool_t *parsec_zhetrf_sp2d = NULL;
306  parsec_zhetrf_sp2d = (parsec_zhetrf_sp2d_taskpool_t *)taskpool;
307 
308  parsec_matrix_del2arena( parsec_zhetrf_sp2d->arenas[PARSEC_zhetrf_sp2d_CBLK_WS_ARENA] );
309  if ( parsec_zhetrf_sp2d->arenas[PARSEC_zhetrf_sp2d_BLOK_WS_ARENA]->elem_size > 0 ) {
310  parsec_matrix_del2arena( parsec_zhetrf_sp2d->arenas[PARSEC_zhetrf_sp2d_BLOK_WS_ARENA] );
311  }
312 
313  parsec_private_memory_fini( parsec_zhetrf_sp2d->_g_p_work );
314  free( parsec_zhetrf_sp2d->_g_p_work );
315 
316  parsec_taskpool_free( taskpool );
317 }
318 
319 /**
320  *******************************************************************************
321  *
322  * @brief Perform a sparse LDL^h factorization with 1D and 2D kernels.
323  *
324  * The function performs the LDL^h factorization of a sparse hermitian matrix A.
325  * The factorization has the form
326  *
327  * \f[ A = L \times D \times L^h \f]
328  *
329  * where L is a sparse lower triangular matrix unitary on the diagonal, and D a
330  * diagonal matrix.
331  *
332  *******************************************************************************
333  *
334  * @param[inout] parsec
335  * The parsec context of the application that will run the operation.
336  *
337  * @param[inout] A
338  * Descriptor of the sparse matrix A.
339  * On exit, A is overwritten with the factorized matrix.
340  *
341  * @param[inout] sopalin_data
342  * Solver matrix information structure that will guide the algorithm.
343  *
344  *******************************************************************************
345  *
346  * @retval NULL if incorrect parameters are given.
347  * @retval The parsec taskpool describing the operation that can be
348  * enqueued in the runtime with parsec_enqueue(). It, then, needs to be
349  * destroy with parsec_zhetrf_sp2d_Destruct().
350  *
351  *******************************************************************************
352  *
353  * @sa parsec_zhetrf_sp2d_New
354  * @sa parsec_zhetrf_sp2d_Destruct
355  *
356  ******************************************************************************/
357 int
358 parsec_zhetrf_sp2d( parsec_context_t *parsec,
360  sopalin_data_t *sopalin_data )
361 {
362  parsec_taskpool_t *parsec_zhetrf_sp2d = NULL;
363  int info = 0;
364 
365  parsec_zhetrf_sp2d = parsec_zhetrf_sp2d_New( A, sopalin_data );
366 
367  if ( parsec_zhetrf_sp2d == NULL ) {
368  return -1;
369  }
370 
371  parsec_context_add_taskpool( parsec, (parsec_taskpool_t*)parsec_zhetrf_sp2d );
372  parsec_context_start( parsec );
373  parsec_context_wait( parsec );
375 
376  return info;
377 }
378 
379 /**
380  *******************************************************************************
381  *
382  * @brief Perform a sparse LDL^h factorization using PaRSEC runtime.
383  *
384  * The function performs the LDL^h factorization of a sparse hermitian matrix A.
385  * The factorization has the form
386  *
387  * \f[ A = L \times D \times L^h \f]
388  *
389  * where L is a sparse lower triangular matrix unitary on the diagonal, and D a
390  * diagonal matrix.
391  *
392  * The algorithm is automatically chosen between the 1D and 2D version based on
393  * the API parameter IPARM_TASKS2D_LEVEL. If IPARM_TASKS2D_LEVEL != 0
394  * the 2D scheme is applied, the 1D otherwise.
395  *
396  *******************************************************************************
397  *
398  * @param[inout] pastix_data
399  * The pastix_data structure that describes the solver instance.
400  *
401  * @param[inout] sopalin_data
402  * Solver matrix information structure that will guide the algorithm.
403  *
404  *******************************************************************************
405  *
406  * @sa parsec_zhetrf_sp1dplus
407  * @sa parsec_zhetrf_sp2d
408  *
409  ******************************************************************************/
410 void
412  sopalin_data_t *sopalin_data )
413 {
414  parsec_sparse_matrix_desc_t *sdesc = sopalin_data->solvmtx->parsec_desc;
415  parsec_context_t *ctx;
416 
417  /*
418  * Start PaRSEC if not already started
419  */
420  if (pastix_data->parsec == NULL) {
421  int argc = 0;
422  pastix_parsec_init( pastix_data, &argc, NULL, NULL );
423  }
424  ctx = pastix_data->parsec;
425 
426  if ( sdesc == NULL ) {
427  /* Create the matrix descriptor */
428  parsec_sparse_matrix_init( sopalin_data->solvmtx,
429  sizeof( pastix_complex64_t ), PastixHermitian,
430  pastix_data->inter_node_procnbr,
431  pastix_data->inter_node_procnum );
432  sdesc = sopalin_data->solvmtx->parsec_desc;
433  }
434 
435  /*
436  * Select 1D or 2D jdf based on 2d tasks level
437  */
438  if ( pastix_data->iparm[IPARM_TASKS2D_LEVEL] != 0 )
439  {
440  parsec_zhetrf_sp2d( ctx, sdesc,
441  sopalin_data );
442  }
443  else {
444  parsec_zhetrf_sp1dplus( ctx, sdesc,
445  sopalin_data );
446  }
447 
448  return;
449 }
450 
451 /**
452  *@}
453  */
BEGIN_C_DECLS typedef int pastix_int_t
Definition: datatypes.h:51
int parsec_zhetrf_sp2d(parsec_context_t *parsec, parsec_sparse_matrix_desc_t *A, sopalin_data_t *sopalin_data)
Perform a sparse LDL^h factorization with 1D and 2D kernels.
parsec_taskpool_t * parsec_zhetrf_sp2d_New(parsec_sparse_matrix_desc_t *A, sopalin_data_t *sopalin_data)
Generate the PaRSEC taskpool object for the LDL^h factorization with 1D and 2D kernels.
void parsec_zhetrf_sp1dplus_Destruct(parsec_taskpool_t *taskpool)
Free the data structure associated to a taskpool created with parsec_zhetrf_sp1dplus_New().
int parsec_zhetrf_sp1dplus(parsec_context_t *parsec, parsec_sparse_matrix_desc_t *A, sopalin_data_t *sopalin_data)
Perform a sparse LDL^h factorization with 1D kernels.
parsec_taskpool_t * parsec_zhetrf_sp1dplus_New(parsec_sparse_matrix_desc_t *A, sopalin_data_t *sopalin_data)
Generate the PaRSEC taskpool object for the LDL^h factorization with 1D kernels.
Definition: parsec_zhetrf.c:79
void parsec_zhetrf(pastix_data_t *pastix_data, sopalin_data_t *sopalin_data)
Perform a sparse LDL^h factorization using PaRSEC runtime.
void parsec_zhetrf_sp2d_Destruct(parsec_taskpool_t *taskpool)
Free the data structure associated to a taskpool created with parsec_zhetrf_sp2d_New().
#define PastixHermitian
Definition: api.h:460
@ PastixCompressNever
Definition: api.h:385
@ IPARM_TASKS2D_LEVEL
Definition: api.h:90
void parsec_sparse_matrix_init(SolverMatrix *solvmtx, int typesize, pastix_mtxtype_t mtxtype, int nodes, int myrank)
Generate the PaRSEC descriptor of the sparse matrix.
void pastix_parsec_init(pastix_data_t *pastix, int *argc, char **argv[], const int *bindtab)
Startup the PaRSEC runtime system.
Definition: parsec.c:61
PaRSEC descriptor stucture for the sparse matrix.
Definition: pastix_parsec.h:35
int inter_node_procnum
Definition: pastixdata.h:83
int inter_node_procnbr
Definition: pastixdata.h:82
void * parsec
Definition: pastixdata.h:86
pastix_int_t * iparm
Definition: pastixdata.h:69
Main PaStiX data structure.
Definition: pastixdata.h:67