Skip to content

Instantly share code, notes, and snippets.

@wwoods
Created August 10, 2016 17:53
Show Gist options
  • Save wwoods/f73d62b6e8599baf8670ed7365debe60 to your computer and use it in GitHub Desktop.
Save wwoods/f73d62b6e8599baf8670ed7365debe60 to your computer and use it in GitHub Desktop.
from job_stream import inline
r"""The following parallelizes:
for i in range(10):
result = 0
while result < 50:
result += i * 2
print(result)
"""
# for i in range(10):
with inline.Work(range(10)) as w:
@w.frame(emit=lambda store: store.result)
def computeBegin(store, n):
if not hasattr(store, 'init'):
store.init = True
# result = 0
store.result = 0
# while result < 50:
if store.result < 50:
return n
@w.job
def multiply2(n):
# i*2
return n*2
@w.frameEnd
def computeEnd(store, n):
# result += i*2
store.result += n
@w.job
def printResult(n):
# print(result)
print(n)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment