Hoffman2:parpoolexample.m: Difference between revisions
Jump to navigation
Jump to search
(Created page with "Example Script: %%%% parpoolexample.m START %%%%% n=20 p = parpool('local',n); poolobj = gcp('nocreate'); % If no pool, do not create new one. if isempty(poolobj)...") |
No edit summary |
||
| (3 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
Example Script: | Example Script of using 20 workers: | ||
%%%% parpoolexample.m START %%%%% | %%%% parpoolexample.m START %%%%% | ||
| Line 20: | Line 20: | ||
toc | toc | ||
delete(p) | delete(p) | ||
%%%% parpoolexample.m STOP %%%%% | |||
If the script is run without the steps mentioned in [[Hoffman2:MATLAB#Running_Parallel_Jobs | Running_Parallel_Jobs]], you will run in to an issue where the local pool will start but wouldn't initialize the workers themselves. | |||
**Create this parpoolexample.m before going through the steps mentioned ** | |||
Latest revision as of 18:43, 2 April 2020
Example Script of using 20 workers:
%%%% parpoolexample.m START %%%%%
n=20
p = parpool('local',n);
poolobj = gcp('nocreate'); % If no pool, do not create new one.
if isempty(poolobj)
poolsize = 0;
else
poolsize = poolobj.NumWorkers
end
tic
ticBytes(gcp);
n = 1024;
A = zeros(n);
parfor (i = 1:n)
A(i,:) = (1:n) .* sin(i*2*pi/1024);
end
tocBytes(gcp)
toc
delete(p)
%%%% parpoolexample.m STOP %%%%%
If the script is run without the steps mentioned in Running_Parallel_Jobs, you will run in to an issue where the local pool will start but wouldn't initialize the workers themselves.
- Create this parpoolexample.m before going through the steps mentioned **