How to Run Java Programs on taki


On this page we’ll see how to use Java on the cluster. Before proceeding, make sure you’ve read the How To Run tutorial first. Java is a popular object-oriented programming language used in general-purpose computing.

Java on taki

Currently the most up to date version of Java is the system default:

[reetam1@taki-usr1 ~]$ which java
[reetam1@taki-usr1 ~]$ javac -version
Picked up _JAVA_OPTIONS: -Xmx2G
javac 1.8.0_181
[reetam1@taki-usr1 ~]$

Example batch script

We’ll write a simple java program.See How to Run Programs on taki for an explanation on the basics of MPI and SLURM’s sbatch.

Download: ..code-2022/java/

We can launch it with a standard SLURM script.

Download: ..code-2022/java/hello.slurm

Once you have saved this code to your workspace, we have to compile it before we can execute it,

[garimak1@taki-usr1 java]$ javac

If successful, no errors or warnings will appear and an executable HelloWorld.class
will have been created, in addition to the source code in 
[garimak1@taki-usr1 Hello_Serial]$ ll
total 12
-rw-rw---- 1 garimak1 pi_jianwu 140 Dec  5 11:57
-rw-rw---- 1 garimak1 pi_jianwu 470 Dec  5 11:54 hello.slurm
-rw-rw---- 1 garimak1 pi_jianwu 423 Dec  5 14:38 HelloWorld.class
[garimak1@taki-usr1 java]$ sbatch hello.slurm
Submitted batch job 11610705
[garimak1@taki-usr1 java]$ cat slurm.out
Hello, World!

In order to execute Java programs, it is important to understand that Java relies on the Java Virtual Machine (JVM) to execute the Java bytecode (precomputed *.class files). The JVM is responsible for the object heap and therefore the infamous java garbage collection utilities. Java Garbage Collection relies heavily on processor power/utilization. More memory means that Garbage Collection takes longer and works harder at freeing memory. For optimal performance, the general rule is to use a quarter of physical memory. This general rule has been set as default in the JVM Java Options.

Redefine _JAVA_OPTIONS variable

In your slurm script, throw in the following line that will override the JVM default and ask only for an amount of memory that you specify:

export _JAVA_OPTIONS="-Xmx1G"

This would configure the JVM to only request 1Gb ("1G"). Alternatively, "512M" for 0.5Gb and so on.