1*27260eb9SSatish Balay 2f621e05eSBarry Smith #if !defined(__PETSCBT_H) 3f621e05eSBarry Smith #define __PETSCBT_H 4f621e05eSBarry Smith PETSC_EXTERN_CXX_BEGIN 519fee000SSatish Balay 6f621e05eSBarry Smith /*S 7f621e05eSBarry Smith PetscBT - PETSc bitarrays 8f621e05eSBarry Smith 9f621e05eSBarry Smith Level: advanced 1019fee000SSatish Balay 116831982aSBarry Smith PetscBTCreate(m,bt) - creates a bit array with enough room to hold m values 126831982aSBarry Smith PetscBTDestroy(bt) - destroys the bit array 136831982aSBarry Smith PetscBTMemzero(m,bt) - zeros the entire bit array (sets all values to false) 146831982aSBarry Smith PetscBTSet(bt,index) - sets a particular entry as true 156831982aSBarry Smith PetscBTClear(bt,index) - sets a particular entry as false 16f1af5d2fSBarry Smith PetscBTLookup(bt,index) - returns the value 17f1af5d2fSBarry Smith PetscBTLookupSet(bt,index) - returns the value and then sets it true 186831982aSBarry Smith PetscBTLength(m) - returns number of bytes in array with m bits 196831982aSBarry Smith PetscBTView(m,bt,viewer) - prints all the entries in a bit array 20eec0b4cfSBarry Smith 21eec0b4cfSBarry Smith The are all implemented as macros with the trivial data structure for efficiency. 22eec0b4cfSBarry Smith 23eec0b4cfSBarry Smith These are not thread safe since they use a few global variables. 2419fee000SSatish Balay 256831982aSBarry Smith We do not currently check error flags on PetscBTSet(), PetscBTClear(), PetscBTLookup(), 266831982aSBarry Smith PetcBTLookupSet(), PetscBTLength() cause error checking would cost hundreds more cycles then 276831982aSBarry Smith the operation. 286831982aSBarry Smith 29b9617806SBarry Smith S*/ 30521d7252SBarry Smith typedef char* PetscBT; 31ca71c51bSBarry Smith 32ff73aad6SKris Buschelman extern PETSC_DLLEXPORT char _BT_mask; 33ff73aad6SKris Buschelman extern PETSC_DLLEXPORT char _BT_c; 34ff73aad6SKris Buschelman extern PETSC_DLLEXPORT PetscInt _BT_idx; 35ca71c51bSBarry Smith 36ccd8e176SBarry Smith #define PetscBTLength(m) ((m)/PETSC_BITS_PER_BYTE+1) 37521d7252SBarry Smith #define PetscBTMemzero(m,array) PetscMemzero(array,sizeof(char)*((m)/PETSC_BITS_PER_BYTE+1)) 3882502324SSatish Balay #define PetscBTDestroy(array) PetscFree(array) 3982502324SSatish Balay 4082502324SSatish Balay #define PetscBTView(m,bt,viewer) 0; {\ 4177431f27SBarry Smith PetscInt __i; PetscErrorCode _8_ierr; \ 42b0a32e0cSBarry Smith PetscViewer __viewer = viewer; \ 43b0a32e0cSBarry Smith if (!__viewer) __viewer = PETSC_VIEWER_STDOUT_SELF;\ 443b71518fSBarry Smith for (__i=0; __i<m; __i++) { \ 4577431f27SBarry Smith _8_ierr = PetscPrintf(((PetscObject)__viewer)->comm,"%D %d\n",__i,PetscBTLookup(bt,__i));CHKERRQ(_8_ierr);\ 463b71518fSBarry Smith }} 473b71518fSBarry Smith 481d73ed98SBarry Smith #define PetscBTCreate(m,array) \ 491d73ed98SBarry Smith (PetscMalloc(((m)/PETSC_BITS_PER_BYTE+1)*sizeof(char),&(array)) || PetscBTMemzero(m,array)) 50ca71c51bSBarry Smith 51f1144a30SSatish Balay #define PetscBTLookupSet(array,index) \ 52f1144a30SSatish Balay (_BT_idx = (index)/PETSC_BITS_PER_BYTE, \ 5319fee000SSatish Balay _BT_c = array[_BT_idx], \ 54b6410449SSatish Balay _BT_mask = (char)1 << ((index)%PETSC_BITS_PER_BYTE), \ 551a89f835SSatish Balay array[_BT_idx] = _BT_c | _BT_mask, \ 561a89f835SSatish Balay _BT_c & _BT_mask) 5719fee000SSatish Balay 58f1144a30SSatish Balay #define PetscBTSet(array,index) \ 59f1144a30SSatish Balay (_BT_idx = (index)/PETSC_BITS_PER_BYTE, \ 60ca71c51bSBarry Smith _BT_c = array[_BT_idx], \ 61b6410449SSatish Balay _BT_mask = (char)1 << ((index)%PETSC_BITS_PER_BYTE), \ 621929aaefSSatish Balay array[_BT_idx] = _BT_c | _BT_mask,0) 6319fee000SSatish Balay 64f1144a30SSatish Balay #define PetscBTClear(array,index) \ 65f1144a30SSatish Balay (_BT_idx = (index)/PETSC_BITS_PER_BYTE, \ 66ca71c51bSBarry Smith _BT_c = array[_BT_idx], \ 67b6410449SSatish Balay _BT_mask = (char)1 << ((index)%PETSC_BITS_PER_BYTE), \ 681929aaefSSatish Balay array[_BT_idx] = _BT_c & (~_BT_mask),0) 69ca71c51bSBarry Smith 70f1144a30SSatish Balay #define PetscBTLookup(array,index) \ 71f1144a30SSatish Balay (_BT_idx = (index)/PETSC_BITS_PER_BYTE, \ 72ca71c51bSBarry Smith _BT_c = array[_BT_idx], \ 73b6410449SSatish Balay _BT_mask = (char)1 << ((index)%PETSC_BITS_PER_BYTE), \ 741a89f835SSatish Balay (_BT_c & _BT_mask) != 0) 75ca71c51bSBarry Smith 76e9fa29b7SSatish Balay PETSC_EXTERN_CXX_END 77ca71c51bSBarry Smith #endif 78