Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Stanislav Bohm
quake
Commits
bd5a998d
Commit
bd5a998d
authored
Mar 26, 2021
by
Stanislav Bohm
Browse files
A simple example added
parent
aa5a2203
Changes
2
Hide whitespace changes
Inline
Side-by-side
LICENSE
0 → 100644
View file @
bd5a998d
MIT License
Copyright (c) 2019-present, Stanislav Bohm
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
examples/twotasks/twotasks.py
0 → 100644
View file @
bd5a998d
#
# The following example submits two MPI tasks
# - The first one takes no parameters, runs on 1 node and produces 4 outputs
# - The second one runs on 4 nodes, takes a configuration (the same for each process)
# and each MPI rank gets 1 output from task 1.
#
#
# /---------------------------\
# | Task 1 (my_preprocessing) |
# |---------------------------|
# | Rank 0 |
# | Out1 Out2 Out3 Out4 |
# \---------------------------/
# | | | \----------------\
# | | | |
# | | \----------\ |
# | | | |
# | \-----\ | |
# v v v v
# /---------------------------------------\
# | Task 2 (my_computation) |
# |---------------------------------------|
# | Rank 0 | Rank 1 | Rank 0 | Rank 0 |
# \---------------------------------------/
import
quake.client
as
quake
@
quake
.
mpi_task
(
n_processes
=
1
,
n_outputs
=
4
)
def
my_preprocessing
():
# Let us produce 4 pieces of something in a simple MPI application with 1 process
return
[
"something1"
,
"something2"
,
"something3"
,
"something4"
]
@
quake
.
mpi_task
(
n_processes
=
4
)
@
quake
.
arg
(
"my_data"
,
layout
=
"scatter"
)
def
my_computation
(
my_config
,
my_data
):
# This is called in 4 MPI processes
from
mpi4py
import
MPI
comm
=
MPI
.
COMM_WORLD
rank
=
comm
.
Get_rank
()
return
"Computation at rank {}: configuration={}, data={}"
.
format
(
rank
,
my_config
,
my_data
)
# Creating a plan
data
=
my_preprocessing
()
computation
=
my_computation
(
"my_configuration"
,
data
)
# Submitting the plan & waiting for results
result
=
quake
.
gather
(
computation
)
for
i
,
r
in
enumerate
(
result
):
print
(
"Output {}: {}"
.
format
(
i
,
r
))
# The expected output:
# Output 0: Computation at rank 0: configuration=my_configuration, data=something1
# Output 1: Computation at rank 1: configuration=my_configuration, data=something2
# Output 2: Computation at rank 2: configuration=my_configuration, data=something3
# Output 3: Computation at rank 3: configuration=my_configuration, data=something4
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment