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,PetscInt **);
      7: EXTERN PetscErrorCode ISRestoreIndices_General(IS,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 PETSCVEC_DLLEXPORT ISStrideToGeneral(IS inis)
     44: {
     46:   PetscInt       step;
     47:   IS_General     *sub;
     48:   PetscTruth     stride,flg;

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

     54:   PetscNew(IS_General,&sub);
     55:   PetscLogObjectMemory(inis,sizeof(IS_General));
     56:
     57:   ISGetIndices(inis,&sub->idx);
     58:   /* Note: we never restore the indices, since we need to keep the copy generated */
     59:   ISGetLocalSize(inis,&sub->n);

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

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

     68:   inis->type         = IS_GENERAL;
     69:   inis->data         = (void*)sub;
     70:   inis->isperm       = PETSC_FALSE;
     71:   PetscMemcpy(inis->ops,&myops,sizeof(myops));
     72:   PetscOptionsHasName(PETSC_NULL,"-is_view",&flg);
     73:   if (flg) {
     74:     ISView(inis,PETSC_VIEWER_STDOUT_(inis->comm));
     75:   }
     76:   return(0);
     77: }