Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| software:java:caviness [2018-08-29 11:51] – anita | software:java:caviness [2021-04-27 16:21] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== Projects in Java on Caviness ====== | ||
| + | |||
| + | Below is a basic Java example and steps you can follow and apply to your '' | ||
| + | |||
| + | <file java HelloWorld.java> | ||
| + | public class HelloWorld | ||
| + | { | ||
| + | public static void main(String[] args) | ||
| + | { | ||
| + | System.out.println(" | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | Check the version of the java compiler and java available on Caviness by using | ||
| + | |||
| + | <code bash> | ||
| + | $ javac -version | ||
| + | $ java -version | ||
| + | </ | ||
| + | |||
| + | and determine if this is acceptable for your java application to compile and create the '' | ||
| + | |||
| + | <code bash> | ||
| + | [traine@login00 ~]$ workgroup -g it_css | ||
| + | [(it_css: | ||
| + | javac 1.8.0_161 | ||
| + | [(it_css: | ||
| + | openjdk version " | ||
| + | OpenJDK Runtime Environment (build 1.8.0_161-b14) | ||
| + | OpenJDK 64-Bit Server VM (build 25.161-b14, mixed mode) | ||
| + | [(it_css: | ||
| + | [(it_css: | ||
| + | public class HelloWorld | ||
| + | { | ||
| + | public static void main(String[] args) | ||
| + | { | ||
| + | System.out.println(" | ||
| + | } | ||
| + | } | ||
| + | [(it_css: | ||
| + | [(it_css: | ||
| + | HelloWorld.class | ||
| + | [(it_css: | ||
| + | Hello, World! | ||
| + | [(it_css: | ||
| + | </ | ||
| + | |||
| + | If you want to compile on a compute node, use '' | ||
| + | |||
| + | <code bash> | ||
| + | [traine@login00 ~]$ workgroup -g it_css | ||
| + | [(it_css: | ||
| + | salloc: Pending job allocation 7299417 | ||
| + | salloc: job 7299417 queued and waiting for resources | ||
| + | salloc: job 7299417 has been allocated resources | ||
| + | salloc: Granted job allocation 7299417 | ||
| + | salloc: Waiting for resource configuration | ||
| + | salloc: Nodes r00n56 are ready for job | ||
| + | [traine@r00n56 ~]$ javac -version | ||
| + | javac 1.8.0_161 | ||
| + | [traine@r00n56 ~]$ java -version | ||
| + | openjdk version " | ||
| + | OpenJDK Runtime Environment (build 1.8.0_161-b14) | ||
| + | OpenJDK 64-Bit Server VM (build 25.161-b14, mixed mode) | ||
| + | [traine@r00n56 ~]$ cd $WORKDIR/ | ||
| + | [traine@r00n56 java]$ cat HelloWorld.java | ||
| + | public class HelloWorld | ||
| + | { | ||
| + | public static void main(String[] args) | ||
| + | { | ||
| + | System.out.println(" | ||
| + | } | ||
| + | } | ||
| + | [traine@r00n56 java]$ javac HelloWorld.java | ||
| + | [traine@r00n56 java]$ ls | ||
| + | HelloWorld.class | ||
| + | [traine@r00n56 java]$ java HelloWorld | ||
| + | Hello, World! | ||
| + | [traine@r00n56 java]$ exit | ||
| + | exit | ||
| + | salloc: Relinquishing job allocation 7299417 | ||
| + | [(it_css: | ||
| + | </ | ||
| + | |||
| + | If you want to run your java job in batch, then you will need a job submission script. | ||
| + | |||
| + | <file bash submit.qs> | ||
| + | #!/bin/bash -l | ||
| + | # | ||
| + | # Sections of this script that can/should be edited are delimited by a | ||
| + | # [EDIT] tag. All Slurm job options are denoted by a line that starts | ||
| + | # with "# | ||
| + | # the command line. Slurm job options can easily be disabled in a | ||
| + | # script by inserting a space in the prefix, e.g. "# SLURM " and | ||
| + | # reenabled by deleting that space. | ||
| + | # | ||
| + | # This is a batch job template for a program using a single processor | ||
| + | # core/thread (a serial job). | ||
| + | # | ||
| + | #SBATCH --ntasks=1 | ||
| + | # | ||
| + | # [EDIT] All jobs have memory limits imposed. | ||
| + | # CPU allocated to the job. The default can be overridden either | ||
| + | # with a per-node value (--mem) or a per-CPU value (--mem-per-cpu) | ||
| + | # with unitless values in MB and the suffixes K|M|G|T denoting | ||
| + | # kibi, mebi, gibi, and tebibyte units. | ||
| + | # the "#" | ||
| + | # | ||
| + | # SBATCH --mem=8G | ||
| + | # SBATCH --mem-per-cpu=1024M | ||
| + | # | ||
| + | # [EDIT] Each node in the cluster has local scratch disk of some sort | ||
| + | # that is always mounted as /tmp. Per-job and per-step temporary | ||
| + | # directories are automatically created and destroyed by the | ||
| + | # auto_tmpdir plugin in the /tmp filesystem. | ||
| + | # amount of free space on /tmp when your job is scheduled, the | ||
| + | # --tmp option can be used; it has the same behavior unit-wise as | ||
| + | # --mem and --mem-per-cpu. | ||
| + | # word SBATCH to enable: | ||
| + | # | ||
| + | # SBATCH --tmp=1T | ||
| + | # | ||
| + | # [EDIT] It can be helpful to provide a descriptive (terse) name for | ||
| + | # the job: | ||
| + | # | ||
| + | #SBATCH --job-name=java_serial_job | ||
| + | # | ||
| + | # [EDIT] The partition determines which nodes can be used and with what | ||
| + | # maximum runtime limits, etc. Partition limits can be displayed | ||
| + | # with the "sinfo --summarize" | ||
| + | # | ||
| + | #SBATCH --partition=devel | ||
| + | # | ||
| + | # [EDIT] The maximum runtime for the job; a single integer is interpreted | ||
| + | # as a number of seconds, otherwise use the format | ||
| + | # | ||
| + | # d-hh:mm:ss | ||
| + | # | ||
| + | # Jobs default to the maximum runtime limit of the chosen partition | ||
| + | # if this option is omitted. | ||
| + | # | ||
| + | #SBATCH --time=0-00: | ||
| + | # | ||
| + | # [EDIT] By default SLURM sends the job's stdout to the file " | ||
| + | # and the job's stderr to the file " | ||
| + | # directory. | ||
| + | # word SBATCH on the following lines; see the man page for sbatch for | ||
| + | # special tokens that can be used in the filenames: | ||
| + | # | ||
| + | # SBATCH --output=%x-%j.out | ||
| + | # SBATCH --error=%x-%j.out | ||
| + | # | ||
| + | # [EDIT] Slurm can send emails to you when a job transitions through various | ||
| + | # states: NONE, BEGIN, END, FAIL, REQUEUE, ALL, TIME_LIMIT, | ||
| + | # TIME_LIMIT_50, | ||
| + | # of these flags (separated by commas) are permissible for the | ||
| + | # --mail-type flag. You MUST set your mail address using --mail-user | ||
| + | # for messages to get off the cluster. | ||
| + | # | ||
| + | # SBATCH --mail-user=' | ||
| + | # SBATCH --mail-type=END, | ||
| + | # | ||
| + | # [EDIT] By default we DO NOT want to send the job submission environment | ||
| + | # to the compute node when the job runs. | ||
| + | # | ||
| + | #SBATCH --export=NONE | ||
| + | # | ||
| + | |||
| + | # | ||
| + | # Do general job environment setup: | ||
| + | # | ||
| + | . / | ||
| + | |||
| + | # | ||
| + | # [EDIT] Add your script statements hereafter, or execute a script or program | ||
| + | # using the srun command. | ||
| + | # | ||
| + | java HelloWorld | ||
| + | </ | ||
| + | |||
| + | Now submit the job using '' | ||
| + | |||
| + | <code bash> | ||
| + | [traine@login00 ~]$ workgroup -g it_css | ||
| + | [(it_css: | ||
| + | Submitted batch job 1231 1 | ||
| + | [(it_css: | ||
| + | HelloWorld.class | ||
| + | [(it_css: | ||
| + | Hello, World! | ||
| + | [(it_css: | ||
| + | </ | ||
| + | |||
| + | <note tip> | ||