SpM Handbook 1.2.4
Loading...
Searching...
No Matches
c_spm_print.c
Go to the documentation of this file.
1/**
2 *
3 * @file c_spm_print.c
4 *
5 * SParse Matrix package printing routines.
6 *
7 * @copyright 2016-2024 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria,
8 * Univ. Bordeaux. All rights reserved.
9 *
10 * @version 1.2.4
11 * @author Mathieu Faverge
12 * @author Alban Bellot
13 * @author Matias Hastaran
14 * @author Tony Delarue
15 * @author Alycia Lisito
16 * @date 2024-06-25
17 *
18 * @generated from /builds/2mk6rsew/0/fpruvost/spm/src/z_spm_print.c, normal z -> c, Fri Nov 29 11:34:28 2024
19 *
20 * @ingroup spm_dev_print
21 * @{
22 *
23 **/
24#include "common.h"
25
26/**
27 *******************************************************************************
28 *
29 * @brief Print a diagonal element within a symmetric/hermitian
30 * matrix with column/row major storage
31 *
32 * Note that column major is using the low triangular part only of the diagonal
33 * element matrices, and row major, by symmetry, is using only the upper
34 * triangular part.
35 *
36 * The comments in the code are made for column major storage.
37 *
38 *******************************************************************************
39 *
40 * @param[in] row
41 * TODO
42 *
43 * @param[in] dofi
44 * TODO
45 *
46 * @param[in] conjfct
47 * TODO
48 *
49 * @param[in] valptr
50 * TODO
51 *
52 * @param[inout] f
53 * TODO
54 *
55 *******************************************************************************/
56static inline void
58 spm_int_t dofi,
59 spm_cconj_fct_t conjfct,
60 const spm_complex32_t *valptr,
61 FILE *f )
62{
63 spm_int_t ii, jj;
64
65 for(jj=0; jj<dofi; jj++)
66 {
67 /* Skip unused upper triangular part */
68 for(ii=0; ii<jj; ii++) {
69 valptr++;
70 }
71
72 /* Diagonal element */
73 c_spmPrintElt( f, row + ii, row + jj, *valptr );
74 valptr++;
75
76 for(ii=jj+1; ii<dofi; ii++, valptr++)
77 {
78 /* Lower part */
79 c_spmPrintElt( f, row + ii, row + jj, *valptr );
80 /* Upper part */
81 c_spmPrintElt( f, row + jj, row + ii, conjfct(*valptr) );
82 }
83 }
84 (void)conjfct;
85}
86
87/**
88 *******************************************************************************
89 *
90 * @brief Print a general element matrix with column major storage
91 *
92 *******************************************************************************
93 *
94 * @param[in] row
95 * TODO
96 *
97 * @param[in] dofi
98 * TODO
99 *
100 * @param[in] col
101 * TODO
102 *
103 * @param[in] dofj
104 * TODO
105 *
106 * @param[in] conjfct
107 * TODO
108 *
109 * @param[in] valptr
110 * TODO
111 *
112 * @param[inout] f
113 * TODO
114 *
115 *******************************************************************************/
116static inline void
118 spm_int_t dofi,
119 spm_int_t col,
120 spm_int_t dofj,
121 spm_cconj_fct_t conjfct,
122 const spm_complex32_t *valptr,
123 FILE *f )
124{
125 spm_int_t ii, jj;
126
127 for(jj=0; jj<dofj; jj++)
128 {
129 for(ii=0; ii<dofi; ii++, valptr++)
130 {
131 c_spmPrintElt( f, row + ii, col + jj, conjfct(*valptr) );
132 }
133 }
134 (void)conjfct;
135}
136
137/**
138 *******************************************************************************
139 *
140 * @brief Print a general element matrix with row major storage
141 *
142 *******************************************************************************
143 *
144 * @param[in] row
145 * TODO
146 *
147 * @param[in] dofi
148 * TODO
149 *
150 * @param[in] col
151 * TODO
152 *
153 * @param[in] dofj
154 * TODO
155 *
156 * @param[in] conjfct
157 * TODO
158 *
159 * @param[in] valptr
160 * TODO
161 *
162 * @param[inout] f
163 * TODO
164 *
165 *******************************************************************************/
166static inline void
168 spm_int_t dofi,
169 spm_int_t col,
170 spm_int_t dofj,
171 spm_cconj_fct_t conjfct,
172 const spm_complex32_t *valptr,
173 FILE *f )
174{
175 spm_int_t ii, jj;
176
177 for(ii=0; ii<dofi; ii++)
178 {
179 for(jj=0; jj<dofj; jj++, valptr++)
180 {
181 c_spmPrintElt( f, row + ii, col + jj, conjfct(*valptr) );
182 }
183 }
184 (void)conjfct;
185}
186
187/**
188 *******************************************************************************
189 *
190 * @brief Print a general element matrix
191 *
192 *******************************************************************************
193 *
194 * @param[in] layout
195 * TODO
196 *
197 * @param[in] row
198 * TODO
199 *
200 * @param[in] dofi
201 * TODO
202 *
203 * @param[in] col
204 * TODO
205 *
206 * @param[in] dofj
207 * TODO
208 *
209 * @param[in] conjfct
210 * TODO
211 *
212 * @param[in] valptr
213 * TODO
214 *
215 * @param[inout] f
216 * TODO
217 *
218 *******************************************************************************/
219static inline void
221 spm_int_t row,
222 spm_int_t dofi,
223 spm_int_t col,
224 spm_int_t dofj,
225 const spm_cconj_fct_t conjfct,
226 const spm_complex32_t *valptr,
227 FILE *f )
228{
229 if ( layout == SpmColMajor ) {
230 c_spm_print_elt_gen_col( row, dofi, col, dofj, conjfct, valptr, f );
231 }
232 else {
233 c_spm_print_elt_gen_row( row, dofi, col, dofj, conjfct, valptr, f );
234 }
235}
236
237/**
238 *******************************************************************************
239 *
240 * @brief Print an off-diagonal element matrix in the symmetric/hermitian case
241 *
242 *******************************************************************************
243 *
244 * @param[in] layout
245 * TODO
246 *
247 * @param[in] row
248 * TODO
249 *
250 * @param[in] dofi
251 * TODO
252 *
253 * @param[in] col
254 * TODO
255 *
256 * @param[in] dofj
257 * TODO
258 *
259 * @param[in] conjfct
260 * TODO
261 *
262 * @param[in] valptr
263 * TODO
264 *
265 * @param[inout] f
266 * TODO
267 *
268 *******************************************************************************/
269static inline void
271 spm_int_t row,
272 spm_int_t dofi,
273 spm_int_t col,
274 spm_int_t dofj,
275 spm_cconj_fct_t conjfct,
276 const spm_complex32_t *valptr,
277 FILE *f )
278{
279 if ( layout == SpmColMajor ) {
280 /* A[ row, col ] */
281 c_spm_print_elt_gen_col( row, dofi, col, dofj, __spm_cid, valptr, f );
282 /*
283 * A[ col, row ] = conjf( A[ row, col ]^t )
284 * => Let's exploit the row major kernel to make it transpose
285 */
286 c_spm_print_elt_gen_row( col, dofj, row, dofi, conjfct, valptr, f );
287 }
288 else {
289 c_spm_print_elt_gen_row( row, dofi, col, dofj, __spm_cid, valptr, f );
290 c_spm_print_elt_gen_col( col, dofj, row, dofi, conjfct, valptr, f );
291 }
292}
293
294/**
295 *******************************************************************************
296 *
297 * @brief Print an element matrix
298 *
299 *******************************************************************************
300 *
301 * @param[in] mtxtype
302 * TODO
303 *
304 * @param[in] layout
305 * TODO
306 *
307 * @param[in] row
308 * TODO
309 *
310 * @param[in] dofi
311 * TODO
312 *
313 * @param[in] col
314 * TODO
315 *
316 * @param[in] dofj
317 * TODO
318 *
319 * @param[in] valptr
320 * TODO
321 *
322 * @param[inout] f
323 * TODO
324 *
325 *******************************************************************************/
326static inline void
328 spm_layout_t layout,
329 spm_int_t row,
330 spm_int_t dofi,
331 spm_int_t col,
332 spm_int_t dofj,
333 const spm_complex32_t *valptr,
334 FILE *f )
335{
336 if ( mtxtype == SpmGeneral ) {
337 c_spm_print_elt_gen( layout, row, dofi, col, dofj, __spm_cid, valptr, f );
338 }
339 else {
340 spm_cconj_fct_t conjfct;
341
342#if defined(PRECISION_c) || defined(PRECISION_z)
343 if ( mtxtype == SpmHermitian ) {
344 conjfct = __spm_cconj;
345 }
346 else
347#endif
348 {
349 conjfct = __spm_cid;
350 }
351
352 if ( row == col ) {
353 assert( dofi == dofj );
354 c_spm_print_elt_sym_diag( row, dofi, conjfct, valptr, f );
355 }
356 else {
357 c_spm_print_elt_sym_offd( layout, row, dofi, col, dofj, conjfct, valptr, f );
358 }
359 }
360}
361
362/**
363 *******************************************************************************
364 *
365 * @brief Write CSC matrix in a file
366 *
367 *******************************************************************************
368 *
369 * @param[inout] f
370 * Output file
371 *
372 * @param[in] spm
373 * The spm structure describing the matrix.
374 *
375 *******************************************************************************/
376void
378 const spmatrix_t *spm )
379{
380 spm_int_t j, k, baseval;
381 spm_int_t ig, dofi, row;
382 spm_int_t jg, dofj, col;
383 const spm_int_t *colptr, *rowptr, *dofs, *loc2glob;
384 const spm_complex32_t *valptr;
385
386 assert( spm->fmttype == SpmCSC );
387 assert( spm->flttype == SpmComplex32 );
388
389 baseval = spm->baseval;
390
391 colptr = spm->colptr;
392 rowptr = spm->rowptr;
393 valptr = (spm_complex32_t*)(spm->values);
394 dofs = spm->dofs;
395 loc2glob = spm->loc2glob;
396
397 for(j=0; j<spm->n; j++, colptr++, loc2glob++)
398 {
399 jg = spm->replicated ? j : (*loc2glob) - baseval;
400 if ( spm->dof > 0 ) {
401 dofj = spm->dof;
402 col = spm->dof * jg;
403 }
404 else {
405 dofj = dofs[jg+1] - dofs[jg];
406 col = dofs[jg] - baseval;
407 }
408
409 for(k=colptr[0]; k<colptr[1]; k++, rowptr++)
410 {
411 ig = (*rowptr - baseval);
412 if ( spm->dof > 0 ) {
413 dofi = spm->dof;
414 row = spm->dof * ig;
415 }
416 else {
417 dofi = dofs[ig+1] - dofs[ig];
418 row = dofs[ig] - baseval;
419 }
420
421 c_spm_print_elt( spm->mtxtype, spm->layout,
422 row, dofi, col, dofj, valptr, f );
423 valptr += dofi * dofj;
424 }
425 }
426 return;
427}
428
429/**
430 *******************************************************************************
431 *
432 * @brief Write CSR matrix in a file
433 *
434 *******************************************************************************
435 *
436 * @param[in] f
437 * Output file
438 *
439 * @param[in] spm
440 * The spm structure describing the matrix.
441 *
442 *******************************************************************************/
443void
445 const spmatrix_t *spm )
446{
447 spm_int_t i, k, baseval;
448 spm_int_t ig, dofi, row;
449 spm_int_t jg, dofj, col;
450 const spm_int_t *colptr;
451 const spm_int_t *rowptr;
452 const spm_int_t *dofs;
453 const spm_int_t *loc2glob;
454 const spm_complex32_t *valptr;
455
456 assert( spm->fmttype == SpmCSR );
457 assert( spm->flttype == SpmComplex32 );
458
459 baseval = spm->baseval;
460
461 colptr = spm->colptr;
462 rowptr = spm->rowptr;
463 valptr = (spm_complex32_t*)(spm->values);
464 dofs = spm->dofs;
465 loc2glob = spm->loc2glob;
466
467 for(i=0; i<spm->n; i++, rowptr++, loc2glob++)
468 {
469 ig = spm->replicated ? i : (*loc2glob) - baseval;
470 if ( spm->dof > 0 ) {
471 dofi = spm->dof;
472 row = spm->dof * ig;
473 }
474 else {
475 dofi = dofs[ig+1] - dofs[ig];
476 row = dofs[ig] - baseval;
477 }
478
479 for(k=rowptr[0]; k<rowptr[1]; k++, colptr++)
480 {
481 jg = (*colptr - baseval);
482 if ( spm->dof > 0 ) {
483 dofj = spm->dof;
484 col = spm->dof * jg;
485 }
486 else {
487 dofj = dofs[jg+1] - dofs[jg];
488 col = dofs[jg] - baseval;
489 }
490
491 c_spm_print_elt( spm->mtxtype, spm->layout,
492 row, dofi, col, dofj, valptr, f );
493 valptr += dofi * dofj;
494 }
495 }
496
497 return;
498}
499
500/**
501 *******************************************************************************
502 *
503 * @brief Write IJV matrix in a file
504 *
505 *******************************************************************************
506 *
507 * @param[in] f
508 * Output file
509 *
510 * @param[in] spm
511 * The spm structure describing the matrix.
512 *
513 *******************************************************************************/
514void
516 const spmatrix_t *spm )
517{
518 spm_int_t k, baseval;
519 spm_int_t i, dofi, row;
520 spm_int_t j, dofj, col;
521 const spm_int_t *colptr;
522 const spm_int_t *rowptr;
523 const spm_int_t *dofs;
524 const spm_complex32_t *valptr;
525
526 assert( spm->fmttype == SpmIJV );
527 assert( spm->flttype == SpmComplex32 );
528
529 baseval = spm->baseval;
530
531 colptr = spm->colptr;
532 rowptr = spm->rowptr;
533 valptr = (spm_complex32_t*)(spm->values);
534 dofs = spm->dofs;
535
536 for(k=0; k<spm->nnz; k++, rowptr++, colptr++)
537 {
538 i = *rowptr - baseval;
539 j = *colptr - baseval;
540
541 if ( spm->dof > 0 ) {
542 dofi = spm->dof;
543 row = spm->dof * i;
544 dofj = spm->dof;
545 col = spm->dof * j;
546 }
547 else {
548 dofi = dofs[i+1] - dofs[i];
549 row = dofs[i] - baseval;
550 dofj = dofs[j+1] - dofs[j];
551 col = dofs[j] - baseval;
552 }
553
554 c_spm_print_elt( spm->mtxtype, spm->layout,
555 row, dofi, col, dofj, valptr, f );
556 valptr += dofi * dofj;
557 }
558 return;
559}
560
561/**
562 *******************************************************************************
563 *
564 * @brief Write a spm matrix in a file
565 *
566 *******************************************************************************
567 *
568 * @param[in] f
569 * Output file
570 *
571 * @param[in] spm
572 * The spm structure describing the matrix.
573 *
574 *******************************************************************************/
575void
576c_spmPrint( FILE *f, const spmatrix_t *spm )
577{
578 switch (spm->fmttype) {
579 case SpmCSC:
580 c_spmCSCPrint( f, spm );
581 break;
582 case SpmCSR:
583 c_spmCSRPrint( f, spm );
584 break;
585 case SpmIJV:
586 c_spmIJVPrint( f, spm );
587 }
588 return;
589}
590
591/**
592 *******************************************************************************
593 *
594 * @brief Write into a file the vectors associated to a spm.
595 *
596 *******************************************************************************
597 *
598 * @param[inout] f
599 * Output file
600 *
601 * @param[in] spm
602 * The spm structure describing the matrix.
603 *
604 * @param[in] nrhs
605 * The number of columns of x.
606 *
607 * @param[in] x
608 * The set of vectors associated to the spm of size ldx-by-nrhs.
609 *
610 * @param[in] ldx
611 * The local leading dimension of the set of vectors (ldx >= spm->n).
612 *
613 *******************************************************************************/
614void
615c_spmPrintRHS( FILE *f, const spmatrix_t *spm,
616 int nrhs, const void *x, spm_int_t ldx )
617{
618 const spm_complex32_t *xptr = (const spm_complex32_t *)x;
619 spm_int_t i, j, ig, baseval;
620
621 baseval = spm->baseval;
622
623 for( j=0; j<nrhs; j++) {
624 for( i=0; i < spm->nexp; i++, xptr++ ) {
625 ig = spm->replicated ? i : spm->loc2glob[i] - baseval;
626
627 c_spmPrintElt( f, ig, j, *xptr );
628 }
629 xptr += ldx - i;
630 }
631}
632
633/**
634 * @}
635 */
static void c_spm_print_elt_gen_col(spm_int_t row, spm_int_t dofi, spm_int_t col, spm_int_t dofj, spm_cconj_fct_t conjfct, const spm_complex32_t *valptr, FILE *f)
Print a general element matrix with column major storage.
static void c_spm_print_elt_sym_offd(spm_layout_t layout, spm_int_t row, spm_int_t dofi, spm_int_t col, spm_int_t dofj, spm_cconj_fct_t conjfct, const spm_complex32_t *valptr, FILE *f)
Print an off-diagonal element matrix in the symmetric/hermitian case.
void c_spmCSRPrint(FILE *f, const spmatrix_t *spm)
Write CSR matrix in a file.
static void c_spm_print_elt(spm_mtxtype_t mtxtype, spm_layout_t layout, spm_int_t row, spm_int_t dofi, spm_int_t col, spm_int_t dofj, const spm_complex32_t *valptr, FILE *f)
Print an element matrix.
static void c_spm_print_elt_gen(spm_layout_t layout, spm_int_t row, spm_int_t dofi, spm_int_t col, spm_int_t dofj, const spm_cconj_fct_t conjfct, const spm_complex32_t *valptr, FILE *f)
Print a general element matrix.
void c_spmIJVPrint(FILE *f, const spmatrix_t *spm)
Write IJV matrix in a file.
static void c_spm_print_elt_sym_diag(spm_int_t row, spm_int_t dofi, spm_cconj_fct_t conjfct, const spm_complex32_t *valptr, FILE *f)
Print a diagonal element within a symmetric/hermitian matrix with column/row major storage.
Definition c_spm_print.c:57
static void c_spm_print_elt_gen_row(spm_int_t row, spm_int_t dofi, spm_int_t col, spm_int_t dofj, spm_cconj_fct_t conjfct, const spm_complex32_t *valptr, FILE *f)
Print a general element matrix with row major storage.
void c_spmCSCPrint(FILE *f, const spmatrix_t *spm)
Write CSC matrix in a file.
float _Complex spm_complex32_t
Definition datatypes.h:161
enum spm_layout_e spm_layout_t
Direction of the matrix storage.
enum spm_mtxtype_e spm_mtxtype_t
Matrix symmetry type property.
@ SpmColMajor
Definition const.h:148
@ SpmComplex32
Definition const.h:65
@ SpmGeneral
Definition const.h:165
@ SpmHermitian
Definition const.h:167
@ SpmCSC
Definition const.h:73
@ SpmCSR
Definition const.h:74
@ SpmIJV
Definition const.h:75
void c_spmPrintRHS(FILE *f, const spmatrix_t *spm, int nrhs, const void *x, spm_int_t ldx)
Write into a file the vectors associated to a spm.
void c_spmPrint(FILE *f, const spmatrix_t *spm)
Write a spm matrix in a file.
spm_coeftype_t flttype
Definition spm.h:67
spm_int_t * dofs
Definition spm.h:85
spm_int_t nexp
Definition spm.h:78
void * values
Definition spm.h:92
spm_int_t nnz
Definition spm.h:75
spm_int_t * rowptr
Definition spm.h:90
spm_fmttype_t fmttype
Definition spm.h:69
spm_int_t dof
Definition spm.h:82
spm_int_t n
Definition spm.h:73
spm_mtxtype_t mtxtype
Definition spm.h:65
spm_int_t * loc2glob
Definition spm.h:91
spm_layout_t layout
Definition spm.h:87
spm_int_t baseval
Definition spm.h:71
spm_int_t * colptr
Definition spm.h:89
int replicated
Definition spm.h:98
int spm_int_t
The main integer datatype used in spm arrays.
Definition datatypes.h:70
The sparse matrix data structure.
Definition spm.h:64
static void c_spmPrintElt(FILE *f, spm_int_t i, spm_int_t j, spm_complex32_t A)
Subroutines to print one element of an spm structure.
Definition spm.h:316