File tree 4 files changed +36
-0
lines changed
4 files changed +36
-0
lines changed Original file line number Diff line number Diff line change 1
1
from mpi4py import MPI
2
2
import numpy
3
+ from sys import stdout
3
4
4
5
comm = MPI .COMM_WORLD
5
6
rank = comm .Get_rank ()
31
32
(rank , len (data ), tgt ))
32
33
33
34
# ... wait for every rank to finish ...
35
+ stdout .flush ()
34
36
comm .barrier ()
35
37
if rank == 0 :
36
38
print ("" )
53
55
(rank , len (data ), tgt ))
54
56
55
57
# ... wait for every rank to finish ...
58
+ stdout .flush ()
56
59
comm .barrier ()
57
60
if rank == 0 :
58
61
print ("" )
78
81
(rank , len (data ), tgt ))
79
82
80
83
# ... wait for every rank to finish ...
84
+ stdout .flush ()
81
85
comm .barrier ()
82
86
if rank == 0 :
83
87
print ("" )
Original file line number Diff line number Diff line change 1
1
from mpi4py import MPI
2
2
import numpy
3
+ from sys import stdout
3
4
4
5
comm = MPI .COMM_WORLD
5
6
rank = comm .Get_rank ()
30
31
print (" Rank %d: received an array filled with %ds." % (rank , buff [0 ]))
31
32
32
33
# ... wait for every rank to finish ...
34
+ stdout .flush ()
33
35
comm .barrier ()
34
36
if rank == 0 :
35
37
print ("" )
51
53
print (" Rank %d: received an array filled with %ds." % (rank , buff [0 ]))
52
54
53
55
# ... wait for every rank to finish ...
56
+ stdout .flush ()
54
57
comm .barrier ()
55
58
if rank == 0 :
56
59
print ("" )
Original file line number Diff line number Diff line change 1
1
from mpi4py import MPI
2
2
import numpy
3
+ from sys import stdout
3
4
4
5
comm = MPI .COMM_WORLD
5
6
rank = comm .Get_rank ()
26
27
buff = numpy .full (8 , - 1 , int )
27
28
28
29
# ... wait for every rank to finish ...
30
+ stdout .flush ()
29
31
comm .barrier ()
30
32
if rank == 0 :
31
33
print ('' )
32
34
print ('-' * 32 )
33
35
print ('' )
34
36
print ('Data vectors:' )
35
37
print (' Task {0}: {1}' .format (rank , data ))
38
+ stdout .flush ()
36
39
comm .barrier ()
37
40
if rank == 0 :
38
41
print ('' )
44
47
45
48
# ... wait for every rank to finish ...
46
49
buff [:] = - 1
50
+ stdout .flush ()
47
51
comm .barrier ()
48
52
if rank == 0 :
49
53
print ('' )
58
62
59
63
# ... wait for every rank to finish ...
60
64
buff [:] = - 1
65
+ stdout .flush ()
61
66
comm .barrier ()
62
67
if rank == 0 :
63
68
print ('' )
Original file line number Diff line number Diff line change
1
+ from mpi4py import MPI
2
+ import numpy
3
+
4
+ comm = MPI .COMM_WORLD
5
+ rank = comm .Get_rank ()
6
+ size = comm .Get_size ()
7
+
8
+ # Send and receive buffers
9
+ n = 100000
10
+ data = numpy .full (n , rank , int )
11
+ buff = numpy .full (n , - 1 , int )
12
+
13
+ # Destination and source for messages (using PROC_NULL for out-of-bounds)
14
+ tgt = rank + 1
15
+ src = rank - 1
16
+ if tgt >= size :
17
+ tgt = MPI .PROC_NULL
18
+ if src < 0 :
19
+ src = MPI .PROC_NULL
20
+
21
+ # Use a single MPI call to do communication
22
+ comm .Sendrecv (data , dest = tgt , recvbuf = buff , source = src )
23
+ print (" Rank %d: receive buffer is filled with %ds." % (rank , buff [0 ]))
24
+
You can’t perform that action at this time.
0 commit comments