Slurm - Job Script Example 09 Mathematica
An example of running a Mathematica program as a job.
Code
Create the following two files in the same directory.
Mathematica script
Create the file testmath.m
:
(* name this file testmath.m *)
(* generate high-precision samples of a mixed distribution *)
Print /@ RandomVariate[MixtureDistribution[
{1,2},
{NormalDistribution[1,2/10],
NormalDistribution[3,1/10]}],
10, WorkingPrecision -> 50]
(* function to produce a plot *)
spectro2 := (
X = ( {
{x1, x2, x3},
{x2, x4, x5},
{x3, x5, x6}
} );
vars = Union@Flatten@X;
dvars = {x, y, z};
m = Length@vars;
n = Length@dvars;
makeMat := X /. (Thread[vars -> #]) &;
proj = makeMat /@ Orthogonalize@RandomReal[{-1, 1}, {n, m}];
mat2 = Total@MapThread[Times, {proj, dvars}, 1] + IdentityMatrix@Length@X;
cons = And @@ (Thread[Eigenvalues[mat2] >= 0]);
RegionPlot3D[Evaluate[cons], {x, -3, 3}, {y, -3, 3}, {z, -3, 3}, PlotRangePadding -> None, Mesh -> 5, PlotStyle -> Opacity[.7], PlotPoints -> 10, PlotRange -> 2.9]
);
(* exports a grid of plots to the file sdp_plots.svg *)
Export["sdp_plots.svg", GraphicsGrid[Table[spectro2, {2}, {3}]]]
Exit[]
Job (batch) script
Create the file mathjob.sh
:
#!/bin/bash
#SBATCH --partition=def
#SBATCH --nodes=1
#SBATCH --ntasks-per-node=12
#SBATCH --mem-per-cpu=1G
#SBATCH --time=00:30:00
. /etc/profile.d/modules.sh
module load shared
module load slurm/picotte
module load mathematica
math -noprompt -run '<<testmath.m'
Job submission
Submit the job: sbatch mathjob.sh
Output
The Print[]
output is written to the job output file named
"slurm-NNNNNNN.out
":
3.08500813438531295729326734620167228798013378284365643234757174769459194545036`50.
1.16375055878740189688532726685045235545862378718332054816089910600094551251977`50.
2.9982174483587063943647638530387059961294305316495297361362025794668510139282`50.
1.07701788556445317777904597772502559520247726898984550518599254154952638821452`50.
2.91051800595061810255695423895705746372485831142860270336839671303575262961244`50.
1.17482163799724220922756031254295052932577694895152625192656119633337814942613`50.
1.12309863880199727827991735781485206075081269559953846858285828978575047201223`50.
3.09383211540201083151304731499123819046448596761987038714653711978825759607339`50.
0.87739526748623142012181253966746794602573291018698775950833222835839129409734`50.
3.05837208812761126361140064474354038160213981811312883560099092996620083851233`50.
while the SVG plot is written to a file named "sdp_plots.svg
":