public static void main(String[] args) { // Initialization for benchmarking int start = 0; int stop = 0; int time = 0; System.out.println("Matrix Benchmark:"); System.out.println("Initializing data..."); long seed = 13; initializeMultiplication(seed); SysDevice sys = IOFactory.getFactory().getSysDevice(); for (int i = 0; i < sys.nrCpu - 1; i++) { Runnable r = new MatrixBenchCMP(i + 1); Startup.setRunnable(r, i); } System.out.println("Start benchmark!"); // Start of measurement start = LowLevel.timeMillis(); // Start of all other CPUs sys.signal = 1; // Start of CPU0 int test0 = processCalculation(); while (true) { synchronized (lock) { if (endCalculation == N) break; } } // End of measurement stop = LowLevel.timeMillis(); System.out.println("StartTime: " + start); System.out.println("StopTime: " + stop); time = stop - start; System.out.println("TimeSpent: " + time); }
/** * Create interrupt handler and preallocated exceptions in a static method instead of <clinit>. * Jikes puts <clinit> as first methods into the table (instead of interrupt()), javac as last * method. * * <p>We could use HWO here. */ static void init() { ih = new Runnable[Native.rdMem(Const.IO_CPUCNT)][Const.NUM_INTERRUPTS]; dh = new DummyHandler(); for (int core = 0; core < Native.rdMem(Const.IO_CPUCNT); ++core) { for (int var = 0; var < Const.NUM_INTERRUPTS; ++var) { JVMHelp.addInterruptHandler(core, var, dh); } } sys = IOFactory.getFactory().getSysDevice(); SOError = new StackOverflowError(); NPExc = new NullPointerException(); ABExc = new ArrayIndexOutOfBoundsException(); ArithExc = new ArithmeticException(); CCExc = new ClassCastException(); RetryExc = RetryException.instance; }
/** @author Martin Schoeberl */ public class SimpleList { static final int MAGIC = -10000; static final int CNT = 1000; static SysDevice sys = IOFactory.getFactory().getSysDevice(); static Vector vecA = new Vector(); static Vector vecB = new Vector(); /** @param args */ public static void main(String[] args) { if (sys.nrCpu < 3) { System.out.println("Not enogh CPUs for this example"); System.exit(-1); } Inserter ins = new Inserter(); Startup.setRunnable(ins, 0); Remover rem = new Remover(); Startup.setRunnable(rem, 1); // start the other CPUs sys.signal = 1; // move one element atomic from one vector to the other for (int i = 0; i < CNT; ) { boolean found = false; Native.wrMem(1, MAGIC); // start transaction int nr = vecA.size(); if (nr > 0) { Object o = vecA.remove(nr - 1); vecB.addElement(o); found = true; } Native.wrMem(0, MAGIC); // end transaction if (found) ++i; } // wait for other CPUs to finish while (!(ins.finished && rem.finished)) {; } } static class Inserter implements Runnable { public boolean finished; public void run() { for (int i = 0; i < CNT; ++i) { Object o = new Object(); Native.wrMem(1, MAGIC); // start transaction vecA.addElement(o); Native.wrMem(0, MAGIC); // end transaction } finished = true; } } static class Remover implements Runnable { public boolean finished; public void run() { for (int i = 0; i < CNT; ) { boolean found = false; Native.wrMem(1, MAGIC); // start transaction int nr = vecB.size(); if (nr > 0) { Object o = vecB.remove(nr - 1); found = true; } Native.wrMem(0, MAGIC); // end transaction if (found) ++i; } finished = true; } } }