Actual source code: bvec3.c
2: /*
3: Implements the sequential vectors.
4: */
6: #include <private/vecimpl.h> /*I "petscvec.h" I*/
7: #include <../src/vec/vec/impls/dvecimpl.h>
9: /*MC
10: VECSEQ - VECSEQ = "seq" - The basic sequential vector
12: Options Database Keys:
13: . -vec_type seq - sets the vector type to VECSEQ during a call to VecSetFromOptions()
15: Level: beginner
17: .seealso: VecCreate(), VecSetType(), VecSetFromOptions(), VecCreateSeqWithArray(), VECMPI, VecType, VecCreateMPI(), VecCreateSeq()
18: M*/
20: #if defined(PETSC_USE_MIXED_PRECISION)
23: #endif
28: PetscErrorCode VecCreate_Seq(Vec V)
29: {
30: Vec_Seq *s;
31: PetscScalar *array;
33: PetscInt n = PetscMax(V->map->n,V->map->N);
34: PetscMPIInt size;
37: MPI_Comm_size(((PetscObject)V)->comm,&size);
38: if (size > 1) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Cannot create VECSEQ on more than one process");
39: #if !defined(PETSC_USE_MIXED_PRECISION)
40: PetscMalloc(n*sizeof(PetscScalar),&array);
41: PetscLogObjectMemory(V, n*sizeof(PetscScalar));
42: PetscMemzero(array,n*sizeof(PetscScalar));
43: VecCreate_Seq_Private(V,array);
44: s = (Vec_Seq*)V->data;
45: s->array_allocated = array;
46: #else
47: if (((PetscObject)V)->precision == PETSC_PRECISION_SINGLE) {
48: float *aarray;
49: PetscMalloc(n*sizeof(float),&aarray);
50: PetscLogObjectMemory(V, n*sizeof(float));
51: PetscMemzero(aarray,n*sizeof(float));
52: VecCreate_Seq_Private(V,aarray);
53: s = (Vec_Seq*)V->data;
54: s->array_allocated = (PetscScalar*)aarray;
55: } else {
56: double *aarray;
57: PetscMalloc(n*sizeof(double),&aarray);
58: PetscLogObjectMemory(V, n*sizeof(double));
59: PetscMemzero(aarray,n*sizeof(double));
60: VecCreate_Seq_Private(V,aarray);
61: s = (Vec_Seq*)V->data;
62: s->array_allocated = (PetscScalar*)aarray;
63: }
64: #endif
65: return(0);
66: }