Actual source code: iscomp.c

 2:  #include petscsys.h
 3:  #include petscis.h

  7: /*@C
  8:    ISEqual  - Compares if two index sets have the same set of indices.

 10:    Collective on IS

 12:    Input Parameters:
 13: .  is1, is2 - The index sets being compared

 15:    Output Parameters:
 16: .  flg - output flag, either PETSC_TRUE (if both index sets have the
 17:          same indices), or PETSC_FALSE if the index sets differ by size 
 18:          or by the set of indices)

 20:    Level: intermediate

 22:    Note: 
 23:    This routine sorts the contents of the index sets before
 24:    the comparision is made, so the order of the indices on a processor is immaterial.

 26:    Each processor has to have the same indices in the two sets, for example,
 27: $           Processor 
 28: $             0      1
 29: $    is1 = {0, 1} {2, 3}
 30: $    is2 = {2, 3} {0, 1}
 31:    will return false.

 33:     Concepts: index sets^equal
 34:     Concepts: IS^equal

 36: @*/
 37: PetscErrorCode ISEqual(IS is1,IS is2,PetscTruth *flg)
 38: {
 39:   PetscInt       sz1,sz2,*ptr1,*ptr2,*a1,*a2;
 40:   PetscTruth     flag;
 41:   MPI_Comm       comm;
 43:   PetscMPIInt    mflg;


 50:   if (is1 == is2) {
 51:     *flg = PETSC_TRUE;
 52:     return(0);
 53:   }

 55:   MPI_Comm_compare(((PetscObject)is1)->comm,((PetscObject)is2)->comm,&mflg);
 56:   if (mflg != MPI_CONGRUENT && mflg != MPI_IDENT) {
 57:     *flg = PETSC_FALSE;
 58:     return(0);
 59:   }

 61:   ISGetSize(is1,&sz1);
 62:   ISGetSize(is2,&sz2);
 63:   if (sz1 != sz2) {
 64:     *flg = PETSC_FALSE;
 65:   } else {
 66:     ISGetLocalSize(is1,&sz1);
 67:     ISGetLocalSize(is2,&sz2);

 69:     if (sz1 != sz2) {
 70:       flag = PETSC_FALSE;
 71:     } else {
 72:       ISGetIndices(is1,&ptr1);
 73:       ISGetIndices(is2,&ptr2);
 74: 
 75:       PetscMalloc(sz1*sizeof(PetscInt),&a1);
 76:       PetscMalloc(sz2*sizeof(PetscInt),&a2);

 78:       PetscMemcpy(a1,ptr1,sz1*sizeof(PetscInt));
 79:       PetscMemcpy(a2,ptr2,sz2*sizeof(PetscInt));

 81:       PetscSortInt(sz1,a1);
 82:       PetscSortInt(sz2,a2);
 83:       PetscMemcmp(a1,a2,sz1*sizeof(PetscInt),&flag);

 85:       ISRestoreIndices(is1,&ptr1);
 86:       ISRestoreIndices(is2,&ptr2);
 87: 
 88:       PetscFree(a1);
 89:       PetscFree(a2);
 90:     }
 91:     PetscObjectGetComm((PetscObject)is1,&comm);
 92:     MPI_Allreduce(&flag,flg,1,MPI_INT,MPI_MIN,comm);
 93:   }
 94:   return(0);
 95: }
 96: