繁体   English   中英

ipython并行中的异步求值

[英]Asynchronous evaluation in ipython parallel

自从1.0.0版发布以来,我一直在使用iPython并行接口。 我正在尝试做的是建立一个异步随机梯度下降系统。 我的看法是,我想向所有节点发送一个函数,并在它们出来时得到结果。 从我能够实现的内容和文档中看,实现的标准视图并不能真正支持这一点。 get(timeout)方法可以做到这一点,但是您实际上不能使用超时循环遍历<ASync_result>对象中的每个条目。 我设法使其运行的方法如下

c = Client()
calls = []
for i,j in enumerate(args):
    calls.append( c[ i % len( c.ids ) ].apply( f, j ) )

while condition:
    dels = []
    for i,j in enumerate( calls ):
         try:
             print j.get(0.01) #or some other timeout
             dels.append( i ) #I keep track of the calls that have been called
             #do something with the last result, throw a new call
             calls.append( c[ i % len(c.ids) ].apply( f, argument )
         except:
             pass

    for i,d in enumerate( dels ):
         del calls[ d - i ] #delete gotten calls

    #evaluate stopping condition

现在,在大家大声疾呼这是可怕的代码和愚蠢的做法之前,我知道这一点。 我可以使这种特殊的方法做得更好,但是我只是想知道在IPython.parallel中是否有某种内置的方法来做类似的事情。

在此先感谢您抽出宝贵的时间。

最好,Al。

您可以创建多个异步调用,然后遍历它们。

c = Client()
dview = c[:]
asyncs = [dview.map_async(f, [arg]) for arg in args]
while asyncs:
    for async in asyncs[:]:
        if async.ready():
            asyncs.remove(async)
            print async.result[0]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM