Multi-threaded Functions
A number of functions in this implementation of the toolbox have been
parallelized using OpenMP to allow them to exploit multiple cores. This should deliver
improved performance for moderate or large datasets when run on a multicore system.
Parallelism has been implemented in many key functions in the areas of:
- Dense and Sparse Linear Algebra
- FFTs
- Random Number Generators
- Quadrature
- Partial Differential Equations
- Interpolation
- Curve and Surface Fitting
- Correlation and Regression Analysis
- Multivariate Methods
- Time Series Analysis
- Financial Option Pricing
Other NAG functions may also benefit to some extent because they internally
call one or more of the parallelized 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:
- Performance improvements depend on many factors, including the nature of
each algorithm, the problem size(s) and other parameters, and the characteristics
of the computer running MATLAB. Users who frequently run very similar problems are
encouraged to experiment with different values of OMP_NUM_THREADS, to see
which value gives the best performance on their code and data.
- Most Intel processors support hyper-threading, which allows each
physical core to appear to the operating system as two logical cores. Thus it may be
advantageous when running parallelized NAG functions to try values of
OMP_NUM_THREADS up to twice the number of physical cores present.
Note that the number of processors or cores reported by the operating
system will be the number of logical cores.
Users 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 variable on Windows do the following:
- Click the Start button, go to the Settings menu,
and select Control Panel.
- On the Control Panel menu, select System.
- In the System Properties dialog box, click the
Advanced tab.
- On the Advanced panel, click the Environment
Variables button.
- In the Environment Variables dialog box, click the
New button in the User Variables section.
- 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.
Resetting the value of the environment variable OMP_NUM_THREADS
within MATLAB using the setenv command will not change the
value used by multi-threaded NAG functions.
Thus NAG Toolbox also includes functions that can be used within your MATLAB program to get and set the number of threads to be used in subsequent calls to multi-threaded NAG functions. See Chapter X06 for details.