Java in Heterogeneous Computing


Java is an Object Oriented Language. It consist of all Object oriented programming concepts such as Inheritance, polymorphism, etc. With Object programming concepts, we can relate this programming to the real world objects. It is different from C++ as the C++ program is which is compile to machine code and executed directly by Central processing units. But Java Program is compiled to byte code which the JVM(Java Virtual Machine) interprets at runtime. Java Implementations do just in time compilation to native machine code.

Life of Java Program

  • Javac
  • Hello.class
  • Hello.jar
  • Java Virtual machine

Open JDK

The place to collaborate on an open-source implementation of the Java Platform, Standard Edition, and related projects.

Java and Heterogeneous computing

  •    Power usage is leading to parallel throughput.
  •    Programmers need to execute a mix of parallel and sequential tasks.
  •    Java remains the tool of choice as hardware tilts toward the parallel.

Main goal of using java and heterogeneous computing is to make easier to program heterogeneous parallel devices.Parallelism in java begin from java.lang.Thread in 2002 in java 1.4, then came the java.util.concurrent in 2004 in java 5.0, then came phasers in 2006 in java 6.0,join/fork framework supported for parallel programming in  7.0 and now its Lambda in java 8.0

Lets see an example

The old way of writing program to find total salary of employees


  •   public static int Salary(List employees, int salary)
  • {
  • int sum=0;
  • for (Employee e : employees)
  • { if (e.getStateCode() == CALIFORNIA)
  • sum += e.getSalary();
  • }
  • return sum;


The above method was more simplistic brittle and serialized. Hence parallelism support in 8th version of this language using Lambda expression. It helps to improve parallelism in Heterogeneous devices.

  •  int sum = employees.parallelStream()
  •                                              .filter(e -> e.getStateCode() == CALIFORNIA)
  •                                             .mapToInt(e -> e.getSalary())
  •                                             .sum();

There is also new parallel methods added to Array.They are:

  • Array.parallelPrefix(anArray, BinaryOperator)
  •  Array.parallelSort(anArray);
  • Array.parallelSetAll(anArray, UnaryOperator)
  • Array.spliterator(anArray)

Challenges for Java in parallel Computing

it is WORA which means Write Once,Run Anywhere ,but with Heterogeneous computing came into existence, there is transition from WORA to a world where one JVM can handle multiple ISA (CPU,GPU,DSP) at once. It is also able to route work to best resource available. Many of the cores are available and optimized for High Throughput, Low latency and Low Power. Heterogeneous systems have bumpy costs with non uniform memory access.

How to meet these challenges in Java??

Sumatra project

This primary goal of this project is to enable Java applications to take advantage of graphics processing units (GPUs) and accelerated processing units (APUs). Also whether they are discrete devices or integrated with a CPU to improve performance. This is an Open JDK Project with leadership from AMD and Oracle. When Oracle join HSA Foundation, Sumatra project came into existence.

Sumatra Demo

If we want to plot a histogram of male/female names found in the books of “Charles Dickens”, we need to use sequence of nested loops.

  •         For each Selected book
  • {
  •        For each name
  •           {
  •                       for each occurrence of ‘name’ in ‘book’
  •                              {
  •                                        name.count++;
  •                                }
  •            }
  • }

The above program can be done in parallel.

    .parallel() // <– Loop over the names in parallel.
    .forEach(name ->
    // for each occurrence of ‘name’ in ‘book’
    // name.count++;

java 8 can efficiently dispatch the enclosed lambda across multiple cores when stream is marked as parallel().[] array)
.forEach(t -> /* lambda */)

Sumatra JVM can dispatch to CPU and HSA enabled GPU Cores by converting Bytecode into HSAIL and executes runtime.

2 Thoughts to “Java in Heterogeneous Computing”

  1. Good and Well written post..

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.