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

Reduction Reduction

Reduction operation is widely used to gather values of some variable stored on different threads. In the presented example the values are communicated to the thread with the id 0. Than reduction operation such as summation is performed.

Than value of the variable a (Shared variable) stored at the thread p is communicated to the thread 0 and added to the local variable sum.

 

import java.io.IOException;
import org.pcj.*;

@RegisterStorage(PcjReductionGet.Shared.class)
public class PcjReductionGet implements StartPoint {
    
    @Storage(PcjReductionGet.class)
    enum Shared { a }
    long a; 

    public static void main(String[] args) throws IOException {
        String nodesFile  = "nodes.txt";     
        PCJ.deploy(PcjReductionGet.classnew NodesDescription("nodes.txt"));
    }

    @Override
    public void main() throws Throwable {
        a = PCJ.myId() + 10;    // set value of a
        long sum = 0; 
        PCJ.barrier();
        if (PCJ.myId() == 0) {
            for (int p = 1; p < PCJ.threadCount(); p++) {
                sum = sum + (long) PCJ.get(p, Shared.a);
            }
        }
      PCJ.barrier();
      System.out.println(PCJ.myId()+ " "+ sum);
    }
}

 

The presented algorithm of the reduction is based on the synchronous communication PCJ.get(). The summation is performed at thread 0 as data is arrived.

 

The asynchronous version requires additional storage at the thread 0. The al[] variable stores values of a variable communicated in asynchronous way: 

 

import java.io.IOException;
import org.pcj.*;

@RegisterStorage(PcjReductionGet.Shared.class)
public class PcjReductionGet implements StartPoint {

    @Storage(PcjReductionGet.class)
    enum Shared { a }
    long a;

    public static void main(String[] args) throws IOException {
        String nodesFile = "nodes.txt";
        PCJ.deploy(PcjReductionGet.classnew NodesDescription("nodes.txt"));
    }

    @Override
    public void main() throws Throwable {
       PcjFuture aL[] = new PcjFuture[PCJ.threadCount()];
       PCJ.barrier();
       long sum;
       if (PCJ.myId() == 0) {         // Asynchronous communication
            for (int p = 0; p < PCJ.threadCount(); p++) {
                aL[p] = PCJ.asyncGet(p, Shared.a);
            }
       }
       PCJ.barrier();                 // Synchronization
       sum = 0;
       if (PCJ.myId() == 0) {         // Sumation of local values
            for (int p = 0; p < PCJ.threadCount(); p++) {
                sum = sum + (long) aL[p].get();
            }
       }
       System.out.println(PCJ.myId() + " " + sum);
    }
}