Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
habrok:examples:mathematica [2019/11/13 11:41] – external edit 127.0.0.1habrok:examples:mathematica [2025/06/11 12:09] (current) – Use Mathematica syntax highlighting pedro
Line 5: Line 5:
 The following example can be used as a template for Mathematica jobs: The following example can be used as a template for Mathematica jobs:
  
-<code>+<code bash>
 #!/bin/bash #!/bin/bash
 #SBATCH --job-name=Mathematica #SBATCH --job-name=Mathematica
Line 13: Line 13:
 #SBATCH --time=00:05:00 #SBATCH --time=00:05:00
  
-module load Mathematica/11.3.0+module purge 
 +module load Mathematica/13.1.0
  
 math -script myscript.m math -script myscript.m
Line 21: Line 22:
 Your script can contain any Mathematica code, e.g.: Your script can contain any Mathematica code, e.g.:
  
-<code>+<code mathematica>
 Select[Range[8000],PrimeQ[2^# - 1]& Select[Range[8000],PrimeQ[2^# - 1]&
 </code> </code>
Line 30: Line 31:
 Once you have started multiple kernels, you can use built-in functions for parallelizing some of the work, e.g. the Parallelize function: Once you have started multiple kernels, you can use built-in functions for parallelizing some of the work, e.g. the Parallelize function:
  
-<code>+<code mathematica>
 LaunchKernels[4] LaunchKernels[4]
 p=Parallelize[Select[Range[8000],PrimeQ[2^# - 1]&]] p=Parallelize[Select[Range[8000],PrimeQ[2^# - 1]&]]
Line 37: Line 38:
 In your job script, leave ''%%--nodes=1%%'', but set ''%%--cpus-per-task=4%%'' in order to get four cores allocated to your job. You can automatically set it in the right way by reading the requested number of cores through an environment variable that is set by the scheduler: In your job script, leave ''%%--nodes=1%%'', but set ''%%--cpus-per-task=4%%'' in order to get four cores allocated to your job. You can automatically set it in the right way by reading the requested number of cores through an environment variable that is set by the scheduler:
  
-<code>+<code mathematica>
 ncores = ToExpression[Environment["SLURM_CPUS_PER_TASK"]] ncores = ToExpression[Environment["SLURM_CPUS_PER_TASK"]]
 LaunchKernels[ncores] LaunchKernels[ncores]