xref: /petsc/src/vec/is/utils/isltog.c (revision 2362add97bf16248c9cc821270daf31c77319b38)
1 #ifndef lint
2 static char vcid[] = "$Id: iscomp.c,v 1.7 1996/08/17 14:35:37 bsmith Exp $";
3 #endif
4 
5 #include "sys.h"   /*I "sys.h" I*/
6 #include "is.h"    /*I "is.h"  I*/
7 
8 /*@C
9   ISEqual  - Compares if two index sets have the same set of indices.
10 
11    Input Parameters:
12 .  is1, is2 - The index sets being compared
13 
14    Output Parameters:
15 .  flg - output flag, either
16 $     PETSC_TRUE if both index sets have the same indices;
17 $     PETSC_FALSE if either the index sets differ by size or
18 $          by the set of indices.
19 
20    Note:
21    This routine sorts the contents of the index sets before
22    the comparision is made, so the order of the indices is immaterial.
23 
24 .keywords: IS, index set, equal
25 @*/
26 int ISEqual(IS is1, IS is2, PetscTruth *flg)
27 {
28 
29   int sz, sz1, sz2, ierr, *ptr1, *ptr2, *a1, *a2;
30 
31   ierr = ISGetSize(is1, &sz1); CHKERRQ(ierr);
32   ierr = ISGetSize(is2, &sz2); CHKERRQ(ierr);
33   if( sz1 != sz2) { *flg = PETSC_FALSE; return 0;}
34 
35   ierr = ISGetIndices(is1, &ptr1); CHKERRQ(ierr);
36   ierr = ISGetIndices(is2, &ptr2); CHKERRQ(ierr);
37 
38   sz   = sz1*sizeof(int);
39   a1   = (int *) PetscMalloc((sz1+1)* sizeof(int));
40   a2   = (int *) PetscMalloc((sz2+1)* sizeof(int));
41 
42   PetscMemcpy(a1, ptr1, sz);
43   PetscMemcpy(a2, ptr2, sz);
44 
45   ierr = PetscSortInt(sz1,a1); CHKERRQ(ierr);
46   ierr = PetscSortInt(sz2,a2); CHKERRQ(ierr);
47   if(!PetscMemcmp(a1, a2, sz)) {*flg = PETSC_TRUE;}
48   else {*flg = PETSC_FALSE;}
49 
50   ierr = ISRestoreIndices(is1, &ptr1); CHKERRQ(ierr);
51   ierr = ISRestoreIndices(is2, &ptr2); CHKERRQ(ierr);
52 
53   PetscFree(a1);
54   PetscFree(a2);
55   return 0;
56 }
57 
58