0
|
6381 Views
|
|
0 Total Likes
View groups...
Share
GROUPS:

# How to speed up list manipulation

Posted 10 years ago
 Hi, I have this code: corrspeckleframessnrbest = Reap[ workingset = ssnr; frame1 = First[workingset]; While[Length[workingset] > 1, restset = Rest[workingset]; If[Length[restset] == 1, Break[]]; maxcorr = 0; frame2 = First[restset]; curcollection = Reap[ While[Length[restset] > 1, corr = Correlation[ First[Extract[speckleframes, Position[snr, frame1] ] ], First[Extract[speckleframes, Position[snr, frame2] ] ] ]; If[corr > maxcorr, Sow[{First[First[Position[snr, frame1] ] ], First[First[Position[snr, frame2] ] ], corr}] ; maxcorr = corr;]; restset = Sort[Complement[restset, {frame2}], Greater]; frame2 = First[restset]; ]; ][[2, 1]]; Sow[Last[curcollection]]; workingset = Sort[Complement[workingset, {frame1}], Greater]; frame1 = workingset[[First[ First[Position[workingset, snr[[Last[curcollection][[2]] ]] ] ] ] ]]; workingset = Sort[Complement[workingset, {frame1}], Greater]; ]; ][[2, 1]]; // Timing {7161.449902, Null}  If I put essentially the same code into a ParallelTable and execute 67 times: In[375]:= corrspeckleframesentbest = ParallelTable[Reap[ workingset = smespeckleRenyialpha[[i]]; frame1 = First[workingset]; While[Length[workingset] > 1, restset = Rest[workingset]; If[Length[restset] == 1, Break[]]; maxcorr = 0; frame2 = First[restset]; curcollection = Reap[ While[Length[restset] > 1, corr = Correlation[ First[Extract[speckleframes, Position[mespeckleRenyialpha[[i]], frame1] ] ], First[Extract[speckleframes, Position[mespeckleRenyialpha[[i]], frame2] ] ] ]; If[corr > maxcorr, Sow[{First[ First[Position[mespeckleRenyialpha[[i]], frame1] ] ], First[First[ Position[mespeckleRenyialpha[[i]], frame2] ] ], corr}] ; maxcorr = corr;]; restset = Sort[Complement[restset, {frame2}], Greater]; frame2 = First[restset]; ]; ][[2, 1]]; Sow[Last[curcollection]]; workingset = Sort[Complement[workingset, {frame1}], Greater]; frame1 = workingset[[First[ First[Position[workingset, mespeckleRenyialpha[[i]][[Last[ curcollection][[2]] ]] ] ] ] ]]; workingset = Sort[Complement[workingset, {frame1}], Greater]; ]; ][[2, 1]], {i, 1, lengthalphaArray}]; // Timing Out[375]= {2784.794970, Null}  it executes almost one-third of the single run time. That says to me that further optimization of the single executed code is possible. I looked long and far, but I see no obvious ways to do it. Maybe someone on the list has much sharper eyes. Thanks ahead, János
Sort By:
Posted 10 years ago
 I think speeding up is a really good idea, but do not forget about the other factors that might affect the program. - Paramount Song
Community posts can be styled and formatted using the Markdown syntax.