-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathspawn_loop.py
36 lines (28 loc) · 964 Bytes
/
spawn_loop.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
"""
Calls the spawn command in spawn.py in a loop.
Run with:
mpiexec -np 4 -oversubscribe -mca btl tcp,sm,self python spawn_loop.py
"""
from mpi4py import MPI
import numpy
import sys
import time
from spawn import spawn
def main(split_into=2, nloops=3):
world = MPI.COMM_WORLD
rank = world.Get_rank()
size = world.Get_size()
if size < split_into:
raise ValueError("The number of cores passed to 'mpiexec' must be greater than the number of desired communicators.")
if rank == 0:
for i in range(nloops):
print("Iteration {}...".format(i))
args = [str(i+1)]
spawn(args, size)
if __name__ == '__main__':
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('-s', '--split_into', default=2, type=int)
parser.add_argument('-n', '--nloops', default=3, type=int)
args = parser.parse_args()
main(split_into=args.split_into, nloops=args.nloops)