Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Xing Wang <[email protected]>
  • Loading branch information
agoscinski and superstar54 authored Sep 11, 2024
1 parent 35c4f72 commit 5497b07
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
17 changes: 9 additions & 8 deletions docs/gallery/howto/autogen/parallel_wf.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,10 @@ def add10_wg(integer):
wgs.append(wg)

# We use wait=False so we can continue submitting
wgs[0].submit(wait=False)
# we wait for the last WorkGraph to finish
wgs[0].submit() # do not wait (by default), so that we can continue to submit next WG.
wgs[1].submit(wait=True)
# we wait for all the WorkGraphs to finish
wgs[0].wait()

# %%
# We print the difference between the mtime (the time the WorkGraph has been last time changed) and the ctime (the time of creation). Since the WorkGraph's status is changed when finished, this give us a good estimate of the running time.
Expand All @@ -160,16 +161,16 @@ def add10_wg(integer):

# This graph_builder runs the add10_wg over a loop and its
@task.graph_builder()
def parallel_add(nb_it):
def parallel_add(nb_iterations):
wg = WorkGraph()
for i in range(nb_it):
for i in range(nb_iterations):
wg.add_task(add10_wg, name=f"add10_{i}", integer=i)
return wg


# Submitting a parallel that adds 10 two times to different numbers
wg = WorkGraph(f"parallel_graph_builder")
add_task = wg.add_task(parallel_add, name="parallel_add", nb_it=2)
add_task = wg.add_task(parallel_add, name="parallel_add", nb_iterations=2)
wg.submit(wait=True)


Expand All @@ -178,7 +179,7 @@ def parallel_add(nb_it):
print("Time for running with graph builder", add_task.mtime - add_task.ctime)

# %%
# We can see that the time is more than 5 seconds which means that the two additions
# We can see that the time is less than 10 seconds which means that the two additions
# were performed in parallel

# %%
Expand All @@ -197,7 +198,7 @@ def parallel_add(nb_it):
# We rerun the last graph builder for 5 iterations

wg = WorkGraph("wg_daemon_worker_1")
wg.add_task(parallel_add, name="parallel_add", nb_it=5)
wg.add_task(parallel_add, name="parallel_add", nb_iterations=5)
wg.submit(wait=True)
print(
f"Time for running with {client.get_numprocesses()['numprocesses']} worker",
Expand All @@ -214,7 +215,7 @@ def parallel_add(nb_it):
# Now we submit again and the time have shortens a bit.

wg = WorkGraph("wg_daemon_worker_2")
wg.add_task(parallel_add, name="parallel_add", nb_it=5)
wg.add_task(parallel_add, name="parallel_add", nb_iterations=5)
wg.submit(wait=True)
print(
f"Time for running with {client.get_numprocesses()['numprocesses']} worker",
Expand Down
1 change: 0 additions & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
"filename_pattern": "/*",
"examples_dirs": gallery_src_dirs, # in sphinx-gallery doc referred as gallery source
"gallery_dirs": sphinx_src_autogen_dirs, # path to where to gallery puts generated files
"run_stale_examples": True,
}

exclude_patterns = []
Expand Down

0 comments on commit 5497b07

Please sign in to comment.