1 /* =============================================================================
5 * =============================================================================
7 * For the license of ssca2, please see ssca2/COPYRIGHT
9 * ------------------------------------------------------------------------
11 * Unless otherwise noted, the following license applies to STAMP files:
13 * Copyright (c) 2007, Stanford University
14 * All rights reserved.
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions are
20 * * Redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer.
23 * * Redistributions in binary form must reproduce the above copyright
24 * notice, this list of conditions and the following disclaimer in
25 * the documentation and/or other materials provided with the
28 * * Neither the name of Stanford University nor the names of its
29 * contributors may be used to endorse or promote products derived
30 * from this software without specific prior written permission.
32 * THIS SOFTWARE IS PROVIDED BY STANFORD UNIVERSITY ``AS IS'' AND ANY
33 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
34 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
35 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL STANFORD UNIVERSITY BE LIABLE
36 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
37 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
38 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
39 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
40 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
41 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
42 * THE POSSIBILITY OF SUCH DAMAGE.
44 * =============================================================================
47 public class Alg_Radix_Smp {
48 public int[] global_myHisto;
49 public int[] global_psHisto;
50 public int[] global_lTemp;
51 public int[] global_lTemp2;
53 public Alg_Radix_Smp() {
54 global_myHisto = null;
55 global_psHisto = null;
60 public int BITS(int x, int k, int j) {
61 int retval = ((x>>k) & ~(~0<<j));
65 /* =============================================================================
68 * R (range) must be a multiple of NODES
69 * q (elems/proc) must be a multiple of NODES
70 * =============================================================================
86 myHisto = new int[numThread*R];
87 global_myHisto = myHisto;
88 psHisto = new int[numThread*R];
89 global_psHisto = psHisto;
92 Barrier.enterBarrier();
94 myHisto = global_myHisto;
95 psHisto = global_psHisto;
99 for (int k = index; k < index+R; k++) {
103 LocalStartStop lss = new LocalStartStop();
104 CreatePartition.createPartition(0, q, myId, numThread, lss);
106 for (int k = lss.i_start; k < lss.i_stop; k++) {
107 myHisto[(myId * R) + BITS(lKey[k],bitOff,m)]++;
110 Barrier.enterBarrier();
112 CreatePartition.createPartition(0, R, myId, numThread, lss);
115 for (int k = lss.i_start; k < lss.i_stop; k++) {
116 last = psHisto[k] = myHisto[k];
117 for (int j = 1; j < numThread; j++) {
118 int temp = psHisto[(j*R) + k] = last + myHisto[(j*R) + k];
123 Barrier.enterBarrier();
127 for (int k = 0; k < R; k++) {
128 myHisto[(myId * R) + k] = (psHisto[(myId * R) + k] - myHisto[(myId * R) + k]) + offset;
129 offset += psHisto[((numThread - 1) * R) + k];
132 Barrier.enterBarrier();
134 CreatePartition.createPartition(0, q, myId, numThread, lss);
136 for (int k = lss.i_start; k < lss.i_stop; k++) {
137 int j = BITS(lKey[k],bitOff,m);
138 lSorted[myHisto[(myId * R) + j]] = lKey[k];
139 myHisto[(myId * R) + j]++;
142 Barrier.enterBarrier();
152 /* =============================================================================
153 * all_countsort_node_aux_seq
155 * R (range) must be a multiple of NODES
156 * q (elems/proc) must be a multiple of NODES
157 * =============================================================================
161 all_countsort_node_aux_seq (int q,
170 int[] myHisto = new int[ R];
171 int[] psHisto = new int[ R];
173 for (int k = 0; k < R; k++) {
177 for (int k = 0; k < q; k++) {
178 myHisto[BITS(lKey[k],bitOff,m)]++;
182 for (int k = 0; k < R; k++) {
183 last = psHisto[k] = myHisto[k];
188 for (int k = 0; k < R; k++) {
189 myHisto[k] = (psHisto[k] - myHisto[k]) + offset;
190 offset += psHisto[k];
193 for (int k = 0; k < q; k++) {
194 int j = BITS(lKey[k], bitOff, m);
195 lSorted[myHisto[j]] = lKey[k];
196 auxSorted[myHisto[j]] = lKey[k];
200 //lSorted[mhp[j]] = lKey[k];
201 //auxSorted[mhp[j]] = auxKey[k];
212 /* =============================================================================
213 * all_countsort_node_aux
215 * R (range) must be a multiple of NODES
216 * q (elems/proc) must be a multiple of NODES
217 * =============================================================================
220 all_countsort_node_aux (int myId,
230 Alg_Radix_Smp rdxsort)
232 int[] myHisto = null;
233 int[] psHisto = null;
236 myHisto = new int[numThread * R];
237 rdxsort.global_myHisto = myHisto;
238 psHisto = new int[numThread * R];
239 rdxsort.global_psHisto = psHisto;
242 Barrier.enterBarrier();
244 myHisto = rdxsort.global_myHisto;
245 psHisto = rdxsort.global_psHisto;
247 for (int k = 0; k < R; k++) {
248 myHisto[((myId*R) + k)] = 0;
251 LocalStartStop lss = new LocalStartStop();
252 CreatePartition.createPartition(0, q, myId, numThread, lss);
254 for (int k = lss.i_start; k < lss.i_stop; k++) {
255 myHisto[(myId*R) + BITS(lKey[k],bitOff,m)]++;
258 Barrier.enterBarrier();
260 CreatePartition.createPartition(0, R, myId, numThread, lss);
263 for (int k = lss.i_start; k < lss.i_stop; k++) {
264 last = psHisto[k] = myHisto[k];
265 for (int j = 1; j < numThread; j++) {
266 int temp = psHisto[(j*R + k)] = last + myHisto[ (j*R + k)];
271 Barrier.enterBarrier();
275 for (int k = 0; k < R; k++) {
276 myHisto[(myId*R)+k] = (psHisto[(myId*R) + k] - myHisto[(myId*R) +k]) + offset;
277 offset += psHisto[((numThread -1) * R) + k];
280 Barrier.enterBarrier();
282 CreatePartition.createPartition(0, q, myId, numThread, lss);
284 for (int k = lss.i_start; k < lss.i_stop; k++) {
285 int j = BITS(lKey[k], bitOff, m);
286 lSorted[myHisto[(myId*R) +j]] = lKey[k];
287 auxSorted[myHisto[(myId*R) +j]] = auxKey[k];
288 myHisto[(myId*R) +j]++;
291 Barrier.enterBarrier();
300 /* =============================================================================
301 * all_radixsort_node_s3
303 * q (elems/proc) must be a multiple of NODES
304 * =============================================================================
308 all_radixsort_node_s3 (int q,
317 global_lTemp = lTemp;
320 Barrier.enterBarrier();
322 lTemp = global_lTemp;
324 all_countsort_node(q, lKeys, lSorted, (1<<11), 0, 11);
325 all_countsort_node(q, lSorted, lTemp, (1<<11), 11, 11);
326 all_countsort_node(q, lTemp, lSorted, (1<<10), 22, 10);
328 Barrier.enterBarrier();
337 /* =============================================================================
338 * all_radixsort_node_s2
340 * q (elems/proc) must be a multiple of NODES
341 * =============================================================================
345 all_radixsort_node_s2 (int q,
354 global_lTemp = lTemp;
357 Barrier.enterBarrier();
359 lTemp = global_lTemp;
361 all_countsort_node(q, lKeys, lTemp, (1<<16), 0, 16);
362 all_countsort_node(q, lTemp, lSorted, (1<<16), 16, 16);
364 Barrier.enterBarrier();
373 /* =============================================================================
374 * all_radixsort_node_aux_s3_seq
376 * q (elems/proc) must be a multiple of NODES
377 * =============================================================================
381 all_radixsort_node_aux_s3_seq (int q,
391 lTemp2 = new int[ q];
393 all_countsort_node_aux_seq(q, lKeys, lSorted, auxKey, auxSorted, (1<<11), 0, 11);
394 all_countsort_node_aux_seq(q, lSorted, lTemp, auxSorted, lTemp2, (1<<11), 11, 11);
395 all_countsort_node_aux_seq(q, lTemp, lSorted, lTemp2, auxSorted, (1<<10), 22, 10);
403 /* =============================================================================
404 * all_radixsort_node_aux_s3
406 * q (elems/proc) must be a multiple of NODES
407 * =============================================================================
410 all_radixsort_node_aux_s3 (int myId,
417 Alg_Radix_Smp rdxsort)
424 rdxsort.global_lTemp = lTemp;
425 lTemp2 = new int[ q];
426 rdxsort.global_lTemp2 = lTemp2;
429 Barrier.enterBarrier();
431 lTemp = rdxsort.global_lTemp;
432 lTemp2 = rdxsort.global_lTemp2;
434 rdxsort.all_countsort_node_aux(myId, numThread, q, lKeys, lSorted, auxKey, auxSorted, (1<<11), 0, 11, rdxsort);
435 rdxsort.all_countsort_node_aux(myId, numThread, q, lSorted, lTemp, auxSorted, lTemp2, (1<<11), 11, 11, rdxsort);
436 rdxsort.all_countsort_node_aux(myId, numThread, q, lTemp, lSorted, lTemp2, auxSorted, (1<<10), 22, 10, rdxsort);
438 Barrier.enterBarrier();
447 /* =============================================================================
449 * End of alg_radix_smp.java
451 * =============================================================================