software:java:farber

Projects in Java on Farber

Below is a basic Java example and steps you can follow and apply to your filename.java. Remember Unix is case sensitive so it is very important for the filename HelloWorld.java match the class name defined in the file as HelloWorld.

HelloWorld.java
public class HelloWorld
{
  public static void main(String[] args)
  {
    System.out.println("Hello, World!");
  }
}
All compiling for Java must be done on a compute node which means you must set your workgroup followed by qlogin to work on a compute node. Remember to use VALET to select the appropriate version of Java.

Check the versions of java development available on your cluster by using

$ vpkg_versions openjdk

and make sure you select the appropriate version to compile and create the HelloWorld.class file. The following example is based on the user traine in workgroup it_css on Farber using commands to create a directory /home/work/it_css/traine/java to store all the files associated with this example, qlogin to a compute node, load openjdk verison 1.8.0 using VALET, compile and test HellowWorld, and lastly exit the compute node and return to the head node.

[farber ~]$ workgroup -g it_css
[(it_css:traine)@farber ~]$ cd /home/work/it_css/traine/java
[(it_css:traine)@farber java]$ cat HelloWorld.java
public class HelloWorld
{
  public static void main(String[] args)
  {
    System.out.println("Hello, World!");
  }
}
[(it_css:traine)@farber java]$ qlogin
Your job 1392265 ("QLOGIN") has been submitted
waiting for interactive job to be scheduled ...
Your interactive job 1392265 has been successfully scheduled.
Establishing /opt/shared/univa/local/qlogin_ssh session to host n040 ...
[(it_css:traine)@n040 java]$ vpkg_devrequire openjdk/1.8.0
Adding package `openjdk/1.8.0` to your environment
[(it_css:traine)@n040 java]$ javac HelloWorld.java
[(it_css:traine)@n040 java]$ ls
HelloWorld.class  HelloWorld.java
[(it_css:traine)@n040 java]$ java HelloWorld
Hello, World!
[(it_css:traine)@n040 java]$ exit
[(it_css:traine)@farber java]$ 

Once we are back on the head node, you will need a job submission script to run your java job. For this simple example, copy serial.qs from /opt/shared/templates/gridengine on Farber, name it submit.qs, and modify it to run the HelloWorld executable.

submit.qs
#
# Template:  Basic Serial Job
# 
# Change the following to #$ and set the amount of memory you need
# per-slot if you're getting out-of-memory errors using the
# default:
# -l m_mem_free=2G
#
# If you want an email message to be sent to you when your job ultimately
# finishes, edit the -M line to have your email address and change the
# next two lines to start with #$ instead of just #
# -m eas
# -M my_address@mail.server.com
#
 
# Add vpkg_require commands after this line:
vpkg_require openjdk/1.8.0
 
# Now append all of your shell commands necessary to run your program
# after this line:
java HelloWorld

Now submit the job using qsub submit.qs on the head node. The example below shows this process incuding commands to monitor the status of job and view results of the job run.

(it_css:traine)@farber java]$ qsub submit.qs
Your job 1392329 ("submit.qs") has been submitted
[(it_css:traine)@farber java]$ qstat
job-ID     prior   name       user         state submit/start at     queue                          jclass                         slots ja-task-ID
------------------------------------------------------------------------------------------------------------------------------------------------
   1392329 0.00000 submit.qs  traine        qw    12/04/2017 16:54:28                                                                   1
[(it_css:traine)@farber java]$ ls
HelloWorld.class  HelloWorld.java  submit.qs  submit.qs.o1392329
[(it_css:traine)@farber java]$ qstat
[(it_css:traine)@farber java]$ cat submit.qs.o1392329
 
[CGROUPS] UD Grid Engine cgroup setup commencing
[CGROUPS] Setting 1073741824 bytes (vmem none bytes) on n038 (master)
[CGROUPS]   with 1 core =
[CGROUPS] done.
 
Adding package `openjdk/1.8.0` to your environment
Hello, World!
[(it_css:traine)@farber java]$
Please review the templates for job submission scripts in /opt/shared/templates/gridengine on Farber. If you do not specify any resources, by default you will get 1 core and 1GB of memory (a simple serial job) on Farber.
  • software/java/farber.txt
  • Last modified: 2021-04-27 16:21
  • by 127.0.0.1