Hoffman2:parpoolexample.m

From Center for Cognitive Neuroscience
Revision as of 18:19, 2 April 2020 by Ravi (talk | contribs) (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)...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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)
    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 %%%%%