Mathematica
Mathematica
Wolfram's Mathematica is a complete tool to perform modeling, simulation, visualization, development, documentation, and deployment. The features include:
Compute and Visualize: Numerics of any precision, symbolics, or visualization--Mathematica is the ultimate computational tool, with system-wide technology to ensure reliability, ease-of-use, and performance. Use Mathematica computation directly, as the engine in an infrastructure, or integrated into a standalone application.
Develop: Develop applets, applications, documents, or infrastructure components and systems using Mathematica's unique mix of capabilities--achieving record times on large projects or making small developments practical at all.
Document and deployment: Mathematica offers a wide range of innovative deployment options based on the Mathematica notebook. Whether your deliverables are interactive documents, applications, infrastructure components, or presentations,Mathematica notebooks are the complete solution--deployable locally or across a network.
Important Notes
When running the parallel version of Mathematica, request the number of processors (ppn) equal to the index value of LaunchKernels.
Mathematica uses network license within campus
Installed Versions
All the available versions of MATHEMATICA for use can be viewed by issuing the following command. This applies for other applications as well.
module avail mathematica
output:
---------------------- /usr/local/share/modulefiles/Core -----------------------
mathematica/11.2 mathematica/11.3 mathematica/12.0 (D)
The default version is identified by "(default)" behind the module name and can be loaded as:
module load mathematica
The other versions of MATHEMATICA can be loaded as:
module load mathematica/<version>
Running Mathematica Jobs
Interactive Job Submission
Graphical Interface: Since you need to set the math font locally, probably you can use only linux box or cygwin to enable Mathematica on the cluster.
Load the mathematica module
module load mathematica
Download math fonts to your local machine. The location of the Mathematica fonts is
$MATHROOT/SystemFiles/Fonts
Once you have it in your home directory on your local terminal, you need to execute the following commands:
xset fp+ ~/math-fonts/Fonts/Type1
xset fp rehash
Request a compute Node:
srun --x11 --pty /bin/bash
After it logs you into one of the comp nodes or at login, type:
module load mathematica
Run Mathematica
mathematica
kernel or command line only:You can run Mathematica in Command Mode (no need to have mathematica fonts installed). Request the compute node and run mathematica as in Graphical User Interface.
In[1]:= 2 + 3
Out[1]= 5
In[2]:= Exit
BatchJob Submission
Serial Batch Job
Prepare a job script "job.slurm" like the one below, where mathtest.m is a mathematica script file also included below.
job.slurm:
#!/bin/bash
#SBATCH --job-name="MathTest"
#SBATCH --time=00:01:00
#SBATCH --nodes=1
#SBATCH --tasks-per-node=2
#SBATCH -o test.o%j
module load mathematica
cp mathtest.m $PFSDIR
cd $PFSDIR
math -noprompt -run "<<mathtest.m"
cp -r * $SLURM_SUBMIT_DIR
mathtest.m:
(* ::Package:: *)
t=Table[Prime[i],{i,100000}];
t>>"t.out";
Exit[]
Submit the job:
sbatch job.slurm
Check the result in "t.out"
Parallel Batch Job
Mathematica will work with local node kernels to spawn kernels on each processor with OpenMP procedure, so we can launch multiple kernels for each job based on the resource (check HPC Resource View). You have to request enough processors in your slurm script to cover your usage.
Prepare a job script (parjob.slurm) like the one below, where parallel.m is a mathematica script file included below as well.
parjob.slurm:
#!/bin/bash
#SBATCH --job-name="test"
#SBATCH --time=00:10:00
#SBATCH --nodes=1
#SBATCH --tasks-per-node=2
#SBATCH -o math_test.o%j
module load mathematica
cp parallel.m $PFSDIR
cd $PFSDIR
math -noprompt -run "<<parallel.m"
cp -r * $SLURM_SUBMIT_DIR
parallel.m:
(* ::Package:: *)
LaunchKernels[2];
Parallelize[Select[Range[1000],PrimeQ[2^# - 1]&]] >>"test.out";
Exit[]
(Important Note: set the index value of LaunchKernels[n] equal to --cpus-per-task value in the slurm script)
Submit the job:
sbatch parjob.slurm
Check the result in "test.out"
Troubleshooting
GUI fails to launch
When using Mathematica version 12 and accessing the cluster via X2Go, if the GUI fails with an error like "Could not initialize GLX", issue the following command in the terminal and then relaunch the GUI:
export QT_XCB_GL_INTEGRATION=none
In general, if the GUI fails to launch when using the bare command "mathematica", it may be helpful to launch by directing the application to open a notebook. For this example, an empty file, called 'blank.nb' is created.
mathematica blank.nb
NetTrain Error
If you experience an error like "NetTrain::TargetDevice -> GPU Could not be used..." make sure you have not loaded any CUDA modules or the Mathematica CUDALink library. The NetTrain library comes packaged with the CUDA runtime that it requires, and uses the wrong runtime if additional ones are loaded.
For license issue, contact hpc-supportATcase.edu
References:
Demo of mathematica: http://www.youtube.com/watch?v=ilm14HYsl6M
A tutorial: ICPR 2010 Tutorial: Designing multi-scale algorithms for quantitative image analysis
Parallel Tutorial: http://reference.wolfram.com/mathematica/ParallelTools/tutorial/Overview.html
Programming CUDA with Mathematica: https://docs.google.com/a/case.edu/open?id=0By0GTaYFOIhdMmZlNTdhNzktNWQzYy00ZGVhLTgwYzMtZWNjODQwYzQ3OGQ1