7.0
general documentation
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-2021 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 
55 typedef enum {
56 
68 
69 /* Matrix fill types (for tuning) */
70 
71 typedef enum {
72 
73  CS_MATRIX_SCALAR, /* Simple scalar matrix */
74  CS_MATRIX_SCALAR_SYM, /* Simple scalar symmetric matrix */
75  CS_MATRIX_BLOCK_D, /* Matrix with diagonal blocks
76  (and m.I extradiagonal blocks) */
77  CS_MATRIX_BLOCK_D_66, /* Matrix with 6x6 diagonal blocks
78  (and 6.I extradiagonal blocks;
79  subcase of CS_MATRIX_BLOCK_D, allows
80  separate tuning) */
81  CS_MATRIX_BLOCK_D_SYM, /* Symmetric matrix with diagonal blocks
82  (and m.I extradiagonal blocks) */
83  CS_MATRIX_BLOCK, /* Block matrix */
84  CS_MATRIX_N_FILL_TYPES /* Number of possible matrix fill types */
85 
87 
88 /* Structure associated with opaque matrix structure object */
89 
90 typedef struct _cs_matrix_structure_t cs_matrix_structure_t;
91 
92 /* Structure associated with opaque matrix object */
93 
94 typedef struct _cs_matrix_t cs_matrix_t;
95 
96 /* Structure associated with opaque matrix tuning results object */
97 
98 typedef struct _cs_matrix_variant_t cs_matrix_variant_t;
99 
100 /* Information structure for extraction of matrix row */
101 
102 typedef struct {
103 
104  cs_lnum_t row_size; /*< Row size from last call */
105  cs_lnum_t buffer_size; /*< Allocated buffer size */
106  const cs_lnum_t *col_id; /*< Pointer to local column ids */
107  cs_lnum_t *_col_id; /*< Pointer to local column ids copy */
108  const cs_real_t *vals; /*< Pointer to local row values */
109  cs_real_t *_vals; /*< Pointer to local row values copy */
110 
112 
113 /*============================================================================
114  * Global variables
115  *============================================================================*/
116 
117 /* Short names for matrix types */
118 
119 extern const char *cs_matrix_type_name[];
120 
121 /* Full names for matrix types */
122 
123 extern const char *cs_matrix_type_fullname[];
124 
125 /* Fill type names for matrices */
126 
127 extern const char *cs_matrix_fill_type_name[];
128 
129 /*=============================================================================
130  * Public function prototypes
131  *============================================================================*/
132 
133 /*----------------------------------------------------------------------------
134  * Create a matrix structure.
135  *
136  * Note that the structure created usually maps to the given existing
137  * cell global number, face -> cell connectivity arrays, and cell halo
138  * structure, so it must be destroyed before they are freed
139  * (usually along with the code's main face -> cell structure).
140  *
141  * Note that the resulting matrix structure will contain either a full or
142  * an empty main diagonal, and that the extra-diagonal structure is always
143  * symmetric (though the coefficients my not be, and we may choose a
144  * matrix format that does not exploit this symmetry). If the edges
145  * connectivity argument is NULL, the matrix will be purely diagonal.
146  *
147  * parameters:
148  * type <-- type of matrix considered
149  * have_diag <-- indicates if the diagonal structure contains nonzeroes
150  * n_rows <-- local number of rows
151  * n_cols_ext <-- number of columns + ghosts
152  * n_edges <-- local number of (undirected) graph edges
153  * edges <-- edges (symmetric row <-> column) connectivity
154  * halo <-- halo structure associated with cells, or NULL
155  * numbering <-- vectorization or thread-related numbering info, or NULL
156  *
157  * returns:
158  * pointer to created matrix structure;
159  *----------------------------------------------------------------------------*/
160 
163  bool have_diag,
164  cs_lnum_t n_rows,
165  cs_lnum_t n_cols_ext,
166  cs_lnum_t n_edges,
167  const cs_lnum_2_t *edges,
168  const cs_halo_t *halo,
169  const cs_numbering_t *numbering);
170 
171 /*----------------------------------------------------------------------------
172  * Create a matrix structure based on a MSR connectivity definition.
173  *
174  * Only CSR and MSR formats are handled.
175  *
176  * col_id is sorted row by row during the creation of this structure.
177  *
178  * In case the property of the row index and col_id arrays are transferred
179  * to the structure, the arrays pointers passed as arguments are set to NULL,
180  * to help ensure the caller does not use the original arrays directly after
181  * this call.
182  *
183  * parameters:
184  * type <-- type of matrix considered
185  * transfer <-- transfer property of row_index and col_id
186  * if true, map them otherwise
187  * have_diag <-- indicates if the structure includes the
188  * diagonal (should be the same for all rows)
189  * n_rows <-- local number of rows
190  * n_cols_ext <-- local number of columns + ghosts
191  * row_index <-> pointer to index on rows
192  * col_id <-> pointer to array of colum ids related to the row index
193  * halo <-- halo structure for synchronization, or NULL
194  * numbering <-- vectorization or thread-related numbering info, or NULL
195  *
196  * returns:
197  * a pointer to a created matrix structure
198  *----------------------------------------------------------------------------*/
199 
202  bool transfer,
203  bool have_diag,
204  cs_lnum_t n_rows,
205  cs_lnum_t n_cols_ext,
206  cs_lnum_t **row_index,
207  cs_lnum_t **col_id,
208  const cs_halo_t *halo,
209  const cs_numbering_t *numbering);
210 
211 /*----------------------------------------------------------------------------
212  * Create an MSR matrix structure sharing an existing connectivity definition.
213  *
214  * Note that as the structure created maps to the given existing
215  * cell global number, face -> cell connectivity arrays, and cell halo
216  * structure, it must be destroyed before they are freed
217  * (usually along with the code's main face -> cell structure).
218  *
219  * parameters:
220  * have_diag <-- indicates if the structure includes the
221  * diagonal (should be the same for all rows)
222  * direct_assembly <-- true if each value corresponds to a unique face
223  * n_rows <-- local number of rows
224  * n_cols_ext <-- local number of columns + ghosts
225  * row_index <-- pointer to index on rows
226  * col_id <-- pointer to array of colum ids related to the row index
227  * halo <-- halo structure for synchronization, or NULL
228  * numbering <-- vectorization or thread-related numbering
229  * info, or NULL
230  *
231  * returns:
232  * a pointer to a created matrix structure
233  *----------------------------------------------------------------------------*/
234 
237  bool direct_assmbly,
238  cs_lnum_t n_rows,
239  cs_lnum_t n_cols_ext,
240  const cs_lnum_t *row_index,
241  const cs_lnum_t *col_id,
242  const cs_halo_t *halo,
243  const cs_numbering_t *numbering);
244 
245 /*----------------------------------------------------------------------------*/
256 /*----------------------------------------------------------------------------*/
257 
261 
262 /*----------------------------------------------------------------------------
263  * Destroy a matrix structure.
264  *
265  * parameters:
266  * ms <-> pointer to matrix structure pointer
267  *----------------------------------------------------------------------------*/
268 
269 void
271 
272 /*----------------------------------------------------------------------------
273  * Create a matrix container using a given structure.
274  *
275  * Note that the matrix container maps to the assigned structure,
276  * so it must be destroyed before that structure.
277  *
278  * parameters:
279  * ms <-- associated matrix structure
280  *
281  * returns:
282  * pointer to created matrix structure;
283  *----------------------------------------------------------------------------*/
284 
285 cs_matrix_t *
287 
288 /*----------------------------------------------------------------------------*/
299 /*----------------------------------------------------------------------------*/
300 
301 cs_matrix_t *
304 
305 /*----------------------------------------------------------------------------*/
318 /*----------------------------------------------------------------------------*/
319 
320 cs_matrix_t *
322 
323 /*----------------------------------------------------------------------------*/
335 /*----------------------------------------------------------------------------*/
336 
337 cs_matrix_t *
339 
340 /*----------------------------------------------------------------------------
341  * Destroy a matrix structure.
342  *
343  * In the case of a compoud matrix, sub-matrices are not destroyed.
344  *
345  * parameters:
346  * matrix <-> pointer to matrix structure pointer
347  *----------------------------------------------------------------------------*/
348 
349 void
351 
352 /*----------------------------------------------------------------------------
353  * Return type of matrix.
354  *
355  * parameters:
356  * matrix --> pointer to matrix structure
357  *----------------------------------------------------------------------------*/
358 
361 
362 /*----------------------------------------------------------------------------
363  * Return number of columns in matrix.
364  *
365  * parameters:
366  * matrix --> pointer to matrix structure
367  *----------------------------------------------------------------------------*/
368 
369 cs_lnum_t
371 
372 /*----------------------------------------------------------------------------
373  * Return number of rows in matrix.
374  *
375  * parameters:
376  * matrix --> pointer to matrix structure
377  *----------------------------------------------------------------------------*/
378 
379 cs_lnum_t
381 
382 /*----------------------------------------------------------------------------
383  * Return number of entries in matrix.
384  *
385  * When the block size is > 1, the number reported is the number of
386  * entry blocks, not individual entries.
387  *
388  * parameters:
389  * matrix --> pointer to matrix structure
390  *----------------------------------------------------------------------------*/
391 
392 cs_lnum_t
394 
395 /*----------------------------------------------------------------------------
396  * Return matrix diagonal block sizes.
397  *
398  * Block sizes are defined by a array of 4 values:
399  * 0: useful block size, 1: vector block extents,
400  * 2: matrix line extents, 3: matrix line*column extents
401  *
402  * parameters:
403  * matrix <-- pointer to matrix structure
404  *
405  * returns:
406  * pointer to block sizes
407  *----------------------------------------------------------------------------*/
408 
409 const cs_lnum_t *
411 
412 /*----------------------------------------------------------------------------
413  * Return matrix extra-diagonal block sizes.
414  *
415  * Block sizes are defined by a array of 4 values:
416  * 0: useful block size, 1: vector block extents,
417  * 2: matrix line extents, 3: matrix line*column extents
418  *
419  * parameters:
420  * matrix <-- pointer to matrix structure
421  *
422  * returns:
423  * pointer to block sizes
424  *----------------------------------------------------------------------------*/
425 
426 const cs_lnum_t *
428 
429 /*----------------------------------------------------------------------------
430  * Return pointer to matrix halo structure.
431  *
432  * parameters:
433  * matrix <-- pointer to matrix structure
434  *
435  * returns:
436  * pointer to halo strucuture
437  *----------------------------------------------------------------------------*/
438 
439 const cs_halo_t *
441 
442 /*----------------------------------------------------------------------------
443  * Get matrix fill type, depending on block sizes.
444  *
445  * Block sizes are defined by an optional array of 4 values:
446  * 0: useful block size, 1: vector block extents,
447  * 2: matrix line extents, 3: matrix line*column extents
448  *
449  * parameters:
450  * symmetric <-- indicates if matrix coefficients are symmetric
451  * diag_block_size <-- block sizes for diagonal, or NULL
452  * extra_diag_block_size <-- block sizes for extra diagonal, or NULL
453  *
454  * returns:
455  * matrix fill type
456  *----------------------------------------------------------------------------*/
457 
459 cs_matrix_get_fill_type(bool symmetric,
460  const cs_lnum_t *diag_block_size,
461  const cs_lnum_t *extra_diag_block_size);
462 
463 /*----------------------------------------------------------------------------
464  * Set matrix coefficients defined relative to a "native" edge graph,
465  * sharing arrays with the caller when possible.
466  *
467  * With shared arrays, the matrix becomes unusable if the arrays passed as
468  * arguments are not be modified (its coefficients should be unset first
469  * to mark this).
470  *
471  * Depending on current options and initialization, values will be copied
472  * or simply mapped.
473  *
474  * Block sizes are defined by an optional array of 4 values:
475  * 0: useful block size, 1: vector block extents,
476  * 2: matrix line extents, 3: matrix line*column extents
477  *
478  * parameters:
479  * matrix <-> pointer to matrix structure
480  * symmetric <-- indicates if matrix coefficients are symmetric
481  * diag_block_size <-- block sizes for diagonal, or NULL
482  * extra_diag_block_size <-- block sizes for extra diagonal, or NULL
483  * n_edges <-- local number of graph edges
484  * edges <-- edges (row <-> column) connectivity
485  * da <-- diagonal values (NULL if zero)
486  * xa <-- extradiagonal values (NULL if zero)
487  * casts as:
488  * xa[n_edges] if symmetric,
489  * xa[n_edges][2] if non symmetric
490  *----------------------------------------------------------------------------*/
491 
492 void
494  bool symmetric,
495  const cs_lnum_t *diag_block_size,
496  const cs_lnum_t *extra_diag_block_size,
497  const cs_lnum_t n_edges,
498  const cs_lnum_2_t edges[],
499  const cs_real_t *da,
500  const cs_real_t *xa);
501 
502 /*----------------------------------------------------------------------------
503  * Set matrix coefficients, copying values to private arrays.
504  *
505  * With private arrays, the matrix becomes independant from the
506  * arrays passed as arguments.
507  *
508  * Block sizes are defined by an optional array of 4 values:
509  * 0: useful block size, 1: vector block extents,
510  * 2: matrix line extents, 3: matrix line*column extents
511  *
512  * parameters:
513  * matrix <-> pointer to matrix structure
514  * symmetric <-- indicates if matrix coefficients are symmetric
515  * diag_block_size <-- block sizes for diagonal, or NULL
516  * extra_diag_block_size <-- block sizes for extra diagonal, or NULL
517  * n_edges <-- local number of graph edges
518  * edges <-- edges (row <-> column) connectivity
519  * da <-- diagonal values (NULL if zero)
520  * xa <-- extradiagonal values (NULL if zero)
521  * casts as:
522  * xa[n_edges] if symmetric,
523  * xa[n_edges][2] if non symmetric
524  *----------------------------------------------------------------------------*/
525 
526 void
528  bool symmetric,
529  const cs_lnum_t *diag_block_size,
530  const cs_lnum_t *extra_diag_block_size,
531  const cs_lnum_t n_edges,
532  const cs_lnum_2_t edges[],
533  const cs_real_t *da,
534  const cs_real_t *xa);
535 
536 /*----------------------------------------------------------------------------
537  * Set matrix coefficients in an MSR format, transferring the
538  * property of those arrays to the matrix.
539  *
540  * If the matrix is also in MSR format, this avoids an extra copy.
541  * If it is in a different format, values are copied to the structure,
542  * and the original arrays freed. In any case, the arrays pointers passed as
543  * arguments are set to NULL, to help ensure the caller does not use the
544  * original arrays directly after this call.
545  *
546  * Block sizes are defined by an optional array of 4 values:
547  * 0: useful block size, 1: vector block extents,
548  * 2: matrix line extents, 3: matrix line*column extents
549  *
550  * parameters:
551  * matrix <-> pointer to matrix structure
552  * symmetric <-- indicates if matrix coefficients are symmetric
553  * diag_block_size <-- block sizes for diagonal, or NULL
554  * extra_diag_block_size <-- block sizes for extra diagonal, or NULL
555  * row_index <-- MSR row index (0 to n-1)
556  * col_id <-- MSR column id (0 to n-1)
557  * d_val <-> diagonal values (NULL if zero)
558  * x_val <-> extradiagonal values (NULL if zero)
559  *----------------------------------------------------------------------------*/
560 
561 void
563  bool symmetric,
564  const cs_lnum_t *diag_block_size,
565  const cs_lnum_t *extra_diag_block_size,
566  const cs_lnum_t row_index[],
567  const cs_lnum_t col_id[],
568  cs_real_t **d_val,
569  cs_real_t **x_val);
570 
571 /*----------------------------------------------------------------------------*/
589 /*----------------------------------------------------------------------------*/
590 
593  const cs_lnum_t *diag_block_size,
594  const cs_lnum_t *extra_diag_block_size);
595 
596 /*----------------------------------------------------------------------------
597  * Release shared matrix coefficients.
598  *
599  * Pointers to mapped coefficients are set to NULL, while
600  * coefficient copies owned by the matrix are not modified.
601  *
602  * This simply ensures the matrix does not maintain pointers
603  * to nonexistant data.
604  *
605  * parameters:
606  * matrix <-> pointer to matrix structure
607  *----------------------------------------------------------------------------*/
608 
609 void
611 
612 /*----------------------------------------------------------------------------
613  * Copy matrix diagonal values.
614  *
615  * In case of matrixes with block diagonal coefficients, only the true
616  * diagonal values are copied.
617  *
618  * parameters:
619  * matrix --> pointer to matrix structure
620  * da --> diagonal (pre-allocated, size: n_rows*block_size
621  *----------------------------------------------------------------------------*/
622 
623 void
625  cs_real_t *restrict da);
626 
627 /*----------------------------------------------------------------------------
628  * Query matrix coefficients symmetry
629  *
630  * parameters:
631  * matrix <-- pointer to matrix structure
632  *
633  * returns:
634  * true if coefficients are symmetric, false otherwise
635  *----------------------------------------------------------------------------*/
636 
637 bool
639 
640 /*----------------------------------------------------------------------------*/
653 /*----------------------------------------------------------------------------*/
654 
655 bool
657 
658 /*----------------------------------------------------------------------------
659  * Get matrix diagonal values.
660  *
661  * In case of matrixes with block diagonal coefficients, a pointer to
662  * the complete block diagonal is returned.
663  *
664  * parameters:
665  * matrix --> pointer to matrix structure
666  *
667  * returns:
668  * pointer to matrix diagonal array
669  *----------------------------------------------------------------------------*/
670 
671 const cs_real_t *
673 
674 /*----------------------------------------------------------------------------
675  * Get pointer to matrix extra-diagonal values in "native" format
676  *
677  * This function currently only functions if the matrix is in "native"
678  * format or the coefficients were mapped from native coefficients using
679  * cs_matrix_set_coefficients(), in which case the pointer returned is
680  * the same as the one passed to that function.
681  *
682  * parameters:
683  * matrix --> pointer to matrix structure
684  *
685  * returns:
686  * pointer to matrix diagonal array
687  *----------------------------------------------------------------------------*/
688 
689 const cs_real_t *
691 
692 /*----------------------------------------------------------------------------
693  * Initialize row info for a given matrix.
694  *
695  * parameters:
696  * r --> row info structure
697  *----------------------------------------------------------------------------*/
698 
699 void
701 
702 /*----------------------------------------------------------------------------
703  * Finalize row info for a given matrix.
704  *
705  * parameters:
706  * r <-> row info structure
707  *----------------------------------------------------------------------------*/
708 
709 void
711 
712 /*----------------------------------------------------------------------------
713  * Get row values for a given matrix.
714  *
715  * This function may not work for all matrix types.
716  *
717  * In the case of blocked matrixes, the true (non-blocked)
718  * values are returned.
719  *
720  * The row information structure must have been previously initialized
721  * using cs_matrix_row_init(), and should be finalized using
722  * using cs_matrix_row_finalize(), so as to free buffers it may have
723  * built for certain matrix formats.
724  *
725  * parameters:
726  * matrix <-- pointer to matrix structure
727  * row_id <-- id of row to query
728  * r <-> row info structure
729  *----------------------------------------------------------------------------*/
730 
731 void
733  const cs_lnum_t row_id,
735 
736 /*----------------------------------------------------------------------------
737  * Get arrays describing a matrix in native format.
738  *
739  * This function works for matrix in native format.
740  *
741  * Matrix block sizes can be obtained by cs_matrix_get_diag_block_size()
742  * and cs_matrix_get_extra_diag_block_size().
743  *
744  * parameters:
745  * matrix <-- pointer to matrix structure
746  * symmetric --> true if symmetric
747  * n_edges --> number of associated faces
748  * edges --> edges (symmetric row <-> column) connectivity
749  * d_val --> diagonal values
750  * x_val --> extra-diagonal values
751  *----------------------------------------------------------------------------*/
752 
753 void
755  bool *symmetric,
756  cs_lnum_t *n_edges,
757  const cs_lnum_2_t **edges,
758  const cs_real_t **d_val,
759  const cs_real_t **x_val);
760 
761 /*----------------------------------------------------------------------------
762  * Get arrays describing a matrix in CSR format.
763  *
764  * This function only works for an CSR matrix (i.e. there is
765  * no automatic conversion from another matrix type).
766  *
767  * Matrix block sizes can be obtained by cs_matrix_get_diag_block_size()
768  * and cs_matrix_get_extra_diag_block_size().
769  *
770  * parameters:
771  * matrix <-- pointer to matrix structure
772  * row_index --> CSR row index
773  * col_id --> CSR column id
774  * val --> values
775  *----------------------------------------------------------------------------*/
776 
777 void
779  const cs_lnum_t **row_index,
780  const cs_lnum_t **col_id,
781  const cs_real_t **val);
782 
783 /*----------------------------------------------------------------------------
784  * Get arrays describing a matrix in MSR format.
785  *
786  * This function only works for an MSR matrix (i.e. there is
787  * no automatic conversion from another matrix type).
788  *
789  * Matrix block sizes can be obtained by cs_matrix_get_diag_block_size()
790  * and cs_matrix_get_extra_diag_block_size().
791  *
792  * parameters:
793  * matrix <-- pointer to matrix structure
794  * row_index --> MSR row index
795  * col_id --> MSR column id
796  * d_val --> diagonal values
797  * x_val --> extra-diagonal values
798  *----------------------------------------------------------------------------*/
799 
800 void
802  const cs_lnum_t **row_index,
803  const cs_lnum_t **col_id,
804  const cs_real_t **d_val,
805  const cs_real_t **x_val);
806 
807 /*----------------------------------------------------------------------------
808  * Assign functions based on a variant to a given matrix.
809  *
810  * If the matrix variant is incompatible with the structure, it is ignored,
811  * and defaults for that structure are used instead.
812  *
813  * parameters:
814  * m <-> associated matrix structure
815  * mv <-- associated matrix variant
816  *
817  * returns:
818  * pointer to created matrix structure;
819  *----------------------------------------------------------------------------*/
820 
821 void
823  const cs_matrix_variant_t *mv);
824 
825 /*----------------------------------------------------------------------------
826  * Matrix.vector product y = A.x
827  *
828  * This function includes a halo update of x prior to multiplication by A.
829  *
830  * parameters:
831  * rotation_mode --> halo update option for rotational periodicity
832  * matrix --> pointer to matrix structure
833  * x <-> multipliying vector values (ghost values updated)
834  * y --> resulting vector
835  *----------------------------------------------------------------------------*/
836 
837 void
839  const cs_matrix_t *matrix,
840  cs_real_t *restrict x,
841  cs_real_t *restrict y);
842 
843 /*----------------------------------------------------------------------------
844  * Matrix.vector product y = A.x with no prior halo update of x.
845  *
846  * This function does not include a halo update of x prior to multiplication
847  * by A, so it should be called only when the halo of x is known to already
848  * be up to date (in which case we avoid the performance penalty of a
849  * redundant update by using this variant of the matrix.vector product).
850  *
851  * parameters:
852  * matrix --> pointer to matrix structure
853  * x --> multipliying vector values
854  * y --> resulting vector
855  *----------------------------------------------------------------------------*/
856 
857 void
859  const cs_real_t *x,
860  cs_real_t *restrict y);
861 
862 /*----------------------------------------------------------------------------
863  * Matrix.vector product y = (A-D).x
864  *
865  * This function includes a halo update of x prior to multiplication by A.
866  *
867  * parameters:
868  * rotation_mode <-- halo update option for rotational periodicity
869  * matrix <-- pointer to matrix structure
870  * x <-> multipliying vector values (ghost values updated)
871  * y --> resulting vector
872  *----------------------------------------------------------------------------*/
873 
874 void
876  const cs_matrix_t *matrix,
877  cs_real_t *restrict x,
878  cs_real_t *restrict y);
879 
880 /*----------------------------------------------------------------------------
881  * Synchronize ghost values prior to matrix.vector product
882  *
883  * parameters:
884  * rotation_mode <-- halo update option for rotational periodicity
885  * matrix <-- pointer to matrix structure
886  * x <-> multipliying vector values (ghost values updated)
887  *----------------------------------------------------------------------------*/
888 
889 void
891  const cs_matrix_t *matrix,
892  cs_real_t *x);
893 
894 /*----------------------------------------------------------------------------*/
908 /*----------------------------------------------------------------------------*/
909 
910 void
912  const cs_lnum_t db_size[4],
913  const cs_lnum_t eb_size[4]);
914 
915 /*----------------------------------------------------------------------------*/
940 /*----------------------------------------------------------------------------*/
941 
942 void
944  cs_lnum_t n,
945  cs_lnum_t stride,
946  const cs_lnum_t row_id[],
947  const cs_lnum_t col_idx[],
948  const cs_real_t vals[]);
949 
950 /*----------------------------------------------------------------------------*/
964 /*----------------------------------------------------------------------------*/
965 
966 void
968  const cs_lnum_t db_size[4],
969  const cs_lnum_t eb_size[4]);
970 
971 /*----------------------------------------------------------------------------*/
996 /*----------------------------------------------------------------------------*/
997 
998 void
1000  cs_lnum_t n,
1001  cs_lnum_t stride,
1002  const cs_lnum_t row_id[],
1003  const cs_lnum_t col_idx[],
1004  const cs_real_t vals[]);
1005 
1006 /*----------------------------------------------------------------------------*/
1017 /*----------------------------------------------------------------------------*/
1018 
1019 void
1021  int *n_variants,
1022  cs_matrix_variant_t **m_variant);
1023 
1024 /*----------------------------------------------------------------------------*/
1033 /*----------------------------------------------------------------------------*/
1034 
1037 
1038 /*----------------------------------------------------------------------------
1039  * Destroy a matrix variant structure.
1040  *
1041  * parameters:
1042  * mv <-> Pointer to matrix variant pointer
1043  *----------------------------------------------------------------------------*/
1044 
1045 void
1047 
1048 /*----------------------------------------------------------------------------*/
1055 /*----------------------------------------------------------------------------*/
1056 
1057 void
1059  cs_matrix_variant_t *mv);
1060 
1061 /*----------------------------------------------------------------------------
1062  * Select the sparse matrix-vector product function to be used by a
1063  * matrix variant for a given fill type.
1064  *
1065  * Currently, possible variant functions are:
1066  *
1067  * CS_MATRIX_NATIVE (all fill types)
1068  * default
1069  * standard
1070  * omp (for OpenMP with compatible numbering)
1071  * vector (For vector machine with compatible numbering)
1072  *
1073  * CS_MATRIX_CSR (for CS_MATRIX_SCALAR or CS_MATRIX_SCALAR_SYM)
1074  * default
1075  * standard
1076  * mkl (with MKL)
1077  *
1078  * CS_MATRIX_CSR_SYM (for CS_MATRIX_SCALAR_SYM)
1079  * default
1080  * standard
1081  * mkl (with MKL)
1082  *
1083  * CS_MATRIX_MSR (all fill types except CS_MATRIX_33_BLOCK)
1084  * default
1085  * standard
1086  * mkl (with MKL, for CS_MATRIX_SCALAR or CS_MATRIX_SCALAR_SYM)
1087  * omp_sched (For OpenMP with scheduling)
1088  *
1089  * parameters:
1090  * mv <-> pointer to matrix variant
1091  * numbering <-- mesh numbering info, or NULL
1092  * fill type <-- matrix fill type to merge from
1093  * ed_flag <-- 0: with diagonal only, 1 exclude only; 2; both
1094  * func_name <-- function type name
1095  *----------------------------------------------------------------------------*/
1096 
1097 void
1099  const cs_numbering_t *numbering,
1100  cs_matrix_fill_type_t fill_type,
1101  int ed_flag,
1102  const char *func_name);
1103 
1104 /*----------------------------------------------------------------------------
1105  * Get the type associated with a matrix variant.
1106  *
1107  * parameters:
1108  * mv <-- pointer to matrix variant structure
1109  *----------------------------------------------------------------------------*/
1110 
1113 
1114 /*----------------------------------------------------------------------------*/
1115 
1117 
1118 #endif /* __CS_MATRIX_H__ */
cs_lnum_t * _col_id
Definition: cs_matrix.h:107
const cs_lnum_t * cs_matrix_get_diag_block_size(const cs_matrix_t *matrix)
Return matrix diagonal block sizes.
Definition: cs_matrix.c:5647
cs_matrix_t * cs_matrix_create_by_copy(cs_matrix_t *src)
Create a matrix container by copying another.
Definition: cs_matrix.c:5358
bool cs_matrix_is_symmetric(const cs_matrix_t *matrix)
Query matrix coefficients symmetry.
Definition: cs_matrix.c:6116
#define restrict
Definition: cs_defs.h:127
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:6562
const cs_halo_t * cs_matrix_get_halo(const cs_matrix_t *matrix)
Return pointer to matrix halo structure.
Definition: cs_matrix.c:5691
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:6615
void cs_matrix_row_finalize(cs_matrix_row_info_t *r)
Finalize row info for a given matrix.
Definition: cs_matrix.c:6304
cs_halo_rotation_t
Definition: cs_halo.h:60
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:6518
Definition: cs_matrix.h:75
cs_matrix_variant_t * cs_matrix_variant_create(cs_matrix_t *m)
Build matrix variant.
Definition: cs_matrix.c:7068
struct _cs_matrix_assembler_values_t cs_matrix_assembler_values_t
Definition: cs_matrix_assembler.h:65
void cs_matrix_row_init(cs_matrix_row_info_t *r)
Initialize row info for a given matrix.
Definition: cs_matrix.c:6285
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:5852
cs_matrix_t * cs_matrix_create(const cs_matrix_structure_t *ms)
Create a matrix container using a given structure.
Definition: cs_matrix.c:5277
struct _cs_matrix_variant_t cs_matrix_variant_t
Definition: cs_matrix.h:98
#define BEGIN_C_DECLS
Definition: cs_defs.h:495
void cs_matrix_release_coefficients(cs_matrix_t *matrix)
Release shared matrix coefficients.
Definition: cs_matrix.c:5983
Definition: cs_matrix.h:84
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:5912
Definition: cs_matrix.h:81
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:5718
Definition: cs_halo.h:71
void cs_matrix_structure_destroy(cs_matrix_structure_t **ms)
Destroy a matrix structure.
Definition: cs_matrix.c:5249
void cs_matrix_copy_diagonal(const cs_matrix_t *matrix, cs_real_t *restrict da)
Copy matrix diagonal values.
Definition: cs_matrix.c:6092
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:6335
const char * cs_matrix_type_fullname[]
const char * cs_matrix_fill_type_name[]
double cs_real_t
Floating-point value.
Definition: cs_defs.h:307
Definition: cs_matrix.h:83
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:112
struct _cs_matrix_t cs_matrix_t
Definition: cs_matrix.h:94
Definition: cs_matrix.h:77
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:6895
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:6744
cs_lnum_t row_size
Definition: cs_matrix.h:104
const char * cs_matrix_type_name[]
void cs_matrix_variant_build_list(const cs_matrix_t *m, int *n_variants, cs_matrix_variant_t **m_variant)
Build list of variants for tuning or testing.
Definition: cs_matrix.c:7107
const cs_lnum_t * col_id
Definition: cs_matrix.h:106
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:5788
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:5671
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:6137
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:5210
Definition: cs_matrix.h:63
Definition: cs_matrix.h:65
cs_matrix_type_t
Definition: cs_matrix.h:55
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:5311
Definition: cs_matrix.h:73
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:6464
Definition: cs_matrix.h:59
cs_matrix_t * cs_matrix_create_by_local_restrict(const cs_matrix_t *src)
Create a matrix based on the local restriction of a base matrix.
Definition: cs_matrix.c:5409
cs_lnum_t cs_lnum_2_t[2]
vector of 2 local mesh-entity ids
Definition: cs_defs.h:313
const cs_real_t * vals
Definition: cs_matrix.h:108
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:6719
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:6963
cs_real_t * _vals
Definition: cs_matrix.h:109
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:5075
void cs_matrix_apply_variant(cs_matrix_t *m, const cs_matrix_variant_t *mv)
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:301
cs_matrix_type_t cs_matrix_get_type(const cs_matrix_t *matrix)
Return matrix type.
Definition: cs_matrix.c:5538
cs_lnum_t cs_matrix_get_n_columns(const cs_matrix_t *matrix)
Return number of columns in a matrix.
Definition: cs_matrix.c:5555
cs_lnum_t buffer_size
Definition: cs_matrix.h:105
void cs_matrix_destroy(cs_matrix_t **matrix)
Definition: cs_matrix.c:5479
#define END_C_DECLS
Definition: cs_defs.h:496
void cs_matrix_variant_destroy(cs_matrix_variant_t **mv)
Destroy a matrix variant structure.
Definition: cs_matrix.c:7401
Definition: cs_matrix.h:102
struct _cs_matrix_assembler_t cs_matrix_assembler_t
Definition: cs_matrix_assembler.h:61
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:4978
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:6803
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:6686
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:6261
Definition: cs_matrix.h:60
Definition: cs_matrix.h:58
cs_lnum_t cs_matrix_get_n_rows(const cs_matrix_t *matrix)
Return number of rows in matrix.
Definition: cs_matrix.c:5572
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:7471
cs_lnum_t cs_matrix_get_n_entries(const cs_matrix_t *matrix)
Return number of entries in matrix.
Definition: cs_matrix.c:5592
const cs_real_t * cs_matrix_get_diagonal(const cs_matrix_t *matrix)
Get matrix diagonal values.
Definition: cs_matrix.c:6161
Definition: cs_matrix.h:57
Definition: cs_matrix.h:74
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.
Definition: cs_matrix.c:5160
void cs_matrix_variant_apply(cs_matrix_t *m, cs_matrix_variant_t *mv)
Apply a variant to a given matrix.
Definition: cs_matrix.c:7417
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:7514
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:6654
Definition: cs_numbering.h:83
struct _cs_matrix_structure_t cs_matrix_structure_t
Definition: cs_matrix.h:90
cs_matrix_fill_type_t
Definition: cs_matrix.h:71
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:6027