VecCreateSeqCUDAWithArray — PETSc 3.25.0 documentation

Skip to main content
`Ctrl`+`K`

# VecCreateSeqCUDAWithArray

Creates a sequential, array-style vector using CUDA, where the user provides the device array space to store the vector values.

## Synopsis

    #include <petscvec.h>
    PetscErrorCode VecCreateSeqCUDAWithArray(MPI_Comm comm, PetscInt bs, PetscInt n, const PetscScalar gpuarray[], Vec *v)

Collective, Possibly Synchronous

## Input Parameters

- comm - the communicator, must be `PETSC_COMM_SELF`

- bs - the block size

- n - the vector length

- gpuarray - GPU memory where the vector elements are to be stored (or `NULL`)

## Output Parameter

- v - the vector

## Notes

If the user-provided array is `NULL`, then `VecCUDAPlaceArray()` can be used at a later stage to SET the array for storing the vector values. Otherwise, the array must be allocated on the device.

The array is NOT freed when the vector is destroyed via `VecDestroy()`. The user must free the array themselves, but not until the vector is destroyed.

Use `VecDuplicate()` or `VecDuplicateVecs()` to form additional vectors of the same type as an existing vector.

This function may initialize `PetscDevice`, which may incur a device synchronization.

## See Also

Vectors and Parallel Data, `PetscDeviceInitialize()`, `VecCreate()`, `VecCreateSeq()`, `VecCreateSeqWithArray()`, `VecCreateMPIWithArray()`, `VecCreateSeqCUDA()`, `VecCreateMPICUDAWithArray()`, `VecCUDAPlaceArray()`, `VecDuplicate()`, `VecDuplicateVecs()`, `VecCreateGhost()`

## Level

intermediate

## Location

src/vec/vec/impls/seq/cupm/cuda/vecseqcupm.cu

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