| MATLAB® | ![]() |
| On this page… |
|---|
The MATLAB software supports two types of multiprocessing: implicit and explicit.
Characteristics of implicit multiprocessing:
Runs multiple threads on a single machine, most often using one thread per processing unit.
Requires a multiple CPU (multiprocessor or multicore) system.
Speeds up elementwise computations such as those done by the sin and log functions, and computations that use the Basic Linear Algebra Subroutines (BLAS) library, such as matrix multiply.
Does not require any changes to your MATLAB code.
Works behind the scenes to take advantage of the processing units available to you. It does this by multithreading the computationally-intensive math library functions that you use in the course of your MATLAB session.
Enable or disable implicit multiprocessing with the MATLAB Preferences Panel, and use it to set the number of threads to be used. You can change the maximum number of threads programmatically using the maxNumCompThreads function.
Characteristics of explicit multiprocessing:
Runs separate processes on one or many machines.
Requires installation of Parallel Computing Toolbox.
Speeds up execution of large MATLAB jobs. Enables you to run jobs simultaneously on a cluster of computers, or as several processes on a single machine.
Requires that you modify your MATLAB code.
The Parallel Computing Toolbox supports programming constructs for distributed arrays and parallel for (parfor) loops. It also supports both interactive and batch execution.
Enable explicit multiprocessing by installing Parallel Computing Toolbox.
Multithreaded computation runs in a single instance of MATLAB and generates simultaneous instruction streams on a multiple CPU (multiprocessor or multicore) system. The multiple processors share the memory of a single computer. The work to be processed is implicitly partitioned for execution on multiple threads. Multithreaded computation in MATLAB speeds up elementwise computations such as those done by the sin and log functions, and computations that use the Basic Linear Algebra Subroutines (BLAS) library, such as matrix multiply.
If you are using a multiple-CPU system, you can run a demo to see the performance impact—see Multithreaded Computation in the Help browser Demos pane, under MATLAB Mathematics.
For information regarding specific functions, search for "Which MATLAB Functions Support Multithreaded Computation" on The MathWorks online Support page.
The BLAS library used for multithreaded computation differs according to which platform you are using:
| Platform | BLAS Used |
|---|---|
| Windows with Intel® processors | Intel MKL BLAS |
| Windows with AMD processors | AMD®ACML™ BLAS |
| Linux[a] with Intel processors | Intel MKL BLAS |
| Linux with AMD processors | AMDACML BLAS |
| Macintosh Intel-based | Intel MKL BLAS |
| Solaris™ | Sun Performance Library BLAS |
[a] Linux is a registered trademark of Linus Torvalds. | |
Note See MATLAB Multiprocessing for an overview of the multiprocessing capabilities provided with MATLAB. |
Multithreaded computation in MATLAB is enabled by default. When enabled, the preference automatically detects the number of CPUs on your system and recommends the number of threads based on that.
You can change the number of threads to use with either the MATLAB Preferences GUI or the maxNumCompThreads function. Use the GUI to set preferences that apply to your current and future MATLAB sessions. Use maxNumCompThreads, in either function code or from the command line, when you want to override your Preferences settings with a temporary setting for your current MATLAB session. See Setting the Number of Threads Programmatically for instructions on using this function.
To change the maximum number of threads to use, follow these steps:
Select File > Preferences > General > Multithreading.
The General Multithreading Preferences panel opens.

Specify the Maximum number of computational threads. The default setting is Automatic, which means that MATLAB automatically sets the value to the actual number of computational cores on your system. This is the recommended setting. Note that if your system uses hyperthreading (where one processor is logically configured as two), MATLAB sets the value to 1.
If you choose Manual, enter the maximum number of threads you want to set; use a positive integer not greater than 16. (Selecting a number other than the recommended value might increase performance for some computations, but might decrease performance for others.)
To disable multithreaded computation, clear the Enable multithreaded computation selection and click OK. Making this setting in the Preferences panel not only affects your current MATLAB session, but future sessions as well.
To set or retrieve the maximum number of computational threads from the command line or from within an M-file program, use the maxNumCompThreads function. You can either set the maximum number of computational threads to a specific number, or indicate that you want the setting to be done automatically by MATLAB.
To set the maximum number of computational threads to a specific number N, use
maxNumCompThreads(N)
To have MATLAB set the maximum number of threads, use:
maxNumCompThreads('automatic')maxNumCompThreads also returns the current maximum number of threads if you call it with an output value:
oldN = MaxNumCompThreads(newN)
Note Settings that you make with the maxNumCompThreads function are displayed in the General Multithreading Preferences panel of the MATLAB Preferences GUI the next time you open the GUI. However, unless you click OK or Apply in the Preferences GUI, these settings apply only to your current MATLAB session. Any changes to the multithreading settings that you make and also apply using the GUI affect future MATLAB sessions as well. Changes applied in the Preferences GUI are reflected in the value returned by maxNumCompThreads. |
See the Parallel Computing Toolbox documentation for information regarding explicit multiprocessing in MATLAB.
[a] Linux is a registered trademark of Linus Torvalds.
![]() | Techniques for Improving Performance | Memory Usage | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |