文件交换的选择

我们最好的用户提交

The Create Persistent Resources on the Parallel Workers

肖恩's pick this week isWorkerObjWrapperMathWorks的并行计算的团队

背景

MATLAB的并行计算工具箱为您提供了MATLAB工人的能力开放游泳池,你可以分配工作与高水平的命令parfor

When communicating with the workers in this pool, there will always be an overhead in data communication, the less data, we can transmit to the workers the better speed improvements we 'l l see. This can be about the When working with large arrays and can later cause the parallel computations to be slower than serial ones.WorkerObjWrapper提供了一个方便的方法使数据持久化一个工人;这可能是大数组,连接数据库或其他的事情,我们需要在每个迭代的parfor循环。

让我们看看它的实际效果

我们要把一些财务数据雅虎使用的连接数据处理工具箱

我有一个列表的证券和相应的字段我想从他们:

% Securities and desired fields证券= {“3”,'PG','MSFT',“山姆”,“厂商”,“yahoo”,“发生”,“光芒四射”};字段= {“高”,{“低”,“高”},“高”,“高”,{“低”,“高”},“低”,{“低”,“体积”},“低”};

First I want to make sure there is an open parallel pool (parpool)分配计算。我有一个两个核心的笔记本电脑,所以我将开放两个当地工人通过选择底部的图标桌面的左手边。

我写三个等效函数将价格从雅虎

  • fetchFOR——使用一个正则循环获取价格
  • fetchPARFOR——使用一个并行循环
  • fetchWOWPARFOR- USES a parallel the for loop and WorkerObjWrapper - to make the connection on all workers.

首先,一个检查,以确保他们都做同样的事情:

ff = fetchFOR(证券、字段);fp = fetchPARFOR(证券、字段);弗兰克-威廉姆斯= fetchWOWPARFOR(证券、字段);断言(isequal (ff、fp fw));%如果他们不等于错误

自主张通过,这意味着函数返回相同的结果,我们现在可以做计时。我将使用timeit

t = 0 (3,1);%测量时间T (1) = timeit (@ () fetchFOR (securities, fields), 1);T (2) = timeit (@ () fetchPARFOR (securities, fields), 1);T (3) = timeit (@ () fetchWOWPARFOR (securities, fields), 1);%显示结果流(' %。3fs %s\n't (1),'for't (2),“parfor”t (3),'parfor with WorkerObjWrapper')
8.631 4.255 5.991 s parfor年代parfor WorkerObjWrapper

所以我们可以看到,创建一旦每个工人在平行的连接池,然后使用parforGives us the best computation time.

评论

Do you have to work with large data or repeat a process multiple times where the parallel computing took a help?I 'm curious to hear your experiences and the challenges that you' ve faced.

试一试,让我们知道你的想法here或者离开The comment为我们的团队并行计算。




发表与MATLAB®R2013b

|

评论

要发表评论,请点击此处Log in to your MathWorks account or create a new account.