Actual source code: iscomp.c

  1: /*$Id: iscomp.c,v 1.35 2001/03/23 23:21:16 balay Exp $*/

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

  8: /*@C
  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: int ISEqual(IS is1,IS is2,PetscTruth *flg)
 39: {
 40:   int        sz1,sz2,ierr,*ptr1,*ptr2,*a1,*a2;
 41:   PetscTruth flag;
 42:   MPI_Comm   comm;


 50:   if (is1 == is2) {
 51:     *flg = PETSC_TRUE;
 52:     return(0);
 53:   }
 54:   ISGetSize(is1,&sz1);
 55:   ISGetSize(is2,&sz2);
 56:   if (sz1 != sz2) {
 57:     *flg = PETSC_FALSE;
 58:   } else {
 59:     ISGetLocalSize(is1,&sz1);
 60:     ISGetLocalSize(is2,&sz2);

 62:     if (sz1 != sz2) {
 63:       flag = PETSC_FALSE;
 64:     } else {
 65:       ISGetIndices(is1,&ptr1);
 66:       ISGetIndices(is2,&ptr2);
 67: 
 68:       PetscMalloc((sz1+1)*sizeof(int),&a1);
 69:       PetscMalloc((sz2+1)*sizeof(int),&a2);

 71:       PetscMemcpy(a1,ptr1,sz1*sizeof(int));
 72:       PetscMemcpy(a2,ptr2,sz2*sizeof(int));

 74:       PetscSortInt(sz1,a1);
 75:       PetscSortInt(sz2,a2);
 76:       PetscMemcmp(a1,a2,sz1*sizeof(int),&flag);

 78:       ISRestoreIndices(is1,&ptr1);
 79:       ISRestoreIndices(is2,&ptr2);
 80: 
 81:       PetscFree(a1);
 82:       PetscFree(a2);
 83:     }
 84:     PetscObjectGetComm((PetscObject)is1,&comm);
 85:     MPI_Allreduce(&flag,flg,1,MPI_INT,MPI_MIN,comm);
 86:   }
 87:   return(0);
 88: }
 89: