function results = md_wrap(n_labs) % Submit a job to run J. Burkardt's molecular dynamics code % with a matlabpool of specified size save_time = zeros(4,6); save_time(1, :) = clock; % [yr month day hour minute seconds] my_job = batch('md_script', 'CaptureDiary', true, ... 'FileDependencies',{'md_parallel'}, ... 'Configuration', defaultParallelConfig, ... 'matlabpool', n_labs); save_time(2, :) = clock; % [yr month day hour minute seconds] wait(my_job); save_time(3, :) = clock; % [yr month day hour minute seconds] % Retrieve output from the job results = getAllOutputArguments(my_job); save_time(4, :) = clock; % [yr month day hour minute seconds] % If the cell array results is empty (say 1 x 0), the script submitted % by 'batch' has failed. % Could alternatively use the load command % results = load(my_job) submit_time = (save_time( 2, 4:6) - save_time( 1, 4:6))*[3600; 60; 1]; wait_time = (save_time( 3, 4:6) - save_time( 2, 4:6))*[3600; 60; 1]; retrieve_time = (save_time( 4, 4:6) - save_time( 3, 4:6))*[3600; 60; 1]; fid = 1; % write to standard output fprintf(fid, 'Time to submit the batch job (s): %6.2f (s) \n', ... submit_time); fprintf(fid, 'Elapsed time with %i labs is: %6.2f (s) \n', ... n_labs, wait_time); fprintf(fid, 'Time to retrieve results (s): %6.2f (s) \n', ... retrieve_time); my_job.diary; % Clean up after the job destroy(my_job);