7.2
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-2022 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_matrix_assembler.h"
39 
40 /*----------------------------------------------------------------------------*/
41 
43 
44 /*============================================================================
45  * Macro definitions
46  *============================================================================*/
47 
48 /*============================================================================
49  * Type definitions
50  *============================================================================*/
51 
52 /* Matrix structure representation types */
53 
54 typedef enum {
55 
69 
70 /* Matrix fill types (for tuning) */
71 
72 typedef enum {
73 
74  CS_MATRIX_SCALAR, /* Simple scalar matrix */
75  CS_MATRIX_SCALAR_SYM, /* Simple scalar symmetric matrix */
76  CS_MATRIX_BLOCK_D, /* Matrix with diagonal blocks
77  (and m.I extradiagonal blocks) */
78  CS_MATRIX_BLOCK_D_66, /* Matrix with 6x6 diagonal blocks
79  (and 6.I extradiagonal blocks;
80  subcase of CS_MATRIX_BLOCK_D, allows
81  separate tuning) */
82  CS_MATRIX_BLOCK_D_SYM, /* Symmetric matrix with diagonal blocks
83  (and m.I extradiagonal blocks) */
84  CS_MATRIX_BLOCK, /* Block matrix */
85  CS_MATRIX_N_FILL_TYPES /* Number of possible matrix fill types */
86 
88 
95 typedef enum {
96 
103 
104 /* Structure associated with opaque matrix structure object */
105 
106 typedef struct _cs_matrix_structure_t cs_matrix_structure_t;
107 
108 /* Structure associated with opaque matrix object */
109 
110 typedef struct _cs_matrix_t cs_matrix_t;
111 
112 /* Structure associated with opaque matrix tuning results object */
113 
114 typedef struct _cs_matrix_variant_t cs_matrix_variant_t;
115 
116 /* Information structure for extraction of matrix row */
117 
118 typedef struct {
119 
120  cs_lnum_t row_size; /*< Row size from last call */
121  cs_lnum_t buffer_size; /*< Allocated buffer size */
122  const cs_lnum_t *col_id; /*< Pointer to local column ids */
123  cs_lnum_t *_col_id; /*< Pointer to local column ids copy */
124  const cs_real_t *vals; /*< Pointer to local row values */
125  cs_real_t *_vals; /*< Pointer to local row values copy */
126 
128 
129 /*============================================================================
130  * Global variables
131  *============================================================================*/
132 
135 extern const char *cs_matrix_fill_type_name[];
136 
139 extern const char *cs_matrix_spmv_type_name[];
140 
141 /*=============================================================================
142  * Public function prototypes
143  *============================================================================*/
144 
145 /*----------------------------------------------------------------------------
146  * Create a matrix structure.
147  *
148  * Note that the structure created usually maps to the given existing
149  * cell global number, face -> cell connectivity arrays, and cell halo
150  * structure, so it must be destroyed before they are freed
151  * (usually along with the code's main face -> cell structure).
152  *
153  * Note that the resulting matrix structure will contain a full main
154  * main diagonal, and that the extra-diagonal structure is always
155  * symmetric (though the coefficients my not be, and we may choose a
156  * matrix format that does not exploit this symmetry). If the edges
157  * connectivity argument is NULL, the matrix will be purely diagonal.
158  *
159  * parameters:
160  * type <-- type of matrix considered
161  * n_rows <-- local number of rows
162  * n_cols_ext <-- number of columns + ghosts
163  * n_edges <-- local number of (undirected) graph edges
164  * edges <-- edges (symmetric row <-> column) connectivity
165  * halo <-- halo structure associated with cells, or NULL
166  * numbering <-- vectorization or thread-related numbering info, or NULL
167  *
168  * returns:
169  * pointer to created matrix structure;
170  *----------------------------------------------------------------------------*/
171 
174  cs_lnum_t n_rows,
175  cs_lnum_t n_cols_ext,
176  cs_lnum_t n_edges,
177  const cs_lnum_2_t *edges,
178  const cs_halo_t *halo,
179  const cs_numbering_t *numbering);
180 
181 /*----------------------------------------------------------------------------
182  * Create a matrix structure based on a MSR connectivity definition.
183  *
184  * Only CSR and MSR formats are handled.
185  *
186  * col_id is sorted row by row during the creation of this structure.
187  *
188  * In case the property of the row index and col_id arrays are transferred
189  * to the structure, the arrays pointers passed as arguments are set to NULL,
190  * to help ensure the caller does not use the original arrays directly after
191  * this call.
192  *
193  * parameters:
194  * type <-- type of matrix considered
195  * transfer <-- transfer property of row_index and col_id
196  * if true, map them otherwise
197  * have_diag <-- indicates if the structure includes the
198  * diagonal (should be the same for all rows)
199  * n_rows <-- local number of rows
200  * n_cols_ext <-- local number of columns + ghosts
201  * row_index <-> pointer to index on rows
202  * col_id <-> pointer to array of colum ids related to the row index
203  * halo <-- halo structure for synchronization, or NULL
204  * numbering <-- vectorization or thread-related numbering info, or NULL
205  *
206  * returns:
207  * a pointer to a created matrix structure
208  *----------------------------------------------------------------------------*/
209 
212  bool transfer,
213  bool have_diag,
214  cs_lnum_t n_rows,
215  cs_lnum_t n_cols_ext,
216  cs_lnum_t **row_index,
217  cs_lnum_t **col_id,
218  const cs_halo_t *halo,
219  const cs_numbering_t *numbering);
220 
221 /*----------------------------------------------------------------------------
222  * Create an MSR matrix structure sharing an existing connectivity definition.
223  *
224  * Note that as the structure created maps to the given existing
225  * cell global number, face -> cell connectivity arrays, and cell halo
226  * structure, it must be destroyed before they are freed
227  * (usually along with the code's main face -> cell structure).
228  *
229  * parameters:
230  * direct_assembly <-- true if each value corresponds to a unique face
231  * n_rows <-- local number of rows
232  * n_cols_ext <-- local number of columns + ghosts
233  * row_index <-- pointer to index on rows
234  * col_id <-- pointer to array of colum ids related to the row index
235  * halo <-- halo structure for synchronization, or NULL
236  * numbering <-- vectorization or thread-related numbering
237  * info, or NULL
238  *
239  * returns:
240  * a pointer to a created matrix structure
241  *----------------------------------------------------------------------------*/
242 
244 cs_matrix_structure_create_msr_shared(bool direct_assmbly,
245  cs_lnum_t n_rows,
246  cs_lnum_t n_cols_ext,
247  const cs_lnum_t *row_index,
248  const cs_lnum_t *col_id,
249  const cs_halo_t *halo,
250  const cs_numbering_t *numbering);
251 
252 /*----------------------------------------------------------------------------*/
263 /*----------------------------------------------------------------------------*/
264 
268 
269 /*----------------------------------------------------------------------------
270  * Destroy a matrix structure.
271  *
272  * parameters:
273  * ms <-> pointer to matrix structure pointer
274  *----------------------------------------------------------------------------*/
275 
276 void
278 
279 /*----------------------------------------------------------------------------
280  * Create a matrix container using a given structure.
281  *
282  * Note that the matrix container maps to the assigned structure,
283  * so it must be destroyed before that structure.
284  *
285  * parameters:
286  * ms <-- associated matrix structure
287  *
288  * returns:
289  * pointer to created matrix structure;
290  *----------------------------------------------------------------------------*/
291 
292 cs_matrix_t *
294 
295 /*----------------------------------------------------------------------------*/
306 /*----------------------------------------------------------------------------*/
307 
308 cs_matrix_t *
311 
312 /*----------------------------------------------------------------------------*/
325 /*----------------------------------------------------------------------------*/
326 
327 cs_matrix_t *
329 
330 /*----------------------------------------------------------------------------*/
342 /*----------------------------------------------------------------------------*/
343 
344 cs_matrix_t *
346 
347 /*----------------------------------------------------------------------------
348  * Destroy a matrix structure.
349  *
350  * In the case of a compoud matrix, sub-matrices are not destroyed.
351  *
352  * parameters:
353  * matrix <-> pointer to matrix structure pointer
354  *----------------------------------------------------------------------------*/
355 
356 void
358 
359 /*----------------------------------------------------------------------------
360  * Return type of matrix.
361  *
362  * parameters:
363  * matrix --> pointer to matrix structure
364  *----------------------------------------------------------------------------*/
365 
368 
369 /*----------------------------------------------------------------------------
370  * Return matrix type name.
371  *
372  * parameters:
373  * matrix --> pointer to matrix structure
374  *----------------------------------------------------------------------------*/
375 
376 const char *
378 
379 /*----------------------------------------------------------------------------
380  * Return matrix type full name.
381  *
382  * parameters:
383  * matrix --> pointer to matrix structure
384  *----------------------------------------------------------------------------*/
385 
386 const char *
388 
389 /*----------------------------------------------------------------------------
390  * Return number of columns in matrix.
391  *
392  * parameters:
393  * matrix --> pointer to matrix structure
394  *----------------------------------------------------------------------------*/
395 
396 cs_lnum_t
398 
399 /*----------------------------------------------------------------------------
400  * Return number of rows in matrix.
401  *
402  * parameters:
403  * matrix --> pointer to matrix structure
404  *----------------------------------------------------------------------------*/
405 
406 cs_lnum_t
408 
409 /*----------------------------------------------------------------------------
410  * Return number of entries in matrix.
411  *
412  * When the block size is > 1, the number reported is the number of
413  * entry blocks, not individual entries.
414  *
415  * parameters:
416  * matrix --> pointer to matrix structure
417  *----------------------------------------------------------------------------*/
418 
419 cs_lnum_t
421 
422 /*----------------------------------------------------------------------------
423  * Return matrix diagonal block sizes.
424  *
425  * parameters:
426  * matrix <-- pointer to matrix structure
427  *
428  * returns:
429  * diagonal block sizes
430  *----------------------------------------------------------------------------*/
431 
432 cs_lnum_t
434 
435 /*----------------------------------------------------------------------------
436  * Return matrix extra-diagonal block sizes.
437  *
438  * parameters:
439  * matrix <-- pointer to matrix structure
440  *
441  * returns:
442  * extra-diagonal block sizes
443  *----------------------------------------------------------------------------*/
444 
445 cs_lnum_t
447 
448 /*----------------------------------------------------------------------------
449  * Return pointer to matrix halo structure.
450  *
451  * parameters:
452  * matrix <-- pointer to matrix structure
453  *
454  * returns:
455  * pointer to halo strucuture
456  *----------------------------------------------------------------------------*/
457 
458 const cs_halo_t *
460 
461 /*----------------------------------------------------------------------------*/
470 /*----------------------------------------------------------------------------*/
471 
472 const cs_gnum_t *
474 
475 /*----------------------------------------------------------------------------*/
483 /*----------------------------------------------------------------------------*/
484 
487 
488 /*----------------------------------------------------------------------------*/
495 /*----------------------------------------------------------------------------*/
496 
497 void
499  cs_alloc_mode_t alloc_mode);
500 
501 /*----------------------------------------------------------------------------
502  * Get matrix fill type, depending on block sizes.
503  *
504  * parameters:
505  * symmetric <-- indicates if matrix coefficients are symmetric
506  * diag_block_size <-- block sizes for diagonal
507  * extra_diag_block_size <-- block sizes for extra diagonal
508  *
509  * returns:
510  * matrix fill type
511  *----------------------------------------------------------------------------*/
512 
514 cs_matrix_get_fill_type(bool symmetric,
515  cs_lnum_t diag_block_size,
516  cs_lnum_t extra_diag_block_size);
517 
518 /*----------------------------------------------------------------------------
519  * Set matrix coefficients defined relative to a "native" edge graph,
520  * sharing arrays with the caller when possible.
521  *
522  * With shared arrays, the matrix becomes unusable if the arrays passed as
523  * arguments are not be modified (its coefficients should be unset first
524  * to mark this).
525  *
526  * Depending on current options and initialization, values will be copied
527  * or simply mapped.
528  *
529  * parameters:
530  * matrix <-> pointer to matrix structure
531  * symmetric <-- indicates if matrix coefficients are symmetric
532  * diag_block_size <-- block sizes for diagonal
533  * extra_diag_block_size <-- block sizes for extra diagonal
534  * n_edges <-- local number of graph edges
535  * edges <-- edges (row <-> column) connectivity
536  * da <-- diagonal values (NULL if zero)
537  * xa <-- extradiagonal values (NULL if zero)
538  * casts as:
539  * xa[n_edges] if symmetric,
540  * xa[n_edges][2] if non symmetric
541  *----------------------------------------------------------------------------*/
542 
543 void
545  bool symmetric,
546  cs_lnum_t diag_block_size,
547  cs_lnum_t extra_diag_block_size,
548  const cs_lnum_t n_edges,
549  const cs_lnum_2_t edges[],
550  const cs_real_t *da,
551  const cs_real_t *xa);
552 
553 /*----------------------------------------------------------------------------
554  * Set matrix coefficients, copying values to private arrays.
555  *
556  * With private arrays, the matrix becomes independant from the
557  * arrays passed as arguments.
558  *
559  * parameters:
560  * matrix <-> pointer to matrix structure
561  * symmetric <-- indicates if matrix coefficients are symmetric
562  * diag_block_size <-- block sizes for diagonal
563  * extra_diag_block_size <-- block sizes for extra diagonal
564  * n_edges <-- local number of graph edges
565  * edges <-- edges (row <-> column) connectivity
566  * da <-- diagonal values (NULL if zero)
567  * xa <-- extradiagonal values (NULL if zero)
568  * casts as:
569  * xa[n_edges] if symmetric,
570  * xa[n_edges][2] if non symmetric
571  *----------------------------------------------------------------------------*/
572 
573 void
575  bool symmetric,
576  cs_lnum_t diag_block_size,
577  cs_lnum_t extra_diag_block_size,
578  const cs_lnum_t n_edges,
579  const cs_lnum_2_t edges[],
580  const cs_real_t *da,
581  const cs_real_t *xa);
582 
583 /*----------------------------------------------------------------------------
584  * Set matrix coefficients in an MSR format, transferring the
585  * property of those arrays to the matrix.
586  *
587  * If the matrix is also in MSR format, this avoids an extra copy.
588  * If it is in a different format, values are copied to the structure,
589  * and the original arrays freed. In any case, the arrays pointers passed as
590  * arguments are set to NULL, to help ensure the caller does not use the
591  * original arrays directly after this call.
592  *
593  * parameters:
594  * matrix <-> pointer to matrix structure
595  * symmetric <-- indicates if matrix coefficients are symmetric
596  * diag_block_size <-- block sizes for diagonal
597  * extra_diag_block_size <-- block sizes for extra diagonal
598  * row_index <-- MSR row index (0 to n-1)
599  * col_id <-- MSR column id (0 to n-1)
600  * d_val <-> diagonal values (NULL if zero)
601  * x_val <-> extradiagonal values (NULL if zero)
602  *----------------------------------------------------------------------------*/
603 
604 void
606  bool symmetric,
607  cs_lnum_t diag_block_size,
608  cs_lnum_t extra_diag_block_size,
609  const cs_lnum_t row_index[],
610  const cs_lnum_t col_id[],
611  cs_real_t **d_val,
612  cs_real_t **x_val);
613 
614 /*----------------------------------------------------------------------------*/
627 /*----------------------------------------------------------------------------*/
628 
631  cs_lnum_t diag_block_size,
632  cs_lnum_t extra_diag_block_size);
633 
634 /*----------------------------------------------------------------------------
635  * Release shared matrix coefficients.
636  *
637  * Pointers to mapped coefficients are set to NULL, while
638  * coefficient copies owned by the matrix are not modified.
639  *
640  * This simply ensures the matrix does not maintain pointers
641  * to nonexistant data.
642  *
643  * parameters:
644  * matrix <-> pointer to matrix structure
645  *----------------------------------------------------------------------------*/
646 
647 void
649 
650 /*----------------------------------------------------------------------------
651  * Copy matrix diagonal values.
652  *
653  * In case of matrixes with block diagonal coefficients, only the true
654  * diagonal values are copied.
655  *
656  * parameters:
657  * matrix --> pointer to matrix structure
658  * da --> diagonal (pre-allocated, size: n_rows*block_size
659  *----------------------------------------------------------------------------*/
660 
661 void
663  cs_real_t *restrict da);
664 
665 /*----------------------------------------------------------------------------
666  * Query matrix coefficients symmetry
667  *
668  * parameters:
669  * matrix <-- pointer to matrix structure
670  *
671  * returns:
672  * true if coefficients are symmetric, false otherwise
673  *----------------------------------------------------------------------------*/
674 
675 bool
677 
678 /*----------------------------------------------------------------------------*/
691 /*----------------------------------------------------------------------------*/
692 
693 bool
695 
696 /*----------------------------------------------------------------------------
697  * Get matrix diagonal values.
698  *
699  * In case of matrixes with block diagonal coefficients, a pointer to
700  * the complete block diagonal is returned.
701  *
702  * parameters:
703  * matrix --> pointer to matrix structure
704  *
705  * returns:
706  * pointer to matrix diagonal array
707  *----------------------------------------------------------------------------*/
708 
709 const cs_real_t *
711 
712 /*----------------------------------------------------------------------------
713  * Get pointer to matrix extra-diagonal values in "native" format
714  *
715  * This function currently only functions if the matrix is in "native"
716  * format or the coefficients were mapped from native coefficients using
717  * cs_matrix_set_coefficients(), in which case the pointer returned is
718  * the same as the one passed to that function.
719  *
720  * parameters:
721  * matrix --> pointer to matrix structure
722  *
723  * returns:
724  * pointer to matrix diagonal array
725  *----------------------------------------------------------------------------*/
726 
727 const cs_real_t *
729 
730 /*----------------------------------------------------------------------------
731  * Initialize row info for a given matrix.
732  *
733  * parameters:
734  * r --> row info structure
735  *----------------------------------------------------------------------------*/
736 
737 void
739 
740 /*----------------------------------------------------------------------------
741  * Finalize row info for a given matrix.
742  *
743  * parameters:
744  * r <-> row info structure
745  *----------------------------------------------------------------------------*/
746 
747 void
749 
750 /*----------------------------------------------------------------------------
751  * Get row values for a given matrix.
752  *
753  * This function may not work for all matrix types.
754  *
755  * In the case of blocked matrixes, the true (non-blocked)
756  * values are returned.
757  *
758  * The row information structure must have been previously initialized
759  * using cs_matrix_row_init(), and should be finalized using
760  * using cs_matrix_row_finalize(), so as to free buffers it may have
761  * built for certain matrix formats.
762  *
763  * parameters:
764  * matrix <-- pointer to matrix structure
765  * row_id <-- id of row to query
766  * r <-> row info structure
767  *----------------------------------------------------------------------------*/
768 
769 void
771  const cs_lnum_t row_id,
773 
774 /*----------------------------------------------------------------------------
775  * Get arrays describing a matrix in native format.
776  *
777  * This function works for matrix in native format.
778  *
779  * Matrix block sizes can be obtained by cs_matrix_get_diag_block_size()
780  * and cs_matrix_get_extra_diag_block_size().
781  *
782  * parameters:
783  * matrix <-- pointer to matrix structure
784  * symmetric --> true if symmetric
785  * n_edges --> number of associated faces
786  * edges --> edges (symmetric row <-> column) connectivity
787  * d_val --> diagonal values
788  * x_val --> extra-diagonal values
789  *----------------------------------------------------------------------------*/
790 
791 void
793  bool *symmetric,
794  cs_lnum_t *n_edges,
795  const cs_lnum_2_t **edges,
796  const cs_real_t **d_val,
797  const cs_real_t **x_val);
798 
799 /*----------------------------------------------------------------------------
800  * Get arrays describing a matrix in CSR format.
801  *
802  * This function only works for an CSR matrix (i.e. there is
803  * no automatic conversion from another matrix type).
804  *
805  * Matrix block sizes can be obtained by cs_matrix_get_diag_block_size()
806  * and cs_matrix_get_extra_diag_block_size().
807  *
808  * parameters:
809  * matrix <-- pointer to matrix structure
810  * row_index --> CSR row index
811  * col_id --> CSR column id
812  * val --> values
813  *----------------------------------------------------------------------------*/
814 
815 void
817  const cs_lnum_t **row_index,
818  const cs_lnum_t **col_id,
819  const cs_real_t **val);
820 
821 /*----------------------------------------------------------------------------
822  * Get arrays describing a matrix in MSR format.
823  *
824  * This function only works for an MSR matrix (i.e. there is
825  * no automatic conversion from another matrix type).
826  *
827  * Matrix block sizes can be obtained by cs_matrix_get_diag_block_size()
828  * and cs_matrix_get_extra_diag_block_size().
829  *
830  * parameters:
831  * matrix <-- pointer to matrix structure
832  * row_index --> MSR row index
833  * col_id --> MSR column id
834  * d_val --> diagonal values
835  * x_val --> extra-diagonal values
836  *----------------------------------------------------------------------------*/
837 
838 void
840  const cs_lnum_t **row_index,
841  const cs_lnum_t **col_id,
842  const cs_real_t **d_val,
843  const cs_real_t **x_val);
844 
845 /*----------------------------------------------------------------------------
846  * Assign functions based on a variant to a given matrix.
847  *
848  * If the matrix variant is incompatible with the structure, it is ignored,
849  * and defaults for that structure are used instead.
850  *
851  * parameters:
852  * m <-> associated matrix structure
853  * mv <-- associated matrix variant
854  *
855  * returns:
856  * pointer to created matrix structure;
857  *----------------------------------------------------------------------------*/
858 
859 void
861  const cs_matrix_variant_t *mv);
862 
863 /*----------------------------------------------------------------------------
864  * Matrix.vector product y = A.x
865  *
866  * This function includes a halo update of x prior to multiplication by A.
867  *
868  * parameters:
869  * matrix --> pointer to matrix structure
870  * x <-> multipliying vector values (ghost values updated)
871  * y --> resulting vector
872  *----------------------------------------------------------------------------*/
873 
874 void
876  cs_real_t *restrict x,
877  cs_real_t *restrict y);
878 
879 #if defined(HAVE_ACCEL)
880 
881 /*----------------------------------------------------------------------------*/
892 /*----------------------------------------------------------------------------*/
893 
894 void
895 cs_matrix_vector_multiply_d(const cs_matrix_t *matrix,
896  cs_real_t *restrict x,
897  cs_real_t *restrict y);
898 
899 #endif /* defined(HAVE_ACCEL) */
900 
901 /*----------------------------------------------------------------------------
902  * Matrix.vector product y = A.x with no prior halo update of x.
903  *
904  * This function does not include a halo update of x prior to multiplication
905  * by A, so it should be called only when the halo of x is known to already
906  * be up to date (in which case we avoid the performance penalty of a
907  * redundant update by using this variant of the matrix.vector product).
908  *
909  * parameters:
910  * matrix --> pointer to matrix structure
911  * x --> multipliying vector values
912  * y <-- resulting vector
913  *----------------------------------------------------------------------------*/
914 
915 void
917  cs_real_t *restrict x,
918  cs_real_t *restrict y);
919 
920 /*----------------------------------------------------------------------------
921  * Partial matrix.vector product.
922  *
923  * This function includes a halo update of x prior to multiplication,
924  * except for the CS_MATRIX_SPMV_L operation type, which does not require it,
925  * as halo adjacencies are only present and useful in the upper-diagonal part..
926  *
927  * parameters:
928  * matrix <-- pointer to matrix structure
929  * op_type <-- SpMV operation type
930  * x <-> multipliying vector values (ghost values updated)
931  * y --> resulting vector
932  *----------------------------------------------------------------------------*/
933 
934 void
936  cs_matrix_spmv_type_t op_type,
937  cs_real_t *restrict x,
938  cs_real_t *restrict y);
939 
940 #if defined(HAVE_ACCEL)
941 
942 /*----------------------------------------------------------------------------*/
956 /*----------------------------------------------------------------------------*/
957 
958 void
959 cs_matrix_vector_multiply_partial_d(const cs_matrix_t *matrix,
960  cs_matrix_spmv_type_t op_type,
961  cs_real_t *restrict x,
962  cs_real_t *restrict y);
963 
964 #endif /* defined(HAVE_ACCEL) */
965 
966 /*----------------------------------------------------------------------------
967  * Synchronize ghost values prior to matrix.vector product
968  *
969  * parameters:
970  * matrix <-- pointer to matrix structure
971  * x <-> multipliying vector values (ghost values updated)
972  *----------------------------------------------------------------------------*/
973 
974 void
976  cs_real_t *x);
977 
978 /*----------------------------------------------------------------------------*/
989 /*----------------------------------------------------------------------------*/
990 
991 void
993  int *n_variants,
994  cs_matrix_variant_t **m_variant);
995 
996 /*----------------------------------------------------------------------------*/
1005 /*----------------------------------------------------------------------------*/
1006 
1009 
1010 /*----------------------------------------------------------------------------
1011  * Destroy a matrix variant structure.
1012  *
1013  * parameters:
1014  * mv <-> Pointer to matrix variant pointer
1015  *----------------------------------------------------------------------------*/
1016 
1017 void
1019 
1020 /*----------------------------------------------------------------------------*/
1027 /*----------------------------------------------------------------------------*/
1028 
1029 void
1031  cs_matrix_variant_t *mv);
1032 
1033 /*----------------------------------------------------------------------------*/
1040 /*----------------------------------------------------------------------------*/
1041 
1042 void
1044  cs_matrix_variant_t *mv);
1045 
1046 /*----------------------------------------------------------------------------
1047  * Select the sparse matrix-vector product function to be used by a
1048  * matrix variant for a given fill type.
1049  *
1050  * Currently, possible variant functions are:
1051  *
1052  * CS_MATRIX_NATIVE (all fill types)
1053  * default
1054  * baseline
1055  * omp (for OpenMP with compatible numbering)
1056  * omp_atomic (for OpenMP with atomics)
1057  * vector (For vector machine with compatible numbering)
1058  *
1059  * CS_MATRIX_CSR (for CS_MATRIX_SCALAR or CS_MATRIX_SCALAR_SYM)
1060  * default
1061  * mkl (with MKL)
1062  *
1063  * CS_MATRIX_MSR (all fill types)
1064  * default
1065  * mkl (with MKL, for CS_MATRIX_SCALAR or CS_MATRIX_SCALAR_SYM)
1066  * omp_sched (For OpenMP with scheduling)
1067  *
1068  * parameters:
1069  * mv <-> pointer to matrix variant
1070  * numbering <-- mesh numbering info, or NULL
1071  * fill type <-- matrix fill type to merge from
1072  * spmv_type <-- SpMV operation type (full or sub-matrix)
1073  * (all types if CS_MATRIX_SPMV_N_TYPES)
1074  * func_name <-- function type name
1075  *----------------------------------------------------------------------------*/
1076 
1077 void
1079  cs_matrix_fill_type_t fill_type,
1080  cs_matrix_spmv_type_t spmv_type,
1081  const cs_numbering_t *numbering,
1082  const char *func_name);
1083 
1084 /*----------------------------------------------------------------------------
1085  * Get the type associated with a matrix variant.
1086  *
1087  * parameters:
1088  * mv <-- pointer to matrix variant structure
1089  *----------------------------------------------------------------------------*/
1090 
1093 
1094 /*----------------------------------------------------------------------------*/
1095 
1097 
1098 #endif /* __CS_MATRIX_H__ */
cs_lnum_t * _col_id
Definition: cs_matrix.h:123
cs_lnum_t cs_matrix_get_diag_block_size(const cs_matrix_t *matrix)
Return matrix diagonal block sizes.
Definition: cs_matrix.c:4897
cs_matrix_t * cs_matrix_create_by_copy(cs_matrix_t *src)
Create a matrix container by copying another.
Definition: cs_matrix.c:4604
cs_matrix_structure_t * cs_matrix_structure_create_msr_shared(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:4404
cs_matrix_fill_type_t cs_matrix_get_fill_type(bool symmetric, cs_lnum_t diag_block_size, cs_lnum_t extra_diag_block_size)
Get matrix fill type, depending on block sizes.
Definition: cs_matrix.c:5016
bool cs_matrix_is_symmetric(const cs_matrix_t *matrix)
Query matrix coefficients symmetry.
Definition: cs_matrix.c:5372
unsigned long cs_gnum_t
global mesh entity number
Definition: cs_defs.h:301
#define restrict
Definition: cs_defs.h:142
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:5870
const cs_halo_t * cs_matrix_get_halo(const cs_matrix_t *matrix)
Return pointer to matrix halo structure.
Definition: cs_matrix.c:4937
void cs_matrix_row_finalize(cs_matrix_row_info_t *r)
Finalize row info for a given matrix.
Definition: cs_matrix.c:5495
void cs_matrix_vector_multiply_nosync(const cs_matrix_t *matrix, cs_real_t *restrict x, cs_real_t *restrict y)
Matrix.vector product y = A.x with no prior halo update of x.
Definition: cs_matrix.c:6011
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:5826
const char * cs_matrix_get_type_name(const cs_matrix_t *matrix)
Definition: cs_matrix.c:4771
Definition: cs_matrix.h:76
cs_matrix_variant_t * cs_matrix_variant_create(cs_matrix_t *m)
Build matrix variant.
Definition: cs_matrix.c:6162
void cs_matrix_variant_set_func(cs_matrix_variant_t *mv, cs_matrix_fill_type_t fill_type, cs_matrix_spmv_type_t spmv_type, const cs_numbering_t *numbering, 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:6517
struct _cs_matrix_assembler_values_t cs_matrix_assembler_values_t
Definition: cs_matrix_assembler.h:65
void cs_matrix_transfer_coefficients_msr(cs_matrix_t *matrix, bool symmetric, cs_lnum_t diag_block_size, 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:5191
void cs_matrix_row_init(cs_matrix_row_info_t *r)
Initialize row info for a given matrix.
Definition: cs_matrix.c:5476
cs_matrix_t * cs_matrix_create(const cs_matrix_structure_t *ms)
Create a matrix container using a given structure.
Definition: cs_matrix.c:4523
struct _cs_matrix_variant_t cs_matrix_variant_t
Definition: cs_matrix.h:114
cs_matrix_structure_t * cs_matrix_structure_create(cs_matrix_type_t type, 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:4216
#define BEGIN_C_DECLS
Definition: cs_defs.h:510
void cs_matrix_release_coefficients(cs_matrix_t *matrix)
Release shared matrix coefficients.
Definition: cs_matrix.c:5262
void cs_matrix_set_alloc_mode(cs_matrix_t *matrix, cs_alloc_mode_t alloc_mode)
Set matrix allocation mode.
Definition: cs_matrix.c:4996
Definition: cs_matrix.h:85
Definition: cs_matrix.h:82
Definition: cs_halo.h:77
void cs_matrix_structure_destroy(cs_matrix_structure_t **ms)
Destroy a matrix structure.
Definition: cs_matrix.c:4495
void cs_matrix_pre_vector_multiply_sync(const cs_matrix_t *matrix, cs_real_t *x)
void cs_matrix_copy_diagonal(const cs_matrix_t *matrix, cs_real_t *restrict da)
Copy matrix diagonal values.
Definition: cs_matrix.c:5348
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:5526
void cs_matrix_vector_multiply_partial(const cs_matrix_t *matrix, cs_matrix_spmv_type_t op_type, cs_real_t *restrict x, cs_real_t *restrict y)
Partial matrix.vector product.
Definition: cs_matrix.c:6067
const char * cs_matrix_spmv_type_name[]
Definition: cs_matrix.h:60
const char * cs_matrix_fill_type_name[]
double cs_real_t
Floating-point value.
Definition: cs_defs.h:322
Definition: cs_matrix.h:84
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
cs_matrix_spmv_type_t
Definition: cs_matrix.h:95
struct _cs_matrix_t cs_matrix_t
Definition: cs_matrix.h:110
Definition: cs_matrix.h:78
Definition: cs_matrix.h:100
cs_lnum_t row_size
Definition: cs_matrix.h:120
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:6207
const cs_lnum_t * col_id
Definition: cs_matrix.h:122
const char * cs_matrix_get_type_fullname(const cs_matrix_t *matrix)
Definition: cs_matrix.c:4788
void cs_matrix_copy_coefficients(cs_matrix_t *matrix, bool symmetric, cs_lnum_t diag_block_size, 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:5136
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:5393
void cs_matrix_vector_multiply(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:5921
cs_alloc_mode_t cs_matrix_get_alloc_mode(const cs_matrix_t *matrix)
Query matrix allocation mode.
Definition: cs_matrix.c:4981
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:4454
Definition: cs_matrix.h:64
Definition: cs_matrix.h:66
cs_matrix_type_t
Definition: cs_matrix.h:54
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:4557
cs_alloc_mode_t
Definition: cs_base_accel.h:142
Definition: cs_matrix.h:74
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:5772
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:4655
cs_lnum_t cs_lnum_2_t[2]
vector of 2 local mesh-entity ids
Definition: cs_defs.h:328
const cs_real_t * vals
Definition: cs_matrix.h:124
cs_real_t * _vals
Definition: cs_matrix.h:125
cs_matrix_assembler_values_t * cs_matrix_assembler_values_init(cs_matrix_t *matrix, cs_lnum_t diag_block_size, cs_lnum_t extra_diag_block_size)
Create and initialize a CSR matrix assembler values structure.
Definition: cs_matrix.c:5306
const cs_gnum_t * cs_matrix_get_l_range(const cs_matrix_t *matrix)
Return a pointer to local global row range associated with a matrix, if available.
Definition: cs_matrix.c:4958
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:4314
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:316
cs_matrix_type_t cs_matrix_get_type(const cs_matrix_t *matrix)
Return matrix type.
Definition: cs_matrix.c:4755
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:4917
cs_lnum_t cs_matrix_get_n_columns(const cs_matrix_t *matrix)
Return number of columns in a matrix.
Definition: cs_matrix.c:4806
Definition: cs_matrix.h:97
cs_lnum_t buffer_size
Definition: cs_matrix.h:121
void cs_matrix_destroy(cs_matrix_t **matrix)
Definition: cs_matrix.c:4724
#define END_C_DECLS
Definition: cs_defs.h:511
void cs_matrix_variant_destroy(cs_matrix_variant_t **mv)
Destroy a matrix variant structure.
Definition: cs_matrix.c:6400
Definition: cs_matrix.h:118
struct _cs_matrix_assembler_t cs_matrix_assembler_t
Definition: cs_matrix_assembler.h:61
void cs_matrix_variant_apply_tuned(cs_matrix_t *m, cs_matrix_variant_t *mv)
Apply variants defined by tuning to a given matrix.
Definition: cs_matrix.c:6451
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:5452
Definition: cs_matrix.h:58
Definition: cs_matrix.h:57
cs_lnum_t cs_matrix_get_n_rows(const cs_matrix_t *matrix)
Return number of rows in matrix.
Definition: cs_matrix.c:4823
cs_lnum_t cs_matrix_get_n_entries(const cs_matrix_t *matrix)
Return number of entries in matrix.
Definition: cs_matrix.c:4843
const cs_real_t * cs_matrix_get_diagonal(const cs_matrix_t *matrix)
Get matrix diagonal values.
Definition: cs_matrix.c:5417
Definition: cs_matrix.h:56
Definition: cs_matrix.h:75
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:6416
void cs_matrix_set_coefficients(cs_matrix_t *matrix, bool symmetric, cs_lnum_t diag_block_size, 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:5077
Definition: cs_matrix.h:98
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:6563
Definition: cs_numbering.h:87
struct _cs_matrix_structure_t cs_matrix_structure_t
Definition: cs_matrix.h:106
cs_matrix_fill_type_t
Definition: cs_matrix.h:72