-
Notifications
You must be signed in to change notification settings - Fork 121
Expand file tree
/
Copy pathmain.py
More file actions
83 lines (57 loc) · 1.6 KB
/
Copy pathmain.py
File metadata and controls
83 lines (57 loc) · 1.6 KB
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
70
71
72
73
74
75
76
77
78
79
80
import multiprocessing
from multiprocessing import Process
from ref import *
import logging
import os
import psutil
# для допа
# def rand_matr():
# rand_sp = []
# rand_sp2 = []
# matr1 = []
# matr2 = []
# for i in range(n*n):
# rand_sp.append(random.randint(1,100))
# rand_sp2.append(random.randint(1,100))
# for i in range(0, len(rand_sp), n):
# matr1.append(rand_sp[i:i + n])
# for i in range(0, len(rand_sp2), n):
# matr2.append(rand_sp2[i:i + n])
# return (matr1,matr2)
res = 0
def element(index, A, B, conn):
global res
i, j = index
res = 0
N = len(A[0]) or len(B)
for k in range(N):
res += A[i][k] * B[k][j]
conn.send(res)
if __name__ == '__main__':
global v
global p1
if v == 3:
inds = [(0, 0), (0, 1),(1, 0),(1, 1)]
elif v == 4:
inds = [(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2), (2, 0), (2, 1), (2, 2)]
procs = []
res = 0
fin = []
l_end, r_end = multiprocessing.Pipe()
for index, number in enumerate(inds):
p1 = Process(target=element, args=(number, mat1, mat2, r_end))
procs.append(p1)
p1.start()
res = l_end.recv()
fin.append(res)
logging.basicConfig(filename='/Users/Aram/Desktop/matrx.log', level=logging.INFO,
format='%(asctime)s - %(message)s')
logging.info(f'{res}')
for p1 in procs:
p1.join()
sp = []
for i in range(0, len(fin), n):
sp.append(fin[i:i + n])
print(sp)
f1 = open('neww.txt', 'w')
f1.write(str(sp))