public Object call() throws Exception { _barrier.await(); // barrier, to force racing start for (long j = 0; j < _count; j++) _map.put( j + _offset, new TestKey(_rand.nextLong(), _rand.nextInt(), (short) _rand.nextInt(Short.MAX_VALUE))); return null; }
public void execute(Tuple input) { if (_exception != null) { throw new RuntimeException(_exception); } // just need an id String genId = Long.toString(_rand.nextLong()); _inputs.put(genId, input); _process.writeBoltMsg(createBoltMessage(input, genId)); }
public static void main(String[] args) throws Exception { int n = 1 << 18; int reps = 1 << 8; Rand[] array = new Rand[n]; for (int i = 0; i < n; ++i) array[i] = new Rand(i + 1); ForkJoinPool fjp = new ForkJoinPool(1); ParallelArray<Rand> pa = ParallelArray.createUsingHandoff(array, fjp); final GetNext getNext = new GetNext(); final Accum accum = new Accum(); final Long zero = Long.valueOf(0); long last, now; double elapsed; for (int j = 0; j < 2; ++j) { long rseed = rng.nextLong(); resetSeeds(array, rseed); long seqsum = 0; last = System.nanoTime(); for (int k = 0; k < reps; ++k) { seqsum += seqMapReduce(array, getNext, accum, zero); Rand tmp = array[k]; array[k] = array[n - k - 1]; array[n - k - 1] = tmp; } now = System.nanoTime(); elapsed = (double) (now - last) / NPS; last = now; System.out.printf("sequential: %7.3f\n", elapsed); for (int i = 2; i <= NCPU; i <<= 1) { resetSeeds(array, rseed); long sum = 0; fjp.setPoolSize(i); last = System.nanoTime(); for (int k = 0; k < reps; ++k) { sum += pa.withMapping(getNext).reduce(accum, zero); Rand tmp = array[k]; array[k] = array[n - k - 1]; array[n - k - 1] = tmp; } now = System.nanoTime(); elapsed = (double) (now - last) / NPS; last = now; System.out.printf("poolSize %3d: %7.3f\n", i, elapsed); if (sum != seqsum) throw new Error("checksum"); } for (int i = NCPU; i >= 1; i >>>= 1) { resetSeeds(array, rseed); long sum = 0; fjp.setPoolSize(i); last = System.nanoTime(); for (int k = 0; k < reps; ++k) { sum += pa.withMapping(getNext).reduce(accum, zero); Rand tmp = array[k]; array[k] = array[n - k - 1]; array[n - k - 1] = tmp; } now = System.nanoTime(); elapsed = (double) (now - last) / NPS; last = now; System.out.printf("poolSize %3d: %7.3f\n", i, elapsed); if (sum != seqsum) throw new Error("checksum"); } } fjp.shutdownNow(); fjp.awaitTermination(1, TimeUnit.SECONDS); Thread.sleep(100); }