1 /**************************************************************************
3 * Java Grande Forum Benchmark Suite - Thread Version 1.0 *
7 * Java Grande Benchmarking Project *
11 * Edinburgh Parallel Computing Centre *
13 * email: epcc-javagrande@epcc.ed.ac.uk *
16 * This version copyright (c) The University of Edinburgh, 2001. *
17 * All rights reserved. *
19 **************************************************************************/
21 // This implements a simple tournament-based barrier, using entirely its
22 // own synchronisation. At present Yield() is called to stop busy-waiting
23 // processes hogging the processor(s)!
25 public class TournamentBarrier {
26 // Array of flags indicating whether the given process and all those
27 // for which it is responsible have finished. The "sense" of this
28 // array alternates with each barrier, to prevent having to
31 public int maxBusyIter;
34 public TournamentBarrier(int n) {
37 // Superclass constructor should record the number of threads
38 // and thread manager.
41 // Initialise the IsDone array. The choice of initial value is
42 // arbitrary, but must be consistent!
43 IsDone = new boolean[numThreads];
44 for(int i = 0; i < n; i++) {
49 // Uses the manager's debug function, so this can only be used after
51 public void debug(String s) {
52 //System.err.println("Debug message" + s);
56 public void setMaxBusyIter(int b) {
61 public void DoBarrier(int myid) {
63 //debug("Thread " + myid + " checking in");
66 boolean donevalue = !IsDone[myid];
68 while(((myid & roundmask) == 0) && (roundmask<(numThreads<<2))) {
69 int spacing = (roundmask+1) >> 2;
70 for(int i=1; i<=3 && myid+i*spacing < numThreads; i++) {
71 //debug("Thread " + myid + " waiting for thread " + (myid+i*spacing));
73 while(IsDone[myid+i*spacing] != donevalue) {
81 roundmask = (roundmask << 2) + 3;
83 //debug("Thread " + myid + " reporting done");
84 IsDone[myid] = donevalue;
86 while(IsDone[0] != donevalue) {
93 //debug("Thread " + myid + " checking out");