1 #define PETSCKSP_DLL 2 3 /********************************bit_mask.c************************************ 4 5 Author: Henry M. Tufo III 6 7 e-mail: hmt@cs.brown.edu 8 9 snail-mail: 10 Division of Applied Mathematics 11 Brown University 12 Providence, RI 02912 13 14 Last Modification: 15 11.21.97 16 *********************************bit_mask.c***********************************/ 17 #include "../src/ksp/pc/impls/tfs/tfs.h" 18 19 20 /*********************************bit_mask.c***********************************/ 21 PetscErrorCode bm_to_proc( char *ptr, PetscInt p_mask, PetscInt *msg_list) 22 { 23 PetscInt i, tmp; 24 25 PetscFunctionBegin; 26 if (msg_list) 27 { 28 /* low to high */ 29 ptr+=(p_mask-1); 30 for (i=p_mask-1;i>=0;i--) 31 { 32 tmp = BYTE*(p_mask-i-1); 33 if (*ptr&BIT_0) 34 {*msg_list = tmp; msg_list++;} 35 if (*ptr&BIT_1) 36 {*msg_list = tmp+1; msg_list++;} 37 if (*ptr&BIT_2) 38 {*msg_list = tmp+2; msg_list++;} 39 if (*ptr&BIT_3) 40 {*msg_list = tmp+3; msg_list++;} 41 if (*ptr&BIT_4) 42 {*msg_list = tmp+4; msg_list++;} 43 if (*ptr&BIT_5) 44 {*msg_list = tmp+5; msg_list++;} 45 if (*ptr&BIT_6) 46 {*msg_list = tmp+6; msg_list++;} 47 if (*ptr&BIT_7) 48 {*msg_list = tmp+7; msg_list++;} 49 ptr --; 50 } 51 } 52 PetscFunctionReturn(0); 53 } 54 55 /*********************************bit_mask.c***********************************/ 56 PetscInt ct_bits( char *ptr, PetscInt n) 57 { 58 PetscInt i, tmp=0; 59 60 PetscFunctionBegin; 61 for(i=0;i<n;i++) 62 { 63 if (*ptr&128) {tmp++;} 64 if (*ptr&64) {tmp++;} 65 if (*ptr&32) {tmp++;} 66 if (*ptr&16) {tmp++;} 67 if (*ptr&8) {tmp++;} 68 if (*ptr&4) {tmp++;} 69 if (*ptr&2) {tmp++;} 70 if (*ptr&1) {tmp++;} 71 ptr++; 72 } 73 74 return(tmp); 75 } 76 77 /*********************************bit_mask.c***********************************/ 78 PetscInt 79 div_ceil( PetscInt numer, PetscInt denom) 80 { 81 PetscInt rt_val; 82 83 if ((numer<0)||(denom<=0)) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_PLIB,"div_ceil() :: numer=%D ! >=0, denom=%D ! >0",numer,denom); 84 85 /* if integer division remainder then increment */ 86 rt_val = numer/denom; 87 if (numer%denom) 88 {rt_val++;} 89 90 return(rt_val); 91 } 92 93 /*********************************bit_mask.c***********************************/ 94 PetscInt 95 len_bit_mask( PetscInt num_items) 96 { 97 PetscInt rt_val, tmp; 98 99 if (num_items<0) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_PLIB,"Value Sent To len_bit_mask() Must be >= 0!"); 100 101 /* mod BYTE ceiling function */ 102 rt_val = num_items/BYTE; 103 if (num_items%BYTE) 104 {rt_val++;} 105 106 /* make mults of sizeof int */ 107 if ((tmp=rt_val%sizeof(PetscInt))) 108 {rt_val+=(sizeof(PetscInt)-tmp);} 109 110 return(rt_val); 111 } 112 113 /*********************************bit_mask.c***********************************/ 114 PetscErrorCode set_bit_mask( PetscInt *bm, PetscInt len, PetscInt val) 115 { 116 PetscInt i, offset; 117 char mask = 1; 118 char *cptr; 119 120 if (len_bit_mask(val)>len) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_PLIB,"The Bit Mask Isn't That Large!"); 121 122 cptr = (char *) bm; 123 124 offset = len/sizeof(PetscInt); 125 for (i=0;i<offset;i++) 126 {*bm=0; bm++;} 127 128 offset = val%BYTE; 129 for (i=0;i<offset;i++) 130 {mask <<= 1;} 131 132 offset = len - val/BYTE - 1; 133 cptr[offset] = mask; 134 PetscFunctionReturn(0); 135 } 136 137 /*********************************bit_mask.c***********************************/ 138 PetscInt len_buf(PetscInt item_size, PetscInt num_items) 139 { 140 PetscInt rt_val, tmp; 141 142 PetscFunctionBegin; 143 rt_val = item_size * num_items; 144 145 /* double precision align for now ... consider page later */ 146 if ((tmp = (rt_val%(PetscInt)sizeof(double)))) 147 {rt_val += (sizeof(double) - tmp);} 148 149 return(rt_val); 150 } 151 152 153 154