Actual source code: bitmask.c
2: /********************************bit_mask.c************************************
4: Author: Henry M. Tufo III
6: e-mail: hmt@cs.brown.edu
8: snail-mail:
9: Division of Applied Mathematics
10: Brown University
11: Providence, RI 02912
13: Last Modification:
14: 11.21.97
15: *********************************bit_mask.c***********************************/
16: #include <../src/ksp/pc/impls/tfs/tfs.h>
18: /*********************************bit_mask.c***********************************/
19: PetscErrorCode PCTFS_bm_to_proc(char *ptr, PetscInt p_mask, PetscInt *msg_list)
20: {
21: PetscInt i, tmp;
23: if (msg_list) {
24: /* low to high */
25: ptr+=(p_mask-1);
26: for (i=p_mask-1;i>=0;i--) {
27: tmp = BYTE*(p_mask-i-1);
28: if (*ptr&BIT_0) {
29: *msg_list = tmp; msg_list++;
30: }
31: if (*ptr&BIT_1) {
32: *msg_list = tmp+1; msg_list++;
33: }
34: if (*ptr&BIT_2) {
35: *msg_list = tmp+2; msg_list++;
36: }
37: if (*ptr&BIT_3) {
38: *msg_list = tmp+3; msg_list++;
39: }
40: if (*ptr&BIT_4) {
41: *msg_list = tmp+4; msg_list++;
42: }
43: if (*ptr&BIT_5) {
44: *msg_list = tmp+5; msg_list++;
45: }
46: if (*ptr&BIT_6) {
47: *msg_list = tmp+6; msg_list++;
48: }
49: if (*ptr&BIT_7) {
50: *msg_list = tmp+7; msg_list++;
51: }
52: ptr--;
53: }
54: }
55: return 0;
56: }
58: /*********************************bit_mask.c***********************************/
59: PetscInt PCTFS_ct_bits(char *ptr, PetscInt n)
60: {
61: PetscInt i, tmp=0;
63: for (i=0;i<n;i++) {
64: if (*ptr&128) tmp++;
65: if (*ptr&64) tmp++;
66: if (*ptr&32) tmp++;
67: if (*ptr&16) tmp++;
68: if (*ptr&8) tmp++;
69: if (*ptr&4) tmp++;
70: if (*ptr&2) tmp++;
71: if (*ptr&1) tmp++;
72: ptr++;
73: }
74: return(tmp);
75: }
77: /*********************************bit_mask.c***********************************/
78: PetscInt PCTFS_div_ceil(PetscInt numer, PetscInt denom)
79: {
80: if ((numer<0)||(denom<=0)) SETERRABORT(PETSC_COMM_SELF,PETSC_ERR_PLIB,"PCTFS_div_ceil() :: numer=%" PetscInt_FMT " ! >=0, denom=%" PetscInt_FMT " ! >0",numer,denom);
81: return(PetscCeilInt(numer,denom));
82: }
84: /*********************************bit_mask.c***********************************/
85: PetscInt PCTFS_len_bit_mask(PetscInt num_items)
86: {
87: PetscInt rt_val, tmp;
91: rt_val = PetscCeilInt(num_items,BYTE);
92: /* make multiple of sizeof PetscInt */
93: if ((tmp=rt_val%sizeof(PetscInt))) rt_val+=(sizeof(PetscInt)-tmp);
94: return(rt_val);
95: }
97: /*********************************bit_mask.c***********************************/
98: PetscErrorCode PCTFS_set_bit_mask(PetscInt *bm, PetscInt len, PetscInt val)
99: {
100: PetscInt i, offset;
101: char mask = 1;
102: char *cptr;
106: cptr = (char*) bm;
108: offset = len/sizeof(PetscInt);
109: for (i=0; i<offset; i++) {
110: *bm=0;
111: bm++;
112: }
114: offset = val%BYTE;
115: for (i=0;i<offset;i++) {
116: mask <<= 1;
117: }
119: offset = len - val/BYTE - 1;
120: cptr[offset] = mask;
121: return 0;
122: }
124: /*********************************bit_mask.c***********************************/
125: PetscInt PCTFS_len_buf(PetscInt item_size, PetscInt num_items)
126: {
127: PetscInt rt_val, tmp;
129: rt_val = item_size * num_items;
131: /* double precision align for now ... consider page later */
132: if ((tmp = (rt_val%(PetscInt)sizeof(double)))) rt_val += (sizeof(double) - tmp);
133: return(rt_val);
134: }