在MATLAB中加速批处理作业的执行 [英] Accelerate batch job execution in MATLAB

查看:116
本文介绍了在MATLAB中加速批处理作业的执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是MATLAB中批处理作业的新手.我正在玩以下代码:

I'm new to batch job execution in MATLAB. I'm playing with the following code:

clear 
a = rand(10,1);
job = batch('l_beta');
wait(job)
load(job,'b')

l_beta只是一行代码:

b = sum(a);

尽管所有操作都很简单,但是令人惊讶的是,在第一个块中执行代码需要花费12秒钟的时间.我在以下链接中查看了讨论

While all the operations are simple, surprisingly, it took 12 seconds to execute the code in the first block. I checked out the discussion in the following link

https://www.mathworks.com /matlabcentral/answers/166757-why-is-batch-so-slow

似乎与启动批处理作业相关的开销很大.我想知道是否有简单的方法来减少这种开销.说,如果我只进行一次配置/预热,然后只要运行MATLAB就不必担心.

It seems that there are a lot of overheads associated with starting batch jobs. I'm wondering whether there are simple ways to reduce this overhead. Say, if I do the configurations/warming-up for once and then don't need to worry about it as long as the MATLAB is running.

推荐答案

您可以使用tic/toc和job属性很容易地调试它.参见下面的示例

You can debug this quite easily using tic/toc and job properties. see below for an example

clc; close all; clear;
a = 10;

tic;
c = parcluster();
fprintf('Creating the cluster: %.2f sec\n', toc);

tic;
job = createJob(c);
fprintf('Creating a job: %.2f sec\n', toc);

tic;
createTask(job, @exp, 1, {a});
createTask(job, @sin, 1, {a});
fprintf('Creating the tasks: %.2f sec\n', toc);

tic;
submit(job);
fprintf('Submitting the job: %.2f sec\n', toc);

% Most of the time goes on scheduling the job here
% pause(10);

tic;
wait(job)
fprintf('Waiting time: %.2f sec\n', toc);

tic;
results = fetchOutputs(job);
fprintf('Fetching Results: %.2f sec\n\n', toc);

fprintf('Job Properties\n');
fprintf('Create Time: %s \n', job.CreateTime);
fprintf('Submit Time: %s \n', job.SubmitTime);
fprintf('Start Time: %s \n', job.StartTime);
fprintf('Finish Time: %s \n', job.FinishTime);

delete(job);

如果运行此命令,则会得到以下信息

If I run this, I get the following

Creating the cluster: 0.01 sec
Creating a job: 0.02 sec
Creating the tasks: 0.04 sec
Submitting the job: 0.19 sec
Waiting time: 4.13 sec
Fetching Results: 0.02 sec

Job Properties
Create Time: Mon May 22 10:30:23 BST 2017 
Submit Time: Mon May 22 10:30:23 BST 2017 
Start Time: Mon May 22 10:30:26 BST 2017 
Finish Time: Mon May 22 10:30:27 BST 2017 

您看到在提交和开始之间大部分时间都浪费了.执行本身非常快.如果您通过从pause(10)中删除评论来引入暂停,则会得到以下内容

You see that most of the time is lost between submission and start. the execution itself is quite fast. If you introduce a pause by removing the comment from pause(10), you get the following

Creating the cluster: 0.01 sec
Creating a job: 0.02 sec
Creating the tasks: 0.04 sec
Submitting the job: 0.19 sec
Waiting time: 0.06 sec
Fetching Results: 0.02 sec

Job Properties
Create Time: Mon May 22 10:31:44 BST 2017 
Submit Time: Mon May 22 10:31:44 BST 2017 
Start Time: Mon May 22 10:31:47 BST 2017 
Finish Time: Mon May 22 10:31:48 BST 2017 

因此,您可以考虑在代码中尽早提交作业,在计划和运行作业时进行其他操作,然后再从代码中获取结果.我希望这会有所帮助.

Therefore, you can think of submitting the jobs early on in your code, doing some other operations while the jobs are being scheduled and run, followed by fetching the results further down your code. I hope this is helpful.

这篇关于在MATLAB中加速批处理作业的执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆