forked from csc-training/hpc-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
skeleton.py
70 lines (56 loc) · 1.44 KB
/
skeleton.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from mpi4py import MPI
import numpy as np
comm = MPI.COMM_WORLD
rank = comm.Get_rank()
size = comm.Get_size()
assert size == 4, 'Number of MPI tasks has to be 4.'
if rank == 0:
print('First collective:')
# TODO: create data vector at task 0 and send it to everyone else
# using collective communication
if rank == 0:
data = ...
else:
data = ...
...
print(' Task {0}: {1}'.format(rank, data))
# Prepare data vectors ..
data = ... # TODO: create the data vectors
# .. and receive buffers
buff = numpy.full(8, -1, int)
# ... wait for every rank to finish ...
comm.barrier()
if rank == 0:
print('')
print('-' * 32)
print('')
print('Data vectors:')
print(' Task {0}: {1}'.format(rank, data))
comm.barrier()
if rank == 0:
print('')
print('c)')
# TODO: how to get the desired receive buffer using a single collective
# communication routine?
...
print(' Task {0}: {1}'.format(rank, buff))
# ... wait for every rank to finish ...
buff[:] = -1
comm.barrier()
if rank == 0:
print('')
print('d)')
# TODO: how to get the desired receive buffer using a single collective
# communication routine?
...
print(' Task {0}: {1}'.format(rank, buff))
# ... wait for every rank to finish ...
buff[:] = -1
comm.barrier()
if rank == 0:
print('')
print('e)')
# TODO: how to get the desired receive buffer using a single collective
# communication routine?
...
print(' Task {0}: {1}'.format(rank, buff))