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: PETSC_EXTERN 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:   MPI_Comm_size(PetscObjectComm((PetscObject)V),&size);
 32: #if !defined(PETSC_USE_MIXED_PRECISION)
 33:   PetscCalloc1(n,&array);
 34:   PetscLogObjectMemory((PetscObject)V, n*sizeof(PetscScalar));
 35:   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:     PetscCalloc1(n,&aarray);
 45:     PetscLogObjectMemory((PetscObject)V, n*sizeof(float));
 46:     VecCreate_Seq_Private(V,aarray);

 48:     s                  = (Vec_Seq*)V->data;
 49:     s->array_allocated = (PetscScalar*)aarray;
 50:   } break;
 51:   case PETSC_PRECISION_DOUBLE: {
 52:     double *aarray;

 54:     PetscCalloc1(n,&aarray);
 55:     PetscLogObjectMemory((PetscObject)V, n*sizeof(double));
 56:     VecCreate_Seq_Private(V,aarray);

 58:     s                  = (Vec_Seq*)V->data;
 59:     s->array_allocated = (PetscScalar*)aarray;
 60:   } break;
 61:   default: SETERRQ(PetscObjectComm((PetscObject)V),PETSC_ERR_SUP,"No support for mixed precision %d",(int)(((PetscObject)V)->precision));
 62:   }
 63: #endif
 64:   return 0;
 65: }