# MatCreateAIJCUSPARSE
Creates a sparse matrix in `MATAIJCUSPARSE` (compressed row) format (the default parallel PETSc format).  This matrix will ultimately pushed down to NVIDIA GPUs and use the CuSPARSE library for calculations. For good matrix assembly performance the user should preallocate the matrix storage by setting the parameter nz (or the array nnz).  By setting these parameters accurately, performance during matrix assembly can be increased by more than a factor of 50. 
## Synopsis
```
#include "petscmat.h" 
PetscErrorCode MatCreateAIJCUSPARSE(MPI_Comm comm, PetscInt m, PetscInt n, PetscInt M, PetscInt N, PetscInt d_nz, const PetscInt d_nnz[], PetscInt o_nz, const PetscInt o_nnz[], Mat *A)
```
Collective


## Input Parameters

- ***comm -*** MPI communicator, set to `PETSC_COMM_SELF`
- ***m -*** number of rows
- ***n -*** number of columns
- ***nz -*** number of nonzeros per row (same for all rows)
- ***nnz -*** array containing the number of nonzeros in the various rows
(possibly different for each row) or NULL



## Output Parameter

- ***A -*** the matrix


It is recommended that one use the `MatCreate()`, `MatSetType()` and/or `MatSetFromOptions()`,
MatXXXXSetPreallocation() paradigm instead of this routine directly.
[MatXXXXSetPreallocation() is, for example, `MatSeqAIJSetPreallocation()`]


## Notes
If nnz is given then nz is ignored

The AIJ format, also called the
compressed row storage), is fully compatible with standard Fortran 77
storage.  That is, the stored row and column indices can begin at
either one (as in Fortran) or zero.  See the users' manual for details.

Specify the preallocated storage with either nz or nnz (not both).
Set nz = `PETSC_DEFAULT` and nnz = NULL for PETSc to control dynamic memory
allocation.  For large problems you MUST preallocate memory or you
will get TERRIBLE performance, see the users' manual chapter on matrices.

By default, this format uses inodes (identical nodes) when possible, to
improve numerical efficiency of matrix-vector products and solves. We
search for consecutive rows with the same nonzero structure, thereby
reusing matrix information to achieve increased efficiency.




## See Also
 `MATAIJCUSPARSE`, `MatCreate()`, `MatCreateAIJ()`, `MatSetValues()`, `MatSeqAIJSetColumnIndices()`, `MatCreateSeqAIJWithArrays()`, `MatCreateAIJ()`, `MATMPIAIJCUSPARSE`, `MATAIJCUSPARSE`

## Level
intermediate

## Location
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/aij/mpi/mpicusparse/mpiaijcusparse.cu.html#MatCreateAIJCUSPARSE">src/mat/impls/aij/mpi/mpicusparse/mpiaijcusparse.cu</A>

## Examples
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/tutorials/ex5cu.cu.html">src/mat/tutorials/ex5cu.cu.html</A><BR>


---
[Edit on GitLab](https://gitlab.com/petsc/petsc/-/edit/release/src/mat/impls/aij/mpi/mpicusparse/mpiaijcusparse.cu)


[Index of all Mat routines](index.md)  
[Table of Contents for all manual pages](/docs/manualpages/index.md)  
[Index of all manual pages](/docs/manualpages/singleindex.md)  
