Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

By using ParallelTable and submitting my Mathematica code to a cluster, I noticed that it was enhancing the speed even when I selected a single core in a single node, comparing to the use of standard Table. Verifying the number of cores using $ProcessorCount, I got 16.

For selecting the number of cores I have submitted a bash file in terminal (already logged in SSH) using

qsub -I

The file "" contains

#PBS -l walltime=10:00:00

#PBS -q par32
#PBS -l nodes=1:ppn=1

where "par32" is a machine with 32GB of RAM.

Is there any reason for Mathematica to ignore the specification of core number and use 16 anyway?

share|improve this question
up vote 5 down vote accepted

Your PBS specifications do not get sent to Mathematica. PBS doesn't control Mathematica. Your job is being run on a machine with 16 cores and Mathematica sees this, hence the result of $ProcessorCount.

To limit Mathematica to a single core, add the following lines to your script

SetSystemOptions["MKLThreads" -> 1]
SetSystemOptions["ParallelOptions" -> "ParallelThreadNumber" -> 1] 

This will not affect the result of $ProcessorCount

share|improve this answer
Thank you. So, the option nodes= :ppn= is useless when using Mathematica? How can I choose the number of nodes in the cluster? – fcpenha Sep 24 '13 at 23:11
Its a two step process, #PBS -l nodes=1:ppn=1 tells your cluster that you intend to use one core and SetSystemOptions["MKLThreads" -> 1] SetSystemOptions["ParallelOptions" -> "ParallelThreadNumber" -> 1] ensures that you really do only use one core – WalkingRandomly Sep 25 '13 at 0:11
You can control the number of kernels used in ParallelTable using LaunchKernels[]. So, LaunchKernels[4] uses four for example. – WalkingRandomly Sep 25 '13 at 0:13
But, for example, that machine has nodes with 16 cores each. If I want to use 20 cores (10 for each node), I should use #PBS -l nodes=2:ppn=10 plus what? LaunchKernels[20] ? – fcpenha Sep 25 '13 at 1:46
If you want to launch kernels across nodes, you or your sysadmin has a lot more work to do. Wolfram lightweight grid may be of use but might be a lot of work to make it play nicely with PBS. I'm not sure...never done it. Life will be much easier for you if you just batch your work into several independent 16 core jobs – WalkingRandomly Sep 25 '13 at 8:22

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.