Actual source code: iscomp.c

  1: #define PETSCVEC_DLL

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

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

 11:    Collective on IS

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

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

 21:    Level: intermediate

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

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

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

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


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

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

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

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

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

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

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