#define PETSCVEC_DLL #include "petscis.h" /*I "petscis.h" I*/ #include "petscbt.h" #undef __FUNCT__ #define __FUNCT__ "ISDifference" /*@ ISDifference - Computes the difference between two index sets. Collective on IS Input Parameter: + is1 - first index, to have items removed from it - is2 - index values to be removed Output Parameters: . isout - is1 - is2 Notes: Negative values are removed from the lists. is2 may have values that are not in is1. This requires O(imax-imin) memory and O(imax-imin) work, where imin and imax are the bounds on the indices in is1. Level: intermediate Concepts: index sets^difference Concepts: IS^difference .seealso: ISDestroy(), ISView(), ISSum(), ISExpand() @*/ PetscErrorCode PETSCVEC_DLLEXPORT ISDifference(IS is1,IS is2,IS *isout) { PetscErrorCode ierr; PetscInt i,*i1,*i2,n1,n2,imin,imax,nout,*iout; PetscBT mask; MPI_Comm comm; PetscFunctionBegin; PetscValidHeaderSpecific(is1,IS_COOKIE,1); PetscValidHeaderSpecific(is2,IS_COOKIE,2); PetscValidPointer(isout,3); ierr = ISGetIndices(is1,&i1);CHKERRQ(ierr); ierr = ISGetLocalSize(is1,&n1);CHKERRQ(ierr); /* Create a bit mask array to contain required values */ if (n1) { imin = PETSC_MAX_INT; imax = 0; for (i=0; i imax) continue; ierr = PetscBTClear(mask,i2[i] - imin);CHKERRQ(ierr); } ierr = ISRestoreIndices(is2,&i2);CHKERRQ(ierr); /* Count the number in the difference */ nout = 0; for (i=0; i1) SETERRQ(PETSC_ERR_SUP,"Currently only for uni-processor IS"); ierr = ISSorted(*is1,&f); CHKERRQ(ierr); if (!f) SETERRQ(PETSC_ERR_ARG_INCOMP,"Arg 1 is not sorted"); ierr = ISSorted(is2,&f); CHKERRQ(ierr); if (!f) SETERRQ(PETSC_ERR_ARG_INCOMP,"Arg 2 is not sorted"); ierr = ISGetLocalSize(*is1,&n1);CHKERRQ(ierr); ierr = ISGetLocalSize(is2,&n2);CHKERRQ(ierr); if (!n2) PetscFunctionReturn(0); ierr = ISGetIndices(*is1,&i1);CHKERRQ(ierr); ierr = ISGetIndices(is2,&i2);CHKERRQ(ierr); p1 = 0; p2 = 0; n3 = 0; do { if (p1==n1) { /* cleanup for is2 */ n3 += n2-p2; break; } else { while (p2