Occasionally the user may benefit from increasing the maximum memory allocation pool for a Java virtual machine (JVM) upon execution. This can be accomplished using the “-Xmx” command with the proceeding memory allocation. For example if we wanted to specify 16 Gigabytes we would put -Xmx16G. This is particularly useful when running large-scale simulations on a high performance cluster (see jar file creation).
When executing a java jar file in command line use “java -Xmx16G -jar TargetJarFile.jar” to execute your model with extra memory. However, while in the IdeaJ environment this is accomplished by the following steps:
- Click on “Edit Configurations” from the dropdown menu on the top right of Intellij next to the run button.
- Specify the memory using the -Xmx argument in the “VM Arguments” box.
When resources are needed that only a high-performance computing (HPC) environment can provide it may be useful to build a jar file of your model to execute independent of any IDE. IntelliJ IDEA makes it very easy to build this ‘artifact.’ There are two ways of executing your jar file. One is with command line arguments and the other is without. The process of building a jar file is the same for both, but with command line arguments you will set variables using ‘args.’ With either case, the GUI should not be used within an HPC command line environment unless you are using port forwarding for graphics. This is dependent on your HPC environment and thus will not be covered here. To simply build a jar file from your project follow these steps:
- Navigate to “File’ -> ‘Project Structure”
- On the left, where we set up our libraries, click on “Artifacts”
- Click the “+” button and select “JAR,” finally click “From modules with dependencies...”, You will only need to do this once!
- Leave all the default options in place.
- Click “Apply” and then “Ok”
- From here go the top menu bar, click on “Build -> Build Artifacts...”
- Using this you can select “Build,” “Rebuild,” “Clean”, or edit which will take you back to Step 3.
- Just choose “Build” (for the first time, you can use “Rebuild” later).
- Your jar file is located within the project directory in the “out/artifacts/jarname/file.jar,”
- the Jar file can be moved to another machine that has Java 8 or above for execution.
- to run the jar file, enter something like: “Java -jar -Xmx16G /path/to/jar/file.jar arg1 arg2 arg3” where the optional flag “-Xmx16G” specifies that we want to use 16GB of memory for the program, “/path/to/jar/file.jar” is the path to the jar file, and “arg1 arg2 arg3” are optional arguments that will show up in your program in the “String args” array in the main function.