How to execute threads in MATLAB?

How to make threads in MATLAB? I want to run one function for two variables at the same time. How to do it?

+4
source share
3 answers

The parallel toolbar contains some tools that may help you. Find below example inserted from matlab help

matlabpool % Use default parallel configuration spmd % By default uses all labs in the pool INP = load(['somedatafile' num2str(labindex) '.mat']); RES = somefun(INP); end 

Then the RES values ​​in the laboratories are accessible from the client as RES{1} from laboratory 1, RES{2} from laboratory 2, etc.

You can also see parfor as a simple parallel replacement for . Hope this helps, even if it’s not exactly what you are looking for.

+6
source

I do not believe MATLAB has multithreading support built in. This comes from a conversation I recently had with a colleague, and with a quick google search

Hope this helps.

+1
source

You can do this with the MEX and std::thread files (see here ).

I did not try to call mexEvalString from the MEX file, and, quite possibly, this will lead to an error at runtime or freezes MATLAB at runtime. But if you can write this particular piece of C ++ code, this might be what you are looking for.

0
source

Source: https://habr.com/ru/post/1308019/


All Articles