programmer's 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-2015 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 
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 
56  CS_MATRIX_NATIVE, /* Native matrix format */
57  CS_MATRIX_CSR, /* Compressed Sparse Row storage format */
58  CS_MATRIX_CSR_SYM, /* Compressed Symmetric Sparse Row storage format */
59  CS_MATRIX_MSR, /* Modified Compressed Sparse Row storage format */
60  CS_MATRIX_N_TYPES /* Number of known matrix types */
61 
63 
64 /* Matrix fill types (for tuning) */
65 
66 typedef enum {
67 
68  CS_MATRIX_SCALAR, /* Simple scalar matrix */
69  CS_MATRIX_SCALAR_SYM, /* Simple scalar symmetric matrix */
70  CS_MATRIX_BLOCK_D, /* Matrix with diagonal blocks
71  (and m.I extradiagonal blocks) */
72  CS_MATRIX_BLOCK_D_66, /* Matrix with 6x6 diagonal blocks
73  (and 6.I extradiagonal blocks;
74  subcase of CS_MATRIX_BLOCK_D, allows
75  separate tuning) */
76  CS_MATRIX_BLOCK_D_SYM, /* Symmetric matrix with diagonal blocks
77  (and m.I extradiagonal blocks) */
78  CS_MATRIX_BLOCK, /* Block matrix */
79  CS_MATRIX_N_FILL_TYPES /* Number of possible matrix fill types */
80 
82 
83 /* Structure associated with opaque matrix structure object */
84 
85 typedef struct _cs_matrix_structure_t cs_matrix_structure_t;
86 
87 /* Structure associated with opaque matrix object */
88 
89 typedef struct _cs_matrix_t cs_matrix_t;
90 
91 /* Structure associated with opaque matrix tuning results object */
92 
93 typedef struct _cs_matrix_variant_t cs_matrix_variant_t;
94 
95 /* Information structure for extraction of matrix row */
96 
97 typedef struct {
98 
99  cs_lnum_t row_size; /*< Row size from last call */
100  cs_lnum_t buffer_size; /*< Allocated buffer size */
101  const cs_lnum_t *col_id; /*< Pointer to local column ids */
102  cs_lnum_t *_col_id; /*< Pointer to local column ids copy */
103  const cs_real_t *vals; /*< Pointer to local row values */
104  cs_real_t *_vals; /*< Pointer to local row values copy */
105 
107 
108 /*============================================================================
109  * Global variables
110  *============================================================================*/
111 
112 /* Short names for matrix types */
113 
114 extern const char *cs_matrix_type_name[];
115 
116 /* Full names for matrix types */
117 
118 extern const char *cs_matrix_type_fullname[];
119 
120 /* Fill type names for matrices */
121 
122 extern const char *cs_matrix_fill_type_name[];
123 
124 /*=============================================================================
125  * Public function prototypes
126  *============================================================================*/
127 
128 /*----------------------------------------------------------------------------
129  * Create a matrix structure.
130  *
131  * Note that the structure created usually maps to the given existing
132  * cell global number, face -> cell connectivity arrays, and cell halo
133  * structure, so it must be destroyed before they are freed
134  * (usually along with the code's main face -> cell structure).
135  *
136  * Note that the resulting matrix structure will contain either a full or
137  * an empty main diagonal, and that the extra-diagonal structure is always
138  * symmetric (though the coefficients my not be, and we may choose a
139  * matrix format that does not exploit this symmetry). If the edges
140  * connectivity argument is NULL, the matrix will be purely diagonal.
141  *
142  * parameters:
143  * type <-- type of matrix considered
144  * have_diag <-- indicates if the diagonal structure contains nonzeroes
145  * n_rows <-- local number of rows
146  * n_cols_ext <-- number of columns + ghosts
147  * n_edges <-- local number of (undirected) graph edges
148  * edges <-- edges (symmetric row <-> column) connectivity
149  * halo <-- halo structure associated with cells, or NULL
150  * numbering <-- vectorization or thread-related numbering info, or NULL
151  *
152  * returns:
153  * pointer to created matrix structure;
154  *----------------------------------------------------------------------------*/
155 
158  bool have_diag,
159  cs_lnum_t n_rows,
160  cs_lnum_t n_cols_ext,
161  cs_lnum_t n_edges,
162  const cs_gnum_t *cell_num,
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 CDO 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  * Destroy a matrix structure.
209  *
210  * parameters:
211  * ms <-> pointer to matrix structure pointer
212  *----------------------------------------------------------------------------*/
213 
214 void
216 
217 /*----------------------------------------------------------------------------
218  * Create a matrix container using a given structure.
219  *
220  * Note that the matrix container maps to the assigned structure,
221  * so it must be destroyed before that structure.
222  *
223  * parameters:
224  * ms <-- associated matrix structure
225  *
226  * returns:
227  * pointer to created matrix structure;
228  *----------------------------------------------------------------------------*/
229 
230 cs_matrix_t *
232 
233 /*----------------------------------------------------------------------------
234  * Create a matrix container using a given variant.
235  *
236  * If the matrix variant is incompatible with the structure, it is ignored,
237  * and defaults for that structure are used instead.
238  *
239  * parameters:
240  * ms <-- associated matrix structure
241  * mv <-- associated matrix variant
242  *
243  * returns:
244  * pointer to created matrix structure;
245  *----------------------------------------------------------------------------*/
246 
247 cs_matrix_t *
249  const cs_matrix_variant_t *mv);
250 
251 /*----------------------------------------------------------------------------
252  * Destroy a matrix structure.
253  *
254  * In the case of a compoud matrix, sub-matrices are not destroyed.
255  *
256  * parameters:
257  * matrix <-> pointer to matrix structure pointer
258  *----------------------------------------------------------------------------*/
259 
260 void
262 
263 /*----------------------------------------------------------------------------
264  * Return type of matrix.
265  *
266  * parameters:
267  * matrix --> pointer to matrix structure
268  *----------------------------------------------------------------------------*/
269 
272 
273 /*----------------------------------------------------------------------------
274  * Return number of columns in matrix.
275  *
276  * parameters:
277  * matrix --> pointer to matrix structure
278  *----------------------------------------------------------------------------*/
279 
280 cs_lnum_t
282 
283 /*----------------------------------------------------------------------------
284  * Return number of rows in matrix.
285  *
286  * parameters:
287  * matrix --> pointer to matrix structure
288  *----------------------------------------------------------------------------*/
289 
290 cs_lnum_t
292 
293 /*----------------------------------------------------------------------------
294  * Return matrix diagonal block sizes.
295  *
296  * Block sizes are defined by a array of 4 values:
297  * 0: useful block size, 1: vector block extents,
298  * 2: matrix line extents, 3: matrix line*column extents
299  *
300  * parameters:
301  * matrix <-- pointer to matrix structure
302  *
303  * returns:
304  * pointer to block sizes
305  *----------------------------------------------------------------------------*/
306 
307 const int *
309 
310 /*----------------------------------------------------------------------------
311  * Return matrix extra-diagonal block sizes.
312  *
313  * Block sizes are defined by a array of 4 values:
314  * 0: useful block size, 1: vector block extents,
315  * 2: matrix line extents, 3: matrix line*column extents
316  *
317  * parameters:
318  * matrix <-- pointer to matrix structure
319  *
320  * returns:
321  * pointer to block sizes
322  *----------------------------------------------------------------------------*/
323 
324 const int *
326 
327 /*----------------------------------------------------------------------------
328  * Return pointer to matrix halo structure.
329  *
330  * parameters:
331  * matrix <-- pointer to matrix structure
332  *
333  * returns:
334  * pointer to halo strucuture
335  *----------------------------------------------------------------------------*/
336 
337 const cs_halo_t *
339 
340 /*----------------------------------------------------------------------------
341  * Get matrix fill type, depending on block sizes.
342  *
343  * Block sizes are defined by an optional array of 4 values:
344  * 0: useful block size, 1: vector block extents,
345  * 2: matrix line extents, 3: matrix line*column extents
346  *
347  * parameters:
348  * symmetric <-- indicates if matrix coefficients are symmetric
349  * diag_block_size <-- block sizes for diagonal, or NULL
350  * extra_diag_block_size <-- block sizes for extra diagonal, or NULL
351  *
352  * returns:
353  * matrix fill type
354  *----------------------------------------------------------------------------*/
355 
357 cs_matrix_get_fill_type(bool symmetric,
358  const int *diag_block_size,
359  const int *extra_diag_block_size);
360 
361 /*----------------------------------------------------------------------------
362  * Set matrix coefficients defined relative to a "native" edge graph,
363  * sharing arrays with the caller when possible.
364  *
365  * With shared arrays, the matrix becomes unusable if the arrays passed as
366  * arguments are not be modified (its coefficients should be unset first
367  * to mark this).
368  *
369  * Depending on current options and initialization, values will be copied
370  * or simply mapped.
371  *
372  * Block sizes are defined by an optional array of 4 values:
373  * 0: useful block size, 1: vector block extents,
374  * 2: matrix line extents, 3: matrix line*column extents
375  *
376  * parameters:
377  * matrix <-> pointer to matrix structure
378  * symmetric <-- indicates if matrix coefficients are symmetric
379  * diag_block_size <-- block sizes for diagonal, or NULL
380  * extra_diag_block_size <-- block sizes for extra diagonal, or NULL
381  * n_edges <-- local number of graph edges
382  * edges <-- edges (row <-> column) connectivity
383  * da <-- diagonal values (NULL if zero)
384  * xa <-- extradiagonal values (NULL if zero)
385  * casts as:
386  * xa[n_edges] if symmetric,
387  * xa[n_edges][2] if non symmetric
388  *----------------------------------------------------------------------------*/
389 
390 void
392  bool symmetric,
393  const int *diag_block_size,
394  const int *extra_diag_block_size,
395  const cs_lnum_t n_edges,
396  const cs_lnum_2_t edges[],
397  const cs_real_t *da,
398  const cs_real_t *xa);
399 
400 /*----------------------------------------------------------------------------
401  * Set matrix coefficients, copying values to private arrays.
402  *
403  * With private arrays, the matrix becomes independant from the
404  * arrays passed as arguments.
405  *
406  * Block sizes are defined by an optional array of 4 values:
407  * 0: useful block size, 1: vector block extents,
408  * 2: matrix line extents, 3: matrix line*column extents
409  *
410  * parameters:
411  * matrix <-> pointer to matrix structure
412  * symmetric <-- indicates if matrix coefficients are symmetric
413  * diag_block_size <-- block sizes for diagonal, or NULL
414  * extra_diag_block_size <-- block sizes for extra diagonal, or NULL
415  * n_edges <-- local number of graph edges
416  * edges <-- edges (row <-> column) connectivity
417  * da <-- diagonal values (NULL if zero)
418  * xa <-- extradiagonal values (NULL if zero)
419  * casts as:
420  * xa[n_edges] if symmetric,
421  * xa[n_edges][2] if non symmetric
422  *----------------------------------------------------------------------------*/
423 
424 void
426  bool symmetric,
427  const int *diag_block_size,
428  const int *extra_diag_block_size,
429  const cs_lnum_t n_edges,
430  const cs_lnum_2_t edges[],
431  const cs_real_t *da,
432  const cs_real_t *xa);
433 
434 /*----------------------------------------------------------------------------
435  * Set matrix coefficients in an MSR format, transferring the
436  * property of those arrays to the matrix.
437  *
438  * If the matrix is also in MSR format, this avoids an extra copy.
439  * If it is in a different format, values are copied to the structure,
440  * and the original arrays freed. In any case, the arrays pointers passed as
441  * arguments are set to NULL, to help ensure the caller does not use the
442  * original arrays directly after this call.
443  *
444  * Block sizes are defined by an optional array of 4 values:
445  * 0: useful block size, 1: vector block extents,
446  * 2: matrix line extents, 3: matrix line*column extents
447  *
448  * parameters:
449  * matrix <-> pointer to matrix structure
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  * row_index <-- MSR row index (0 to n-1)
454  * col_id <-- MSR column id (0 to n-1)
455  * d_val <-> diagonal values (NULL if zero)
456  * x_val <-> extradiagonal values (NULL if zero)
457  *----------------------------------------------------------------------------*/
458 
459 void
461  bool symmetric,
462  const int *diag_block_size,
463  const int *extra_diag_block_size,
464  const cs_lnum_t row_index[],
465  const cs_lnum_t col_id[],
466  cs_real_t **d_val,
467  cs_real_t **x_val);
468 
469 /*----------------------------------------------------------------------------
470  * Release shared matrix coefficients.
471  *
472  * Pointers to mapped coefficients are set to NULL, while
473  * coefficient copies owned by the matrix are not modified.
474  *
475  * This simply ensures the matrix does not maintain pointers
476  * to nonexistant data.
477  *
478  * parameters:
479  * matrix <-> pointer to matrix structure
480  *----------------------------------------------------------------------------*/
481 
482 void
484 
485 /*----------------------------------------------------------------------------
486  * Copy matrix diagonal values.
487  *
488  * In case of matrixes with block diagonal coefficients, only the true
489  * diagonal values are copied.
490  *
491  * parameters:
492  * matrix --> pointer to matrix structure
493  * da --> diagonal (pre-allocated, size: n_rows*block_size
494  *----------------------------------------------------------------------------*/
495 
496 void
498  cs_real_t *restrict da);
499 
500 /*----------------------------------------------------------------------------
501  * Query matrix coefficients symmetry
502  *
503  * parameters:
504  * matrix <-- pointer to matrix structure
505  *
506  * returns:
507  * true if coefficients are symmetric, false otherwise
508  *----------------------------------------------------------------------------*/
509 
510 bool
512 
513 /*----------------------------------------------------------------------------
514  * Get matrix diagonal values.
515  *
516  * In case of matrixes with block diagonal coefficients, a pointer to
517  * the complete block diagonal is returned.
518  *
519  * parameters:
520  * matrix --> pointer to matrix structure
521  *
522  * returns:
523  * pointer to matrix diagonal array
524  *----------------------------------------------------------------------------*/
525 
526 const cs_real_t *
528 
529 /*----------------------------------------------------------------------------
530  * Get pointer to matrix extra-diagonal values in "native" format
531  *
532  * This function currently only functions if the matrix is in "native"
533  * format or the coefficients were mapped from native coefficients using
534  * cs_matrix_set_coefficients(), in which case the pointer returned is
535  * the same as the one passed to that function.
536  *
537  * parameters:
538  * matrix --> pointer to matrix structure
539  *
540  * returns:
541  * pointer to matrix diagonal array
542  *----------------------------------------------------------------------------*/
543 
544 const cs_real_t *
546 
547 /*----------------------------------------------------------------------------
548  * Initialize row info for a given matrix.
549  *
550  * parameters:
551  * r --> row info structure
552  *----------------------------------------------------------------------------*/
553 
554 void
556 
557 /*----------------------------------------------------------------------------
558  * Finalize row info for a given matrix.
559  *
560  * parameters:
561  * r <-> row info structure
562  *----------------------------------------------------------------------------*/
563 
564 void
566 
567 /*----------------------------------------------------------------------------
568  * Get row values for a given matrix.
569  *
570  * This function may not work for all matrix types.
571  *
572  * In the case of blocked matrixes, the true (non-blocked)
573  * values are returned.
574  *
575  * The row information structure must have been previously initialized
576  * using cs_matrix_row_init(), and should be finalized using
577  * using cs_matrix_row_finalize(), so as to free buffers it may have
578  * built for certain matrix formats.
579  *
580  * parameters:
581  * matrix <-- pointer to matrix structure
582  * row_id <-- id of row to query
583  * r <-> row info structure
584  *----------------------------------------------------------------------------*/
585 
586 void
588  const cs_lnum_t row_id,
590 
591 /*----------------------------------------------------------------------------
592  * Get arrays describing a matrix in native format.
593  *
594  * This function works for matrix in native format.
595  *
596  * Matrix block sizes can be obtained by cs_matrix_get_diag_block_size()
597  * and cs_matrix_get_extra_diag_block_size().
598  *
599  * parameters:
600  * matrix <-- pointer to matrix structure
601  * symmetric --> true if symmetric
602  * n_edges --> number of associated faces
603  * edges --> edges (symmetric row <-> column) connectivity
604  * d_val --> diagonal values
605  * x_val --> extra-diagonal values
606  *----------------------------------------------------------------------------*/
607 
608 void
610  bool *symmetric,
611  cs_lnum_t *n_edges,
612  const cs_lnum_2_t **edges,
613  const cs_real_t **d_val,
614  const cs_real_t **x_val);
615 
616 /*----------------------------------------------------------------------------
617  * Get arrays describing a matrix in CSR format.
618  *
619  * This function only works for an CSR matrix (i.e. there is
620  * no automatic conversion from another matrix type).
621  *
622  * Matrix block sizes can be obtained by cs_matrix_get_diag_block_size()
623  * and cs_matrix_get_extra_diag_block_size().
624  *
625  * parameters:
626  * matrix <-- pointer to matrix structure
627  * row_index --> CSR row index
628  * col_id --> CSR column id
629  * val --> values
630  *----------------------------------------------------------------------------*/
631 
632 void
634  const cs_lnum_t **row_index,
635  const cs_lnum_t **col_id,
636  const cs_real_t **val);
637 
638 /*----------------------------------------------------------------------------
639  * Get arrays describing a matrix in MSR format.
640  *
641  * This function only works for an MSR matrix (i.e. there is
642  * no automatic conversion from another matrix type).
643  *
644  * Matrix block sizes can be obtained by cs_matrix_get_diag_block_size()
645  * and cs_matrix_get_extra_diag_block_size().
646  *
647  * parameters:
648  * matrix <-- pointer to matrix structure
649  * row_index --> MSR row index
650  * col_id --> MSR column id
651  * d_val --> diagonal values
652  * x_val --> extra-diagonal values
653  *----------------------------------------------------------------------------*/
654 
655 void
657  const cs_lnum_t **row_index,
658  const cs_lnum_t **col_id,
659  const cs_real_t **d_val,
660  const cs_real_t **x_val);
661 
662 /*----------------------------------------------------------------------------
663  * Matrix.vector product y = A.x
664  *
665  * This function includes a halo update of x prior to multiplication by A.
666  *
667  * parameters:
668  * rotation_mode --> halo update option for rotational periodicity
669  * matrix --> pointer to matrix structure
670  * x <-> multipliying vector values (ghost values updated)
671  * y --> resulting vector
672  *----------------------------------------------------------------------------*/
673 
674 void
676  const cs_matrix_t *matrix,
677  cs_real_t *restrict x,
678  cs_real_t *restrict y);
679 
680 /*----------------------------------------------------------------------------
681  * Matrix.vector product y = A.x with no prior halo update of x.
682  *
683  * This function does not include a halo update of x prior to multiplication
684  * by A, so it should be called only when the halo of x is known to already
685  * be up to date (in which case we avoid the performance penalty of a
686  * redundant update by using this variant of the matrix.vector product).
687  *
688  * parameters:
689  * matrix --> pointer to matrix structure
690  * x --> multipliying vector values
691  * y --> resulting vector
692  *----------------------------------------------------------------------------*/
693 
694 void
696  const cs_real_t *x,
697  cs_real_t *restrict y);
698 
699 /*----------------------------------------------------------------------------
700  * Matrix.vector product y = (A-D).x
701  *
702  * This function includes a halo update of x prior to multiplication by A.
703  *
704  * parameters:
705  * rotation_mode <-- halo update option for rotational periodicity
706  * matrix <-- pointer to matrix structure
707  * x <-> multipliying vector values (ghost values updated)
708  * y --> resulting vector
709  *----------------------------------------------------------------------------*/
710 
711 void
713  const cs_matrix_t *matrix,
714  cs_real_t *restrict x,
715  cs_real_t *restrict y);
716 
717 /*----------------------------------------------------------------------------
718  * Build list of variants for tuning or testing.
719  *
720  * parameters:
721  * n_fill_types <-- number of fill types tuned for
722  * fill_types <-- array of fill types tuned for
723  * type_filter <-- true for matrix types tuned for, false for others
724  * numbering <-- vectorization or thread-related numbering info,
725  * or NULL
726  * n_variants --> number of variants
727  * m_variant --> array of matrix variants
728  *----------------------------------------------------------------------------*/
729 
730 void
731 cs_matrix_variant_build_list(int n_fill_types,
732  cs_matrix_fill_type_t fill_types[],
733  bool type_filter[],
734  const cs_numbering_t *numbering,
735  int *n_variants,
736  cs_matrix_variant_t **m_variant);
737 
738 /*----------------------------------------------------------------------------
739  * Build matrix variant
740  *
741  * The variant will initially use default matrix-vector functions,
742  * which can be later modified using cs_matrix_variant_set_func().
743  *
744  * parameters:
745  * type <-- type of matrix considered
746  * numbering <-- vectorization or thread-related numbering info,
747  * or NULL
748  *----------------------------------------------------------------------------*/
749 
752  const cs_numbering_t *numbering);
753 
754 /*----------------------------------------------------------------------------
755  * Destroy a matrix variant structure.
756  *
757  * parameters:
758  * mv <-> Pointer to matrix variant pointer
759  *----------------------------------------------------------------------------*/
760 
761 void
763 
764 /*----------------------------------------------------------------------------
765  * Select the sparse matrix-vector product function to be used by a
766  * matrix variant for a given fill type.
767  *
768  * Currently, possible variant functions are:
769  *
770  * CS_MATRIX_NATIVE (all fill types)
771  * standard
772  * fixed (for CS_MATRIX_??_BLOCK_D or CS_MATRIX_??_BLOCK_D_SYM)
773  * omp (for OpenMP with compatible numbering)
774  * vector (For vector machine with compatible numbering)
775  *
776  * CS_MATRIX_CSR (for CS_MATRIX_SCALAR or CS_MATRIX_SCALAR_SYM)
777  * standard
778  * mkl (with MKL)
779  *
780  * CS_MATRIX_CSR_SYM (for CS_MATRIX_SCALAR_SYM)
781  * standard
782  * mkl (with MKL)
783  *
784  * CS_MATRIX_MSR (all fill types except CS_MATRIX_33_BLOCK)
785  * standard
786  * generic (for CS_MATRIX_??_BLOCK_D or CS_MATRIX_??_BLOCK_D_SYM)
787  * mkl (with MKL, for CS_MATRIX_SCALAR or CS_MATRIX_SCALAR_SYM)
788  *
789  * parameters:
790  * mv <-> pointer to matrix variant
791  * numbering <-- mesh numbering info, or NULL
792  * fill type <-- matrix fill type to merge from
793  * ed_flag <-- 0: with diagonal only, 1 exclude only; 2; both
794  * func_name <-- function type name
795  *----------------------------------------------------------------------------*/
796 
797 void
799  const cs_numbering_t *numbering,
800  cs_matrix_fill_type_t fill_type,
801  int ed_flag,
802  const char *func_name);
803 
804 /*----------------------------------------------------------------------------
805  * Merge a functions to a matrix variant from another variant sharing
806  * the same structure.
807  *
808  * Functions from the structure to merge for the selected fill type are
809  * assigned to the main variant.
810  *
811  * This can be useful when tuning has been done separately for different fill
812  * types, and the resulting selected structure is identical.
813  *
814  * parameters:
815  * mv <-> pointer to matrix variant
816  * mv_merge <-- pointer to matrix variant to merge
817  * fill_type <-- matrix fill type to merge from
818  *----------------------------------------------------------------------------*/
819 
820 void
822  const cs_matrix_variant_t *mv_merge,
823  cs_matrix_fill_type_t fill_type);
824 
825 /*----------------------------------------------------------------------------
826  * Get the type associated with a matrix variant.
827  *
828  * parameters:
829  * mv <-- pointer to matrix variant structure
830  *----------------------------------------------------------------------------*/
831 
834 
835 /*----------------------------------------------------------------------------
836  * Test local matrix.vector product operations.
837  *
838  * parameters:
839  * n_rows <-- number of local rows
840  * n_cols_ext <-- number of columns + ghosts
841  * n_edges <-- local number of (undirected) graph edges
842  * cell_num <-- optional global cell numbers (1 to n), or NULL
843  * edges <-- edges (symmetric row <-> column) connectivity
844  * halo <-- cell halo structure
845  * numbering <-- vectorization or thread-related numbering info, or NULL
846  *----------------------------------------------------------------------------*/
847 
848 void
850  cs_lnum_t n_cols_ext,
851  cs_lnum_t n_edges,
852  const cs_gnum_t *cell_num,
853  const cs_lnum_2_t *edges,
854  const cs_halo_t *halo,
855  const cs_numbering_t *numbering);
856 
857 /*----------------------------------------------------------------------------*/
858 
860 
861 #endif /* __CS_MATRIX_H__ */
cs_lnum_t * _col_id
Definition: cs_matrix.h:102
const int * cs_matrix_get_diag_block_size(const cs_matrix_t *matrix)
Return matrix diagonal block sizes.
Definition: cs_matrix.c:5523
bool cs_matrix_is_symmetric(const cs_matrix_t *matrix)
Query matrix coefficients symmetry.
Definition: cs_matrix.c:5920
void cs_matrix_copy_coefficients(cs_matrix_t *matrix, bool symmetric, const int *diag_block_size, const int *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:5729
unsigned long cs_gnum_t
global mesh entity number
Definition: cs_defs.h:280
#define restrict
Definition: cs_defs.h:122
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:6340
const cs_halo_t * cs_matrix_get_halo(const cs_matrix_t *matrix)
Return pointer to matrix halo structure.
Definition: cs_matrix.c:5567
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:6387
void cs_matrix_row_finalize(cs_matrix_row_info_t *r)
Finalize row info for a given matrix.
Definition: cs_matrix.c:6082
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:6535
cs_halo_rotation_t
Definition: cs_halo.h:59
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:6296
Definition: cs_matrix.h:70
const int * cs_matrix_get_extra_diag_block_size(const cs_matrix_t *matrix)
Return matrix extra-diagonal block sizes.
Definition: cs_matrix.c:5547
void cs_matrix_transfer_coefficients_msr(cs_matrix_t *matrix, bool symmetric, const int *diag_block_size, const int *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:5789
void cs_matrix_row_init(cs_matrix_row_info_t *r)
Initialize row info for a given matrix.
Definition: cs_matrix.c:6063
cs_matrix_t * cs_matrix_create(const cs_matrix_structure_t *ms)
Create a matrix container using a given structure.
Definition: cs_matrix.c:5251
struct _cs_matrix_variant_t cs_matrix_variant_t
Definition: cs_matrix.h:93
#define BEGIN_C_DECLS
Definition: cs_defs.h:429
void cs_matrix_release_coefficients(cs_matrix_t *matrix)
Release shared matrix coefficients.
Definition: cs_matrix.c:5860
Definition: cs_matrix.h:79
Definition: cs_matrix.h:76
Definition: cs_halo.h:70
void cs_matrix_structure_destroy(cs_matrix_structure_t **ms)
Destroy a matrix structure.
Definition: cs_matrix.c:5194
void cs_matrix_copy_diagonal(const cs_matrix_t *matrix, cs_real_t *restrict da)
Copy matrix diagonal values.
Definition: cs_matrix.c:5896
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:6113
void cs_matrix_set_coefficients(cs_matrix_t *matrix, bool symmetric, const int *diag_block_size, const int *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:5664
const char * cs_matrix_type_fullname[]
const char * cs_matrix_fill_type_name[]
Definition: cs_matrix.h:78
struct _cs_matrix_t cs_matrix_t
Definition: cs_matrix.h:89
Definition: cs_matrix.h:72
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:6858
cs_matrix_fill_type_t cs_matrix_get_fill_type(bool symmetric, const int *diag_block_size, const int *extra_diag_block_size)
Get matrix fill type, depending on block sizes.
Definition: cs_matrix.c:5594
cs_lnum_t row_size
Definition: cs_matrix.h:99
const char * cs_matrix_type_name[]
const cs_lnum_t * col_id
Definition: cs_matrix.h:101
Definition: cs_matrix.h:60
cs_matrix_type_t
Definition: cs_matrix.h:54
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_gnum_t *cell_num, const cs_lnum_2_t *edges, const cs_halo_t *halo, const cs_numbering_t *numbering)
Create a matrix structure.
Definition: cs_matrix.c:5032
void matrix(const cs_int_t *const iconvp, const cs_int_t *const idiffp, const cs_int_t *const ndircp, const cs_int_t *const isym, const cs_real_t *const thetap, const cs_int_t *const 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_matrix.h:68
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:6242
Definition: cs_matrix.h:58
int cs_lnum_2_t[2]
vector of 2 local mesh-entity ids
Definition: cs_defs.h:301
const cs_real_t * vals
Definition: cs_matrix.h:103
cs_real_t * _vals
Definition: cs_matrix.h:104
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:6492
void cs_matrix_variant_test(cs_lnum_t n_rows, cs_lnum_t n_cols_ext, cs_lnum_t n_edges, const cs_gnum_t *cell_num, 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:6907
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:5130
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:292
cs_matrix_type_t cs_matrix_get_type(const cs_matrix_t *matrix)
Return number of columns in matrix.
Definition: cs_matrix.c:5466
cs_lnum_t cs_matrix_get_n_columns(const cs_matrix_t *matrix)
Return number of columns in matrix.
Definition: cs_matrix.c:5483
cs_lnum_t buffer_size
Definition: cs_matrix.h:100
void cs_matrix_destroy(cs_matrix_t **matrix)
Definition: cs_matrix.c:5410
#define END_C_DECLS
Definition: cs_defs.h:430
void cs_matrix_variant_destroy(cs_matrix_variant_t **mv)
Destroy a matrix variant structure.
Definition: cs_matrix.c:6770
Definition: cs_matrix.h:97
double cs_real_t
Definition: cs_defs.h:296
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:6456
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:6039
Definition: cs_matrix.h:59
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:5381
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:5500
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:6812
const cs_real_t * cs_matrix_get_diagonal(const cs_matrix_t *matrix)
Get matrix diagonal values.
Definition: cs_matrix.c:5939
Definition: cs_matrix.h:56
Definition: cs_matrix.h:69
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:6884
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:6425
Definition: cs_numbering.h:78
struct _cs_matrix_structure_t cs_matrix_structure_t
Definition: cs_matrix.h:85
cs_matrix_fill_type_t
Definition: cs_matrix.h:66