parfor

MATLAB parfor slicing issue?

好久不见. 提交于 2019-12-01 04:15:14
I have a section of code that finds Harris corners in a sequence of images. I need to do this for 92 images, but it's rather slow. As such, I'd like to run the code in parallel. The code I have below has an error related to the variable "corners" %% Harris corners max_pts = 900; corners = zeros(max_pts,2,size(images,3)); parfor i = 1:size(images,3) I = images(:,:,i); [y x] = get_corners(I,max_pts); corners(1:length(y),:,i) = [y x]; end Which says: MATLAB runs loops in parfor functions by dividing the loop iterations into groups, and then sending them to MATLAB workers where they run in

Bad version or endian-key in MATLAB parfor?

可紊 提交于 2019-12-01 03:25:49
I am doing parallel computations with MATALB parfor . The code structure looks pretty much like %%% assess fitness %%% % save communication overheads bitmaps = pop(1, new_indi_idices); porosities = pop(2, new_indi_idices); mid_fitnesses = zeros(1, numel(new_indi_idices)); right_fitnesses = zeros(1, numel(new_indi_idices)); % parallelization starts parfor idx = 1:numel(new_indi_idices) % only assess the necessary bitmap = bitmaps{idx}; if porosities{idx}>POROSITY_MIN && porosities{idx}<POROSITY_MAX [mid_dsp, right_dsp] = compute_displacement(bitmap, ['1/' num2str(PIX_NO_PER_SIDE)]); mid_fitness

MATLAB parfor slicing issue?

大憨熊 提交于 2019-12-01 00:46:30
问题 I have a section of code that finds Harris corners in a sequence of images. I need to do this for 92 images, but it's rather slow. As such, I'd like to run the code in parallel. The code I have below has an error related to the variable "corners" %% Harris corners max_pts = 900; corners = zeros(max_pts,2,size(images,3)); parfor i = 1:size(images,3) I = images(:,:,i); [y x] = get_corners(I,max_pts); corners(1:length(y),:,i) = [y x]; end Which says: MATLAB runs loops in parfor functions by

MATLAB: How to set random seed in parfor to produce same results as serial for?

假装没事ソ 提交于 2019-11-30 15:27:53
I set up the following minimal example: rng(0); randseedoffset = random('unid', 10^5) + 1; t = cell(10,1); for i = 1:10 rng(randseedoffset+i); t{i} = random('unid', 1000); end disp(t); This will generate 10 random numbers and store them in t . It will always produce the same random numbers reliably because I set the seed with rng in the for loop. If I now change for to parfor , I get different results ! Though they will also always be reproducible. I want to accelerate my code with parfor and still obtain the same exact same random numbers as with for... Ok, I just found the reason: MATLAB

MATLAB: How to set random seed in parfor to produce same results as serial for?

孤街浪徒 提交于 2019-11-29 21:21:12
问题 I set up the following minimal example: rng(0); randseedoffset = random('unid', 10^5) + 1; t = cell(10,1); for i = 1:10 rng(randseedoffset+i); t{i} = random('unid', 1000); end disp(t); This will generate 10 random numbers and store them in t . It will always produce the same random numbers reliably because I set the seed with rng in the for loop. If I now change for to parfor , I get different results ! Though they will also always be reproducible. I want to accelerate my code with parfor and

parfor doesn't consider information about vectors which are used in it

一世执手 提交于 2019-11-29 12:50:34
This is a part of my code in Matlab. I tried to make it parallel but there is an error: The variable gax in a parfor cannot be classified. I know why the error occurs. because I should tell Matlab that v is an incresing vector which doesn't contain repeated elements. Could anyone help me to use this information to parallelize the code? v=[1,3,6,8]; ggx=5.*ones(15,14); gax=ones(15,14); for m=v if m > 1 parfor j=1:m-1 gax(j,m-1) = ggx(j,m-1); end end if m<nn parfor jo=m+1:15 gax(jo,m) = ggx(jo,m); end end end Optimizing a code should be closely related to its purpose, especially when you use

Matlab: Print progress from parfor loop

醉酒当歌 提交于 2019-11-28 18:54:46
I run a lot of long simulations in Matlab, typically taking from a couple of minutes to a couple of hours, so to speed things up I decided to run the simulations simultaneously using a parfor loop. arglist = [arg1, arg2, arg3, arg4]; parfor ii = 1:size(arglist, 2) myfun(arglist(ii)); end Everything worked just fine, except for one thing: the progress printing. Since each simulation takes a lot of time, I usually print progress using something like prevlength = 0; for ii = 1:tot_iter % Some calculations here msg = sprintf('Working on %d of %d, %.2f percent done', ii, tot_iter, ii/tot_iter);

globals and parfor

一笑奈何 提交于 2019-11-28 11:26:33
Inside a parfor loop, I am trying to call a function that accesses a global to no avail. The function function a = getA() global OPTIONS; a=OPTIONS.PROBLEM.A; end The loop: parfor i=1:3 b=getA(); end The error: Error using parallel_function (line 589) Attempt to reference field of non-structure array. What am I doing wrong? Rody Oldenhuis From the documentation on parfor : The body of a parfor-loop cannot contain global or persistent variable declarations. In the context of your problem, i.e., calling a function within the parfor that in turn references a global , this translates into: "

Sending data to workers

被刻印的时光 ゝ 提交于 2019-11-27 23:44:47
I am trying to create a piece of parallel code to speed up the processing of a very large (couple of hundred million rows) array. In order to parallelise this, I chopped my data into 8 (my number of cores) pieces and tried sending each worker 1 piece. Looking at my RAM usage however, it seems each piece is send to each worker, effectively multiplying my RAM usage by 8. A minimum working example: A = 1:16; for ii = 1:8 data{ii} = A(2*ii-1:2*ii); end Now, when I send this data to workers using parfor it seems to send the full cell instead of just the desired piece: output = cell(1,8); parfor ii

globals and parfor

一世执手 提交于 2019-11-27 19:22:39
问题 Inside a parfor loop, I am trying to call a function that accesses a global to no avail. The function function a = getA() global OPTIONS; a=OPTIONS.PROBLEM.A; end The loop: parfor i=1:3 b=getA(); end The error: Error using parallel_function (line 589) Attempt to reference field of non-structure array. What am I doing wrong? 回答1: From the documentation on parfor : The body of a parfor-loop cannot contain global or persistent variable declarations. In the context of your problem, i.e., calling