What is wrong with the code?

1 view (last 30 days)
Ahash Thayalan
Ahash Thayalan on 26 Nov 2022
Answered: Image Analyst on 26 Nov 2022
Error; Index exceeds the number of array elements. Index must not exceed 1.
Error in ParallelProcessing (line 81)
if Result(i, 2) == DataSizes(2)
code;
clear all
close all
FileName = 'Model/o3_surface_20180701000000.nc';
[Contents, Lat, Lon] = ReadFilePar(FileName);
NumHours = 5;
DataSizes = [100]; % Data options to test
Workers = [2]; % Worker Options to test
%% 2: Processing parameters
% ## provided by customer ##
RadLat = 30.2016;
RadLon = 24.8032;
RadO3 = 4.2653986e-08;
StartLat = 1;
NumLat = 400;
StartLon = 1;
NumLon = 700;
Result = [];
NumLocations = (NumLon - 4) * (NumLat - 4);
%% 4: Cycle through the hours and load all the models for each hour and record memory use
% We use an index named 'NumHour' in our loop
% The section 'parallel processing' will process the data location one
% after the other, reporting on the time involved.
Steps = 100;
Result = [];
tic
for idx1 = 1:size(DataSizes, 2)
DataOpt = DataSizes(idx1);
for idx2 = 1:size(Workers, 2)
WorkerNum = Workers(idx2);
tic
for idxTime = 1:NumHours
[HourlyData] = LoadDataParallel(FileName, Contents, idxTime, StartLat, NumLat, StartLon, NumLon);
[Data2Process, LatLon] = PrepareData(HourlyData, Lat, Lon);
[EnsembleVectorPar, T3] = Parallelanalysis(RadLat, RadLon, RadO3, idxTime, DataOpt, Steps, WorkerNum, Data2Process, LatLon);
times(idxTime) = T3;
end
T2 = toc;
fprintf('Total processing time for %i workers = %.2f s\n', WorkerNum, sum(times))
Result = [Result; DataOpt, WorkerNum, sum(times)];
delete(gcp);
end
end
x1Values = Workers;
y1Values = [];
x2Values = Workers;
y2Values = [];
x3Values = Workers;
y3Values = [];
Result(1, 3)
size(Result, 1)
%% Iterate through all of the results and decide which array to append the result to.
for i = 1 : size(Result, 1)
if Result(i, 2) == DataSizes(1)
y1Values = [y1Values; Result(i, 3)];
end
if Result(i, 2) == DataSizes(2)
y2Values = [y2Values; Result(i, 3)];
end
if Result(i, 2) == DataSizes(3)
y3Values = [y3Values; Result(i, 3)];
end
end
figure(1)
yyaxis left
plot(Workers, Result, '-bd')
xlabel('Number of Processors')
ylabel('Processing time (s)')
title('Processing time vs number of processors')
%% 10: Reshape ensemble values to Lat, lon, hour format%% Parallel Analysis
%EnsembleVectorPar = reshape(EnsembleVectorPar, 696, 396, []);

Answers (1)

Image Analyst
Image Analyst on 26 Nov 2022
Since you define Datasizes as a scalar:
DataSizes = [100]; % Data options to test
why do you think that a second element exists, as if it's an array or something, instead of a scalar?

Products


Release

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!