f

#### Nested parfor loop: Classification of Matrix inside loop

```Hello,

I am having problems with the following loop, since it is taking too much time. Hence, I would like to use parallel processing, specifically parfor function.

Can anyone, please, help me to convert the following 'far' loop into 'parfor'?

P = numel(scaleX); %  quite BIG number
sz = P;
start = 1;
sqrL = 10; %  sqr len
e = 200;
A = false(sz, sz);

parfor m = sz-sqrL/2:(-1)*sqrL:start
for n = M(m):-sqrL:1
temp = [scaleX(m), scaleY(m); scaleX(n), scaleY(n)];
d = pdist(temp, 'euclidean');
if d < e
A(m, n) = 1;
end
end
end

Thank you!
```
 0
Bek
4/14/2015 1:14:42 AM
comp.soft-sys.matlab 211266 articles. 13 followers. lunamoonmoon (258) is leader.

1 Replies
476 Views

Similar Articles

[PageSpeed] 21

```"Bek Abdik" <beknazar@unist.ac.kr> writes:

> I am having problems with the following loop, since it is taking too
> much time. Hence, I would like to use parallel processing,
> specifically parfor function.
>
> Can anyone, please, help me to convert the following 'far' loop into 'parfor'?
>
> P = numel(scaleX); %  quite BIG number
> sz = P;
> start = 1;
> sqrL = 10; %  sqr len
> e = 200;
> A = false(sz, sz);
>
> parfor m = sz-sqrL/2:(-1)*sqrL:start
>    for n = M(m):-sqrL:1
>        temp = [scaleX(m), scaleY(m); scaleX(n), scaleY(n)];
>        d = pdist(temp, 'euclidean');
>        if d < e
>            A(m, n) = 1;
>        end
>    end
> end

As the code analyzer message informs you, the range of a PARFOR loop
must be consecutive integers. There's more about the restriction here:

<http://www.mathworks.com/help/distcomp/parfor.html>

The other problem you have is that the form of indexing you're using
with 'A' still wouldn't work. This is because of the form of your inner
FOR loop, as described here:

<http://www.mathworks.com/help/distcomp/nesting-and-flow-in-parfor-loops.html#bq__cs7-9>

To work around that, I would normally create a temporary vector and then
assign a whole row of A, something like this:

....
mv = sz-sqrL/2:(-1)*sqrL:start;
parfor mi = 1:numel(mv)
m = mv(mi);
Arow = false(1, sz);
for n = 100:-sqrL:1
temp = [scaleX(m), scaleY(m); scaleX(n), scaleY(n)];
d = pdist(temp, 'euclidean');
if d < e
Arow(n) = true;
end
end
A(mi, :) = Arow;
end

Obviously, you need to map back from the 'A' that has been created since
your original loop is only accessing some of the rows of A.

Cheers,
Edric.
```
 0
Edric
4/14/2015 7:40:45 AM

Similar Artilces:

Nested parfor loop: Classification of Matrix inside loop #2
Hello, I am having problems with the following loop, since it is taking too much time. Hence, I would like to use parallel processing, specifically parfor function. Can anyone, please, help me to convert the following 'far' loop into 'parfor'? P = numel(scaleX); % quite BIG number sz = P; start = 1; sqrL = 10; % sqr len e = 200; A = false(sz, sz); parfor m = sz-sqrL/2:(-1)*sqrL:start for n = M(m):-sqrL:1 temp = [scaleX(m), scaleY(m); scaleX(n), scaleY(n)]; d = pdist(temp, 'euclidean'); if d < e A(m, n) =...

Triple nested loop python (While loop insde of for loop inside of while loop)
try to make my triple nested loop working. My code would be: c = 4 y1 = [] m1 = [] std1 = [] while c <24: c = c + 1 a = [] f.seek(0,0) for columns in ( raw.strip().split() for raw in f ): a.append(columns[c]) x = np.array(a, float) not_nan = np.logical_not(np.isnan(x)) indices = np.arange(len(x)) interp = interp1d(indices[not_nan], x[not_nan], kind = 'nearest') p = interp(indices) N = len(p) dt = 900.0 #Time step (seconds) fs = 1./dt #Sampling frequency KA,PSD = oned_Fourierspectrum(p,dt) # Call Song's 1D FS function time_axis = np.linspace(0.0,N,num = N,endpoint = False)*15/(60*24) plot_freq = 24*3600.*KA #Convert to cycles per day plot_period = 1.0/plot_freq # convert to days/cycle fpsd = plot_freq*PSD d = -1 while d <335: d = d + 1 y = fpsd[d] y1 = y1 + [y] m = np.mean(y1) m1 = m1 + [m] print m1 -------------------------------------------------------------------------------- My purpose is make a list of [mean(fpsd[0]), mean(fpsd[1]), mean(fpsd[2]).. mean(fpsd[335])]. Each y1 would be the list of fpsd[d]. I check it is working pretty well before second while l...

nesting for loops in a parfor loop
Hi, I am trying to nest several for loops in a parfor loop. I have even read the documentation and several other queries/replies before posting here. I have a large dataset that I need to iterate over, calculating a property which would result in a prohibitively large array if I sent each answer to a separate element, and doing this on one cpu will take a prohibitively long time. Instead, what I am doing is reducing the array by another property, and then combining the calculated results in bins of this second property (essentially making a histogram). The parfor section of my code looks like this: parfor i=1:box(1); for j=1:box(2); for k=1:box(3); for l=1:box(1); for m=1:box(2); for n=1:box(3); prop(horrendousfunction(i,j,k,l,m,n)) = prop(horrendousfunction(i,j,k,l,m,n)) + data(i,j,k)*data(l,m,n); end end end end end end Trialling this on one cpu over i=j=k=l=m=n=[1:15] works fine and takes a few minutes. The data array is the initial large array, but as written the code will iterate over every element of it many times within each parfor step, and therefore the data transmission I/O overhead shouldn't be too onerous with respect to the overall computation time. (Expected complete running time is ~1 month on 1 cpu, and I have several of these to do) A few other (small, negligible I/O) arrays are also required. hor...

Nested While loop inside For loop
I have been coding in matlab for a while and I am confused about the below code: It seems like the "For loop" iterator variable "Index" does not update inside the "While loop". Please help me understand! I hate to assume this is some error induced on Matlab's end. ---------- CODE ------------ for Index = 390000:length(Stopxy) fprintf('Index: %d, \n',Index); while (Stopxy_YCoord(Index) < LowToHighThresh) fprintf('Index: %d, Yval: %f \n',Index,Stopxy_YCoord(Index)); Stopxy_YCoord(Index); Index = Index + 1; ...

parfor loop with nested for loop
Hi all, I'm new to this group, but googling my problem always points here so I thought I'd sign up. I'm running multiple iterations of a time-evolving Monte Carlo simulation in Matlab. Since each iteration is initialized randomly at the first time point, the iterations can safely be run in parallel on a quad core PC. I've previously been doing this by simply running 4 simultaneous Matlab sessions on one machine, but I thought I would save my institution some licenses and automate the process at the same time. The problem is that my code essentially has multiple nested for ...

Nested FOR loops. (a loop within a loop)
I can't get my head around them. I have two MySQL tables, one contains the categories, the other contains the posts. Each post is linked to a category. Now I'm trying to display each post with a drop down menu that has the categories in it and have the category that the post is in selected. Here's my code for the drop down menu where my woes lie. for (\$i=0; \$i<count(\$posts); \$i++) { for (\$j=1; \$j<=count(\$categories); \$j++) { if (\$j == \$post[\$i]['id']) { selected = ' selected="selected"'; } else { sele...

parfor loop with nested for loop #2
Hi All I just got a parallel toolbox and trying to modify my previous serial program. Can parfor loop be nested with a for loop like the following? c = zeros(m*n+1); parfor i = 1:m for j = 1:n id = (i-1)*n+j; c(id) = id; end end I got a error message saying "valid indices for 'c' are restricted in parfor loops". Does this mean I have to change this nested loop to a single loop? Is there a simpler way? Thanks! Cindy "Cindy" <xzhan2@fhcrc.org> wrote in message <h15vkh\$fia\$1@fred.mathworks.com>... > Hi All > > I just g...

while-loops nested in while-loop
Hi! I'm new to labview and I've got some problems. I want to program a control for a testing facility. therefore I want to program several while-loops&nbsp; nested in each other, according to a designed Nassi-Shneiderman-diagram. So if the stop condition for an inner while loop is true (e.g. measure device mistake), the program should jump out of that while loop in the next outer while-loop. is that possible? Thank you right now! Yes it is possible When you stop the inner loop, from inside the inner loop, just&nbsp;wire/pass an appropriate&nbsp;stop condition ( stop if tr...

while loop inside a for loop
Hi, can someone please tell me why "time" (t) is not updated correctly within the while loop? Please run this small code in your machine and you'll know what I'm taking about. What I want is: for t=1 run the "while loop" until iq<=(numberc-1) then t=2 run the "while loop" again until iq<=(numberc-1), and so on. Basically, this code runs through all the nonzero elements of A and attempts to divide them individually into two, once a certain time has passed. Please feel free to ask for clarifications. Many thanks in advance. A=[0 0 0 0 0 0 ...

nested loops only loop once
I am using two while loops that are nested. The first loop (post name) returns the full column of results, but the second (post modified) only returns the first row of the column. Is there another way I could write this to get both loops to complete fully? I am using the two while loops to pull data from different tables, and insert that data into a list that has html code surrounding each loop. while (\$url = mysql_fetch_array(\$urls, MYSQL_ASSOC)) { \$pn = \$url['post_name']; while (\$date = mysql_fetch_array(\$lmdate, MYSQL_ASSOC)) { \$lm = \$date['post_modified']; ...

For loop over a while loop
Hi, I am computing a quantity that depends on two variables. The computation itself is iterative (i'm using 3 while loops to compute it). Now i want to do a sensitivity analysis of the input variables and do a 3D plot where I can start making sense out of my results, however not sure how to write a for loop over these while loops to compute different combinations of what I define as my parametric space for my two input variables. Thanks in advance, Vash Please add a code example and/or more specific question.... ...

FOR loop not looping
I have the below script that uses 2 for loops. for some reason they loop is not looping ! /bin/ksh CURR_PATH='/main/nedcor/flexcube' cd \$CURR_PATH for DIR1 in 'WIP' 'INPUT';do echo \$DIR1 for DIR in \$(find . -name \$DIR1);do RESULT=`ls -A \$DIR | egrep -v "BKUP|BKP"` echo \$DIR echo \$RESULT echo \$RESULT1 if [ -z "\$RESULT" ] ; then echo "No Files found" exit 0 else echo file \$RESULT found exit 1 ...

For loop while loop
I need to evaluate a function from 0:200 then create an array of every 5th value in the 0:200 array using a for loop then using a while loop. I can't get the for loop to work at all because I cannot use >,< controllers, only an =. So I focused on the While loop: n=0:200;%creates 201 cell array from 0-200 x=n.^2+.25;%calculates x plotcol=(length(n)-1)/5;%=(201-1)/5=40 y=zeros(1,plotcol);%creates 1X40 vector col=1;%used for incrementing in while loop while col<=plotcol; y(1,col)=x(1,5*col); col=col+1; end Unfortunately the output starts at 16 when it should start ...

while loop in a while loop
Hi All, I have the following situation: while(rs.next()) { //loop1 while(rs2.next()) { //loop 2 } } It seems like loop 2 is only beeing used once. Should I after loop2 put the cursor back to the beginning? if so, how do I do that? Thanks! -- Posted by news://news.nb.nu Steven wrote: > Hi All, > > I have the following situation: > > > while(rs.next()) { //loop1 > > while(rs2.next()) { > //loop 2 > } > > } > The architypal loop (for a List eg ArrayList of Blah objects) is: for(It...

loops in loops
In the attached vi, the one second loop runs at one second and can't be touched.&nbsp; In the ten second loop, the ten second clock is a stand in for a process that generates a finished signal. The problem is once the process is complete, to start it again, leave the one second loop running, and start an additional process that will take less time than 10 seconds. thanks internal loops.vi: http://forums.ni.com/attachments/ni/170/319512/1/internal loops.vi Hi exo, what do you try there? If you start your vi, the value from your stop button will be read and after that, both loops &quo...

while loop in a while loop
Hi all, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; I am trying to write a program with a while loop within another while loop. When I run the vi both while loops&nbsp; run but then only the inner while loop seems to update, I adjust controls and they have no effect on the indicators. &nbsp; Thanks.. You need to familiarize with the concept of dataflow programming. Run your VI in "execution highligthing" mode while watching the diagram and you'll get a better feeling on how things work. :) &nbsp; If both loops need to run in para...

for loop into for loop.
Hello this is my first time that i am writing here.. I need your help to improve my code. This is my code for a=1:numberOfShortestPaths for b=a+1:a+numberOfShortestPaths for c=b+1:b+numberOfShortestPaths for d=c+1:c+numberOfShortestPaths for e=d+1:d+numberOfShortestPaths total_weight=weight(:,:,a)+weight(:,:,b)+weight(:,:,c)+weight(:,:,d)+weight(:,:,e); maximum=max(total_weight); end end end end end i want to do this function "automatically" because the letters ...

LOOP and +LOOP
With LOOP, since the index (I) increases by 1 with each loop iteration, we can test for equality as a means to determine if it's time to exit the loop or not: : TEST 10 0 DO I . LOOP ; TEST 0 1 2 3 4 5 6 7 8 9 Here, when I gets to 10, the loop exits. It's not so easy with +LOOP, since the index can be changed by any arbitrary value on each iteration: : TEST 100 0 DO I . RANDOM +LOOP ; Here, we cannot test for equality. We have to test for crossing a boundary instead, at least as far as I can see. With that in mind, are these following results correct: : TEST 10 0 DO I . 1 +LOOP ...

loop not looping
This should be relatively easy for someone more experienced to pick out what I'm doing wrong here...All I want is my loop to run as many times as there are .dat files in the specified directory. I've hacked up my code a bit just so i can get it to work and realize it's not as simple or efficient as it could be. My script only runs through the loop once and I can't figure out why it never loads 'binary_002.dat' and so on. thanks for your help counter_value = 1; %counter value set back to 0 when while loop = false slice_thicknessMM = 1.5; tf = isdir('C:\Documen...

Loop in a loop?
Hi, I'm new to Python and have come across a problem I don't know how to solve, enter com.lang.python :) I'm writing some small apps to learn the language, and I like it a lot so far. My problem I've stumbled upon is that I don't know how to do what I want. I want to do a loop in a loop. I think. I've got two arrays with some random stuff in, like this. array1 = ['one','two','three','four'] array2 = ['a','b','c','d'] I want to loop through array1 and add elements from array2 at the end, so it looks lik...

WHILE LOOP AS FOR LOOP
its possible? For each id in (SELECT * FROM table) INSERT INTO table2(id,fk,nombre) values(1,id,'xxx'); Jessica Gonz�lez (jess.rgm@gmail.com) writes: > its possible? > > For each id in (SELECT * FROM table) > INSERT INTO table2(id,fk,nombre) > values(1,id,'xxx'); > So in SQL, you don't normally code the loops explicitly - the loops are hidden on the inside. Logically, it is an operation of a set. INSERT table(id, fk, nombre) SELECT 1, id, 'xxx' FROM table -- Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se Books Online for SQL Server 2005 at http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx Books Online for SQL Server 2000 at http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx thanks.. but SET IDENTITY_INSERT table ON; INSERT INTO table(pk,activo,permiso,rol) SELECT IDENT_CURRENT('table')+1,'S',id, 1 FROM table2 return error Violation of PRIMARY KEY constraint 'PK__table__3213E83F2B947552'. Cannot insert duplicate key in object 'table'. The duplicate key value is (6). only 'id' i need get from table2 Jessica Gonz�lez (jess.rgm@gmail.com) writes: > thanks.. but > > SET IDENTITY_INSERT table ON; > INSERT INTO table(pk,activo,permiso,rol) > SELECT IDENT_CURRENT('table')+1,'S',id, 1 > ...

for to parfor loop,and for with logical indexing to parfor loop
Hi, I have got two doubts: -> the first one is to change this for loop to parfor loop, I have done all, but due to the last sentence I cannot use the parfor loop: ORGINAL LOOP: for n=1:fbaseDatosAct [vehDel(1),vehDel(2),vehDel(3)]=vehDelanteMia(baseDatosAct,n,t); [baseDatosAct(n,columnaV),estaParado]=reduceVelocidad(t,baseDatosAct(n,:),vmin,vehDel,pasoTemp); end PARFOR LOOP: parfor n=1:fbaseDatosAct veDelanteMiaTemp=zeros(1,3);%variable estatica para la paralelizacion baseDatosRow = baseDatosAct(n,:);%varia...

Nested loops, does it run the inner loop first then the outer loop?
I wrote this simple code for i=1:6 for c=1:6 fprintf('%i\n c:',c); fprintf('%i\n i:',i); end end and got the following output c:1 i:2 c:1 i:3 c:1 i:4 c:1 i:5 c:1 i:6 c:1 i:1 c:2 i:2 c:2 i:3 c:2 i:4 c:2 i:5 c:2 i:6 c:2 i:1 c:3 i:2 c:3 i:3 c:3 i:4 c:3 i:5 c:3 i:6 c:3 i:1 c:4 i:2 c:4 i:3 c:4 i:4 c:4 i:5 c:4 i:6 c:4 i:1 c:5 i:2 c:5 i:3 c:5 i:4 c:5 i:5 c:5 i:6 c:5 i:1 c:6 i:2 c:6 i:3 c:6 i:4 c:6 i:5 c:6 ...

Parfor nested for loops, triangular matrix structure
I am looking for advice in handling a large square matrix, C, of integer values. My code works well enough when tested for sizes 353x353 (takes several minutes to run), 5500x5500 (takes several hours to run), 8000x8000 and up to 13890x13890 (takes several days to run). I would now like to run my code one last time for size 45000x45000. Essentially, my code constructs a distance matrix whose elements describe the minimal weight of the path from vertex ii to vertex jj in a weighted, directed graph. Thus, the number of vertices could be N=353, 5500, 13890, 45,000 etc. To do this, I conside...

Web resources about - Nested parfor loop: Classification of Matrix inside loop - comp.soft-sys.matlab

Classification - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

1,000 pages of Clinton emails released; 84 classifications
The State Department has released more than 1,000 new pages of Hillary Clinton's emails.

Ford recalls F-150 for occupant classification system issue
Filed under: Recalls , Ford , Safety , Truck Ford will recall the 2016 F-150 with multi-contour seats because if the massage function is on, ...

BISMARCK CAMPAIGN HIT WITH ANOTHER SALVO: Hillary’s Emails Altered to Hide Classification Markings
Johnny Dollar relays a story from Catherine Herridge that describes another set of Clinton felonies . Just tack these on to a laundry list of ...

New On-Demand Economy Study Casts Worker Classification Debate in a New Light
New data from Intuit Inc. and Emergent Research is shedding new light on the debate about worker classification in the on-demand economy.

Clinton campaign pushes back on "top secret" classification of emails - Videos - CBS News
Just two days before the Iowa caucuses, Hillary Clinton's campaign is in damage control mode over new information about her private email server ...

Michael Mukasey Accuses Clinton Of Removing Classification On Emails
Former Bush Attorney General and torture apologist turned Jeb! Bush adviser , Michael Mukasey made an appearance on CNN's Smerconish this Saturday ...

Report: Emails At The Highest Classification Levels Found On Hillary’s Private Server
Report: Emails At The Highest Classification Levels Found On Hillary’s Private Server

1,000 pages of Hillary Clinton emails released; 84 classifications
WASHINGTON >> The State Department has released more than 1,000 new pages of Hillary Clinton’s emails.Eighty-one messages were classified, mostly ...

How Do You Set Your Company Up For Success With Data Classification?
Defining your data via data discovery and classification is the foundation for data security strategy. The idea that you must understand what ...

Resources last updated: 3/9/2016 10:23:21 AM