Updated 2020-04-07

Run Mathematica Interactively On Cluster

Overview

  • The main way to run Mathematica is interactively with notebook functionality. It can also be run text-based in the terminal, and (not recommended) can be run in batch mode with some work.
  • This guide will focus on setting up the standard notebook functionality, using many cores to enable parallelism.
  • Running just the Mathematica kernal in the terminal (text-based) will be covered as well

Screenshot

Parallelism

  • Setting up Mathematica according to this guide will give you multiple cores on a compute node
  • Unlike Matlab, once you start the Mathematica notebook, no extra setup must be performed to enable parallelism
  • Parallelism is enabled in your code. Mathematica Parallel Documentation can be found here.
  • This guide will also include a few samples of parallel code, straight from the Mathematica docs.

Set up Interactive (VNC) Session

  • Please see the VNC guide for instructions on how to set up the Interactive VNC session

Start Mathematica on VNC

  • Open terminal in the vnc window by clicking top left Applications > System Tools > scroll down to terminal
  • all commands here on will be typed in terminal in VNC
  • To see available versions of Mathematica run
module avail mathematica
  • Load mathematica module and start mathematica
module load <version of mathematica>  #example: module load mathematica/11.0
  • To start the kernal-only (terminal version), run math
  • To start the standard version with notebook functionality, run mathematica

Screenshot

Open a Notebook and Run Code

  • Simply click "open" and open notebooks (.nb files) as you normally would. Make sure you open your user folder when looking for .nb files. Refer to the file transfer guide to get .nb files on the cluster.
  • Or, click on New Document to create a new notebook
  • Additionally, you can sign in and access notebooks from the cloud
  • Once you open a notebook, using Mathematica is the same as usual

Parallelism Example

  • In terms of setup, once you are up and running and have a notebook open, you do not have to do any additional steps to enable parallelism
  • Instead, parallelism is achieved through code. There are many different ways to code parallelism, a great resource is the mathematica documentation on parallelism
  • This example code uses the Parallelize[expr] function, which evaluates expr using automatic parallelization.
  • Example Code from Mathematica documentation:
$TrigFunctions = {Sin, Cos, Sec, Csc, Tan, Cot, ArcSin, ArcCos,
   ArcSec, ArcCsc, ArcTan, ArcCot};

   Parallelize@
    Table[Plot3D[Abs[f[x + I y]], {x, -2, 2}, {y, -2, 2},
      MeshFunctions ->
       Function @@@ { { {x, y, z}, Re[f[x + I y]]}, { {x, y, z},
          Im[f[x + I y]]} },
      MeshShading -> { {Orange, None}, {None, Green} }, PlotLabel -> f,
      Ticks -> None, ImageSize -> 100], {f, $TrigFunctions}]
  • Notebook should look like:

Screenshot

Saving and Transferring Notebooks

  • Save as you normally would in the notebook environment (click save as / save)
  • Notebook will be saved to a dir of your choice in your home folder
  • To transfer notebook files off the cluster, you can use a number of file transfer techniques. Globus is recommended.
  • Congratulations! You have succesfully run Mathematica on the cluster.