Skip to main content
`Ctrl`+`K`

# MatMPIAdjSetPreallocation

Sets the array used for storing the matrix elements

## Synopsis

    #include "petscmat.h"
    PetscErrorCode MatMPIAdjSetPreallocation(Mat B, PetscInt *i, PetscInt *j, PetscInt *values)

Logically Collective

## Input Parameters

- B - the matrix

- i - the indices into `j` for the start of each row

- j - the column indices for each row (sorted for each row). The indices in `i` and `j` start with zero (NOT with one).

- values - [use `NULL` if not provided] edge weights

## Notes

The indices in `i` and `j` start with zero (NOT with one).

You must NOT free the `i`, `values` and `j` arrays yourself. PETSc will free them when the matrix is destroyed; you must allocate them with `PetscMalloc()`.

You should not include the matrix diagonal elements.

If you already have a matrix, you can create its adjacency matrix by a call to `MatConvert()`, specifying a type of `MATMPIADJ`.

Possible values for `MatSetOption()` - `MAT_STRUCTURALLY_SYMMETRIC`

## Fortran Note

From Fortran the indices and values are copied so the array space need not be provided with `PetscMalloc()`.

## See Also

Matrices, `Mat`, `MatCreate()`, `MatCreateMPIAdj()`, `MatSetValues()`, `MATMPIADJ`

## Level

intermediate

## Location

src/mat/impls/adj/mpi/mpiadj.c

## Implementations

MatMPIAdjSetPreallocation_MPIAdj() in src/mat/impls/adj/mpi/mpiadj.c

Index of all Mat routines
Table of Contents for all manual pages
Index of all manual pages