- You are here:
- GT Home
- Home
- Support
- PACE Software

**Introduction**

Mathematica is a software suite of mathematical tools that excel at symbolic math and plotting of symbolic math. Many statistical packages are now included (that used to be an additional cost) and the performance is on par with other major software packages such as MatLab.

To load the mathematica module, enter:

module load mathematica/9.0

To start mathematica in command line mode:

math

Mathematica in command line mode is extremely similar to the standard, default notebook interface found in the default installation on GUI mathematica, there is just less room for formatting. We provide a basic overview of mathematica, but for more details, you should use the mathematica help or go to http://reference.wolfram.com/language/. This is just intended as a starting point.

To quit mathematica in command line mode:

Quit

There are other ways of running mathematica code that is previously written - it can be formed into a script or invoked as a script from mathematica. For more details check: http://www.wolfram.com/mathematica/new-in-8/mathematica-shell-scripts/

## Some Basic Operations in Mathematica on force-6 and iw-shared-6 queues:

#### File I/O

The general method of getting results out of cluster jobs involves the running of many jobs and output of each of those jobs to some kind of text file. To export data:

exportVar="This is a test!";

Export["Test.txt", exportVar]

This creates a file and puts the second argument in that file.

Similarly, to import a file:

Import["Test.txt"]

#### Parallelization

Please do not reserve more kernels than you reserved cores!

To open additional XX- number kernels for parallel processing:

LaunchKernels[XX]

As a test:

In[9]:=

Timing[Total[Table[Prime[i], {i, 1, 10^6}]]]

Out[9]= {4.241355, 7472966967499}

In[10]:=

LaunchKernels[2]

Out[10]= {KernelObject[43, local], KernelObject[44, local]}

In[11]:=

Timing[Total[Parallelize[Table[Prime[i], {i, 10^6}]]]]

Out[11]= {2.203665, 7472966967499}

To close open kernels:

CloseKernels[]

#### Use of mathematica packages

Packages are essentially code loaded into mathematica into the back-end (as opposed to .nb files, which are considered front-end). They may be easier to work with when transitioning from local desktop stations to the cluster. Packages may contain compiled or uncompiled code, where uncompiled code is in the Package.m file and compiled code is in Packagecompiled.m.

To load a package:

Get[Package.m]

To unload packages reliably, one can quit the kernel by entering:

Quit

As an example, put both PackageCompiled.m and PackagePractice.math in the same folder. Change to that directory and run:

math -script PackagePractice.math

The .math script file should load the PackageCompiled package, create, and output to compiledOutput.txt.

#### Submitting lots of mathematica jobs

Often, many jobs are needed for parameter sweeps or other research applications. The preferred method for moab and torque is through job arrays. Job arrays are single jobs that use indexing to run many subjobs. They run more efficiently on pace managed clusters and can be used with a great degree of control. Currently, pace has a 2000 job array limit, but additonal 2000 job arrays may be submitted. The following is intended as an example of one way for implementing job arrays, but it is by no means the only way to do it.

In this example, a variety of different conditions are to be run through the same function and the output is written to different files. For simplicity, all files are read and created within a single directory.

Here, a single file, called conditions.csv is used to determine all individual run conditions, where each successive line is used as a different set of conditions that will be run as a separate job array index. Each condition is comma and space separated followed by a return, or alterantively, created and editied in Microsoft Excel (other spreadsheet software may work just as well).

The script ArrayTest.math, run in mathematica, is used to open the conditions.csv file, load all the conditions, and run the function for the set of conditions that matches the current job array ID. The job array index number is used to determine the line number in conditions.csv.

To submit the jobs, ArrayTest.pbs is used. This is just pbs script that is used repeatedly for every job array id.

The above three scripts are all that is needed. To run an example, simply put all three in the same folder, ssh into the testflight headnode, and run:

msub -t JobName.[1-2] ArrayTest.pbs

Where the numbers in the brackets are 1- number of lines in the conditions.csv file. The default is 2.

As an additional step of convienience, a simple script can be written to automate the job submission process. Arraytest.txt checks the number of lines in the conditions.csv and submits the job for you. This is way of taking user error out of the process of submitting jobs where you might change the conditions but forget to change the number of arrays. To use the script, enter:

sh ArrayTest.txt

Feel free to rename ArrayTest.txt to ArrayTest.sh and make it executable. If more than 2000 conditions are needed, simply create a second conditions file and use that file to create a second job array.

Additional resources for mathematica is at wolfram's website http://reference.wolfram.com/language/, and more information about job arrays can be found here: http://docs.adaptivecomputing.com/mwm/7-0/Content/topics/jobAdministration/jobarrays.html.

As always, we're here to help. If you habe questions or have found an error in what is presented here, please let us know at:

pace-support@oit.gatech.edu.