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: If you never call VecSetType() or VecSetFromOptions() it will generate an
9: error when you try to use the vector.
11: Collective
13: Input Parameter:
14: . comm - The communicator for the vector object
16: Output Parameter:
17: . vec - The vector object
19: Level: beginner
21: .seealso: `VecSetType()`, `VecSetSizes()`, `VecCreateMPIWithArray()`, `VecCreateMPI()`, `VecDuplicate()`,
22: `VecDuplicateVecs()`, `VecCreateGhost()`, `VecCreateSeq()`, `VecPlaceArray()`
23: @*/
24: PetscErrorCode VecCreate(MPI_Comm comm, Vec *vec)
25: {
26: Vec v;
28: PetscFunctionBegin;
30: *vec = NULL;
31: PetscCall(VecInitializePackage());
33: PetscCall(PetscHeaderCreate(v, VEC_CLASSID, "Vec", "Vector", "Vec", comm, VecDestroy, VecView));
35: PetscCall(PetscLayoutCreate(comm, &v->map));
36: v->array_gotten = PETSC_FALSE;
37: v->petscnative = PETSC_FALSE;
38: v->offloadmask = PETSC_OFFLOAD_UNALLOCATED;
39: #if defined(PETSC_HAVE_VIENNACL) || defined(PETSC_HAVE_CUDA) || defined(PETSC_HAVE_HIP)
40: v->minimum_bytes_pinned_memory = 0;
41: v->pinned_memory = PETSC_FALSE;
42: #endif
43: #if defined(PETSC_HAVE_DEVICE)
44: v->boundtocpu = PETSC_TRUE;
45: #endif
46: PetscCall(PetscStrallocpy(PETSCRANDER48, &v->defaultrandtype));
47: *vec = v;
48: PetscFunctionReturn(PETSC_SUCCESS);
49: }