示例#1
0
  /** @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)) {;
    }
  }
示例#2
0
  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);
  }