Actual source code: veccreate.c
2: #include <petsc/private/vecimpl.h>
4: /*@
5: VecCreate - Creates an empty vector object. The type can then be set with `VecSetType()`,
6: or `VecSetFromOptions().`
8: Collective
10: Input Parameter:
11: . comm - The communicator for the vector object
13: Output Parameter:
14: . vec - The vector object
16: Level: beginner
18: Notes:
19: If you never call `VecSetType()` or `VecSetFromOptions()` it will generate an
20: error when you try to use the vector.
22: .seealso: [](ch_vectors), `Vec`, `VecSetType()`, `VecSetSizes()`, `VecCreateMPIWithArray()`, `VecCreateMPI()`, `VecDuplicate()`,
23: `VecDuplicateVecs()`, `VecCreateGhost()`, `VecCreateSeq()`, `VecPlaceArray()`
24: @*/
25: PetscErrorCode VecCreate(MPI_Comm comm, Vec *vec)
26: {
27: Vec v;
29: PetscFunctionBegin;
31: *vec = NULL;
32: PetscCall(VecInitializePackage());
34: PetscCall(PetscHeaderCreate(v, VEC_CLASSID, "Vec", "Vector", "Vec", comm, VecDestroy, VecView));
36: PetscCall(PetscLayoutCreate(comm, &v->map));
37: v->array_gotten = PETSC_FALSE;
38: v->petscnative = PETSC_FALSE;
39: v->offloadmask = PETSC_OFFLOAD_UNALLOCATED;
40: #if defined(PETSC_HAVE_VIENNACL) || defined(PETSC_HAVE_CUDA) || defined(PETSC_HAVE_HIP)
41: v->minimum_bytes_pinned_memory = 0;
42: v->pinned_memory = PETSC_FALSE;
43: #endif
44: #if defined(PETSC_HAVE_DEVICE)
45: v->boundtocpu = PETSC_TRUE;
46: #endif
47: PetscCall(PetscStrallocpy(PETSCRANDER48, &v->defaultrandtype));
48: *vec = v;
49: PetscFunctionReturn(PETSC_SUCCESS);
50: }