-
Notifications
You must be signed in to change notification settings - Fork 0
/
gather-mpi-multiplication.py
37 lines (27 loc) · 917 Bytes
/
gather-mpi-multiplication.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
import time
from mpi4py import MPI
from functions import line_and_second_matrix_multiplication
from functions import get_matrix
comm = MPI.COMM_WORLD
my_rank = comm.Get_rank()
num_of_processes = comm.Get_size()
second_matrix = get_matrix(num_of_processes, 36.6)
if my_rank == 0:
first_matrix = get_matrix(num_of_processes, 1.23)
first_matrix_row = [x for x in first_matrix]
else:
first_matrix_row = None
if my_rank == 0:
time_start = time.time()
first_matrix_row = comm.scatter(first_matrix_row, root=0)
line = [my_rank, line_and_second_matrix_multiplication(
first_matrix_row, second_matrix)]
data = comm.gather(line, root=0)
if my_rank == 0:
result_matrix = [[] for i in range(0, num_of_processes)]
for row in data:
result_matrix[row[0]] = row[1]
# print(result_matrix)
if my_rank == 0:
print("Finished in %s seconds" % (time.time() - time_start))
MPI.Finalize