PCJ is a library for Java language that helps to perform parallel and distributed calculations. The current version is able to work on the multicore systems connected with the typical interconnect such as ethernet or infiniband providing users with the uniform view across nodes.

Download PCJ library (jar file of 29.04.2017 ver. 5.0.6)  Latest (bug fixing release)!

Download PCJ manual (pdf) for PCJ 5 New!

The PCJ library can be used with no cost at BSD license. It requires Java 8 and no additional tools or comilers.  The PCJ library for Java 7 is available in the dowload section.

The source code is available at GitHub: https://github.com/hpdcj/pcj

Version 5 introduces asyncPut() and asyncGet() methods; put() and get() methods are now synchronous. There is new handling of shared variables. The code developed for PCJ 4 hast to be modified. For details please reffer to the JavaDoc file.

The usage should be acknowledged by reference to the PCJ web site and/or reference to the papers:

Full paper list can be found here: http://pcj.icm.edu.pl/pcj-papers

Contact: bala@icm.edu.pl faramir@icm.edu.pl

Approximation of π using integral Approximation of π using integral

The value of πis calculated using rectangles method that approximates following integral:

π = 01 4.0 / (1 + x2 ) dx

In our code, the interval is divided into equal subintervals and we take top middle point of each subinterval to calculate area of the rectangle.

The calculations will start by executing the main method from PcjExamplePiI class. Four tasks will be involved in calculations: on local machine. The listing contains comments that should clarify what program is doing. The user can easily change number of tasks by providing more host names to the deploy method. The PCJ will launch calculations on specified nodes.

import org.pcj.NodesDescription;
import org.pcj.PCJ;
import org.pcj.StartPoint;
import org.pcj.Storage;
import org.pcj.PcjFuture;
import org.pcj.RegisterStorage;

public class PcjExamplePiI implements StartPoint {

    private double f(final double x) {
        return (4.0 / (1.0 + x * x));

    enum Shared {
    double sum;

    public void main() {

        double time = System.nanoTime();

        long nAll = 1_280_000_000;
        double w = 1.0 / (double) nAll;
        sum = 0.0;
// Calculate partial results with the cyclic distribution
        for (int i = PCJ.myId(); i < nAll; i += PCJ.threadCount()) {
            sum = sum + f(((double) i + 0.5) * w);
        sum = sum * w;

// Wait for all tasksk to finish

// Gather results
        PcjFuture cL[] = new PcjFuture[PCJ.threadCount()];
        double pi = sum;
        if (PCJ.myId() == 0) {
            for (int p = 1; p < PCJ.threadCount(); p++) {
                cL[p] = PCJ.asyncGet(p, Shared.sum);
            for (int p = 1; p < PCJ.threadCount(); p++) {
                pi = pi + cL[p].get();

// Print results
        time = System.nanoTime() - time;

        if (PCJ.myId() == 0) {
            System.out.format(" %.7f  %.7f time %.5f \n", pi, time * 1.0E-9, time);

    public static void main(String[] args) {
        PCJ.deploy(PcjExamplePiI.classnew NodesDescription("nodes.txt"));