High-Performance Computing at the NIH
GitHub YouTube @nih_hpc RSS Feed
Mathematica on Biowulf and Helix

Mathematica is a fully integrated environment for technical and scientific computing. Mathematica combines numerical and symbolic computation, visualization, and programming in a single, flexible interactive system. The Mathematica system is very broad, and provides a systematic interface to all sorts of computations, from traditional numeric and symbolic computation, to visualization, to data format conversion, and the creation of user interfaces.

Running Mathematica on the systems

There are multiple versions of Mathematica available. An easy way of selecting the version is to use modules. To see the modules available, type

[user@helix ~]$ module avail mathematica

To select a module, type

[user@helix ~]$ module load mathematica/[ver]

where [ver] is the version of choice. The default version is 10.2.

Running the Mathematica GUI Interactively

To run the Mathematica graphics interface, an X-Windows connection is required. Open an X-Windows connection to helix.nih.gov, and check that it is working by typing 'xclock' at the prompt.

[user@helix ~]$ module load mathemtica
[user@helix ~]$ mathematica &

You should see the Mathematica Welcome Screen as below:

Mathematica Welcome Screen

The main Mathematica Notebook window will appear when you open a file by clicking Open or a file listed on the Welcome screen.

To run a demo, in the main Mathematica window, click Open. Enter the filename /usr/local/apps/Mathematica/10.2/Documentation/English/Demos/Animations.nb. You should see a window appear with several graphic images. Double-click on one of them to animate:

Mathematica demo image

Run Mathematica interactively without the GUI

It is also possible to run Mathematica interactively on the command-line, without the GUI. This would be useful if you do not wish to use Xwindows, and is obviously most useful for calculations rather than interactive graphics. Sample session (user input in bold):

[user@helix ~]$ math
Mathematica 10.2 for Linux x86 (64-bit)
Copyright 1988-2015 Wolfram Research, Inc.

In[1]:= data=ReadList["rmsdplot.list",{Number,Number,Number}];

In[2]:= [..enter other Mathematica commands..]

In[22]:= Exit[]
[user@helix ~]$
Run Mathematica using a math command file

You can insert Mathematica commands into a math command file, and run that file interactively at the prompt. This is convenient if you perform the same Mathematica tasks frequently. Sample session with a Math command file bfactorplot.math.

[user@helix ~]$ math
Mathematica 10.2 for Linux x86 (64-bit)
Copyright 1988-2015 Wolfram Research, Inc.

In[1]:= <<bfactorplot.math
In[2]:= Exit[]
[user@helix ~]$

Alternatively, you can type directly at the command prompt:

[user@helix ~] math -run "<<rmsd.math"

Below is an example of the command file "rmsd.math", which produces EPS graphic output.

<----------------------------file rmsd.math----------------------------------
 (* file geomanal/rmsdplot.math  -- make a plot rmsd vs residue     *)
 (*===>*)    data=ReadList["rmsdplot.list",{Number,Number,Number}];
SetOptions[Plot,DisplayFunction->Identity]
     column0 = Transpose[data][[1]]; 
     column1 = Transpose[data][[2]]; 
     column2 = Transpose[data][[3]];
	len=Length[column0];
	b1=Join[column0,column1];
	b2=Partition[b1,len];
	b3=Transpose[b2];
    	xmax=Max[column0];
	xmin=Min[column0];
	y1max=Max[column1];
	y1min=Min[column1];
	y2max=Max[column2];
	y2min=Min[column2];
	plot1=     ListPlot[b3,  
       AxesLabel->{"Res. No.","RMSD"}, 
       Ticks->{Range[0,xmax+5,50],Range[0.0, y1max+0.2 ,0.5]},
       PlotLabel->"Backbone",Axes->{0,0},PlotJoined->True, 
       PlotRange->{{0,xmax+2 }, {0., y1max +0.1 }},
       AxesStyle->{PostScript
          ["/Times-Roman findfont 13 scalefont setfont"]} ];
	s1=Join[column0,column2];
	s2=Partition[s1,len];
	s3=Transpose[s2];
	Export["a.eps",plot1]
	Exit[]
------------------------------------------------------------------------------

Tip: The output graphics file "a.eps" can be converted to a PDF with the command epstopdf a.eps producing the PDF file "a.pdf".

Running Mathematica Jobs on Biowulf

Mathematica provides a seamless, integrated and automated environment for parallel computing. To submit a Mathematica job to the batch system, you must create a .m file containing the mathematica commands. The .m script will be passed to the math command in an sbatch file.

------------------------ simple-math.m-------------------------------
A = Sum[i, {i,1,100}]
B = Mean[{25, 36, 22, 16, 8, 42}]
Answer = A + B
Quit[];
--------------------end simple-math.m -------------------------------

The above example can be sent to batch with the following script:

------------------------ simple-math.bat-------------------------------
#!/bin/bash

#SBATCH --job-name=simple-math
#SBATCH --output=math-simple.out
#SBATCH --error=math-simple.err
#SBATCH --time=00:05:00
#SBATCH --ntasks=1

module load mathematica

math -run < simple-math.m

--------------------end simple-math.bat -------------------------------

Submit with sbatch [options] simple-math.bat

Using Multiple Cores in Mathematica on Biowulf

Create a .m file much like the example below:

------------------------ parallel-math.m-------------------------------
(*Limits Mathematica to requested resources*)
Unprotect[$ProcessorCount];$ProcessorCount = 8;
 
(*Prints the machine name that each kernel is running on*)
Print[ParallelEvaluate[$MachineName]];

(*Prints all Mersenne PRime numbers less than 2000*)
Print[Parallelize[Select[Range[2000],PrimeQ[2^#-1]&]]];


--------------------end parallel-math.m -------------------------------

The above example can be sent to batch with the following script:

------------------------ parallel-math.bat-------------------------------
#!/bin/bash
#SBATCH --job-name=mathematica_example
#SBATCH --output=mathematica_example.out
#SBATCH --error=mathematica_example.err
#SBATCH --nodes=1
#SBATCH --ntasks-per-node=8

module load mathematica

math -run < ./parallel-math.m

--------------------end parallel-math.bat -------------------------------

Submit the above with sbatch [options] parallel-math.bat

You can add or subtract SBATCH options within either the .bat file or at the time of submission. If you want to use all CPUs on a node, you must use the --exclusive option when submitting.

Documentation

Wolfram Mathematica Documentation Center
Mathematica FAQs