.. _mathematica: single: mathematica single: Mathematica .. index:: pair: Mathematica; Index .. _mdoc_mathematica: =========== Mathematica =========== Mathematica is powerful and intuitive computation software. It is capable of geometric, audio, graphical, and raw data analysis. The embedded Wolfram Language is an incredibly powerful scripting tool for doing sybolic math analysis and granting command line style access to the plethora of algorithms within the software. Mathematica has a GUI and CLI that can be used. .. contents:: :local: Getting Started =============== To gain access to Mathematica, a Mathematica module must be loaded with the command: .. code:: bash module load mathematica A full list of available Mathematica versions can be obtained by calling the command: .. code:: bash module avail mathematica Using Mathematica's Graphical Interface ======================================= To use Mathematica's GUI interface on Midway, we reccomend connecting to Midway via ThinLinc. Information about how to use ThinLinc can be found in the :ref:`thinlinc` section of the user guide. Note that once connected via ThinLinc, you will be accessing a Midway login node. In order to run Mathematica with its GUI interface on a compute node, obtain a terminal in the ThinLinc desktop and issue the **sinteractive** command. This will deliver you to a compute node. From there, you can launch Mathematica with the commands: .. code:: bash module load mathematica mathematica and have access to the GUI interface. Using Mathematica's Textual Interface ===================================== Once a Mathematica software module has been loaded, Mathematica's command line interface can be started with the command ``math``. .. code:: bash $ module load mathematica $ math Mathematica 8.0 for Linux x86 (64-bit) Copyright 1988-2011 Wolfram Research, Inc. In[1]:= a=1; In[2]:= b=2; In[3]:= a+b Out[3]= 3 In[4]:= Quit[]; More information about using the command line interface to Mathematica is available here: http://reference.wolfram.com/language/tutorial/UsingATextBasedInterface.html Running Mathematica Jobs with SLURM =================================== To submit Mathematica jobs to Midway's resource scheduler, SLURM, the Mathematica commands to be executed must be containined in a single .m script. The .m script will then be passed to the ``math`` command in an sbatch file. For example: :download:`math-simple.m` is a basic Mathematica script that computes the sum of A and B: .. literalinclude:: math-simple.m :language: bash This script can be submited to SLURM with :download:`math-simple.sbatch` which will send the job to a compute node: .. literalinclude:: math-simple.sbatch :language: bash To run this example, download both files to a directory on Midway. Then, enter the following command to submit the job to the scheduler: .. code:: bash sbatch math-simple.sbatch Output from this example can be found in the file named math-simple.out which will be created in the same directory. Using Multiple CPUs in Mathematica ================================== Mathematica can be run in parallel using the built in ``Parallel`` commands or by utilizing parallel API. Parallel Mathematica jobs are limited to one node, but can utilize all CPU cores on the node if allocated. A parallel Mathematica script must either be submitted to a node that was requested with the ``exclusive`` flag or the script must specify the number of processors allocated. As an example of the latter, the following Mathematica script would be appropriate for a SLURM request of 1 node with 8 tasks per node. Sample Parallel Job Submission ------------------------------ SBATCH script: Click here to download the script: :download:`sample-sbatch.sbatch` .. literalinclude:: sample-sbatch.sbatch :language: bash Mathematica script: Click here to download the script: :download:`sample-parallel.m` .. literalinclude:: sample-parallel.m :language: bash