Java Code Examples for java.util.concurrent.ForkJoinPool#getParallelism()

The following examples show how to use java.util.concurrent.ForkJoinPool#getParallelism() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NQueensCS.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
static void test(ForkJoinPool g, int i) throws Exception {
    boardSize = i;
    int ps = g.getParallelism();
    long start = System.nanoTime();
    NQueensCS task = new NQueensCS(new int[0]);
    g.invoke(task);
    int solutions = task.solutions;
    long time = System.nanoTime() - start;
    double secs = (double) time / NPS;
    if (solutions != expectedSolutions[i])
        throw new Error();
    System.out.printf("NQueensCS %3d", i);
    System.out.printf(" Time: %7.3f", secs);
    long sc = g.getStealCount();
    long ns = sc - lastStealCount;
    lastStealCount = sc;
    System.out.printf(" Steals/t: %5d", ns/ps);
    System.out.println();
}
 
Example 2
Source File: NQueensCS.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
static void test(ForkJoinPool g, int i) throws Exception {
    boardSize = i;
    int ps = g.getParallelism();
    long start = System.nanoTime();
    NQueensCS task = new NQueensCS(new int[0]);
    g.invoke(task);
    int solutions = task.solutions;
    long time = System.nanoTime() - start;
    double secs = (double) time / NPS;
    if (solutions != expectedSolutions[i])
        throw new Error();
    System.out.printf("NQueensCS %3d", i);
    System.out.printf(" Time: %7.3f", secs);
    long sc = g.getStealCount();
    long ns = sc - lastStealCount;
    lastStealCount = sc;
    System.out.printf(" Steals/t: %5d", ns/ps);
    System.out.println();
}
 
Example 3
Source File: NQueensCS.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
static void test(ForkJoinPool g, int i) throws Exception {
    boardSize = i;
    int ps = g.getParallelism();
    long start = System.nanoTime();
    NQueensCS task = new NQueensCS(new int[0]);
    g.invoke(task);
    int solutions = task.solutions;
    long time = System.nanoTime() - start;
    double secs = (double) time / NPS;
    if (solutions != expectedSolutions[i])
        throw new Error();
    System.out.printf("NQueensCS %3d", i);
    System.out.printf(" Time: %7.3f", secs);
    long sc = g.getStealCount();
    long ns = sc - lastStealCount;
    lastStealCount = sc;
    System.out.printf(" Steals/t: %5d", ns/ps);
    System.out.println();
}
 
Example 4
Source File: NQueensCS.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
static void test(ForkJoinPool g, int i) throws Exception {
    boardSize = i;
    int ps = g.getParallelism();
    long start = System.nanoTime();
    NQueensCS task = new NQueensCS(new int[0]);
    g.invoke(task);
    int solutions = task.solutions;
    long time = System.nanoTime() - start;
    double secs = (double) time / NPS;
    if (solutions != expectedSolutions[i])
        throw new Error();
    System.out.printf("NQueensCS %3d", i);
    System.out.printf(" Time: %7.3f", secs);
    long sc = g.getStealCount();
    long ns = sc - lastStealCount;
    lastStealCount = sc;
    System.out.printf(" Steals/t: %5d", ns/ps);
    System.out.println();
}
 
Example 5
Source File: NQueensCS.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
static void test(ForkJoinPool g, int i) throws Exception {
    boardSize = i;
    int ps = g.getParallelism();
    long start = System.nanoTime();
    NQueensCS task = new NQueensCS(new int[0]);
    g.invoke(task);
    int solutions = task.solutions;
    long time = System.nanoTime() - start;
    double secs = (double) time / NPS;
    if (solutions != expectedSolutions[i])
        throw new Error();
    System.out.printf("NQueensCS %3d", i);
    System.out.printf(" Time: %7.3f", secs);
    long sc = g.getStealCount();
    long ns = sc - lastStealCount;
    lastStealCount = sc;
    System.out.printf(" Steals/t: %5d", ns/ps);
    System.out.println();
}
 
Example 6
Source File: NQueensCS.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
static void test(ForkJoinPool g, int i) throws Exception {
    boardSize = i;
    int ps = g.getParallelism();
    long start = System.nanoTime();
    NQueensCS task = new NQueensCS(new int[0]);
    g.invoke(task);
    int solutions = task.solutions;
    long time = System.nanoTime() - start;
    double secs = (double) time / NPS;
    if (solutions != expectedSolutions[i])
        throw new Error();
    System.out.printf("NQueensCS %3d", i);
    System.out.printf(" Time: %7.3f", secs);
    long sc = g.getStealCount();
    long ns = sc - lastStealCount;
    lastStealCount = sc;
    System.out.printf(" Steals/t: %5d", ns/ps);
    System.out.println();
}
 
Example 7
Source File: NQueensCS.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
static void test(ForkJoinPool g, int i) throws Exception {
    boardSize = i;
    int ps = g.getParallelism();
    long start = System.nanoTime();
    NQueensCS task = new NQueensCS(new int[0]);
    g.invoke(task);
    int solutions = task.solutions;
    long time = System.nanoTime() - start;
    double secs = (double) time / NPS;
    if (solutions != expectedSolutions[i])
        throw new Error();
    System.out.printf("NQueensCS %3d", i);
    System.out.printf(" Time: %7.3f", secs);
    long sc = g.getStealCount();
    long ns = sc - lastStealCount;
    lastStealCount = sc;
    System.out.printf(" Steals/t: %5d", ns/ps);
    System.out.println();
}
 
Example 8
Source File: NQueensCS.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
static void test(ForkJoinPool g, int i) throws Exception {
    boardSize = i;
    int ps = g.getParallelism();
    long start = System.nanoTime();
    NQueensCS task = new NQueensCS(new int[0]);
    g.invoke(task);
    int solutions = task.solutions;
    long time = System.nanoTime() - start;
    double secs = (double) time / NPS;
    if (solutions != expectedSolutions[i])
        throw new Error();
    System.out.printf("NQueensCS %3d", i);
    System.out.printf(" Time: %7.3f", secs);
    long sc = g.getStealCount();
    long ns = sc - lastStealCount;
    lastStealCount = sc;
    System.out.printf(" Steals/t: %5d", ns/ps);
    System.out.println();
}
 
Example 9
Source File: NQueensCS.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
static void test(ForkJoinPool g, int i) throws Exception {
    boardSize = i;
    int ps = g.getParallelism();
    long start = System.nanoTime();
    NQueensCS task = new NQueensCS(new int[0]);
    g.invoke(task);
    int solutions = task.solutions;
    long time = System.nanoTime() - start;
    double secs = (double) time / NPS;
    if (solutions != expectedSolutions[i])
        throw new Error();
    System.out.printf("NQueensCS %3d", i);
    System.out.printf(" Time: %7.3f", secs);
    long sc = g.getStealCount();
    long ns = sc - lastStealCount;
    lastStealCount = sc;
    System.out.printf(" Steals/t: %5d", ns/ps);
    System.out.println();
}
 
Example 10
Source File: NQueensCS.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
static void test(ForkJoinPool g, int i) throws Exception {
    boardSize = i;
    int ps = g.getParallelism();
    long start = System.nanoTime();
    NQueensCS task = new NQueensCS(new int[0]);
    g.invoke(task);
    int solutions = task.solutions;
    long time = System.nanoTime() - start;
    double secs = (double) time / NPS;
    if (solutions != expectedSolutions[i])
        throw new Error();
    System.out.printf("NQueensCS %3d", i);
    System.out.printf(" Time: %7.3f", secs);
    long sc = g.getStealCount();
    long ns = sc - lastStealCount;
    lastStealCount = sc;
    System.out.printf(" Steals/t: %5d", ns/ps);
    System.out.println();
}
 
Example 11
Source File: NQueensCS.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
static void test(ForkJoinPool g, int i) throws Exception {
    boardSize = i;
    int ps = g.getParallelism();
    long start = System.nanoTime();
    NQueensCS task = new NQueensCS(new int[0]);
    g.invoke(task);
    int solutions = task.solutions;
    long time = System.nanoTime() - start;
    double secs = (double) time / NPS;
    if (solutions != expectedSolutions[i])
        throw new Error();
    System.out.printf("NQueensCS %3d", i);
    System.out.printf(" Time: %7.3f", secs);
    long sc = g.getStealCount();
    long ns = sc - lastStealCount;
    lastStealCount = sc;
    System.out.printf(" Steals/t: %5d", ns/ps);
    System.out.println();
}
 
Example 12
Source File: NQueensCS.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
static void test(ForkJoinPool g, int i) throws Exception {
    boardSize = i;
    int ps = g.getParallelism();
    long start = System.nanoTime();
    NQueensCS task = new NQueensCS(new int[0]);
    g.invoke(task);
    int solutions = task.solutions;
    long time = System.nanoTime() - start;
    double secs = (double) time / NPS;
    if (solutions != expectedSolutions[i])
        throw new Error();
    System.out.printf("NQueensCS %3d", i);
    System.out.printf(" Time: %7.3f", secs);
    long sc = g.getStealCount();
    long ns = sc - lastStealCount;
    lastStealCount = sc;
    System.out.printf(" Steals/t: %5d", ns/ps);
    System.out.println();
}
 
Example 13
Source File: MiGzOutputStream.java    From migz with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Creates a new MiGzOutputStream that will output MiGz-compressed bytes to the specified underlying outputStream.
 *
 * @param outputStream the stream to which compressed bytes will be written
 * @param threadPool the {@link ForkJoinPool} where compression worker tasks will be executed
 * @param blockSize the number of bytes that comprise each block to be compressed; larger blocks result in better
 *                  compression at the expense of more RAM usage when compressing and decompressing.
 * @param shouldShutdownThreadPool true if this instance "owns" the thread pool and should shut it down when close()
 *                                 is called
 */
private MiGzOutputStream(OutputStream outputStream, ForkJoinPool threadPool, int blockSize,
    boolean shouldShutdownThreadPool) {
  _outputStream = outputStream;
  _maxCompressedSize = MiGzUtil.maxCompressedSize(blockSize);
  _threadCount = threadPool.getParallelism();
  _blockSize = blockSize;

  // calculate the total number of buffers in the pool, including the starts-as-checked-out _currentBuffer
  int bufferPoolSize = PENDING_TASKS_TARGET + _threadCount + 1;

  // the number of pending writes is limited by the number of buffers in the pool:
  _writeQueue = new SequentialQueue<>(bufferPoolSize + 1); // writes to this queue should never block
  _exclusiveWriter = new ExclusiveIdempotentMethod(this::writeToUnderlyingStream);

  _threadPool = threadPool;
  _shouldShutdownThreadPool = shouldShutdownThreadPool;

  // create pooled buffers
  _currentBuffer = createBuffer();
  _bufferPool = new LinkedBlockingQueue<>(
      IntStream.range(0, bufferPoolSize - 1).mapToObj(i -> createBuffer()).collect(Collectors.toList()));
}
 
Example 14
Source File: NQueensCS.java    From native-obfuscator with GNU General Public License v3.0 6 votes vote down vote up
static void test(ForkJoinPool g, int i) throws Exception {
    boardSize = i;
    int ps = g.getParallelism();
    long start = System.nanoTime();
    NQueensCS task = new NQueensCS(new int[0]);
    g.invoke(task);
    int solutions = task.solutions;
    long time = System.nanoTime() - start;
    double secs = (double) time / NPS;
    if (solutions != expectedSolutions[i])
        throw new Error();
    System.out.printf("NQueensCS %3d", i);
    System.out.printf(" Time: %7.3f", secs);
    long sc = g.getStealCount();
    long ns = sc - lastStealCount;
    lastStealCount = sc;
    System.out.printf(" Steals/t: %5d", ns/ps);
    System.out.println();
}
 
Example 15
Source File: NQueensCS.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
static void test(ForkJoinPool g, int i) throws Exception {
    boardSize = i;
    int ps = g.getParallelism();
    long start = System.nanoTime();
    NQueensCS task = new NQueensCS(new int[0]);
    g.invoke(task);
    int solutions = task.solutions;
    long time = System.nanoTime() - start;
    double secs = (double) time / NPS;
    if (solutions != expectedSolutions[i])
        throw new Error();
    System.out.printf("NQueensCS %3d", i);
    System.out.printf(" Time: %7.3f", secs);
    long sc = g.getStealCount();
    long ns = sc - lastStealCount;
    lastStealCount = sc;
    System.out.printf(" Steals/t: %5d", ns/ps);
    System.out.println();
}
 
Example 16
Source File: ForkJoinStarvationTest.java    From a-foundation with Apache License 2.0 5 votes vote down vote up
@Test
public void testLocalQueueFifo() throws InterruptedException {
    pool = new ForkJoinPool (pool.getParallelism (), pool.getFactory (), pool.getUncaughtExceptionHandler (), true);

    for (int i=0; i<100; i++) {
        pool.execute (new ForkingTask (-2));
    }

    // Give the pool time to get plenty of work done - whatever remains after this interval is assumed never to happen
    Thread.sleep (2000);

    assertEquals (2* pool.getParallelism (), perThread.intValue ());
}
 
Example 17
Source File: PoolBenchmark.java    From a-foundation with Apache License 2.0 4 votes vote down vote up
private static ForkJoinPool createForkJoin (boolean fifo) {
    final ForkJoinPool p = ForkJoinPool.commonPool ();
    return new ForkJoinPool (p.getParallelism (), p.getFactory (), p.getUncaughtExceptionHandler (), fifo); //TODO use NUM_THREADS to actually limit the number of threads
}
 
Example 18
Source File: MiGzInputStream.java    From migz with BSD 2-Clause "Simplified" License 2 votes vote down vote up
/**
 * Creates a new MiGzInputStream that will read MiGz-compressed bytes from the specified underlying
 * inputStream.  The number of worker threads will be equal to the parallelism of the pool.
 *
 * @param inputStream the stream from which compressed bytes will be read
 * @param threadPool the thread pool on which worker threads will be scheduled
 */
public MiGzInputStream(InputStream inputStream, ForkJoinPool threadPool) {
  this(inputStream, threadPool, threadPool.getParallelism());
}