This version is outdated by a newer approved version.DiffThis version (2015/05/13 08:19) is a draft.
Approvals: 0/1

This is an old revision of the document!


Mathematica Batch Jobs

The simplest way is to create a file with your mathematica commands, e.g. 'math-input.m', and just input that in the batch file.

# the following option makes sure the job will run in the current directory
#$ -cwd
# this option makes sure the job has the same environment variables as the submission shell
#$ -V

MATHDIR=/opt/sw/Mathematica/90/bin
$MATHDIR/math < math-input.m

If we name the above file as math-job.sh and place it in the same directory as math-input.m we can submit it from the same directory with

user@l01 $ qsub math-job.sh

The output will be left in file math-job.sh.o$JOB_ID and any errors in math-job.e$JOB_ID.

You could also incorporate mathematica commands in the job file itself, rather then have them in a separate file:

#$ -cwd
#$ -V

MATHDIR=/opt/sw/Mathematica/90/bin

$MATHDIR/math <<END_MATH_COMMANDS
1+1
3*3
END_MATH_COMMANDS

The above notations means that everything between “«END_MATH_COMMANDS” and “END_MATH_COMMANDS” will be used as math program's input. You can again submit this job with qsub.

Jobscript:

#$ -N parallel
#$ -q all.q
#$ -pe mpich 32


#learn how to read in this file into mathematica directly
cp -v $TMPDIR/machines machines_tmp

/opt/sw/Mathematica/90/bin/math -run "<<math.m"

Mathematica script named math.m:

(* configuration for starting remote kernels *)

Needs["SubKernels`RemoteKernels`"]
$RemoteCommand= "ssh `1` -n -l `3` \"/opt/sw/Mathematica/90/bin/math -mathlink -linkmode Connect `4` -linkname `2` -subkernel -noinit >& /dev/null &\""


(* initialize the kernels on all machines defined in the host file *)

hosts=Import["machines_tmp","List"] 

(* on the master node initialize only one kernel less, since one is already running *)
imin=2;
imax=Length[hosts];
idelta=1;

Do[
	Print["starting Kernel: ",i," on ",hosts[[i]]];
	LaunchKernels[RemoteMachine[hosts[[i]]]];,
	{i,imin,imax,idelta}
]


(* actual calculation *)
primelist = ParallelTable[Prime[k], {k, 1, 20000000}];
Print[primelist]

SLURM

In order to be able to use Mathematica, you have to load the program with the module load xyz command

[username@l32]$ module avail  # select a Mathematica version
[username@l32]$ module load Mathematica/10.0.2 # load selected version
[username@l32]$ module list   # check loaded modules
Currently Loaded Modulefiles:
  1) Mathematica/10.0.2  

(See also the introduction to the module command.)

Now, Mathematica can be called by

[username@l32]$ math 

Using the same Mathematica script example math.m as used for for VSC-2, we use create a job script called jobPar.sh:

#!/bin/bash
#
#SBATCH -J par                      # job name
#SBATCH -N 2                        # number of nodes=2
#SBATCH --ntasks-per-node=16        # uses all cpus of one node      
#SBATCH --ntasks-per-core=1
#SBATCH --threads-per-core=1

math -run "<<math.m"
[username@l32]$ sbatch jobPar.sh      # submit your job
[username@l32]$ squeue -u username    # check state of your job
  • doku/mathematica.1431505160.txt.gz
  • Last modified: 2015/05/13 08:19
  • by ir