Mathematica/Example

From ScientificComputing
Jump to: navigation, search

As an example for running a Mathematica job on the cluster, we look at numbers of the form 2^x-1 and check if they are prime numbers.

[leonhard@euler04 mathematica]$ cat test.m
LaunchKernels[2];
a=Parallelize[Select[Range[500],PrimeQ[2^# - 1]&]]
Print[a]
CloseKernels[];
[leonhard@euler04 mathematica]$ module load mathematica/10.2.0
[leonhard@euler04 mathematica]$ bsub -n 2 -W 4:00 -R "rusage[mem=512]" "math -script test.m > output.out"
Mathematica job.
Job <25719610> is submitted to queue <normal.4h>.
[leonhard@euler04 mathematica]$ bjobs
JOBID      USER        STAT  QUEUE      FROM_HOST   EXEC_HOST   JOB_NAME   SUBMIT_TIME
25719610   leonhard    PEND  normal.4h  euler04
[leonhard@euler04 mathematica]$ bjobs
JOBID      USER        STAT  QUEUE      FROM_HOST   EXEC_HOST   JOB_NAME   SUBMIT_TIME
25719610   leonhard    RUN   normal.4h  euler04     2*e2248     *utput.out Aug 25 08:31
[leonhard@euler04 mathematica]$ bjobs
No unfinished job found
[leonhard@euler04 mathematica]$ cat output.out 
{2, 3, 5, 7, 13, 17, 19, 31, 61, 89, 107, 127}

The output lists the exponents of all Mersenne prime number smaller than 2^{500}.