xref: /petsc/include/petscbt.h (revision e9fa29b77eaf32efadba30e98aa12b45e655e5d0)
173f4d377SMatthew Knepley /* $Id: petscbt.h,v 1.22 2001/09/07 20:13:16 bsmith Exp $ */
2bd3dcc6dSSatish Balay 
319fee000SSatish Balay /*
419fee000SSatish Balay 
53b71518fSBarry Smith           BT - Bit array objects: used to compactly store logical arrays of variables.
619fee000SSatish Balay 
76831982aSBarry Smith      PetscBTCreate(m,bt)        - creates a bit array with enough room to hold m values
86831982aSBarry Smith      PetscBTDestroy(bt)         - destroys the bit array
96831982aSBarry Smith      PetscBTMemzero(m,bt)       - zeros the entire bit array (sets all values to false)
106831982aSBarry Smith      PetscBTSet(bt,index)       - sets a particular entry as true
116831982aSBarry Smith      PetscBTClear(bt,index)     - sets a particular entry as false
12f1af5d2fSBarry Smith      PetscBTLookup(bt,index)    - returns the value
13f1af5d2fSBarry Smith      PetscBTLookupSet(bt,index) - returns the value and then sets it true
146831982aSBarry Smith      PetscBTLength(m)           - returns number of bytes in array with m bits
156831982aSBarry Smith      PetscBTView(m,bt,viewer)   - prints all the entries in a bit array
16eec0b4cfSBarry Smith 
17eec0b4cfSBarry Smith     These routines do not currently have manual pages.
18eec0b4cfSBarry Smith 
19eec0b4cfSBarry Smith     The are all implemented as macros with the trivial data structure for efficiency.
20eec0b4cfSBarry Smith 
21eec0b4cfSBarry Smith     These are not thread safe since they use a few global variables.
2219fee000SSatish Balay 
236831982aSBarry Smith     We do not currently check error flags on PetscBTSet(), PetscBTClear(), PetscBTLookup(),
246831982aSBarry Smith     PetcBTLookupSet(), PetscBTLength() cause error checking would cost hundreds more cycles then
256831982aSBarry Smith     the operation.
266831982aSBarry Smith 
2719fee000SSatish Balay */
280a835dfdSSatish Balay #if !defined(__PETSCBT_H)
290a835dfdSSatish Balay #define __PETSCBT_H
30*e9fa29b7SSatish Balay PETSC_EXTERN_CXX_BEGIN
31ca71c51bSBarry Smith 
32b9617806SBarry Smith /*S
33b9617806SBarry Smith      PetscBT - PETSc bitarrays
34b9617806SBarry Smith 
35b9617806SBarry Smith    Level: advanced
36b9617806SBarry Smith 
37b9617806SBarry Smith    Notes: the PetscBT routines do not currently have manual pages. See include/petscbt.h for
38b9617806SBarry Smith           documentation
39b9617806SBarry Smith 
40b9617806SBarry Smith .seealso:  PetscBTCreate(), PetscBTDestroy(), PetscBTMemzero(), PetscBTSet(), PetscBTClear(),
41b9617806SBarry Smith            PetscBTLookup(), PetscBTLookupSet(), PetscBTLength(), PetscBTView()
42b9617806SBarry Smith S*/
43f1af5d2fSBarry Smith typedef char* PetscBT;
44ca71c51bSBarry Smith 
451a89f835SSatish Balay extern char _BT_mask,_BT_c;
4635c17c5bSBarry Smith extern int  _BT_idx;
47ca71c51bSBarry Smith 
48b6410449SSatish Balay #define PetscBTLength(m)        ((m)/PETSC_BITS_PER_BYTE+1)*sizeof(char)
49b6410449SSatish Balay #define PetscBTMemzero(m,array) PetscMemzero(array,(m)/PETSC_BITS_PER_BYTE+1)
5082502324SSatish Balay #define PetscBTDestroy(array)   PetscFree(array)
5182502324SSatish Balay 
5282502324SSatish Balay #define PetscBTView(m,bt,viewer) 0; {\
53ef66eb69SBarry Smith   int    __i,_8_ierr; \
54b0a32e0cSBarry Smith   PetscViewer __viewer = viewer; \
55b0a32e0cSBarry Smith   if (!__viewer) __viewer = PETSC_VIEWER_STDOUT_SELF;\
563b71518fSBarry Smith   for (__i=0; __i<m; __i++) { \
57ef66eb69SBarry Smith     _8_ierr = PetscPrintf(((PetscObject)__viewer)->comm,"%d %d\n",__i,PetscBTLookup(bt,__i));CHKERRQ(_8_ierr);\
583b71518fSBarry Smith   }}
593b71518fSBarry Smith 
6082502324SSatish Balay #define PetscBTCreate(m,array)  0; { \
61ef66eb69SBarry Smith   int _9_ierr; \
62b6410449SSatish Balay   _9_ierr = PetscMalloc(((m)/PETSC_BITS_PER_BYTE+1)*sizeof(char),&(array));CHKERRQ(_9_ierr);\
63ef66eb69SBarry Smith   _9_ierr = PetscBTMemzero(m,array);CHKERRQ(_9_ierr);\
6482502324SSatish Balay   }
65ca71c51bSBarry Smith 
66b6410449SSatish Balay #define PetscBTLookupSet(array,index)   (_BT_idx           = (index)/PETSC_BITS_PER_BYTE, \
6719fee000SSatish Balay                                         _BT_c           = array[_BT_idx], \
68b6410449SSatish Balay                                         _BT_mask        = (char)1 << ((index)%PETSC_BITS_PER_BYTE), \
691a89f835SSatish Balay                                         array[_BT_idx]  = _BT_c | _BT_mask, \
701a89f835SSatish Balay                                         _BT_c & _BT_mask)
7119fee000SSatish Balay 
72b6410449SSatish Balay #define PetscBTSet(array,index)         (_BT_idx          = (index)/PETSC_BITS_PER_BYTE, \
73ca71c51bSBarry Smith                                         _BT_c           = array[_BT_idx], \
74b6410449SSatish Balay                                         _BT_mask        = (char)1 << ((index)%PETSC_BITS_PER_BYTE), \
751929aaefSSatish Balay                                         array[_BT_idx]  = _BT_c | _BT_mask,0)
7619fee000SSatish Balay 
77ca71c51bSBarry Smith 
78b6410449SSatish Balay #define PetscBTClear(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), \
811929aaefSSatish Balay                                    array[_BT_idx]  = _BT_c & (~_BT_mask),0)
82ca71c51bSBarry Smith 
83b6410449SSatish Balay #define PetscBTLookup(array,index) (_BT_idx          = (index)/PETSC_BITS_PER_BYTE, \
84ca71c51bSBarry Smith                                    _BT_c           = array[_BT_idx], \
85b6410449SSatish Balay                                    _BT_mask        = (char)1 << ((index)%PETSC_BITS_PER_BYTE), \
861a89f835SSatish Balay                                    (_BT_c & _BT_mask) != 0)
87ca71c51bSBarry Smith 
88*e9fa29b7SSatish Balay PETSC_EXTERN_CXX_END
89ca71c51bSBarry Smith #endif
90