run matlab functions in thread-based environment
hundreds of functions in matlab® and other toolboxes can run in a thread-based environment. you can use
backgroundpool
or parpool("threads")
to run code in
a thread-based environment.
to run a function in the background, use and .
for more information about thread pools, see (parallel computing toolbox).
run functions in the background
if a function is supported in a thread-based environment, you can use
parfeval
and backgroundpool
to run it in the
background.
use the rand
function to generate a
100
-by-100
matrix of random numbers in the
background.
f = parfeval(backgroundpool,@rand,1,100);
for more information about running code in the background, see .
run functions on a thread pool
if a function is supported in a thread-based environment, you can run it on a thread pool if you have parallel computing toolbox™.
parpool("threads"); parfor i = 1:100 a{i} = rand(100); end
for more information about thread pools, see threadpool
(parallel computing toolbox).
automatically scale up
if you have parallel computing toolbox, your code that uses backgroundpool
automatically scales
up to use more available cores.
for information about the number of cores that you can use, see the
numworkers
property of .
by running multiple functions in the background at the same time when you use parallel computing toolbox, you can speed up the following code.
for i = 1:100 f(i) = parfeval(backgroundpool,@rand,1,100); end
check thread supported functions
if a matlab function has thread support, you can consult additional thread usage information on its function page. see "thread-based environment" in the extended capabilities section at the end of the function page.
tip
for a filtered list of matlab functions that have thread support, see .
in general, functionality in graphics, app building, external language interfaces, , and environment and settings is not supported.
matlab and several toolboxes include functions with built-in thread support. to view lists of all functions in matlab and these toolboxes that have thread support, use the links in the following table. functions in the lists with warning indicators have limitations or usage notes specific to running the function on threads. you can check the usage notes and limitations in the extended capabilities section of the function reference page. for information about updates to individual thread-supported functions, see the release notes.
product | list of functions supported on threads |
---|---|
matlab | |
image processing toolbox™ | (image processing toolbox) |
signal processing toolbox™ | (signal processing toolbox) |
see also
|
related topics
- run matlab functions on a gpu (parallel computing toolbox)