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*/ 4149773a63SBarry Smith #define PetscBT char* 42ca71c51bSBarry Smith 431a89f835SSatish Balay extern char _BT_mask,_BT_c; 44da94ea09SBarry Smith extern PetscInt _BT_idx; 45ca71c51bSBarry Smith 46b6410449SSatish Balay #define PetscBTLength(m) ((m)/PETSC_BITS_PER_BYTE+1)*sizeof(char) 47b6410449SSatish Balay #define PetscBTMemzero(m,array) PetscMemzero(array,(m)/PETSC_BITS_PER_BYTE+1) 4882502324SSatish Balay #define PetscBTDestroy(array) PetscFree(array) 4982502324SSatish Balay 5082502324SSatish Balay #define PetscBTView(m,bt,viewer) 0; {\ 51*77431f27SBarry 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++) { \ 55*77431f27SBarry 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 61b6410449SSatish Balay #define PetscBTLookupSet(array,index) (_BT_idx = (index)/PETSC_BITS_PER_BYTE, \ 6219fee000SSatish Balay _BT_c = array[_BT_idx], \ 63b6410449SSatish Balay _BT_mask = (char)1 << ((index)%PETSC_BITS_PER_BYTE), \ 641a89f835SSatish Balay array[_BT_idx] = _BT_c | _BT_mask, \ 651a89f835SSatish Balay _BT_c & _BT_mask) 6619fee000SSatish Balay 67b6410449SSatish Balay #define PetscBTSet(array,index) (_BT_idx = (index)/PETSC_BITS_PER_BYTE, \ 68ca71c51bSBarry Smith _BT_c = array[_BT_idx], \ 69b6410449SSatish Balay _BT_mask = (char)1 << ((index)%PETSC_BITS_PER_BYTE), \ 701929aaefSSatish Balay array[_BT_idx] = _BT_c | _BT_mask,0) 7119fee000SSatish Balay 72ca71c51bSBarry Smith 73b6410449SSatish Balay #define PetscBTClear(array,index) (_BT_idx = (index)/PETSC_BITS_PER_BYTE, \ 74ca71c51bSBarry Smith _BT_c = array[_BT_idx], \ 75b6410449SSatish Balay _BT_mask = (char)1 << ((index)%PETSC_BITS_PER_BYTE), \ 761929aaefSSatish Balay array[_BT_idx] = _BT_c & (~_BT_mask),0) 77ca71c51bSBarry Smith 78b6410449SSatish Balay #define PetscBTLookup(array,index) (_BT_idx = (index)/PETSC_BITS_PER_BYTE, \ 79ca71c51bSBarry Smith _BT_c = array[_BT_idx], \ 80b6410449SSatish Balay _BT_mask = (char)1 << ((index)%PETSC_BITS_PER_BYTE), \ 811a89f835SSatish Balay (_BT_c & _BT_mask) != 0) 82ca71c51bSBarry Smith 83e9fa29b7SSatish Balay PETSC_EXTERN_CXX_END 84ca71c51bSBarry Smith #endif 85