Main Content

maxNumCompThreads

Control maximum number of computational threads

Description

N = maxNumCompThreads returns the current maximum number of computational threads.

Currently, the maximum number of computational threads is equal to the number of physical cores on your machine.

example

LASTN = maxNumCompThreads(n) sets the maximum number of computational threads to n and returns the previous maximum number of computational threads, LASTN.

LASTN = maxNumCompThreads('automatic') sets the maximum number of computational threads using what the MATLAB® software determines to be the most desirable. It additionally returns the previous maximum number of computational threads, LASTN.

Note

If you set the maximum number of computational threads using maxNumCompThreads, the change does not persist across MATLAB sessions.

Examples

collapse all

Display the current maximum number of computational threads.

N = maxNumCompThreads
N = 
4

Input Arguments

collapse all

Maximum number of computational threads, specified as a positive integer scalar.

Output Arguments

collapse all

Current maximum number of computational threads, returned as a positive integer scalar.

Previous maximum number of computational threads, returned as a positive integer scalar.

Tips

  • To limit MATLAB to a single computational thread, you can use the -singleCompThread option when starting MATLAB at the system prompt: matlab -singleCompThread. By default, MATLAB uses the multithreading capabilities of the computer on which it is running.

  • On machines running Windows® 11 (or later) or Windows Server 2022 (or later) with multiple processor groups, the default maximum number of computational threads depends on the version of MATLAB you are using.

    • MATLAB R2025a and later — The default maximum number of computational threads is the number of physical cores across all processor groups.

    • MATLAB R2024b and earlier — The default maximum number of computational threads is the number of physical cores within the processor group that is running MATLAB.

Version History

Introduced in R2007b

See Also