Actual source code: strgen.c

  1: #define PETSCVEC_DLL
 2:  #include ../src/vec/is/impls/general/general.h

  4: EXTERN PetscErrorCode ISDuplicate_General(IS,IS *);
  5: EXTERN PetscErrorCode ISDestroy_General(IS);
  6: EXTERN PetscErrorCode ISGetIndices_General(IS,const PetscInt *[]);
  7: EXTERN PetscErrorCode ISRestoreIndices_General(IS,const PetscInt *[]);
  8: EXTERN PetscErrorCode ISGetSize_General(IS,PetscInt *);
  9: EXTERN PetscErrorCode ISGetLocalSize_General(IS,PetscInt *);
 10: EXTERN PetscErrorCode ISInvertPermutation_General(IS,PetscInt,IS *);
 11: EXTERN PetscErrorCode ISView_General(IS,PetscViewer);
 12: EXTERN PetscErrorCode ISSort_General(IS);
 13: EXTERN PetscErrorCode ISSorted_General(IS,PetscTruth*);

 15: static struct _ISOps myops = { ISGetSize_General,
 16:                                ISGetLocalSize_General,
 17:                                ISGetIndices_General,
 18:                                ISRestoreIndices_General,
 19:                                ISInvertPermutation_General,
 20:                                ISSort_General,
 21:                                ISSorted_General,
 22:                                ISDuplicate_General,
 23:                                ISDestroy_General,
 24:                                ISView_General};

 28: /*@C
 29:    ISStrideToGeneral - Converts a stride index set to a general index set.

 31:    Collective on IS

 33:    Input Parameters:
 34: .    is - the index set

 36:    Level: advanced

 38:    Concepts: index sets^converting
 39:    Concepts: stride^converting index sets

 41: .seealso: ISCreateStride(), ISCreateBlock(), ISCreateGeneral()
 42: @*/
 43: PetscErrorCode  ISStrideToGeneral(IS inis)
 44: {
 46:   PetscInt       step;
 47:   IS_General     *sub;
 48:   PetscTruth     stride,flg = PETSC_FALSE;
 49:   const PetscInt *idx;

 52:   ISStride(inis,&stride);
 53:   if (!stride) SETERRQ(PETSC_ERR_SUP,"Can only convert stride index sets");

 55:   PetscNewLog(inis,IS_General,&sub);
 56: 
 57:   ISGetLocalSize(inis,&sub->n);
 58:   ISGetIndices(inis,&idx);
 59:   PetscMalloc(sub->n*sizeof(PetscInt),&sub->idx);
 60:   PetscMemcpy(sub->idx,idx,sub->n*sizeof(PetscInt));
 61:   ISRestoreIndices(inis,&idx);

 63:   ISStrideGetInfo(inis,PETSC_NULL,&step);
 64:   if (step > 0) sub->sorted = PETSC_TRUE; else sub->sorted = PETSC_FALSE;
 65:   sub->allocated = PETSC_TRUE;

 67:   /* Remove the old stride data set */
 68:   PetscFree(inis->data);

 70:   ((PetscObject)inis)->type         = IS_GENERAL;
 71:   inis->data         = (void*)sub;
 72:   inis->isperm       = PETSC_FALSE;
 73:   PetscMemcpy(inis->ops,&myops,sizeof(myops));
 74:   PetscOptionsGetTruth(PETSC_NULL,"-is_view",&flg,PETSC_NULL);
 75:   if (flg) {
 76:     PetscViewer viewer;
 77:     PetscViewerASCIIGetStdout(((PetscObject)inis)->comm,&viewer);
 78:     ISView(inis,viewer);
 79:   }
 80:   return(0);
 81: }