-
Notifications
You must be signed in to change notification settings - Fork 108
/
trialparallel.py
48 lines (34 loc) · 973 Bytes
/
trialparallel.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import time
from random import random
import numpy as np
from IPython.parallel import Client, depend, dependent, require
import Py6S
@require("random", "Py6S")
def run(azimuth, zenith):
s = Py6S.SixS()
s.ground_reflectance = Py6S.GroundReflectance.HomogeneousRoujean(0.037, 0.0, 0.133)
s.geometry.view_a = azimuth
s.geometry.view_z = zenith
print(zenith)
s.run()
return s.outputs.pixel_radiance
pstart = time.time()
c = Client()
lv = c.load_balanced_view()
tasks = []
azimuths = np.linspace(0, 360, 36)
zeniths = np.linspace(0, 80, 8)
for azimuth in azimuths:
for zenith in zeniths:
tasks.append(lv.apply(run, azimuth, zenith))
result = [task.get() for task in tasks]
pend = time.time()
print(result)
sstart = time.time()
res = []
for azimuth in azimuths:
for zenith in zeniths:
res.append(run(azimuth, zenith))
send = time.time()
print("Parallel %f" % (pend - pstart))
print("Serial %f" % (send - sstart))