# Difference between revisions of "Mathematica/Batch"

(→Non-graphical commands in batch mode) |
|||

Line 10: | Line 10: | ||

{|class="wikitable" | {|class="wikitable" | ||

!Command | !Command | ||

− | ! | + | !Description |

|- | |- | ||

|math | |math |

## Revision as of 13:47, 29 August 2016

When you run Mathematica on a HPC cluster, then there is a difference between commands that produce graphical output and commands that don't.

### Non-graphical commands in batch mode

In general you can submit a Mathematica batch job as

bsub [LSF options] "math -script input.m > output.out"

Here you need to replace *[LSF options]* with LSF parameters for the resource requirements of the job. Please find a documentation about the parameters of `bsub` on the wiki page about the batch system. The single parts of the Mathematica command are explained in the table below.

Command | Description |
---|---|

math | calls the Mathematica kernel, which is used to execute jobs in batch mode |

-script | tells Mathematica that the job shall be executed in batch mode |

input.m | is the file that contains the Mathematica commands |

> output.out | redirects the output of the Mathematica kernel to output.out |

It is important that the whole mathematica command (red color) is enclosed within double quotes. Otherwise the redirection of the output fails and your output file will be empty, whereas the LSF file contains the output.

### Graphical commands in batch mode

The use of graphical commands as Plot or Display in batch mode is possible by exporting the plots as images. Since Mathematica expects a front end to display (even to export) graphics, we need to make Mathematica think that there is a graphical front end, by using a virtual frame buffer. The exporting of plots is done with the following commands:

b = Plot[....]; -> assign your plot to a variable and suppress output with a semicolone Export["my_nice_plot.eps", b] -> exports the image as .eps image (several other formats are also possible)

A batch job containing graphical commands is then submitted with gmath instead of math:

bsub [LSF parameters] "gmath -script input.m > output.out"

LSF parameters are documented on the wiki page about using the batch system.