'UNSW - Science

UNSW - Science - HPC

BASH Config File Examples

Every time you log into the cluster or submit a job the commands in your $HOME/.bashrc file will be executed. Here are some examples of changes that you can make to your $HOME/.bashrc file using a text editor so that your environment is automatically configured when a new shell is opened.

Adding module commands to your .bashrc

As can be seen on the modules page the majority of software on one of the clusters is not available until the module command is used to load the software. By adding the relevant snippets to the .bashrc you can automatically load certain modules each time a new session is opened.

The first snippet clears any modules that may be globally loaded:

    # Clear any modules that may have been globally .
    module purge

The next snippet adds the default Intel and Matlab modules so that they are loaded when a new shell is opened. To find out what version of the Intel and Matlab modules are default you can run the module avail command.

    # Load the default Intel and Matlab modules.
    module add intel
    module add matlab

Running the module avail command on Katana currently (Feb 2014) shows version 2012a as default as shown below.

[z1234567@katana ~]$ module avail
-------------------- /share/apps/modules/matlab ------------------
matlab/2007b          matlab/2009b          matlab/2013a         
matlab/2011a          matlab/2012a(default) matlab/2013b
matlab/2008b          matlab/2010b          
matlab/2011b          matlab/2012b

If you want to load a different version of Matlab to the default then you just need to add that module instead as shown in the next snippet.

    # Load a version of Matlab different to the default.
    module add matlab/2013b

Adding environment variables to your .bashrc

Loading software via the module command changes the PATH and LIBRARY variables but you can also make changes to these variables yourself.

The first snippet shows how you can add a directory such as $HOME/bin to your $PATH so that you can put commands and scripts there to run them more easily.

    # Add $HOME/bin to your $PATH to make your commands easier to run.

The next snippet shows how you can change the LD_LIBRARY_PATH so that your local library directory such as $HOME/MyLibrary is included in the library search path.

    # Add $HOME/MyLibrary directory to $LD_LIBRARY_PATH environment variable .

With both the PATH and LD_LIBRARY_PATH the order of the directories is the order that they are searched in. If you have want to make sure that the library in your $HOME/MyLibrary is loaded instead of a library of the same name elsewhere then the following snippet shows how

    # Add $HOME/MyLibrary directory to $LD_LIBRARY_PATH environment variable .

You can also create your own environment variables such as $MY_VARIABLE which you can then use in your commands and scripts. For example

   # Create a new variable $MY_VARIABLE so that it is available for later use. 
   export MY_VARIABLE=$HOME/code/fred