119fee000SSatish Balay /* 219fee000SSatish Balay 33b71518fSBarry Smith BT - Bit array objects: used to compactly store logical arrays of variables. 419fee000SSatish Balay 56831982aSBarry Smith PetscBTCreate(m,bt) - creates a bit array with enough room to hold m values 66831982aSBarry Smith PetscBTDestroy(bt) - destroys the bit array 76831982aSBarry Smith PetscBTMemzero(m,bt) - zeros the entire bit array (sets all values to false) 86831982aSBarry Smith PetscBTSet(bt,index) - sets a particular entry as true 96831982aSBarry Smith PetscBTClear(bt,index) - sets a particular entry as false 10f1af5d2fSBarry Smith PetscBTLookup(bt,index) - returns the value 11f1af5d2fSBarry Smith PetscBTLookupSet(bt,index) - returns the value and then sets it true 126831982aSBarry Smith PetscBTLength(m) - returns number of bytes in array with m bits 136831982aSBarry Smith PetscBTView(m,bt,viewer) - prints all the entries in a bit array 14eec0b4cfSBarry Smith 15eec0b4cfSBarry Smith These routines do not currently have manual pages. 16eec0b4cfSBarry Smith 17eec0b4cfSBarry Smith The are all implemented as macros with the trivial data structure for efficiency. 18eec0b4cfSBarry Smith 19eec0b4cfSBarry Smith These are not thread safe since they use a few global variables. 2019fee000SSatish Balay 216831982aSBarry Smith We do not currently check error flags on PetscBTSet(), PetscBTClear(), PetscBTLookup(), 226831982aSBarry Smith PetcBTLookupSet(), PetscBTLength() cause error checking would cost hundreds more cycles then 236831982aSBarry Smith the operation. 246831982aSBarry Smith 2519fee000SSatish Balay */ 260a835dfdSSatish Balay #if !defined(__PETSCBT_H) 270a835dfdSSatish Balay #define __PETSCBT_H 28e9fa29b7SSatish Balay PETSC_EXTERN_CXX_BEGIN 29ca71c51bSBarry Smith 30b9617806SBarry Smith /*S 31b9617806SBarry Smith PetscBT - PETSc bitarrays 32b9617806SBarry Smith 33b9617806SBarry Smith Level: advanced 34b9617806SBarry Smith 35b9617806SBarry Smith Notes: the PetscBT routines do not currently have manual pages. See include/petscbt.h for 36b9617806SBarry Smith documentation 37b9617806SBarry Smith 38b9617806SBarry Smith .seealso: PetscBTCreate(), PetscBTDestroy(), PetscBTMemzero(), PetscBTSet(), PetscBTClear(), 39b9617806SBarry Smith PetscBTLookup(), PetscBTLookupSet(), PetscBTLength(), PetscBTView() 40b9617806SBarry Smith S*/ 41521d7252SBarry Smith typedef char* PetscBT; 42ca71c51bSBarry Smith 431a89f835SSatish Balay extern char _BT_mask,_BT_c; 44da94ea09SBarry Smith extern PetscInt _BT_idx; 45ca71c51bSBarry Smith 46ccd8e176SBarry Smith #define PetscBTLength(m) ((m)/PETSC_BITS_PER_BYTE+1) 47521d7252SBarry Smith #define PetscBTMemzero(m,array) PetscMemzero(array,sizeof(char)*((m)/PETSC_BITS_PER_BYTE+1)) 4882502324SSatish Balay #define PetscBTDestroy(array) PetscFree(array) 4982502324SSatish Balay 5082502324SSatish Balay #define PetscBTView(m,bt,viewer) 0; {\ 5177431f27SBarry Smith PetscInt __i; PetscErrorCode _8_ierr; \ 52b0a32e0cSBarry Smith PetscViewer __viewer = viewer; \ 53b0a32e0cSBarry Smith if (!__viewer) __viewer = PETSC_VIEWER_STDOUT_SELF;\ 543b71518fSBarry Smith for (__i=0; __i<m; __i++) { \ 5577431f27SBarry Smith _8_ierr = PetscPrintf(((PetscObject)__viewer)->comm,"%D %d\n",__i,PetscBTLookup(bt,__i));CHKERRQ(_8_ierr);\ 563b71518fSBarry Smith }} 573b71518fSBarry Smith 581d73ed98SBarry Smith #define PetscBTCreate(m,array) \ 591d73ed98SBarry Smith (PetscMalloc(((m)/PETSC_BITS_PER_BYTE+1)*sizeof(char),&(array)) || PetscBTMemzero(m,array)) 60ca71c51bSBarry Smith 61*f1144a30SSatish Balay #define PetscBTLookupSet(array,index) \ 62*f1144a30SSatish Balay (_BT_idx = (index)/PETSC_BITS_PER_BYTE, \ 6319fee000SSatish Balay _BT_c = array[_BT_idx], \ 64b6410449SSatish Balay _BT_mask = (char)1 << ((index)%PETSC_BITS_PER_BYTE), \ 651a89f835SSatish Balay array[_BT_idx] = _BT_c | _BT_mask, \ 661a89f835SSatish Balay _BT_c & _BT_mask) 6719fee000SSatish Balay 68*f1144a30SSatish Balay #define PetscBTSet(array,index) \ 69*f1144a30SSatish Balay (_BT_idx = (index)/PETSC_BITS_PER_BYTE, \ 70ca71c51bSBarry Smith _BT_c = array[_BT_idx], \ 71b6410449SSatish Balay _BT_mask = (char)1 << ((index)%PETSC_BITS_PER_BYTE), \ 721929aaefSSatish Balay array[_BT_idx] = _BT_c | _BT_mask,0) 7319fee000SSatish Balay 74*f1144a30SSatish Balay #define PetscBTClear(array,index) \ 75*f1144a30SSatish Balay (_BT_idx = (index)/PETSC_BITS_PER_BYTE, \ 76ca71c51bSBarry Smith _BT_c = array[_BT_idx], \ 77b6410449SSatish Balay _BT_mask = (char)1 << ((index)%PETSC_BITS_PER_BYTE), \ 781929aaefSSatish Balay array[_BT_idx] = _BT_c & (~_BT_mask),0) 79ca71c51bSBarry Smith 80*f1144a30SSatish Balay #define PetscBTLookup(array,index) \ 81*f1144a30SSatish Balay (_BT_idx = (index)/PETSC_BITS_PER_BYTE, \ 82ca71c51bSBarry Smith _BT_c = array[_BT_idx], \ 83b6410449SSatish Balay _BT_mask = (char)1 << ((index)%PETSC_BITS_PER_BYTE), \ 841a89f835SSatish Balay (_BT_c & _BT_mask) != 0) 85ca71c51bSBarry Smith 86e9fa29b7SSatish Balay PETSC_EXTERN_CXX_END 87ca71c51bSBarry Smith #endif 88