concept original array in category parallel computing
appears as: original array

This is an excerpt from Manning's book Parallel and High Performance Computing.
We place a dot for the center of each face in the hash bucket where it falls.
- Every cell writes its cell number into the bin at the center of each face. If the face is to the left and up from the center, it writes its index to the first of two places in the bin, else it writes to the second place.
- Every cell checks for each face to see if there is a number in the other bucket. If there is, it is the neighbor cell. If not, it is an external face with no neighbor.
- We have found our neighbors in a single write and single read!
Listing 5.14 The read phase for the single-write spatial hash remap on the CPU
AMR_remap/singlewrite_remap.cc from CompactHashRemap 132 for (uint i = 0; i < ocells.ncells; i++) { 133 uint io = ocells.i[i]; 134 uint jo = ocells.j[i]; 135 uint lev = ocells.level[i]; 136 137 uint lev_mod = two_to_the(ocells.levmax - lev); 138 uint ii = io*lev_mod; 139 uint ji = jo*lev_mod; 140 141 uint key = ji*i_max + ii; 142 int probe = hash[key]; 144 145 if (lev > ocells.levmax){lev = ocells.levmax;} 146 147 while(probe < 0 && lev > 0) { #A 148 lev--; 149 uint lev_diff = ocells.levmax - lev; 150 ii >>= lev_diff; 151 ii <<= lev_diff; 152 ji >>= lev_diff; 153 ji <<= lev_diff; 154 key = ji*i_max + ii; 155 probe = hash[key]; 156 } 157 if (lev >= icells.level[probe]) { 158 ocells.values[i] = icells.values[probe]; #B 159 } else { 160 ocells.values[i] = avg_sub_cells(icells, ji, ii, lev, hash); #C 161 } 162 } 163 double avg_sub_cells (cell_list icells, uint ji, uint ii, uint level, int *hash) { 164 uint key, i_max, jump; 165 double sum = 0.0; 166 i_max = icells.ibasesize*two_to_the(icells.levmax); 167 jump = two_to_the(icells.levmax - level - 1); 168 169 for (int j = 0; j < 2; j++) { 170 for (int i = 0; i < 2; i++) { 171 key = ((ji + (j*jump)) * i_max) + (ii + (i*jump)); 172 int ic = hash[key]; 173 if (icells.level[ic] == (level + 1)) { 174 sum += icells.values[ic]; #D 175 } else { 176 sum += avg_sub_cells(icells, ji + (j*jump), ii + (i*jump), level+1, hash); #E 177 } 178 } 179 } 180 181 return sum/4.0; 182 }