Parfor Data Collection in Matlab
7 次查看(过去 30 天)
显示 更早的评论
Good evening,
May I please get help with saving data from a parfor loop? I have the following:
% Run Time
tic
% Preallocate memory to increase speed
b=zeros(24,1); %Make space for this array.
%c=zeros(500000,1);
% d=zeros(500000,1);
% e=zeros(500000,1);
% f=zeros(500000,1);
% g=zeros(500000,1);
%h=zeros(500000,1);
%table=[];
for j = 1:length(out(1,:)) %iterate over each run
parfor i = 1:length(out(1,j).PN.time) % Set length of vector
b=out(1,j).PN.signals.values(:,i); % Find the values to work on
c(i)=b(19,:); % Distance to target (m)
d(i)=b(20,:); % Lat. Accelerations, integrated twice (m)
e(i)=b(21,:); % Long. Acceleration, integrated twice (m)
f(i)=b(22,:); % Lat. Guidance Error
g(i)=b(23,:); % Long. Guidance Error
h(i)=b(24,:); % time to target (sec)
end
%For c_min, there's extranous zeros popping up, exclude them
[c_min,I_1]=min(c(c>0)); % Collect the closest missile/target approach (most critical value)
[d_max,I_2]=max(d); % We need to find the max value per run, but wish for the min value over all runs.
[e_max,I_3]=max(e); % We need to find the max value per run, but wish for the min value over all runs.
[f_min,I_4]=min(f); % We just want the minimum value here.
[g_min,I_5]=min(g); % We just want the minimum value here.
[h_max,I_6]=max(h); % The minimum time is 2nd most critical value, after distance to target.
table(:,j)=[c_min d_max e_max f_min g_min h_max];
end
toc
% tf=out(1,1).PN.signals.values(:,6)
I have a parsim data set consisting of 10 individual data sets, each an array of 24 rows, and a varying number of columns (usually between 200,000 and 300,000 columns). I wish to run the parfor loop, collect maximum and minimum values from each data set and compile the results in a table. What I'm finding is that, the compiled data is not consistent (the data is not lining up with the data set it should have come from). For example, a value I may expect to see from data set 2 might be from data set 1, or the results of data set 3 may repeat over and over until data set 7, etc.
4 个评论
Walter Roberson
2020-9-13
Is the overall problem solved, or just that that one small section now works better and the main problem remains?
回答(1 个)
Gaurav Garg
2020-9-16
Hi John,
In order to achieve what you want (ending up with a table with 10 columns, in parallel manner), you can run the outside for loop as parfor and inner parfor can be serialized using an ordniary for loop.
Since there is no dependence of data between 2 iterations of the loop, you can parallelize the outer loop. However, you will be needing to declare table outside the loop and you cannot run both the loops using parfor.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!