MATLAB Multiprocessing

Overview

The MATLAB software supports two types of multiprocessing: implicit and explicit.

Implicit Multiprocessing

Characteristics of implicit multiprocessing:

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.

Explicit Multiprocessing

Characteristics of explicit multiprocessing:

Enable explicit multiprocessing by installing Parallel Computing Toolbox.

Implicit Multiprocessing

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.

Platform Differences and Multithreaded Computation

The BLAS library used for multithreaded computation differs according to which platform you are using:

PlatformBLAS Used
Windows with Intel® processorsIntel MKL BLAS
Windows with AMD processorsAMD®ACML™ BLAS
Linux[a] with Intel processorsIntel MKL BLAS
Linux with AMD processorsAMDACML BLAS
Macintosh Intel-basedIntel MKL BLAS
Solaris™Sun Performance Library BLAS

[a] Linux is a registered trademark of Linus Torvalds.

Enabling Multithreaded Computation

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:

  1. Select File > Preferences > General > Multithreading.

    The General Multithreading Preferences panel opens.

    Image of default setting for Multithreading Preferences panel; multithreading is selected.

  2. 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.

Setting the Number of Threads Programmatically

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)

Explicit Multiprocessing

See the Parallel Computing Toolbox documentation for information regarding explicit multiprocessing in MATLAB.


[a] Linux is a registered trademark of Linus Torvalds.

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS