8.1
general documentation
cs_matrix_petsc.c File Reference

Sparse Matrix Representation and Operations using PETSc. More...

#include "cs_defs.h"
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <math.h>
#include <petscmat.h>
#include <petscvec.h>
#include <petscversion.h>
#include <petscviewer.h>
#include "bft_mem.h"
#include "bft_error.h"
#include "bft_printf.h"
#include "cs_base.h"
#include "cs_halo.h"
#include "cs_log.h"
#include "cs_numbering.h"
#include "cs_timer.h"
#include "cs_matrix.h"
#include "cs_base_accel.h"
#include "cs_matrix_default.h"
#include "cs_matrix_petsc.h"
#include "cs_matrix_petsc_priv.h"
#include "cs_matrix_priv.h"
+ Include dependency graph for cs_matrix_petsc.c:

Functions

void cs_matrix_set_type_petsc (cs_matrix_t *matrix, const char *type_name)
 Switch matrix type to PETSc. More...
 

Detailed Description

Sparse Matrix Representation and Operations using PETSc.

Setting a matrix type to PETc directly allows avoidind duplicating values, and assigning them directly to PETSc.

This should save memory, thoght performance might not be optimal, as the current implementation requires many calls to MatSetValues. MatSetValues can require at least one call per matrix block, as the values arrays passed to it assume a dense rectangular block. Block structures are not exploited yet.

Performance could possibly be improved by assembling local arrays in a manner similar to code_saturne's CS_MATRIX_DIST matrix, but using PETSc types (to ensure sizes are the same), and assigning it to PETSc using MatCreateMPIAIJWithSplitArrays. Use of this function is not recommended by PETSc as it is considered cumbersome and inflexible. This would not be too much of an issue here (since we already have that capacity), but might not be compatible with all PETSc matrix formats. An alternative would be to use MatCreateMPIAIJWithArrays with a temporary copy, but would involve higher peak memory use. Finally, the MatSetValuesBatch function mighr be used in the future, if it is extended so as to allow multiple calls for a given matrix.

Function Documentation

◆ cs_matrix_set_type_petsc()

void cs_matrix_set_type_petsc ( cs_matrix_t matrix,
const char *  type_name 
)

Switch matrix type to PETSc.

This releases previous coefficients if present, so should be called just after matrix creation, before assigning coefficients.

Parameters
[in,out]matrixpointer to matrix structure
[in]type_namestring matching PETSc matrix type name, defaults to "MATAIJ" if NULL