1
我想通過一個類到iPython並行執行。實際上,這段代碼會運行,但每次都會加載「時區」。這個類每個負載需要大約10s,所以這個開銷是不可接受的,除非它只發生一次,或者每個核心發生一次。 我對並行化非常陌生,現在我想知道將進口移出函數。至少我認爲這是正確的做法。傳遞類到iPython並行
from IPython import parallel
clients = parallel.Client()
lview = clients.load_balanced_view()
lview.block = True
lats = [32.21, 34.98]
lons = [109.45, -102.4]
times = ['2014-03-12T16:20:44.000000000Z', '2014-03-12T15:48:52.000000000Z']
@lview.parallel()
def f(lats, lons, times):
import sys,os
sys.path.append("../utils/") # For grabbing 'Timezone'
import Timezone as Timezone
tz = Timezone.Timezone()
# Use tz to compute local time
a = tz.compute_local_time(lats, lons, times)
return a
%time f.map(lats, lons, times)
結果:在時間(約22秒),
in sync results <function __call__ at 0x105d2db18>
CPU times: user 700 ms, sys: 232 ms, total: 932 ms
Wall time: 11.6 s
Out[15]:
[('Asia/Chongqing', '2014-03-13 00:20:44'),
('America/Chicago', '2014-03-12 10:48:52')]
結果雙如果I雙輸入數據的長度。 我怎樣才能通過tz
並讓每個核心都調用Timezone
方法。