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