Actual source code: bvec3.c
2: /*
3: Implements the sequential vectors.
4: */
6: #include <../src/vec/vec/impls/dvecimpl.h>
7: /*MC
8: VECSEQ - VECSEQ = "seq" - The basic sequential vector
10: Options Database Keys:
11: . -vec_type seq - sets the vector type to VECSEQ during a call to VecSetFromOptions()
13: Level: beginner
15: .seealso: `VecCreate()`, `VecSetType()`, `VecSetFromOptions()`, `VecCreateSeqWithArray()`, `VECMPI`, `VecType`, `VecCreateMPI()`, `VecCreateSeq()`
16: M*/
18: #if defined(PETSC_USE_MIXED_PRECISION)
19: extern PetscErrorCode VecCreate_Seq_Private(Vec, const float *);
20: extern PetscErrorCode VecCreate_Seq_Private(Vec, const double *);
21: #endif
23: PetscErrorCode VecCreate_Seq(Vec V)
24: {
25: Vec_Seq *s;
26: PetscScalar *array;
27: PetscInt n = PetscMax(V->map->n, V->map->N);
28: PetscMPIInt size;
30: PetscFunctionBegin;
31: PetscCallMPI(MPI_Comm_size(PetscObjectComm((PetscObject)V), &size));
32: PetscCheck(size <= 1, PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "Cannot create VECSEQ on more than one process");
33: #if !defined(PETSC_USE_MIXED_PRECISION)
34: PetscCall(PetscCalloc1(n, &array));
35: PetscCall(VecCreate_Seq_Private(V, array));
37: s = (Vec_Seq *)V->data;
38: s->array_allocated = array;
39: #else
40: switch (((PetscObject)V)->precision) {
41: case PETSC_PRECISION_SINGLE: {
42: float *aarray;
44: PetscCall(PetscCalloc1(n, &aarray));
45: PetscCall(VecCreate_Seq_Private(V, aarray));
47: s = (Vec_Seq *)V->data;
48: s->array_allocated = (PetscScalar *)aarray;
49: } break;
50: case PETSC_PRECISION_DOUBLE: {
51: double *aarray;
53: PetscCall(PetscCalloc1(n, &aarray));
54: PetscCall(VecCreate_Seq_Private(V, aarray));
56: s = (Vec_Seq *)V->data;
57: s->array_allocated = (PetscScalar *)aarray;
58: } break;
59: default:
60: SETERRQ(PetscObjectComm((PetscObject)V), PETSC_ERR_SUP, "No support for mixed precision %d", (int)(((PetscObject)V)->precision));
61: }
62: #endif
63: PetscFunctionReturn(PETSC_SUCCESS);
64: }