1 2 #if !defined(__PETSCBT_H) 3 #define __PETSCBT_H 4 PETSC_EXTERN_CXX_BEGIN 5 6 /*S 7 PetscBT - PETSc bitarrays 8 9 Level: advanced 10 11 PetscBTCreate(m,bt) - creates a bit array with enough room to hold m values 12 PetscBTDestroy(bt) - destroys the bit array 13 PetscBTMemzero(m,bt) - zeros the entire bit array (sets all values to false) 14 PetscBTSet(bt,index) - sets a particular entry as true 15 PetscBTClear(bt,index) - sets a particular entry as false 16 PetscBTLookup(bt,index) - returns the value 17 PetscBTLookupSet(bt,index) - returns the value and then sets it true 18 PetscBTLength(m) - returns number of bytes in array with m bits 19 PetscBTView(m,bt,viewer) - prints all the entries in a bit array 20 21 The are all implemented as macros with the trivial data structure for efficiency. 22 23 These are not thread safe since they use a few global variables. 24 25 We do not currently check error flags on PetscBTSet(), PetscBTClear(), PetscBTLookup(), 26 PetcBTLookupSet(), PetscBTLength() cause error checking would cost hundreds more cycles then 27 the operation. 28 29 S*/ 30 typedef char* PetscBT; 31 32 extern char _BT_mask; 33 extern char _BT_c; 34 extern PetscInt _BT_idx; 35 36 #define PetscBTLength(m) ((m)/PETSC_BITS_PER_BYTE+1) 37 #define PetscBTMemzero(m,array) PetscMemzero(array,sizeof(char)*((m)/PETSC_BITS_PER_BYTE+1)) 38 #define PetscBTDestroy(array) PetscFree(array) 39 40 #define PetscBTView(m,bt,viewer) 0; {\ 41 PetscInt __i; PetscErrorCode _8_ierr; \ 42 PetscViewer __viewer = viewer; \ 43 if (!__viewer) __viewer = PETSC_VIEWER_STDOUT_SELF;\ 44 _8_ierr = PetscViewerASCIISynchronizedAllow(__viewer,PETSC_TRUE);CHKERRQ(_8_ierr);\ 45 for (__i=0; __i<m; __i++) { \ 46 _8_ierr = PetscViewerASCIISynchronizedPrintf(__viewer,"%D %d\n",__i,PetscBTLookup(bt,__i));CHKERRQ(_8_ierr);\ 47 } _8_ierr = PetscViewerFlush(__viewer);CHKERRQ(_8_ierr);\ 48 _8_ierr = PetscViewerASCIISynchronizedAllow(__viewer,PETSC_FALSE);CHKERRQ(_8_ierr);} 49 50 #define PetscBTCreate(m,array) \ 51 (PetscMalloc(((m)/PETSC_BITS_PER_BYTE+1)*sizeof(char),&(array)) || PetscBTMemzero(m,array)) 52 53 #define PetscBTLookupSet(array,index) \ 54 (_BT_idx = (index)/PETSC_BITS_PER_BYTE, \ 55 _BT_c = array[_BT_idx], \ 56 _BT_mask = (char)1 << ((index)%PETSC_BITS_PER_BYTE), \ 57 array[_BT_idx] = _BT_c | _BT_mask, \ 58 _BT_c & _BT_mask) 59 60 #define PetscBTSet(array,index) \ 61 (_BT_idx = (index)/PETSC_BITS_PER_BYTE, \ 62 _BT_c = array[_BT_idx], \ 63 _BT_mask = (char)1 << ((index)%PETSC_BITS_PER_BYTE), \ 64 array[_BT_idx] = _BT_c | _BT_mask,0) 65 66 #define PetscBTClear(array,index) \ 67 (_BT_idx = (index)/PETSC_BITS_PER_BYTE, \ 68 _BT_c = array[_BT_idx], \ 69 _BT_mask = (char)1 << ((index)%PETSC_BITS_PER_BYTE), \ 70 array[_BT_idx] = _BT_c & (~_BT_mask),0) 71 72 #define PetscBTLookup(array,index) \ 73 (_BT_idx = (index)/PETSC_BITS_PER_BYTE, \ 74 _BT_c = array[_BT_idx], \ 75 _BT_mask = (char)1 << ((index)%PETSC_BITS_PER_BYTE), \ 76 (_BT_c & _BT_mask) != 0) 77 78 PETSC_EXTERN_CXX_END 79 #endif 80