Chapter Contents
NAG Toolbox

Multi-Threaded Functions

A number of functions in this implementation of the toolbox have been enhanced to allow them to exploit multiple cores. This should deliver speed-ups for moderate or large datasets over the single-threaded versions when run on a multicore system. Parallelism has been implemented in many key functions in the areas of: Other NAG functions may also benefit to some extent because they internally call one or more of the parallelised functions. The complete list is available here.

Enabling Multi-Threading

The parallelism within the NAG Toolbox is implemented using OpenMP and so the environment variable OMP_NUM_THREADS should be set to a number greater than 1 to enable this. The number chosen will be the maximum number of processor cores which the toolbox can use. As a rule of thumb this should be the number of available (idle) processor cores on the computer running MATLAB. However: User are also advised to turn off any power saving OS features, such as facilities that reduce the clock speed of idle cores, if they wish to achieve the best performance.

Note that other applications use OpenMP so it is possible that the OMP_NUM_THREADS environment variable has already been defined on your system. To check this, type

getenv 'OMP_NUM_THREADS'
in MATLAB. If the answer is an integer then the variable has been set. If it is an empty string ('') then it has not.

To set an environment on Windows do the following:

  1. Click the Start button, go to the Settings menu, and select Control Panel.
  2. On the Control Panel menu, select System.
  3. In the System Properties dialog box, click the Advanced tab.
  4. On the Advanced panel, click the Environment Variables button.
  5. In the Environment Variables dialog box, click the New button in the User Variables section.
  6. In the New User Variable dialog box, enter the name of the variable as OMP_NUM_THREADS and set the value of the variable as described above.

On Linux the precise syntax for setting environment variables depends on the user's shell.