Mathematica: Difference between revisions

From RCSWiki
Jump to navigation Jump to search
(Mathematica page created)
 
(Add example)
Line 18: Line 18:
= Running Mathematica on the ARC cluster =
= Running Mathematica on the ARC cluster =
Although it is possible to run Mathematica interactively, the expectation is that most calculations with Mathematica on ARC will be completed by submitting a batch job script to the Slurm job scheduler with the sbatch command.
Although it is possible to run Mathematica interactively, the expectation is that most calculations with Mathematica on ARC will be completed by submitting a batch job script to the Slurm job scheduler with the sbatch command.
Suppose that the following Mathematica code to print out the first million prime numbers is in a file, prime_list.m :
<pre>
primelist = Table[Prime[k],{k,1,1000000}];
Export["primes_1000000.out",primelist,"Table","FieldSeparators"->" "];
</pre>
The following Slurm batch job script, prime_list.slurm, can be used to run the prime_list.m code on a single complete compute node.
<pre>
#!/bin/bash
#SBATCH --nodes=1
#SBATCH --time=00:30:00
#SBATCH --mem=0
#SBATCH --partition=pawson-bf,apophis-bf,razi-bf,single,lattice,parallel,cpu2019,cpu2013
# Mathematica batch processing example.
# 2020-05-28.
# Select Mathematica command to run:
MATH=/global/software/mathematica/mathematica1101/bin/math
# Specify the name of the input file of Mathematica text commands:
INPUT=primes_list.m
OUTPUT=$(basename $INPUT .m)_${SLURM_JOB_ID}.out
echo "Current working directory is $(pwd)"
echo "Running on compute node $(hostname)"
echo "Starting run at: $(date)"
$MATH -noprompt -run -script $INPUT > $OUTPUT
echo "Finished with at: $(date)"
</pre>
Submit the job with
<pre>
sbatch primes_list.slurm
</pre>
For the case of million primes, the run took about 30 seconds on a compute node in one of the slowest partitions (single) on ARC.  The time and memory limits should be adjusted to match the requirements of your calculations, but, some testing is usually required to fine tune those settings.

Revision as of 07:06, 28 May 2020


Introduction

Mathematica (external link) is a general-purpose high-level programming package for both symbolic and numerical calculations.

The main purpose of this page is to show how to use Mathematica on the University of Calgary ARC (Advanced Research Computing) cluster. It is presumed that you already have an account an ARC and have read the material on reserving resources and running jobs with the Slurm job management system.

Licensing

At the University of Calgary, Information Technologies has purchased a site license for using Mathematica for teaching and learning and non-commercial research purposes. The software has been installed on the ARC cluster, where multiple instances can be run at the same time. When Mathematica starts up, it checks with a central license server.

For information about installing Mathematica on your own computer, see the Information Technologies Knowledge Base article on Mathematica.

Running Mathematica on the ARC cluster

Although it is possible to run Mathematica interactively, the expectation is that most calculations with Mathematica on ARC will be completed by submitting a batch job script to the Slurm job scheduler with the sbatch command.

Suppose that the following Mathematica code to print out the first million prime numbers is in a file, prime_list.m :

primelist = Table[Prime[k],{k,1,1000000}];
Export["primes_1000000.out",primelist,"Table","FieldSeparators"->" "];

The following Slurm batch job script, prime_list.slurm, can be used to run the prime_list.m code on a single complete compute node.

#!/bin/bash
#SBATCH --nodes=1
#SBATCH --time=00:30:00
#SBATCH --mem=0
#SBATCH --partition=pawson-bf,apophis-bf,razi-bf,single,lattice,parallel,cpu2019,cpu2013

# Mathematica batch processing example.
# 2020-05-28.

# Select Mathematica command to run:
MATH=/global/software/mathematica/mathematica1101/bin/math

# Specify the name of the input file of Mathematica text commands:
INPUT=primes_list.m
OUTPUT=$(basename $INPUT .m)_${SLURM_JOB_ID}.out

echo "Current working directory is $(pwd)"
echo "Running on compute node $(hostname)"

echo "Starting run at: $(date)"

$MATH -noprompt -run -script $INPUT > $OUTPUT

echo "Finished with at: $(date)"

Submit the job with

sbatch primes_list.slurm

For the case of million primes, the run took about 30 seconds on a compute node in one of the slowest partitions (single) on ARC. The time and memory limits should be adjusted to match the requirements of your calculations, but, some testing is usually required to fine tune those settings.