@@ -18,11 +18,11 @@ def acknowledge(comm):
1818 comm .barrier ()
1919 rank = comm .Get_rank ()
2020 size = comm .Get_size ()
21- print (f'process { rank } out of { size } ' )
21+ print (f'acknowledge { rank } out of { size } ' )
2222 comm .barrier ()
2323
2424
25- def pingpong (comm , nr_iters , msg_size ):
25+ def pingpong (comm , nr_iters , msg_size , file ):
2626 comm .barrier ()
2727 rank = comm .Get_rank ()
2828 size = comm .Get_size ()
@@ -39,7 +39,8 @@ def pingpong(comm, nr_iters, msg_size):
3939 print (f'{ rank } received { msg } , expected { dest } ' ,
4040 file = sys .stderr )
4141 comm .Abort (1 )
42- print (f'{ rank } -> { dest } pingpong: { end_time - start_time } ' )
42+ print (f'pingpong { rank } -> { dest } { start_time } : '
43+ f'{ end_time - start_time } ' , file = file )
4344 if rank == dest :
4445 start_time = time .time ()
4546 msg = comm .recv (source = source )
@@ -49,11 +50,12 @@ def pingpong(comm, nr_iters, msg_size):
4950 print (f'{ rank } received { msg } , expected { source } ' ,
5051 file = sys .stderr )
5152 comm .Abort (1 )
52- print (f'{ rank } -> { source } pingpong: { end_time - start_time } ' )
53+ print (f'pingpong { rank } -> { source } { start_time } : '
54+ f'{ end_time - start_time } ' , file = file )
5355 comm .barrier ()
5456
5557
56- def broadcast (comm , nr_iters , msg_size ):
58+ def broadcast (comm , nr_iters , msg_size , file ):
5759 comm .barrier ()
5860 rank = comm .Get_rank ()
5961 size = comm .Get_size ()
@@ -65,14 +67,15 @@ def broadcast(comm, nr_iters, msg_size):
6567 start_time = time .time ()
6668 msg = comm .bcast (msg , root = root )
6769 end_time = time .time ()
68- print (f'{ root } -> { rank } bcast: { end_time - start_time } ' )
70+ print (f'bcast { root } -> { rank } { start_time } : { end_time - start_time } ' ,
71+ file = file )
6972 if msg != make_msg (root , msg_size ):
7073 print (f'{ rank } received unexpected bcast message' )
7174 comm .Abort (2 )
7275 comm .barrier ()
7376
7477
75- def scatter (comm , nr_iters , msg_size ):
78+ def scatter (comm , nr_iters , msg_size , file ):
7679 comm .barrier ()
7780 rank = comm .Get_rank ()
7881 size = comm .Get_size ()
@@ -84,14 +87,15 @@ def scatter(comm, nr_iters, msg_size):
8487 start_time = time .time ()
8588 msg = comm .scatter (msg , root = root )
8689 end_time = time .time ()
87- print (f'{ root } -> { rank } scatter: { end_time - start_time } ' )
90+ print (f'scatter { root } -> { rank } { start_time } : { end_time - start_time } ' ,
91+ file = file )
8892 if msg != make_msg (rank , msg_size ):
8993 print (f'{ rank } received unexpected scatter message' )
9094 comm .Abort (2 )
9195 comm .barrier ()
9296
9397
94- def gather (comm , nr_iters , msg_size ):
98+ def gather (comm , nr_iters , msg_size , file ):
9599 comm .barrier ()
96100 rank = comm .Get_rank ()
97101 size = comm .Get_size ()
@@ -101,7 +105,8 @@ def gather(comm, nr_iters, msg_size):
101105 start_time = time .time ()
102106 msg = comm .gather (msg , root = root )
103107 end_time = time .time ()
104- print (f'{ root } -> { rank } gather: { end_time - start_time } ' )
108+ print (f'gather { root } -> { rank } { start_time } : { end_time - start_time } ' ,
109+ file = file )
105110 if (rank == root ):
106111 if len (msg ) != size :
107112 print (f'{ rank } received unexpected gather message' )
@@ -113,7 +118,7 @@ def gather(comm, nr_iters, msg_size):
113118 comm .barrier ()
114119
115120
116- def alltoall (comm , nr_iters , msg_size ):
121+ def alltoall (comm , nr_iters , msg_size , file ):
117122 comm .barrier ()
118123 rank = comm .Get_rank ()
119124 size = comm .Get_size ()
@@ -122,7 +127,7 @@ def alltoall(comm, nr_iters, msg_size):
122127 start_time = time .time ()
123128 msg = comm .alltoall (msg )
124129 end_time = time .time ()
125- print (f'{ rank } alltoall : { end_time - start_time } ' )
130+ print (f'alltoall { rank } { start_time } : { end_time - start_time } ' , file = file )
126131 if len (msg ) != size :
127132 print (f'{ rank } received unexpected alltoall message' )
128133 comm .Abort (2 )
@@ -133,7 +138,7 @@ def alltoall(comm, nr_iters, msg_size):
133138 comm .barrier ()
134139
135140
136- def reduce (comm , nr_iters , msg_size ):
141+ def reduce (comm , nr_iters , msg_size , file ):
137142 comm .barrier ()
138143 rank = comm .Get_rank ()
139144 size = comm .Get_size ()
@@ -143,7 +148,8 @@ def reduce(comm, nr_iters, msg_size):
143148 start_time = time .time ()
144149 msg = comm .reduce (msg , op = MPI .SUM , root = root )
145150 end_time = time .time ()
146- print (f'{ root } -> { rank } reduce: { end_time - start_time } ' )
151+ print (f'reduce { root } -> { rank } { start_time } : { end_time - start_time } ' ,
152+ file = file )
147153 comm .barrier ()
148154
149155
@@ -155,6 +161,7 @@ def main():
155161 print (f'# acknowledgment' )
156162 acknowledge (comm )
157163 arg_parser = ArgumentParser (description = 'MPI performance benchmark' )
164+ arg_parser .add_argument ('file_base' , help = 'base file name for performance info' )
158165 arg_parser .add_argument ('--nr_pingpongs' , type = int , default = 10 ,
159166 help = 'number of ping-pong iterations to perform' )
160167 arg_parser .add_argument ('--pingpong_size' , type = int , default = 8 ,
@@ -180,43 +187,44 @@ def main():
180187 arg_parser .add_argument ('--reduce_size' , type = int , default = 8 ,
181188 help = 'number of bytes for reduce message' )
182189 options = arg_parser .parse_args ()
183- comm .barrier ()
184- if (rank == root ):
185- print (f'# { options .nr_pingpongs } ping-pong iterations, '
186- f'size { options .pingpong_size } ' )
187- comm .barrier ()
188- pingpong (comm , options .nr_pingpongs , options .pingpong_size )
189- comm .barrier ()
190- if (rank == root ):
191- print (f'# { options .nr_bcasts } broadcast iterations, '
192- f'size { options .bcast_size } ' )
193- comm .barrier ()
194- broadcast (comm , options .nr_bcasts , options .bcast_size )
195- comm .barrier ()
196- if (rank == root ):
197- print (f'# { options .nr_scatters } scatter iterations, '
198- f'size { options .scatter_size } ' )
199- comm .barrier ()
200- scatter (comm , options .nr_scatters , options .scatter_size )
201- comm .barrier ()
202- if (rank == root ):
203- print (f'# { options .nr_gathers } gather iterations, '
204- f'size { options .gather_size } ' )
205- comm .barrier ()
206- gather (comm , options .nr_gathers , options .gather_size )
207- comm .barrier ()
208- if (rank == root ):
209- print (f'# { options .nr_alltoalls } alltoall iterations, '
210- f'size { options .alltoall_size } ' )
211- comm .barrier ()
212- alltoall (comm , options .nr_alltoalls , options .alltoall_size )
213- comm .barrier ()
214- if (rank == root ):
215- print (f'# { options .nr_reduces } reduce iterations, '
216- f'size { options .reduce_size } ' )
217- comm .barrier ()
218- reduce (comm , options .nr_reduces , options .reduce_size )
219- comm .barrier ()
190+ with open (f'{ options .file_base } _{ rank :04d} .txt' , 'w' ) as file :
191+ comm .barrier ()
192+ if (rank == root ):
193+ print (f'# { options .nr_pingpongs } ping-pong iterations, '
194+ f'size { options .pingpong_size } ' , file = file )
195+ comm .barrier ()
196+ pingpong (comm , options .nr_pingpongs , options .pingpong_size , file )
197+ comm .barrier ()
198+ if (rank == root ):
199+ print (f'# { options .nr_bcasts } broadcast iterations, '
200+ f'size { options .bcast_size } ' , file = file )
201+ comm .barrier ()
202+ broadcast (comm , options .nr_bcasts , options .bcast_size , file )
203+ comm .barrier ()
204+ if (rank == root ):
205+ print (f'# { options .nr_scatters } scatter iterations, '
206+ f'size { options .scatter_size } ' , file = file )
207+ comm .barrier ()
208+ scatter (comm , options .nr_scatters , options .scatter_size , file )
209+ comm .barrier ()
210+ if (rank == root ):
211+ print (f'# { options .nr_gathers } gather iterations, '
212+ f'size { options .gather_size } ' , file = file )
213+ comm .barrier ()
214+ gather (comm , options .nr_gathers , options .gather_size , file )
215+ comm .barrier ()
216+ if (rank == root ):
217+ print (f'# { options .nr_alltoalls } alltoall iterations, '
218+ f'size { options .alltoall_size } ' , file = file )
219+ comm .barrier ()
220+ alltoall (comm , options .nr_alltoalls , options .alltoall_size , file )
221+ comm .barrier ()
222+ if (rank == root ):
223+ print (f'# { options .nr_reduces } reduce iterations, '
224+ f'size { options .reduce_size } ' , file = file )
225+ comm .barrier ()
226+ reduce (comm , options .nr_reduces , options .reduce_size , file )
227+ comm .barrier ()
220228 return 0
221229
222230
0 commit comments