{"id":1040,"date":"2018-11-26T15:11:21","date_gmt":"2018-11-26T15:11:21","guid":{"rendered":"http:\/\/ri.itservices.manchester.ac.uk\/csf3\/?page_id=1040"},"modified":"2025-10-27T11:13:32","modified_gmt":"2025-10-27T11:13:32","slug":"java","status":"publish","type":"page","link":"https:\/\/ri.itservices.manchester.ac.uk\/csf3\/software\/tools\/java\/","title":{"rendered":"Java"},"content":{"rendered":"<h2>Overview<\/h2>\n<p>Please read the following information carefully if running java applications on the CSF, whether they be your own code or 3rd-party applications. This is to ensure you use the correct number of threads when running java.<\/p>\n<p>Java Runtime Environment Versions 1.8.0 is installed on the CSF. You do not need to load any module to use this version.<br \/>\nNote that loading the OPENJDK modulefile will also give you access to the OpenJDK development packages (including the <code>javac<\/code> compiler).<\/p>\n<h2>Restrictions on use<\/h2>\n<p>There are no licensing restrictions to running this software. Please note that Java (and the Java compiler) will not run on the login node due to memory restrictions on that node. Please see our <a href=\"\/csf3\/software\/compilers\/javac\">Java compilation<\/a> notes for more information on compiling Java code.<\/p>\n<h2>Set up procedure<\/h2>\n<p>The default is 1.8.0. It is not necessary to load a modulefile for this version, but you can if you wish:<\/p>\n<pre>\r\nmodule load tools\/java\/1.8.0           # Default version if no modulefile loaded\r\n\r\n# Other versions\r\nmodule load tools\/openjdk\/25.0.1       # JDK 25\r\nmodule load tools\/openjdk\/23.0.2       # JDK 23\r\nmodule load tools\/openjdk\/22.0.2       # JDK 22\r\nmodule load tools\/openjdk\/20.0.2       # JDK 20\r\nmodule load tools\/openjdk\/17.0.2       # JDK 17\r\nmodule load tools\/openjdk\/11.0.2       # JDK 11\r\n\r\n# Other versions (<strong>Not recommended<\/strong>. Use openjdk modules shown above instead)\r\nmodule load tools\/java\/23\r\nmodule load tools\/java\/22\r\nmodule load tools\/java\/11\r\n\r\n# These are no longer available on CSF3 (Slurm)\r\nmodule load tools\/java\/1.7.0           # NOT installed on CSF3 (Slurm)\r\nmodule load tools\/java\/1.6.0           # NOT installed on CSF3 (Slurm)\r\n<\/pre>\n<h2>Running the application<\/h2>\n<p>Java will not run on the login node and you will receive the following error if you try to run <code>java<\/code> there:<\/p>\n<pre>Error occurred during initialization of VM\r\nCannot create VM thread. Out of system resources.\r\n<\/pre>\n<p>Jobs should be submitted to the compute nodes via batch. Note that Java may use several cores for garbage collection unless explicitly instructed not to. See below for how to run serial java code correctly.<\/p>\n<h3>Serial batch job submission<\/h3>\n<p>You <strong>must<\/strong> restrict the number of threads used by the java garbage collector otherwise it will attempt to use all of the cores in a node. If you are submitting a serial job then you will be using cores which have not been assigned to your job and will be trampling on other users&#8217; jobs. Please add the following flags to your java command line:<\/p>\n<pre>-XX:ParallelGCThreads=1 -XX:ParallelCMSThreads=1\r\n<\/pre>\n<p>Java may also try to use more than one core&#8217;s share of the memory in a node. Add the following flag to your java command line to restrict memory usage to 4GB for example (if using a single core on an Intel 64GB compute node). For other nodes, please check the available memory per core and specify that number.<\/p>\n<pre>-Xmx4G              # 4G tells Java it can use 4 GB of RAM\r\n<\/pre>\n<p>The above flags can be added to the <code>java<\/code> command-line (see jobscript examples below). For example, the following jobscript will run a serial java program safely:<\/p>\n<pre class=\"slurm\">\r\n#!\/bin\/bash --login\r\n#SBATCH -p serial  # Partition is required. Runs on an Intel hardware.\r\n                   # Or submit batch jobs to the \"interactive\" partition for AMD Genoa serial jobs.\r\n#SBATCH -t 4-0     # Wallclock limit (days-hours). Required!\r\n                   # Max permitted is 7 days (7-0).\r\n\r\nmodule purge\r\n# Load the modulefile tools\/openjdk\/25.0.1 in the jobscript\r\nmodule load tools\/openjdk\/25.0.1\r\n\r\njava -XX:ParallelGCThreads=1 -XX:ParallelCMSThreads=1 -Xmx4G <em>my_app_class<\/em> <em>arg1<\/em> <em>arg2...<\/em>\r\n\r\n# If you have a .jar file:\r\njava -XX:ParallelGCThreads=1 -XX:ParallelCMSThreads=1 -Xmx4G -jar <em>myapp.jar<\/em> <em>arg1<\/em> <em>arg2...<\/em>\r\n<\/pre>\n<p>Submit the jobscript using:<\/p>\n<pre>sbatch <em>scriptname<\/em><\/pre>\n<p>where <em>scriptname<\/em> is the name of your jobscript.<\/p>\n<p>If you are running another application which uses Java, for example MATLAB or a python program that uses Java libraries (SK-Learn is an example), then you will need to check the documentation for that application to see how to pass the Java flags to the application. You could also try setting the environment variable <code>_JAVA_OPTIONS<\/code> with a list of the flags. For example:<\/p>\n<pre class=\"slurm\">\r\n#!\/bin\/bash --login\r\n#SBATCH -p serial  # Partition is required. Runs on an Intel hardware.\r\n                   # Or submit batch jobs to the \"interactive\" partition for AMD Genoa serial jobs.\r\n#SBATCH -t 4-0     # Wallclock limit (days-hours). Required!\r\n                   # Max permitted is 7 days (7-0).\r\n\r\nmodule purge\r\n# Load the modulefile tools\/openjdk\/25.0.1 in the jobscript\r\nmodule load tools\/openjdk\/25.0.1\r\n# Load the application module next\r\nmodule load my\/java\/dependent\/app\r\n\r\n# Add the following to a jobscript to set java options. Your application may\r\n# be able to use this setting and you should check if it has worked or not!\r\nexport _JAVA_OPTIONS=\"-XX:ParallelGCThreads=1 -XX:ParallelCMSThreads=1 -Xmx4G\"\r\n\r\n# Now the commands to run your app that uses java\r\nmyapp <em>arg1<\/em> <em>arg2...<\/em>\r\n<\/pre>\n<p>Submit the jobscript using:<\/p>\n<pre>sbatch <em>scriptname<\/em><\/pre>\n<p>where <em>scriptname<\/em> is the name of your jobscript.<\/p>\n<p>Note that by setting the above environment variable, Java will usually create a log file in your home directory showing which settings have been applied. You should delete this file to keep your home directory tidy. You will have a different log file <em>every time<\/em> you run a job that uses this environment variable.<\/p>\n<h3>Parallel batch job submission<\/h3>\n<p>If your application uses Java Threads for parallelism then you should submit the job to the <code>multicore_small<\/code> partition and request an appropriate number of cores.<\/p>\n<p>Note that some Java code will use as many threads as possible and there is no way to restrict the number of threads (there is no equivalent of <code>OMP_NUM_THREADS<\/code> in Java). Hence you should submit a job of 32 or 24 cores as per the example below. This ensures you will have a entire node to yourself and so do not need to restrict the garbage collection threads or heap size. For example:<\/p>\n<p><strong>Example Job Script<\/strong><\/p>\n<pre class=\"slurm\">\r\n#!\/bin\/bash --login\r\n#SBATCH -p multicore_small  # Partition is required. Runs on haswell or skylake node.\r\n#SBATCH -C skylake          # skylake for 32 cores and 6GB\/core.\r\n                            # haswell for 24 cores and 5GB\/core.\r\n#SBATCH -n 32               # (or --ntasks=) select between 32 or 24.\r\n#SBATCH -t 4-0              # Wallclock limit (days-hours). Required!\r\n                            # Max permitted is 7 days (7-0).\r\n\r\n# Load the modulefile\r\nmodule load tools\/openjdk\/25.0.1\r\n\r\njava <em>my_parallel_app_class<\/em> <em>arg1<\/em> <em>arg2...<\/em>\r\n<\/pre>\n<p><!---- COMMENTING OUT THIS SECTION\n\n\n<table class=\"striped\">\n\n\n<thead>\n\n\n<tr>\n\n\n<th style=\"width: 17%;\">SGE <em>arch<\/em> Flag<\/th>\n\n\n\n\n<th style=\"width: 43%;\">Cores for smp.pe line<\/th>\n\n\n\n\n<th style=\"width: 40%;\">Additional usage guidance<\/th>\n\n\n<\/tr>\n\n\n<\/thead>\n\n\n\n\n<tbody>\n\n\n<tr>\n\n\n<td><code>-l haswell<\/code><\/td>\n\n\n\n\n<td>24 cores (do not set a higher or lower number than this)<\/td>\n\n\n\n\n<td>Standard Haswell node.<\/td>\n\n\n<\/tr>\n\n\n\n\n<tr>\n\n\n<td><code>-l broadwell<\/code><\/td>\n\n\n\n\n<td>28 cores (do not set a higher or lower number than this)<\/td>\n\n\n\n\n<td>Standard Broadwell node.<\/td>\n\n\n<\/tr>\n\n\n\n\n<tr>\n\n\n<td><code>-l skylake<\/code><\/td>\n\n\n\n\n<td>32 cores (do not set a higher or lower number than this)<\/td>\n\n\n\n\n<td>Standard Skylake node.<\/td>\n\n\n<\/tr>\n\n\n\n\n<tr>\n\n\n<td><code>-l mem512<\/code><\/td>\n\n\n\n\n<td>16 cores (do not set a higher or lower number than this)<\/td>\n\n\n\n\n<td>Job will run on an Ivybridge or haswell high memory node (32GB per core of RAM).<strong>Jobs must genuinely need the higher memory<\/strong><\/td>\n\n\n<\/tr>\n\n\n<\/tbody>\n\n\n<\/table>\n\n\n(11.08.2021 - Sandybridge nodes removed from service.)\n\n<strong>Which compute node type should I run on?<\/strong>\n\nAll of the above examples are for all of the possible Intel node types and which of these you use makes very little difference for most java applications. The batch system spreads works as evenly as possible across all the different types of node so no one set of nodes is likely to be busier or quieter than another.\n\nCOMMENTING OUT OF SECTION ENDS ----><\/p>\n<h2>Further info<\/h2>\n<ul>\n<li><a href=\"\/csf3\/software\/compilers\/javac\">Javac compiler on the CSF<\/a><\/li>\n<li><a href=\"https:\/\/openjdk.org\/\" target=\"_blank\" rel=\"noopener\">OpenJDK Website<\/a><\/li>\n<\/ul>\n<h2>Updates<\/h2>\n<p>None.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Overview Please read the following information carefully if running java applications on the CSF, whether they be your own code or 3rd-party applications. This is to ensure you use the correct number of threads when running java. Java Runtime Environment Versions 1.8.0 is installed on the CSF. You do not need to load any module to use this version. Note that loading the OPENJDK modulefile will also give you access to the OpenJDK development packages.. <a href=\"https:\/\/ri.itservices.manchester.ac.uk\/csf3\/software\/tools\/java\/\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"parent":144,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-1040","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/ri.itservices.manchester.ac.uk\/csf3\/wp-json\/wp\/v2\/pages\/1040","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ri.itservices.manchester.ac.uk\/csf3\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/ri.itservices.manchester.ac.uk\/csf3\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/ri.itservices.manchester.ac.uk\/csf3\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/ri.itservices.manchester.ac.uk\/csf3\/wp-json\/wp\/v2\/comments?post=1040"}],"version-history":[{"count":20,"href":"https:\/\/ri.itservices.manchester.ac.uk\/csf3\/wp-json\/wp\/v2\/pages\/1040\/revisions"}],"predecessor-version":[{"id":11267,"href":"https:\/\/ri.itservices.manchester.ac.uk\/csf3\/wp-json\/wp\/v2\/pages\/1040\/revisions\/11267"}],"up":[{"embeddable":true,"href":"https:\/\/ri.itservices.manchester.ac.uk\/csf3\/wp-json\/wp\/v2\/pages\/144"}],"wp:attachment":[{"href":"https:\/\/ri.itservices.manchester.ac.uk\/csf3\/wp-json\/wp\/v2\/media?parent=1040"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}