{"id":1002,"date":"2018-11-23T15:25:24","date_gmt":"2018-11-23T15:25:24","guid":{"rendered":"http:\/\/ri.itservices.manchester.ac.uk\/csf3\/?page_id=1002"},"modified":"2026-03-20T12:41:30","modified_gmt":"2026-03-20T12:41:30","slug":"mathematica","status":"publish","type":"page","link":"https:\/\/ri.itservices.manchester.ac.uk\/csf3\/software\/applications\/mathematica\/","title":{"rendered":"Mathematica"},"content":{"rendered":"<h2>Overview<\/h2>\n<p><a href=\"https:\/\/www.wolfram.com\/mathematica\/\">Mathematica<\/a> is an integrated technical computing environment which combines numeric and symbolic compute engines, a graphics system, a programming language, a documentation system and connectivity to other programs. Mathematica may be used for handling complex symbolic calculations involving millions of terms, analyzing and visualizing data, numerical modelling and simulation, rapid application development, producing publication-quality output and presentations.<\/p>\n<h2>Set up procedure<\/h2>\n<p>To set up the Mathematica environment you need to issue <em>one<\/em> of the following commands<\/p>\n<pre>\r\nmodule load apps\/binapps\/mathematica\/14.2.1\r\nmodule load apps\/binapps\/mathematica\/13.2.1\r\n\r\n# These may no longer work on the CSF.\r\nmodule load apps\/binapps\/mathematica\/12.2.0\r\nmodule load apps\/binapps\/mathematica\/11.3.0\r\nmodule load apps\/binapps\/mathematica\/11.2.0\r\n<\/pre>\n<h2>Running the application interactively<\/h2>\n<p>To run Mathematica interactively you should first log into the CSF using the -X switch as follows<\/p>\n<pre>\r\nssh -X <em>username<\/em>@csf3.itservices.manchester.ac.uk\r\n     #\r\n     # UPPERcase X\r\n<\/pre>\n<p>Next, load the Mathematica modulefile<\/p>\n<pre>\r\nmodule load apps\/binapps\/mathematica\/14.2.1\r\n<\/pre>\n<p>Finally, run Mathematica via <a href=\"\/csf3\/batch-batch\/srun\/\">srun<\/a><\/p>\n<pre>\r\n# 14.2.1 only has the command-line interface (we are working on getting the GUI interface)\r\nsrun -p interactive -t 0-1 --pty math\r\n\r\n# 13.2.1 has the GUI interface, started with the mathematica command\r\nsrun -p interactive -t 0-1 --pty mathematica\r\n<\/pre>\n<ul>\n<li><a href=\"\/csf3\/getting-started\/connecting\/gui-apps\/\">Further information about how to start X-Windows and GUI applications on the CSF<\/a>.<\/li>\n<li><a href=\"\/csf3\/batch-slurm\/srun\/\">More details concerning srun<\/a><\/li>\n<\/ul>\n<h2>Serial batch job submission<\/h2>\n<p><strong>It is not possible to run Mathematica .nb files in batch mode.<\/strong> Instead, you must create a text-only file containing your Mathematica program. For example, create a text file called <code>input.m<\/code> containing the following<\/p>\n<pre>\r\nTable[\r\n NIntegrate[Sin[x^n], {x, 1, 10}, MaxRecursion -&gt; 1000]\r\n , {n, 1, 70}]\r\n<\/pre>\n<p>A suitable Slurm submission script, <code>mathematica_job.sbatch<\/code>, for the above would be<\/p>\n<pre>\r\n#!\/bin\/bash --login\r\n#SBATCH -p serial         # Use the nodes dedicated to 1-core jobs\r\n#SBATCH -t 2-0            # Max time the job can run for (2-0 is 2 days, max permitted is 7 days)\r\n\r\nmodule purge\r\nmodule load apps\/binapps\/mathematica\/14.2.1\r\n\r\n# Output will be written to the slurm-<em>JOBID<\/em>.out file\r\nmath -noprompt &lt; input.m\r\n<\/pre>\n<p>Note that the executable that runs your script is <strong>math<\/strong> (i.e. the Mathematica Kernel) and not <strong>mathematica<\/strong> (The notebook interface)<\/p>\n<p>To run the above job you should then use <code>qsub<\/code><\/p>\n<pre>\r\nsbatch mathematica_job.sbatch\r\n<\/pre>\n<h2>Parallel batch job submission<\/h2>\n<p>A parallel version of <code>input.m<\/code> is<\/p>\n<pre>\r\nLaunchKernels[4];\r\nParallelTable[\r\n  NIntegrate[Sin[x^n], {x, 1, 10}, MaxRecursion -&gt; 1000], {n, 1, 70}] \/\/ AbsoluteTiming\r\nCloseKernels[];\r\n<\/pre>\n<p>A suitable submission script is<\/p>\n<pre>\r\n#!\/bin\/bash --login\r\n#SBATCH -p multicore       # Use the AMD 168-core nodes for parallel jobs\r\n#SBATCH -n 4               # (or --ntasks=) Number of cores to use\r\n#SBATCH -t 2-0             # Wallclock timelimit for the job (2-0 is 2 days, max permitted is 7 days)\r\n\r\nmodule purge\r\nmodule load apps\/binapps\/mathematica\/14.2.1\r\n\r\n# Inform mathematica how many cores it can use. $SLURM_NTASKS is the -n number above.\r\nexport OMP_NUM_THREADS=$SLURM_NTASKS\r\n\r\n# Output will be written to the slurm-<em>JOBID<\/em>.out file\r\nmath -noprompt &lt; input.m\r\n<\/pre>\n<p>Use <code>sbatch <em>jobscript<\/em><\/code> to submit the job as before.<\/p>\n<h2>Using &#8216;Export&#8217; in batch job to create an image file<\/h2>\n<h3>A simple .m file example<\/h3>\n<pre>\r\nExport[\"testred.png\", Graphics@{Red, Disk[{0, 0}, 1]}];\r\n<\/pre>\n<h3>Issue<\/h3>\n<p>If you receive the following error:<\/p>\n<pre>\r\nThe 'Export' option relies on the Linux DISPLAY variable which is not available to a batch job and results in errors similar to:\r\nQt issued a fatal error: QXcbConnection: Could not connect to display localhost:21.0\r\nAborted \"${MathematicaFE}\" -topDirectory \"${TopDirectory}\" \"$@\"\r\n<\/pre>\n<p>and an empty image file, try the following jobscript.<\/p>\n<h3>Solution<\/h3>\n<p>Use a utility called <code>xvfb-run<\/code>. An example batch script:<\/p>\n<pre>\r\n#!\/bin\/bash --login\r\n#SBATCH -p serial         # Use the nodes dedicated to 1-core jobs\r\n#SBATCH -t 2-0            # Max time the job can run for (2-0 is 2 days, max permitted is 7 days)\r\n\r\nmodule purge\r\nmodule load apps\/binapps\/mathematica\/14.2.1\r\n\r\nxvfb-run math -noprompt &lt; input.m\r\n<\/pre>\n<h2>Further info<\/h2>\n<ul>\n<li><a href=\"http:\/\/www.applications.itservices.manchester.ac.uk\/show_product.php?id=38\">IT Services webpage for Mathematica.<\/a><\/li>\n<li><a href=\"http:\/\/www.walkingrandomly.com\/?p=3635\">Making Mathematica faster with the Compile function.<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Overview Mathematica is an integrated technical computing environment which combines numeric and symbolic compute engines, a graphics system, a programming language, a documentation system and connectivity to other programs. Mathematica may be used for handling complex symbolic calculations involving millions of terms, analyzing and visualizing data, numerical modelling and simulation, rapid application development, producing publication-quality output and presentations. Set up procedure To set up the Mathematica environment you need to issue one of the following.. <a href=\"https:\/\/ri.itservices.manchester.ac.uk\/csf3\/software\/applications\/mathematica\/\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":7,"featured_media":0,"parent":86,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-1002","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/ri.itservices.manchester.ac.uk\/csf3\/wp-json\/wp\/v2\/pages\/1002","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ri.itservices.manchester.ac.uk\/csf3\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/ri.itservices.manchester.ac.uk\/csf3\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/ri.itservices.manchester.ac.uk\/csf3\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/ri.itservices.manchester.ac.uk\/csf3\/wp-json\/wp\/v2\/comments?post=1002"}],"version-history":[{"count":20,"href":"https:\/\/ri.itservices.manchester.ac.uk\/csf3\/wp-json\/wp\/v2\/pages\/1002\/revisions"}],"predecessor-version":[{"id":12173,"href":"https:\/\/ri.itservices.manchester.ac.uk\/csf3\/wp-json\/wp\/v2\/pages\/1002\/revisions\/12173"}],"up":[{"embeddable":true,"href":"https:\/\/ri.itservices.manchester.ac.uk\/csf3\/wp-json\/wp\/v2\/pages\/86"}],"wp:attachment":[{"href":"https:\/\/ri.itservices.manchester.ac.uk\/csf3\/wp-json\/wp\/v2\/media?parent=1002"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}