Date: 2013-07-02T14:40:01+00:00

Actual source code: bvec3.c
petsc-3.4.2 2013-07-02

      2: /*
      3:    Implements the sequential vectors.
      4: */

      6: #include <../src/vec/vec/impls/dvecimpl.h>          /*I "petscvec.h" I*/
      7: #include <petscthreadcomm.h>
      8: /*MC
      9:    VECSEQ - VECSEQ = "seq" - The basic sequential vector

     11:    Options Database Keys:
     12: . -vec_type seq - sets the vector type to VECSEQ during a call to VecSetFromOptions()

     14:   Level: beginner

     16: .seealso: VecCreate(), VecSetType(), VecSetFromOptions(), VecCreateSeqWithArray(), VECMPI, VecType, VecCreateMPI(), VecCreateSeq()
     17: M*/

     19: #if defined(PETSC_USE_MIXED_PRECISION)
     20: extern PetscErrorCode VecCreate_Seq_Private(Vec,const float*);
     21: extern PetscErrorCode VecCreate_Seq_Private(Vec,const double*);
     22: #endif

     26: PETSC_EXTERN PetscErrorCode VecCreate_Seq(Vec V)
     27: {
     28:   Vec_Seq        *s;
     29:   PetscScalar    *array;
     31:   PetscInt       n = PetscMax(V->map->n,V->map->N);
     32:   PetscMPIInt    size;

     35:   MPI_Comm_size(PetscObjectComm((PetscObject)V),&size);
     36:   if (size > 1) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Cannot create VECSEQ on more than one process");
     37: #if !defined(PETSC_USE_MIXED_PRECISION)
     38:   PetscMalloc(n*sizeof(PetscScalar),&array);
     39:   PetscLogObjectMemory(V, n*sizeof(PetscScalar));
     40:   VecCreate_Seq_Private(V,array);

     42:   s                  = (Vec_Seq*)V->data;
     43:   s->array_allocated = array;

     45:   VecSet(V,0.0);
     46: #else
     47:   switch (((PetscObject)V)->precision) {
     48:   case PETSC_PRECISION_SINGLE: {
     49:     float *aarray;

     51:     PetscMalloc(n*sizeof(float),&aarray);
     52:     PetscLogObjectMemory(V, n*sizeof(float));
     53:     PetscMemzero(aarray,n*sizeof(float));
     54:     VecCreate_Seq_Private(V,aarray);

     56:     s                  = (Vec_Seq*)V->data;
     57:     s->array_allocated = (PetscScalar*)aarray;
     58:   } break;
     59:   case PETSC_PRECISION_DOUBLE: {
     60:     double *aarray;

     62:     PetscMalloc(n*sizeof(double),&aarray);
     63:     PetscLogObjectMemory(V, n*sizeof(double));
     64:     PetscMemzero(aarray,n*sizeof(double));
     65:     VecCreate_Seq_Private(V,aarray);

     67:     s                  = (Vec_Seq*)V->data;
     68:     s->array_allocated = (PetscScalar*)aarray;
     69:   } break;
     70:   default: SETERRQ1(PetscObjectComm((PetscObject)V),PETSC_ERR_SUP,"No support for mixed precision %d",(int)(((PetscObject)V)->precision));
     71:   }
     72: #endif
     73:   return(0);
     74: }