#define PETSCVEC_DLL /* Routines to be used by MatIncreaseOverlap() for BAIJ and SBAIJ matrices */ #include "petscis.h" #include "petscbt.h" #include "petscctable.h" #undef __FUNCT__ #define __FUNCT__ "ISCompressIndicesGeneral" /*@C ISCompressIndicesGeneral - convert the indices into block indices Input Parameters: + n - the length of the index set . bs - the size of block . imax - the number of index sets - is_in - the non-blocked array of index sets Output Parameter: . is_out - the blocked new index set Level: intermediate @*/ PetscErrorCode PETSCVEC_DLLEXPORT ISCompressIndicesGeneral(PetscInt n,PetscInt bs,PetscInt imax,const IS is_in[],IS is_out[]) { PetscErrorCode ierr; PetscInt isz,len,i,j,*idx,ival,Nbs; #if defined (PETSC_USE_CTABLE) PetscTable gid1_lid1; PetscInt tt, gid1, *nidx; PetscTablePosition tpos; #else PetscInt *nidx; PetscBT table; #endif PetscFunctionBegin; Nbs =n/bs; #if defined (PETSC_USE_CTABLE) ierr = PetscTableCreate(Nbs,&gid1_lid1);CHKERRQ(ierr); #else ierr = PetscMalloc(Nbs*sizeof(PetscInt),&nidx);CHKERRQ(ierr); ierr = PetscBTCreate(Nbs,table);CHKERRQ(ierr); #endif for (i=0; iNbs) SETERRQ(PETSC_ERR_ARG_OUTOFRANGE,"index greater than mat-dim"); if(!PetscBTLookupSet(table,ival)) { nidx[isz++] = ival;} #endif } ierr = ISRestoreIndices(is_in[i],&idx);CHKERRQ(ierr); #if defined (PETSC_USE_CTABLE) ierr = PetscMalloc(isz*sizeof(PetscInt),&nidx);CHKERRQ(ierr); ierr = PetscTableGetHeadPosition(gid1_lid1,&tpos);CHKERRQ(ierr); j = 0; while (tpos) { ierr = PetscTableGetNext(gid1_lid1,&tpos,&gid1,&tt);CHKERRQ(ierr); if (tt-- > isz) { SETERRQ(PETSC_ERR_ARG_OUTOFRANGE,"index greater than array-dim"); } nidx[tt] = gid1 - 1; j++; } if (j != isz) { SETERRQ(PETSC_ERR_ARG_OUTOFRANGE,"table error: jj != isz"); } ierr = ISCreateGeneral(PETSC_COMM_SELF,isz,nidx,(is_out+i));CHKERRQ(ierr); ierr = PetscFree(nidx);CHKERRQ(ierr); #else ierr = ISCreateGeneral(PETSC_COMM_SELF,isz,nidx,(is_out+i));CHKERRQ(ierr); #endif } #if defined (PETSC_USE_CTABLE) ierr = PetscTableDelete(gid1_lid1);CHKERRQ(ierr); #else ierr = PetscBTDestroy(table);CHKERRQ(ierr); ierr = PetscFree(nidx);CHKERRQ(ierr); #endif PetscFunctionReturn(0); } #undef __FUNCT__ #define __FUNCT__ "ISCompressIndicesSorted" PetscErrorCode PETSCVEC_DLLEXPORT ISCompressIndicesSorted(PetscInt n,PetscInt bs,PetscInt imax,const IS is_in[],IS is_out[]) { PetscErrorCode ierr; PetscInt i,j,k,val,len,*idx,*nidx,*idx_local,bbs; PetscTruth flg,isblock; #if defined (PETSC_USE_CTABLE) PetscInt maxsz; #else PetscInt Nbs=n/bs; #endif PetscFunctionBegin; for (i=0; i maxsz) maxsz = len; } ierr = PetscMalloc(maxsz*sizeof(PetscInt),&nidx);CHKERRQ(ierr); #else ierr = PetscMalloc(Nbs*sizeof(PetscInt),&nidx);CHKERRQ(ierr); #endif /* Now check if the indices are in block order */ for (i=0; i maxsz) maxsz = len*bs; } ierr = PetscMalloc(maxsz*sizeof(PetscInt),&nidx);CHKERRQ(ierr); #else Nbs = n/bs; ierr = PetscMalloc(Nbs*bs*sizeof(PetscInt),&nidx);CHKERRQ(ierr); #endif for (i=0; i