# Mathematica

## Contents

## General Description

**Mathematica** is a computational software program used in scientific, engineering, and mathematical fields and other areas of technical computing. It was conceived by Stephen Wolfram and is developed by Wolfram Research of Champaign, Illinois.

- Not just for computation, but for modeling, simulation, visualization, development, documentation, and deployment.
- Largest collection of algorithms in a single system--each able to operate across the widest applicable scope of numeric, symbolic, or graphical input.
- Functions or data, discrete objects, diagrams, images, or annotations--Mathematica's visualization engine powers professional-quality static or dynamic representations, automatically optimizing the balance between computational efficiency and visual sophistication.
- With integrated symbolic computation, you can work directly on precise models--transforming, optimizing, solving, and visualizing--only substituting approximate or specific numerical values where necessary. Whether it's for simulation set-up or as part of a hybrid approach with numerics, integrated symbolic computation is now recognized as an essential element of any error-free engineering or scientific workflow. Mathematica is the world's leading symbolic computation system, both in functionality and integration with numerics
- Ready-to-use curated data is built into Mathematica in areas as diverse as chemistry, geopolitics, finance, and geometry. Compiled and collated by Wolfram Research, data paclets are immediately ready for computational use within Mathematica.
- Mathematica's numerics support any precision or number size across all functions, in contrast to the typical fixed 16-digit limitation found in other computing systems. Without this you may be unable to produce answers accurate even to a small number of digits, as the internal workings of many calculations require much higher-precision input than they produce as output.

## Basic Usage

Mathematica can be run in both a GUI-based mode and a text-based mode. The GUI mode should be used for interactive access to Mathematica where you require a graphical interface. For batch-mode submissions to the compute nodes (without graphics) you are required to use the text mode.

### GUI Usage

- Interactive Front-End Usage - Invoke Mathematica directly on the command line (with an optional script file):

> mathematica -mesa -script foo.m

- Interactive Compute Node Usage - Use the following template to invoke Mathematica in your SGE submission script (with an optional script file). Your script must be submitted from the crcfe02.crc.nd.edu front-end node (
*so that the graphical display can be forwarded from the compute nodes*):

#!/bin/csh #$ -M netid@nd.edu #$ -m abe #$ -q long #$ -pe smp 1 #$ -V # required for graphic forwarding module load mathematica mathematica -mesa -script foo.m

### Non-GUI Usage

- Compute Node Usage - To run on the compute nodes without graphics you need to invoke the Mathematica
*MathKernel*in your SGE submission script with a script file. Your submission script can be submitted from*any*front-end node:

#!/bin/csh #$ -M netid@nd.edu #$ -m abe #$ -q long #$ -pe smp 1 module load mathematica math -script foo.m

By default, Mathematica will try to automatically multithread processing on all the cores available on a machine. If you are only requesting a single core in your submission script, you need to add the following two lines in your Mathematica main script file:

SetSystemOptions["ParallelOptions" -> "MKLThreadNumber" -> 1] SetSystemOptions["ParallelOptions" -> "ParallelThreadNumber" -> 1]

This is to prevent Mathematica job overloading the machine and interfering with other user's running jobs.

### Parallel Mathematica

Parallel Computing in Mathematica

In order to submit/run parallel Mathematica jobs on the ND CRC cluster, you can use below script file and mathematica file which are developed by Dr. Szabolcs Horvát in the Department of Physics:

job.sh:

#!/bin/csh #$ -M netid@nd.edu # change this to your email address #$ -m abe #$ -q long #$ -pe mpi-24 24 # requesting 24 cores module load mathematica cd $SGE_O_WORKDIR math -script job.m

job.m:

(* ::Package:: *) Needs["CRC`"] Export["result.txt", ParallelTable[{$MachineName, $KernelID}, {$KernelCount}], "Table"]

CRC.m:

(* ::Package:: *) (* This package will auto-configure the appropriate number of kernels to be used in a CRC job. DO NOT load this package more than once or it will break your kernel configuration for the session. It is recommended to load using Needs["CRC`"] to avoid double-loading. *) (* :Context: CRC` *) (* :Authors: Sz. Horvat <szhorvat@nd.edu> *) (* :Package Version: 0.1 *) BeginPackage["CRC`"] CRCKernel::usage = "CRCKernel[host, cores] creates a configuration of 'cores' number of remote kernels on cluster node 'host'." Begin["`Private`"] (* Load RemoteKernels package without adding it to $ContextPath *) Block[{$ContextPath}, Needs["SubKernels`RemoteKernels`"]] (* Only this version of rsh works. The one in /usr/bin does not. Since Mathematica adds /usr/bin to the beginning of PATH, we need to use an absolute PATH to the correct rsh *) rsh = "/usr/kerberos/bin/rsh" math = FileNameJoin[{$InstallationDirectory, "bin", "math"}] (* It is important to redirect all output to /dev/null, otherwise rsh will hang even if put to the background. See the BUGS section in man rsh *) CRCKernel[host_String, cores_Integer]:= SubKernels`RemoteKernels`RemoteMachine[ host, rsh <> " -n `1` \"" <> math <> " -mathlink -linkmode Connect `4` -linkname '`2`' -subkernel -noinit >& /dev/null &\"", cores] CRCKernel::args = "Called with incorrect arguments." CRCKernel[___] := Message[CRCKernel::args] hostfile = Environment["PE_HOSTFILE"] If[hostfile =!= $Failed, (* if we're running in a batch job *) hosts = Import[hostfile, "Table"][[All, 1;;2]]; $ConfiguredKernels = Join[$ConfiguredKernels, CRCKernel @@@ Rest[hosts]] ] End[] EndPackage[]

For more details and download the files, please visit this page.

## Useful Options

To convert an existing notebook to a script (for submission through our batch system) please follow these instructions:

- Open Notebook file (.nb) in Mathematica GUI
- Select Everything In The Notebook (Edit-> Select All)
- Execute the command: Alt 8 on linux (or, Cmd 8 on Mac)
- Save As A Text File (Save As-> choose file type of Plain text) or .m file

## License Information

- Notre Dame has basically an Educational Unlimited Site license for Mathematica
- Currently 1000 Controlling Process (the number of simultaneous network users) and 4000 Computing Process (the number of simultaneous computations) licenses.

## Further Information

See the official website: Wolfram