% script to run maxEig function 200 times and print average. count = 200; dim = 5001; sumMaxe = 0; i = 0; id = str2num(getenv('SLURM_JOB_ID')); rc = 0; rc = str2num(getenv('SLURM_RESTART_COUNT')); tic; if isempty(rc); for i=1:count; sumMaxe = sumMaxe + maxEig(i,dim); counter = "counter: "+i; %Add this line disp(counter); %Add this line end; else filename = ['checkpoint-', num2str(id), '.out']; % Specify the file name where you want to search searchString = 'ended on counter'; % Specify the string you want to search for fileID = fopen(filename, 'r'); % Open the text file for reading if fileID == -1 error('Unable to open the file.'); end lineNumber = 0; % Read lines from the file and search for the target string while ~feof(fileID) line = fgetl(fileID); if ischar(line) lineNumber = lineNumber + 1; if ~isempty(strfind(line, searchString)) num=regexp(line,'counter:\s(\d+)', 'tokens'); counterNumber = str2double(num{1}{1});% Record the counter number end end end fclose(fileID); % Close the file for i =counterNumber:count; % Once the job restarted, it will continue from the last counter number sumMaxe = sumMaxe + maxEig(i,dim); counter = "counter: "+i; disp(counter); end; end; toc avgMaxEig = sumMaxe/count quit