My Project
programmer's documentation
Loading...
Searching...
No Matches
cs_matrix.h
Go to the documentation of this file.
1#ifndef __CS_MATRIX_H__
2#define __CS_MATRIX_H__
3
4/*============================================================================
5 * Sparse Matrix Representation and Operations
6 *============================================================================*/
7
8/*
9 This file is part of Code_Saturne, a general-purpose CFD tool.
10
11 Copyright (C) 1998-2019 EDF S.A.
12
13 This program is free software; you can redistribute it and/or modify it under
14 the terms of the GNU General Public License as published by the Free Software
15 Foundation; either version 2 of the License, or (at your option) any later
16 version.
17
18 This program is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
21 details.
22
23 You should have received a copy of the GNU General Public License along with
24 this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
25 Street, Fifth Floor, Boston, MA 02110-1301, USA.
26*/
27
28/*----------------------------------------------------------------------------*/
29
30/*----------------------------------------------------------------------------
31 * Local headers
32 *----------------------------------------------------------------------------*/
33
34#include "cs_defs.h"
35
36#include "cs_halo.h"
37#include "cs_numbering.h"
38#include "cs_halo_perio.h"
39#include "cs_matrix_assembler.h"
40
41/*----------------------------------------------------------------------------*/
42
44
45/*============================================================================
46 * Macro definitions
47 *============================================================================*/
48
49/*============================================================================
50 * Type definitions
51 *============================================================================*/
52
53/* Matrix structure representation types */
54
55typedef enum {
56
57 CS_MATRIX_NATIVE, /* Native matrix format */
58 CS_MATRIX_CSR, /* Compressed Sparse Row storage format */
59 CS_MATRIX_CSR_SYM, /* Compressed Symmetric Sparse Row storage format */
60 CS_MATRIX_MSR, /* Modified Compressed Sparse Row storage format */
61 CS_MATRIX_N_TYPES /* Number of known matrix types */
62
64
65/* Matrix fill types (for tuning) */
66
67typedef enum {
68
69 CS_MATRIX_SCALAR, /* Simple scalar matrix */
70 CS_MATRIX_SCALAR_SYM, /* Simple scalar symmetric matrix */
71 CS_MATRIX_BLOCK_D, /* Matrix with diagonal blocks
72 (and m.I extradiagonal blocks) */
73 CS_MATRIX_BLOCK_D_66, /* Matrix with 6x6 diagonal blocks
74 (and 6.I extradiagonal blocks;
75 subcase of CS_MATRIX_BLOCK_D, allows
76 separate tuning) */
77 CS_MATRIX_BLOCK_D_SYM, /* Symmetric matrix with diagonal blocks
78 (and m.I extradiagonal blocks) */
79 CS_MATRIX_BLOCK, /* Block matrix */
80 CS_MATRIX_N_FILL_TYPES /* Number of possible matrix fill types */
81
83
84/* Structure associated with opaque matrix structure object */
85
86typedef struct _cs_matrix_structure_t cs_matrix_structure_t;
87
88/* Structure associated with opaque matrix object */
89
90typedef struct _cs_matrix_t cs_matrix_t;
91
92/* Structure associated with opaque matrix tuning results object */
93
94typedef struct _cs_matrix_variant_t cs_matrix_variant_t;
95
96/* Information structure for extraction of matrix row */
97
98typedef struct {
99
100 cs_lnum_t row_size; /*< Row size from last call */
101 cs_lnum_t buffer_size; /*< Allocated buffer size */
102 const cs_lnum_t *col_id; /*< Pointer to local column ids */
103 cs_lnum_t *_col_id; /*< Pointer to local column ids copy */
104 const cs_real_t *vals; /*< Pointer to local row values */
105 cs_real_t *_vals; /*< Pointer to local row values copy */
106
108
109/*============================================================================
110 * Global variables
111 *============================================================================*/
112
113/* Short names for matrix types */
114
115extern const char *cs_matrix_type_name[];
116
117/* Full names for matrix types */
118
119extern const char *cs_matrix_type_fullname[];
120
121/* Fill type names for matrices */
122
123extern const char *cs_matrix_fill_type_name[];
124
125/*=============================================================================
126 * Public function prototypes
127 *============================================================================*/
128
129/*----------------------------------------------------------------------------
130 * Create a matrix structure.
131 *
132 * Note that the structure created usually maps to the given existing
133 * cell global number, face -> cell connectivity arrays, and cell halo
134 * structure, so it must be destroyed before they are freed
135 * (usually along with the code's main face -> cell structure).
136 *
137 * Note that the resulting matrix structure will contain either a full or
138 * an empty main diagonal, and that the extra-diagonal structure is always
139 * symmetric (though the coefficients my not be, and we may choose a
140 * matrix format that does not exploit this symmetry). If the edges
141 * connectivity argument is NULL, the matrix will be purely diagonal.
142 *
143 * parameters:
144 * type <-- type of matrix considered
145 * have_diag <-- indicates if the diagonal structure contains nonzeroes
146 * n_rows <-- local number of rows
147 * n_cols_ext <-- number of columns + ghosts
148 * n_edges <-- local number of (undirected) graph edges
149 * edges <-- edges (symmetric row <-> column) connectivity
150 * halo <-- halo structure associated with cells, or NULL
151 * numbering <-- vectorization or thread-related numbering info, or NULL
152 *
153 * returns:
154 * pointer to created matrix structure;
155 *----------------------------------------------------------------------------*/
156
159 bool have_diag,
160 cs_lnum_t n_rows,
161 cs_lnum_t n_cols_ext,
162 cs_lnum_t n_edges,
163 const cs_lnum_2_t *edges,
164 const cs_halo_t *halo,
165 const cs_numbering_t *numbering);
166
167/*----------------------------------------------------------------------------
168 * Create a matrix structure based on a MSR connectivity definition.
169 *
170 * Only CSR and MSR formats are handled.
171 *
172 * col_id is sorted row by row during the creation of this structure.
173 *
174 * In case the property of the row index and col_id arrays are transferred
175 * to the structure, the arrays pointers passed as arguments are set to NULL,
176 * to help ensure the caller does not use the original arrays directly after
177 * this call.
178 *
179 * parameters:
180 * type <-- type of matrix considered
181 * transfer <-- transfer property of row_index and col_id
182 * if true, map them otherwise
183 * have_diag <-- indicates if the structure includes the
184 * diagonal (should be the same for all rows)
185 * n_rows <-- local number of rows
186 * n_cols_ext <-- local number of columns + ghosts
187 * row_index <-> pointer to index on rows
188 * col_id <-> pointer to array of colum ids related to the row index
189 * halo <-- halo structure for synchronization, or NULL
190 * numbering <-- vectorization or thread-related numbering info, or NULL
191 *
192 * returns:
193 * a pointer to a created matrix structure
194 *----------------------------------------------------------------------------*/
195
198 bool transfer,
199 bool have_diag,
200 cs_lnum_t n_rows,
201 cs_lnum_t n_cols_ext,
202 cs_lnum_t **row_index,
203 cs_lnum_t **col_id,
204 const cs_halo_t *halo,
205 const cs_numbering_t *numbering);
206
207/*----------------------------------------------------------------------------
208 * Create an MSR matrix structure sharing an existing connectivity definition
209 * as well as an optional edge-based definition.
210 *
211 * Note that as the structure created maps to the given existing
212 * cell global number, face -> cell connectivity arrays, and cell halo
213 * structure, it must be destroyed before they are freed
214 * (usually along with the code's main face -> cell structure).
215 *
216 * parameters:
217 * have_diag <-- indicates if the structure includes the
218 * diagonal (should be the same for all rows)
219 * direct_assembly <-- true if each value corresponds to a unique face
220 * n_rows <-- local number of rows
221 * n_cols_ext <-- local number of columns + ghosts
222 * row_index <-- pointer to index on rows
223 * col_id <-- pointer to array of colum ids related to the row index
224 * halo <-- halo structure for synchronization, or NULL
225 * numbering <-- vectorization or thread-related numbering
226 * info, or NULL
227 *
228 * returns:
229 * a pointer to a created CDO matrix structure
230 *----------------------------------------------------------------------------*/
231
234 bool direct_assmbly,
235 cs_lnum_t n_rows,
236 cs_lnum_t n_cols_ext,
237 const cs_lnum_t *row_index,
238 const cs_lnum_t *col_id,
239 const cs_halo_t *halo,
240 const cs_numbering_t *numbering);
241
242/*----------------------------------------------------------------------------*/
253/*----------------------------------------------------------------------------*/
254
258
259/*----------------------------------------------------------------------------
260 * Destroy a matrix structure.
261 *
262 * parameters:
263 * ms <-> pointer to matrix structure pointer
264 *----------------------------------------------------------------------------*/
265
266void
268
269/*----------------------------------------------------------------------------
270 * Create a matrix container using a given structure.
271 *
272 * Note that the matrix container maps to the assigned structure,
273 * so it must be destroyed before that structure.
274 *
275 * parameters:
276 * ms <-- associated matrix structure
277 *
278 * returns:
279 * pointer to created matrix structure;
280 *----------------------------------------------------------------------------*/
281
284
285/*----------------------------------------------------------------------------
286 * Create a matrix container using a given variant.
287 *
288 * If the matrix variant is incompatible with the structure, it is ignored,
289 * and defaults for that structure are used instead.
290 *
291 * parameters:
292 * ms <-- associated matrix structure
293 * mv <-- associated matrix variant
294 *
295 * returns:
296 * pointer to created matrix structure;
297 *----------------------------------------------------------------------------*/
298
301 const cs_matrix_variant_t *mv);
302
303/*----------------------------------------------------------------------------*/
314/*----------------------------------------------------------------------------*/
315
319
320/*----------------------------------------------------------------------------*/
333/*----------------------------------------------------------------------------*/
334
337
338/*----------------------------------------------------------------------------
339 * Destroy a matrix structure.
340 *
341 * In the case of a compoud matrix, sub-matrices are not destroyed.
342 *
343 * parameters:
344 * matrix <-> pointer to matrix structure pointer
345 *----------------------------------------------------------------------------*/
346
347void
349
350/*----------------------------------------------------------------------------
351 * Return type of matrix.
352 *
353 * parameters:
354 * matrix --> pointer to matrix structure
355 *----------------------------------------------------------------------------*/
356
359
360/*----------------------------------------------------------------------------
361 * Return number of columns in matrix.
362 *
363 * parameters:
364 * matrix --> pointer to matrix structure
365 *----------------------------------------------------------------------------*/
366
369
370/*----------------------------------------------------------------------------
371 * Return number of rows in matrix.
372 *
373 * parameters:
374 * matrix --> pointer to matrix structure
375 *----------------------------------------------------------------------------*/
376
379
380/*----------------------------------------------------------------------------
381 * Return number of entries in matrix.
382 *
383 * When the block size is > 1, the number reported is the number of
384 * entry blocks, not individual entries.
385 *
386 * parameters:
387 * matrix --> pointer to matrix structure
388 *----------------------------------------------------------------------------*/
389
392
393/*----------------------------------------------------------------------------
394 * Return matrix diagonal block sizes.
395 *
396 * Block sizes are defined by a array of 4 values:
397 * 0: useful block size, 1: vector block extents,
398 * 2: matrix line extents, 3: matrix line*column extents
399 *
400 * parameters:
401 * matrix <-- pointer to matrix structure
402 *
403 * returns:
404 * pointer to block sizes
405 *----------------------------------------------------------------------------*/
406
407const cs_lnum_t *
409
410/*----------------------------------------------------------------------------
411 * Return matrix extra-diagonal block sizes.
412 *
413 * Block sizes are defined by a array of 4 values:
414 * 0: useful block size, 1: vector block extents,
415 * 2: matrix line extents, 3: matrix line*column extents
416 *
417 * parameters:
418 * matrix <-- pointer to matrix structure
419 *
420 * returns:
421 * pointer to block sizes
422 *----------------------------------------------------------------------------*/
423
424const cs_lnum_t *
426
427/*----------------------------------------------------------------------------
428 * Return pointer to matrix halo structure.
429 *
430 * parameters:
431 * matrix <-- pointer to matrix structure
432 *
433 * returns:
434 * pointer to halo strucuture
435 *----------------------------------------------------------------------------*/
436
437const cs_halo_t *
439
440/*----------------------------------------------------------------------------
441 * Get matrix fill type, depending on block sizes.
442 *
443 * Block sizes are defined by an optional array of 4 values:
444 * 0: useful block size, 1: vector block extents,
445 * 2: matrix line extents, 3: matrix line*column extents
446 *
447 * parameters:
448 * symmetric <-- indicates if matrix coefficients are symmetric
449 * diag_block_size <-- block sizes for diagonal, or NULL
450 * extra_diag_block_size <-- block sizes for extra diagonal, or NULL
451 *
452 * returns:
453 * matrix fill type
454 *----------------------------------------------------------------------------*/
455
457cs_matrix_get_fill_type(bool symmetric,
458 const cs_lnum_t *diag_block_size,
459 const cs_lnum_t *extra_diag_block_size);
460
461/*----------------------------------------------------------------------------
462 * Set matrix coefficients defined relative to a "native" edge graph,
463 * sharing arrays with the caller when possible.
464 *
465 * With shared arrays, the matrix becomes unusable if the arrays passed as
466 * arguments are not be modified (its coefficients should be unset first
467 * to mark this).
468 *
469 * Depending on current options and initialization, values will be copied
470 * or simply mapped.
471 *
472 * Block sizes are defined by an optional array of 4 values:
473 * 0: useful block size, 1: vector block extents,
474 * 2: matrix line extents, 3: matrix line*column extents
475 *
476 * parameters:
477 * matrix <-> pointer to matrix structure
478 * symmetric <-- indicates if matrix coefficients are symmetric
479 * diag_block_size <-- block sizes for diagonal, or NULL
480 * extra_diag_block_size <-- block sizes for extra diagonal, or NULL
481 * n_edges <-- local number of graph edges
482 * edges <-- edges (row <-> column) connectivity
483 * da <-- diagonal values (NULL if zero)
484 * xa <-- extradiagonal values (NULL if zero)
485 * casts as:
486 * xa[n_edges] if symmetric,
487 * xa[n_edges][2] if non symmetric
488 *----------------------------------------------------------------------------*/
489
490void
492 bool symmetric,
493 const cs_lnum_t *diag_block_size,
494 const cs_lnum_t *extra_diag_block_size,
495 const cs_lnum_t n_edges,
496 const cs_lnum_2_t edges[],
497 const cs_real_t *da,
498 const cs_real_t *xa);
499
500/*----------------------------------------------------------------------------
501 * Set matrix coefficients, copying values to private arrays.
502 *
503 * With private arrays, the matrix becomes independant from the
504 * arrays passed as arguments.
505 *
506 * Block sizes are defined by an optional array of 4 values:
507 * 0: useful block size, 1: vector block extents,
508 * 2: matrix line extents, 3: matrix line*column extents
509 *
510 * parameters:
511 * matrix <-> pointer to matrix structure
512 * symmetric <-- indicates if matrix coefficients are symmetric
513 * diag_block_size <-- block sizes for diagonal, or NULL
514 * extra_diag_block_size <-- block sizes for extra diagonal, or NULL
515 * n_edges <-- local number of graph edges
516 * edges <-- edges (row <-> column) connectivity
517 * da <-- diagonal values (NULL if zero)
518 * xa <-- extradiagonal values (NULL if zero)
519 * casts as:
520 * xa[n_edges] if symmetric,
521 * xa[n_edges][2] if non symmetric
522 *----------------------------------------------------------------------------*/
523
524void
526 bool symmetric,
527 const cs_lnum_t *diag_block_size,
528 const cs_lnum_t *extra_diag_block_size,
529 const cs_lnum_t n_edges,
530 const cs_lnum_2_t edges[],
531 const cs_real_t *da,
532 const cs_real_t *xa);
533
534/*----------------------------------------------------------------------------
535 * Set matrix coefficients in an MSR format, transferring the
536 * property of those arrays to the matrix.
537 *
538 * If the matrix is also in MSR format, this avoids an extra copy.
539 * If it is in a different format, values are copied to the structure,
540 * and the original arrays freed. In any case, the arrays pointers passed as
541 * arguments are set to NULL, to help ensure the caller does not use the
542 * original arrays directly after this call.
543 *
544 * Block sizes are defined by an optional array of 4 values:
545 * 0: useful block size, 1: vector block extents,
546 * 2: matrix line extents, 3: matrix line*column extents
547 *
548 * parameters:
549 * matrix <-> pointer to matrix structure
550 * symmetric <-- indicates if matrix coefficients are symmetric
551 * diag_block_size <-- block sizes for diagonal, or NULL
552 * extra_diag_block_size <-- block sizes for extra diagonal, or NULL
553 * row_index <-- MSR row index (0 to n-1)
554 * col_id <-- MSR column id (0 to n-1)
555 * d_val <-> diagonal values (NULL if zero)
556 * x_val <-> extradiagonal values (NULL if zero)
557 *----------------------------------------------------------------------------*/
558
559void
561 bool symmetric,
562 const cs_lnum_t *diag_block_size,
563 const cs_lnum_t *extra_diag_block_size,
564 const cs_lnum_t row_index[],
565 const cs_lnum_t col_id[],
566 cs_real_t **d_val,
567 cs_real_t **x_val);
568
569/*----------------------------------------------------------------------------*/
587/*----------------------------------------------------------------------------*/
588
591 const cs_lnum_t *diag_block_size,
592 const cs_lnum_t *extra_diag_block_size);
593
594/*----------------------------------------------------------------------------
595 * Release shared matrix coefficients.
596 *
597 * Pointers to mapped coefficients are set to NULL, while
598 * coefficient copies owned by the matrix are not modified.
599 *
600 * This simply ensures the matrix does not maintain pointers
601 * to nonexistant data.
602 *
603 * parameters:
604 * matrix <-> pointer to matrix structure
605 *----------------------------------------------------------------------------*/
606
607void
609
610/*----------------------------------------------------------------------------
611 * Copy matrix diagonal values.
612 *
613 * In case of matrixes with block diagonal coefficients, only the true
614 * diagonal values are copied.
615 *
616 * parameters:
617 * matrix --> pointer to matrix structure
618 * da --> diagonal (pre-allocated, size: n_rows*block_size
619 *----------------------------------------------------------------------------*/
620
621void
623 cs_real_t *restrict da);
624
625/*----------------------------------------------------------------------------
626 * Query matrix coefficients symmetry
627 *
628 * parameters:
629 * matrix <-- pointer to matrix structure
630 *
631 * returns:
632 * true if coefficients are symmetric, false otherwise
633 *----------------------------------------------------------------------------*/
634
635bool
637
638/*----------------------------------------------------------------------------*/
651/*----------------------------------------------------------------------------*/
652
653bool
655
656/*----------------------------------------------------------------------------
657 * Get matrix diagonal values.
658 *
659 * In case of matrixes with block diagonal coefficients, a pointer to
660 * the complete block diagonal is returned.
661 *
662 * parameters:
663 * matrix --> pointer to matrix structure
664 *
665 * returns:
666 * pointer to matrix diagonal array
667 *----------------------------------------------------------------------------*/
668
669const cs_real_t *
671
672/*----------------------------------------------------------------------------
673 * Get pointer to matrix extra-diagonal values in "native" format
674 *
675 * This function currently only functions if the matrix is in "native"
676 * format or the coefficients were mapped from native coefficients using
677 * cs_matrix_set_coefficients(), in which case the pointer returned is
678 * the same as the one passed to that function.
679 *
680 * parameters:
681 * matrix --> pointer to matrix structure
682 *
683 * returns:
684 * pointer to matrix diagonal array
685 *----------------------------------------------------------------------------*/
686
687const cs_real_t *
689
690/*----------------------------------------------------------------------------
691 * Initialize row info for a given matrix.
692 *
693 * parameters:
694 * r --> row info structure
695 *----------------------------------------------------------------------------*/
696
697void
699
700/*----------------------------------------------------------------------------
701 * Finalize row info for a given matrix.
702 *
703 * parameters:
704 * r <-> row info structure
705 *----------------------------------------------------------------------------*/
706
707void
709
710/*----------------------------------------------------------------------------
711 * Get row values for a given matrix.
712 *
713 * This function may not work for all matrix types.
714 *
715 * In the case of blocked matrixes, the true (non-blocked)
716 * values are returned.
717 *
718 * The row information structure must have been previously initialized
719 * using cs_matrix_row_init(), and should be finalized using
720 * using cs_matrix_row_finalize(), so as to free buffers it may have
721 * built for certain matrix formats.
722 *
723 * parameters:
724 * matrix <-- pointer to matrix structure
725 * row_id <-- id of row to query
726 * r <-> row info structure
727 *----------------------------------------------------------------------------*/
728
729void
731 const cs_lnum_t row_id,
733
734/*----------------------------------------------------------------------------
735 * Get arrays describing a matrix in native format.
736 *
737 * This function works for matrix in native format.
738 *
739 * Matrix block sizes can be obtained by cs_matrix_get_diag_block_size()
740 * and cs_matrix_get_extra_diag_block_size().
741 *
742 * parameters:
743 * matrix <-- pointer to matrix structure
744 * symmetric --> true if symmetric
745 * n_edges --> number of associated faces
746 * edges --> edges (symmetric row <-> column) connectivity
747 * d_val --> diagonal values
748 * x_val --> extra-diagonal values
749 *----------------------------------------------------------------------------*/
750
751void
753 bool *symmetric,
754 cs_lnum_t *n_edges,
755 const cs_lnum_2_t **edges,
756 const cs_real_t **d_val,
757 const cs_real_t **x_val);
758
759/*----------------------------------------------------------------------------
760 * Get arrays describing a matrix in CSR format.
761 *
762 * This function only works for an CSR matrix (i.e. there is
763 * no automatic conversion from another matrix type).
764 *
765 * Matrix block sizes can be obtained by cs_matrix_get_diag_block_size()
766 * and cs_matrix_get_extra_diag_block_size().
767 *
768 * parameters:
769 * matrix <-- pointer to matrix structure
770 * row_index --> CSR row index
771 * col_id --> CSR column id
772 * val --> values
773 *----------------------------------------------------------------------------*/
774
775void
777 const cs_lnum_t **row_index,
778 const cs_lnum_t **col_id,
779 const cs_real_t **val);
780
781/*----------------------------------------------------------------------------
782 * Get arrays describing a matrix in MSR format.
783 *
784 * This function only works for an MSR matrix (i.e. there is
785 * no automatic conversion from another matrix type).
786 *
787 * Matrix block sizes can be obtained by cs_matrix_get_diag_block_size()
788 * and cs_matrix_get_extra_diag_block_size().
789 *
790 * parameters:
791 * matrix <-- pointer to matrix structure
792 * row_index --> MSR row index
793 * col_id --> MSR column id
794 * d_val --> diagonal values
795 * x_val --> extra-diagonal values
796 *----------------------------------------------------------------------------*/
797
798void
800 const cs_lnum_t **row_index,
801 const cs_lnum_t **col_id,
802 const cs_real_t **d_val,
803 const cs_real_t **x_val);
804
805/*----------------------------------------------------------------------------
806 * Matrix.vector product y = A.x
807 *
808 * This function includes a halo update of x prior to multiplication by A.
809 *
810 * parameters:
811 * rotation_mode --> halo update option for rotational periodicity
812 * matrix --> pointer to matrix structure
813 * x <-> multipliying vector values (ghost values updated)
814 * y --> resulting vector
815 *----------------------------------------------------------------------------*/
816
817void
819 const cs_matrix_t *matrix,
822
823/*----------------------------------------------------------------------------
824 * Matrix.vector product y = A.x with no prior halo update of x.
825 *
826 * This function does not include a halo update of x prior to multiplication
827 * by A, so it should be called only when the halo of x is known to already
828 * be up to date (in which case we avoid the performance penalty of a
829 * redundant update by using this variant of the matrix.vector product).
830 *
831 * parameters:
832 * matrix --> pointer to matrix structure
833 * x --> multipliying vector values
834 * y --> resulting vector
835 *----------------------------------------------------------------------------*/
836
837void
839 const cs_real_t *x,
841
842/*----------------------------------------------------------------------------
843 * Matrix.vector product y = (A-D).x
844 *
845 * This function includes a halo update of x prior to multiplication by A.
846 *
847 * parameters:
848 * rotation_mode <-- halo update option for rotational periodicity
849 * matrix <-- pointer to matrix structure
850 * x <-> multipliying vector values (ghost values updated)
851 * y --> resulting vector
852 *----------------------------------------------------------------------------*/
853
854void
856 const cs_matrix_t *matrix,
859
860/*----------------------------------------------------------------------------
861 * Synchronize ghost values prior to matrix.vector product
862 *
863 * parameters:
864 * rotation_mode <-- halo update option for rotational periodicity
865 * matrix <-- pointer to matrix structure
866 * x <-> multipliying vector values (ghost values updated)
867 *----------------------------------------------------------------------------*/
868
869void
871 const cs_matrix_t *matrix,
872 cs_real_t *x);
873
874/*----------------------------------------------------------------------------*/
888/*----------------------------------------------------------------------------*/
889
890void
892 const cs_lnum_t db_size[4],
893 const cs_lnum_t eb_size[4]);
894
895/*----------------------------------------------------------------------------*/
920/*----------------------------------------------------------------------------*/
921
922void
924 cs_lnum_t n,
925 cs_lnum_t stride,
926 const cs_lnum_t row_id[],
927 const cs_lnum_t col_idx[],
928 const cs_real_t vals[]);
929
930/*----------------------------------------------------------------------------*/
944/*----------------------------------------------------------------------------*/
945
946void
948 const cs_lnum_t db_size[4],
949 const cs_lnum_t eb_size[4]);
950
951/*----------------------------------------------------------------------------*/
976/*----------------------------------------------------------------------------*/
977
978void
980 cs_lnum_t n,
981 cs_lnum_t stride,
982 const cs_lnum_t row_id[],
983 const cs_lnum_t col_idx[],
984 const cs_real_t vals[]);
985
986/*----------------------------------------------------------------------------
987 * Build list of variants for tuning or testing.
988 *
989 * parameters:
990 * n_fill_types <-- number of fill types tuned for
991 * fill_types <-- array of fill types tuned for
992 * type_filter <-- true for matrix types tuned for, false for others
993 * numbering <-- vectorization or thread-related numbering info,
994 * or NULL
995 * n_variants --> number of variants
996 * m_variant --> array of matrix variants
997 *----------------------------------------------------------------------------*/
998
999void
1000cs_matrix_variant_build_list(int n_fill_types,
1001 cs_matrix_fill_type_t fill_types[],
1002 bool type_filter[],
1003 const cs_numbering_t *numbering,
1004 int *n_variants,
1005 cs_matrix_variant_t **m_variant);
1006
1007/*----------------------------------------------------------------------------
1008 * Build matrix variant
1009 *
1010 * The variant will initially use default matrix-vector functions,
1011 * which can be later modified using cs_matrix_variant_set_func().
1012 *
1013 * parameters:
1014 * type <-- type of matrix considered
1015 * numbering <-- vectorization or thread-related numbering info,
1016 * or NULL
1017 *----------------------------------------------------------------------------*/
1018
1021 const cs_numbering_t *numbering);
1022
1023/*----------------------------------------------------------------------------
1024 * Destroy a matrix variant structure.
1025 *
1026 * parameters:
1027 * mv <-> Pointer to matrix variant pointer
1028 *----------------------------------------------------------------------------*/
1029
1030void
1032
1033/*----------------------------------------------------------------------------
1034 * Select the sparse matrix-vector product function to be used by a
1035 * matrix variant for a given fill type.
1036 *
1037 * Currently, possible variant functions are:
1038 *
1039 * CS_MATRIX_NATIVE (all fill types)
1040 * standard
1041 * fixed (for CS_MATRIX_??_BLOCK_D or CS_MATRIX_??_BLOCK_D_SYM)
1042 * omp (for OpenMP with compatible numbering)
1043 * vector (For vector machine with compatible numbering)
1044 *
1045 * CS_MATRIX_CSR (for CS_MATRIX_SCALAR or CS_MATRIX_SCALAR_SYM)
1046 * standard
1047 * mkl (with MKL)
1048 *
1049 * CS_MATRIX_CSR_SYM (for CS_MATRIX_SCALAR_SYM)
1050 * standard
1051 * mkl (with MKL)
1052 *
1053 * CS_MATRIX_MSR (all fill types except CS_MATRIX_33_BLOCK)
1054 * standard
1055 * generic (for CS_MATRIX_??_BLOCK_D or CS_MATRIX_??_BLOCK_D_SYM)
1056 * mkl (with MKL, for CS_MATRIX_SCALAR or CS_MATRIX_SCALAR_SYM)
1057 *
1058 * parameters:
1059 * mv <-> pointer to matrix variant
1060 * numbering <-- mesh numbering info, or NULL
1061 * fill type <-- matrix fill type to merge from
1062 * ed_flag <-- 0: with diagonal only, 1 exclude only; 2; both
1063 * func_name <-- function type name
1064 *----------------------------------------------------------------------------*/
1065
1066void
1068 const cs_numbering_t *numbering,
1069 cs_matrix_fill_type_t fill_type,
1070 int ed_flag,
1071 const char *func_name);
1072
1073/*----------------------------------------------------------------------------
1074 * Merge a functions to a matrix variant from another variant sharing
1075 * the same structure.
1076 *
1077 * Functions from the structure to merge for the selected fill type are
1078 * assigned to the main variant.
1079 *
1080 * This can be useful when tuning has been done separately for different fill
1081 * types, and the resulting selected structure is identical.
1082 *
1083 * parameters:
1084 * mv <-> pointer to matrix variant
1085 * mv_merge <-- pointer to matrix variant to merge
1086 * fill_type <-- matrix fill type to merge from
1087 *----------------------------------------------------------------------------*/
1088
1089void
1091 const cs_matrix_variant_t *mv_merge,
1092 cs_matrix_fill_type_t fill_type);
1093
1094/*----------------------------------------------------------------------------
1095 * Get the type associated with a matrix variant.
1096 *
1097 * parameters:
1098 * mv <-- pointer to matrix variant structure
1099 *----------------------------------------------------------------------------*/
1100
1103
1104/*----------------------------------------------------------------------------
1105 * Test local matrix.vector product operations.
1106 *
1107 * parameters:
1108 * n_rows <-- number of local rows
1109 * n_cols_ext <-- number of columns + ghosts
1110 * n_edges <-- local number of (undirected) graph edges
1111 * edges <-- edges (symmetric row <-> column) connectivity
1112 * halo <-- cell halo structure
1113 * numbering <-- vectorization or thread-related numbering info, or NULL
1114 *----------------------------------------------------------------------------*/
1115
1116void
1118 cs_lnum_t n_cols_ext,
1119 cs_lnum_t n_edges,
1120 const cs_lnum_2_t *edges,
1121 const cs_halo_t *halo,
1122 const cs_numbering_t *numbering);
1123
1124/*----------------------------------------------------------------------------*/
1125
1127
1128#endif /* __CS_MATRIX_H__ */
#define restrict
Definition cs_defs.h:127
#define BEGIN_C_DECLS
Definition cs_defs.h:467
double cs_real_t
Floating-point value.
Definition cs_defs.h:302
int cs_lnum_2_t[2]
vector of 2 local mesh-entity ids
Definition cs_defs.h:308
#define END_C_DECLS
Definition cs_defs.h:468
int cs_lnum_t
local mesh entity id
Definition cs_defs.h:298
cs_halo_rotation_t
Definition cs_halo.h:60
void cs_matrix_row_finalize(cs_matrix_row_info_t *r)
Finalize row info for a given matrix.
Definition cs_matrix.c:6473
struct _cs_matrix_variant_t cs_matrix_variant_t
Definition cs_matrix.h:94
const cs_lnum_t * cs_matrix_get_diag_block_size(const cs_matrix_t *matrix)
Return matrix diagonal block sizes.
Definition cs_matrix.c:5816
bool cs_matrix_is_symmetric(const cs_matrix_t *matrix)
Query matrix coefficients symmetry.
Definition cs_matrix.c:6285
cs_matrix_t * cs_matrix_create_by_copy(cs_matrix_t *src)
Create a matrix container by copying another.
Definition cs_matrix.c:5602
cs_matrix_variant_t * cs_matrix_variant_create(cs_matrix_type_t type, const cs_numbering_t *numbering)
Build matrix variant.
Definition cs_matrix.c:7239
const cs_real_t * cs_matrix_get_diagonal(const cs_matrix_t *matrix)
Get matrix diagonal values.
Definition cs_matrix.c:6330
cs_matrix_structure_t * cs_matrix_structure_create(cs_matrix_type_t type, bool have_diag, cs_lnum_t n_rows, cs_lnum_t n_cols_ext, cs_lnum_t n_edges, const cs_lnum_2_t *edges, const cs_halo_t *halo, const cs_numbering_t *numbering)
Create a matrix structure.
Definition cs_matrix.c:5188
cs_matrix_structure_t * cs_matrix_structure_create_msr_shared(bool have_diag, bool direct_assmbly, cs_lnum_t n_rows, cs_lnum_t n_cols_ext, const cs_lnum_t *row_index, const cs_lnum_t *col_id, const cs_halo_t *halo, const cs_numbering_t *numbering)
Create an MSR matrix structure sharing an existing connectivity definition as well as an optional edg...
Definition cs_matrix.c:5370
const char * cs_matrix_type_name[]
void cs_matrix_copy_diagonal(const cs_matrix_t *matrix, cs_real_t *restrict da)
Copy matrix diagonal values.
Definition cs_matrix.c:6261
const char * cs_matrix_type_fullname[]
cs_matrix_structure_t * cs_matrix_structure_create_from_assembler(cs_matrix_type_t type, cs_matrix_assembler_t *ma)
Create a matrix structure using a matrix assembler.
Definition cs_matrix.c:5420
struct _cs_matrix_structure_t cs_matrix_structure_t
Definition cs_matrix.h:86
cs_matrix_type_t cs_matrix_variant_type(const cs_matrix_variant_t *mv)
Get the type associated with a matrix variant.
Definition cs_matrix.c:7629
struct _cs_matrix_t cs_matrix_t
Definition cs_matrix.h:90
void cs_matrix_variant_merge(cs_matrix_variant_t *mv, const cs_matrix_variant_t *mv_merge, cs_matrix_fill_type_t fill_type)
Merge a functions to a matrix variant from another variant sharing the same structure.
Definition cs_matrix.c:7603
cs_lnum_t cs_matrix_get_n_entries(const cs_matrix_t *matrix)
Return number of entries in matrix.
Definition cs_matrix.c:5761
void cs_matrix_destroy(cs_matrix_t **matrix)
Definition cs_matrix.c:5648
void cs_matrix_exdiag_vector_multiply(cs_halo_rotation_t rotation_mode, const cs_matrix_t *matrix, cs_real_t *restrict x, cs_real_t *restrict y)
Matrix.vector product y = (A-D).x.
Definition cs_matrix.c:6855
void cs_matrix_msr_assembler_values_add(void *matrix_p, cs_lnum_t n, cs_lnum_t stride, const cs_lnum_t row_id[], const cs_lnum_t col_idx[], const cs_real_t vals[])
Function pointer for addition to MSR matrix coefficients using local row ids and column indexes.
Definition cs_matrix.c:7132
void cs_matrix_variant_build_list(int n_fill_types, cs_matrix_fill_type_t fill_types[], bool type_filter[], const cs_numbering_t *numbering, int *n_variants, cs_matrix_variant_t **m_variant)
Build list of variants for tuning or testing.
Definition cs_matrix.c:7282
cs_matrix_t * cs_matrix_create(const cs_matrix_structure_t *ms)
Create a matrix container using a given structure.
Definition cs_matrix.c:5487
void cs_matrix_variant_test(cs_lnum_t n_rows, cs_lnum_t n_cols_ext, cs_lnum_t n_edges, const cs_lnum_2_t *edges, const cs_halo_t *halo, const cs_numbering_t *numbering)
Test local matrix.vector product operations.
Definition cs_matrix.c:7651
cs_matrix_t * cs_matrix_create_from_assembler(cs_matrix_type_t type, cs_matrix_assembler_t *ma)
Create a matrix directly from assembler.
Definition cs_matrix.c:5555
cs_matrix_fill_type_t cs_matrix_get_fill_type(bool symmetric, const cs_lnum_t *diag_block_size, const cs_lnum_t *extra_diag_block_size)
Get matrix fill type, depending on block sizes.
Definition cs_matrix.c:5887
void cs_matrix_get_csr_arrays(const cs_matrix_t *matrix, const cs_lnum_t **row_index, const cs_lnum_t **col_id, const cs_real_t **val)
Get arrays describing a matrix in CSR format.
Definition cs_matrix.c:6687
void cs_matrix_msr_assembler_values_init(void *matrix_p, const cs_lnum_t db_size[4], const cs_lnum_t eb_size[4])
Function for initialization of MSR matrix coefficients using local row ids and column indexes.
Definition cs_matrix.c:7064
void cs_matrix_vector_multiply(cs_halo_rotation_t rotation_mode, const cs_matrix_t *matrix, cs_real_t *restrict x, cs_real_t *restrict y)
Matrix.vector product y = A.x.
Definition cs_matrix.c:6784
void cs_matrix_csr_assembler_values_init(void *matrix_p, const cs_lnum_t db_size[4], const cs_lnum_t eb_size[4])
Function for initialization of CSR matrix coefficients using local row ids and column indexes.
Definition cs_matrix.c:6913
void cs_matrix_row_init(cs_matrix_row_info_t *r)
Initialize row info for a given matrix.
Definition cs_matrix.c:6454
void cs_matrix_get_msr_arrays(const cs_matrix_t *matrix, const cs_lnum_t **row_index, const cs_lnum_t **col_id, const cs_real_t **d_val, const cs_real_t **x_val)
Get arrays describing a matrix in MSR format.
Definition cs_matrix.c:6731
cs_matrix_fill_type_t
Definition cs_matrix.h:67
@ CS_MATRIX_BLOCK_D_66
Definition cs_matrix.h:73
@ CS_MATRIX_N_FILL_TYPES
Definition cs_matrix.h:80
@ CS_MATRIX_SCALAR
Definition cs_matrix.h:69
@ CS_MATRIX_BLOCK_D
Definition cs_matrix.h:71
@ CS_MATRIX_BLOCK
Definition cs_matrix.h:79
@ CS_MATRIX_SCALAR_SYM
Definition cs_matrix.h:70
@ CS_MATRIX_BLOCK_D_SYM
Definition cs_matrix.h:77
const char * cs_matrix_fill_type_name[]
void cs_matrix_transfer_coefficients_msr(cs_matrix_t *matrix, bool symmetric, const cs_lnum_t *diag_block_size, const cs_lnum_t *extra_diag_block_size, const cs_lnum_t row_index[], const cs_lnum_t col_id[], cs_real_t **d_val, cs_real_t **x_val)
Set matrix coefficients in an MSR format, transfering the property of those arrays to the matrix.
Definition cs_matrix.c:6081
void cs_matrix_pre_vector_multiply_sync(cs_halo_rotation_t rotation_mode, const cs_matrix_t *matrix, cs_real_t *x)
Definition cs_matrix.c:6888
const cs_halo_t * cs_matrix_get_halo(const cs_matrix_t *matrix)
Return pointer to matrix halo structure.
Definition cs_matrix.c:5860
void cs_matrix_vector_multiply_nosync(const cs_matrix_t *matrix, const cs_real_t *x, cs_real_t *restrict y)
Matrix.vector product y = A.x with no prior halo update of x.
Definition cs_matrix.c:6823
cs_matrix_structure_t * cs_matrix_structure_create_msr(cs_matrix_type_t type, bool transfer, bool have_diag, cs_lnum_t n_rows, cs_lnum_t n_cols_ext, cs_lnum_t **row_index, cs_lnum_t **col_id, const cs_halo_t *halo, const cs_numbering_t *numbering)
Create a matrix structure based on a MSR connectivity definition.
Definition cs_matrix.c:5285
void cs_matrix_variant_destroy(cs_matrix_variant_t **mv)
Destroy a matrix variant structure.
Definition cs_matrix.c:7515
const cs_lnum_t * cs_matrix_get_extra_diag_block_size(const cs_matrix_t *matrix)
Return matrix extra-diagonal block sizes.
Definition cs_matrix.c:5840
cs_matrix_type_t
Definition cs_matrix.h:55
@ CS_MATRIX_CSR
Definition cs_matrix.h:58
@ CS_MATRIX_MSR
Definition cs_matrix.h:60
@ CS_MATRIX_CSR_SYM
Definition cs_matrix.h:59
@ CS_MATRIX_N_TYPES
Definition cs_matrix.h:61
@ CS_MATRIX_NATIVE
Definition cs_matrix.h:57
bool cs_matrix_is_mapped_from_native(const cs_matrix_t *matrix)
Indicate whether coefficients were mapped from native face-based arrays.
Definition cs_matrix.c:6306
void cs_matrix_copy_coefficients(cs_matrix_t *matrix, bool symmetric, const cs_lnum_t *diag_block_size, const cs_lnum_t *extra_diag_block_size, const cs_lnum_t n_edges, const cs_lnum_2_t edges[], const cs_real_t *da, const cs_real_t *xa)
Set matrix coefficients, copying values to private arrays.
Definition cs_matrix.c:6021
void cs_matrix_csr_assembler_values_add(void *matrix_p, cs_lnum_t n, cs_lnum_t stride, const cs_lnum_t row_id[], const cs_lnum_t col_idx[], const cs_real_t vals[])
Function pointer for addition to CSR matrix coefficients using local row ids and column indexes.
Definition cs_matrix.c:6972
cs_matrix_t * cs_matrix_create_by_variant(const cs_matrix_structure_t *ms, const cs_matrix_variant_t *mv)
Create a matrix container using a given variant.
Definition cs_matrix.c:5520
cs_matrix_assembler_values_t * cs_matrix_assembler_values_init(cs_matrix_t *matrix, const cs_lnum_t *diag_block_size, const cs_lnum_t *extra_diag_block_size)
Create and initialize a CSR matrix assembler values structure.
Definition cs_matrix.c:6196
void cs_matrix_release_coefficients(cs_matrix_t *matrix)
Release shared matrix coefficients.
Definition cs_matrix.c:6152
void cs_matrix_get_row(const cs_matrix_t *matrix, const cs_lnum_t row_id, cs_matrix_row_info_t *r)
Get row values for a given matrix.
Definition cs_matrix.c:6504
cs_matrix_type_t cs_matrix_get_type(const cs_matrix_t *matrix)
Return matrix type.
Definition cs_matrix.c:5707
cs_lnum_t cs_matrix_get_n_rows(const cs_matrix_t *matrix)
Return number of rows in matrix.
Definition cs_matrix.c:5741
void cs_matrix_structure_destroy(cs_matrix_structure_t **ms)
Destroy a matrix structure.
Definition cs_matrix.c:5459
cs_lnum_t cs_matrix_get_n_columns(const cs_matrix_t *matrix)
Return number of columns in a matrix.
Definition cs_matrix.c:5724
void cs_matrix_variant_set_func(cs_matrix_variant_t *mv, const cs_numbering_t *numbering, cs_matrix_fill_type_t fill_type, int ed_flag, const char *func_name)
Select the sparse matrix-vector product function to be used by a matrix variant for a given fill type...
Definition cs_matrix.c:7557
void cs_matrix_get_native_arrays(const cs_matrix_t *matrix, bool *symmetric, cs_lnum_t *n_edges, const cs_lnum_2_t **edges, const cs_real_t **d_val, const cs_real_t **x_val)
Get arrays describing a matrix in native format.
Definition cs_matrix.c:6633
const cs_real_t * cs_matrix_get_extra_diagonal(const cs_matrix_t *matrix)
Get pointer to matrix extra-diagonal values in "native" format.
Definition cs_matrix.c:6430
void cs_matrix_set_coefficients(cs_matrix_t *matrix, bool symmetric, const cs_lnum_t *diag_block_size, const cs_lnum_t *extra_diag_block_size, const cs_lnum_t n_edges, const cs_lnum_2_t edges[], const cs_real_t *da, const cs_real_t *xa)
Set matrix coefficients defined relative to a "native" edge graph, sharing arrays with the caller whe...
Definition cs_matrix.c:5957
struct _cs_matrix_assembler_t cs_matrix_assembler_t
Definition cs_matrix_assembler.h:61
struct _cs_matrix_assembler_values_t cs_matrix_assembler_values_t
Definition cs_matrix_assembler.h:65
void matrix(const int *iconvp, const int *idiffp, const int *ndircp, const int *isym, const cs_real_t *thetap, const int *imucpp, const cs_real_t coefbp[], const cs_real_t cofbfp[], const cs_real_t rovsdt[], const cs_real_t i_massflux[], const cs_real_t b_massflux[], const cs_real_t i_visc[], const cs_real_t b_visc[], const cs_real_t xcpp[], cs_real_t da[], cs_real_t xa[])
Definition cs_matrix_building.c:111
Definition cs_halo.h:71
Definition cs_matrix.h:98
cs_lnum_t buffer_size
Definition cs_matrix.h:101
cs_real_t * _vals
Definition cs_matrix.h:105
const cs_lnum_t * col_id
Definition cs_matrix.h:102
cs_lnum_t * _col_id
Definition cs_matrix.h:103
cs_lnum_t row_size
Definition cs_matrix.h:100
const cs_real_t * vals
Definition cs_matrix.h:104
Definition cs_numbering.h:83