Differences

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

Link to this comparison view

Both sides previous revision Previous revision
habrok:examples:mathematica [2023/03/22 13:25] fokkehabrok: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 22: 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 31: 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 38: 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]