Skip to content

Перемножение матриц. Галоян Арам ПИ20-1 #69

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 83 additions & 16 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,83 @@


def element(index, A, B):
i, j = index
res = 0
# get a middle dimension
N = len(A[0]) or len(B)
for k in range(N):
res += A[i][k] * B[k][j]
return res


matrix1 = [[1, 2], [3, 4]]
matrix2 = [[2, 0], [1, 2]]

print(element((1, 0), matrix1, matrix2))
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))



2 changes: 2 additions & 0 deletions matrs.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[[1, 2], [3, 4]]
[[2, 2], [2, 2]]
208 changes: 208 additions & 0 deletions matrx.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
2021-11-17 23:46:53,664 - 4
2021-11-17 23:46:53,727 - 4
2021-11-17 23:46:53,789 - 10
2021-11-17 23:46:53,853 - 8
2021-11-17 23:48:33,516 - 6
2021-11-17 23:48:33,578 - 6
2021-11-17 23:48:33,640 - 14
2021-11-17 23:48:33,703 - 14
2021-11-17 23:56:08,645 - 6
2021-11-17 23:56:08,707 - 6
2021-11-17 23:56:08,768 - 14
2021-11-17 23:56:08,830 - 14
2021-11-17 23:56:59,016 - 6
2021-11-17 23:56:59,078 - 6
2021-11-17 23:56:59,144 - 14
2021-11-17 23:56:59,207 - 14
2021-11-18 02:46:51,415 - 6
2021-11-18 02:46:51,498 - 6
2021-11-18 02:46:51,561 - 14
2021-11-18 02:46:51,624 - 14
2021-11-18 02:47:07,151 - 4
2021-11-18 02:47:07,214 - 4
2021-11-18 02:47:07,276 - 10
2021-11-18 02:47:07,339 - 8
2021-11-18 02:54:51,796 - 4
2021-11-18 02:54:51,911 - 4
2021-11-18 02:54:51,974 - 10
2021-11-18 02:54:52,036 - 8
2021-11-18 02:58:11,582 - 10
2021-11-18 02:58:11,659 - 10
2021-11-18 02:58:11,722 - 20
2021-11-18 02:58:11,784 - 25
2021-11-18 02:58:11,848 - 22
2021-11-18 02:58:11,910 - 50
2021-11-18 02:58:11,974 - 40
2021-11-18 02:58:12,036 - 34
2021-11-18 02:58:12,098 - 80
2021-11-18 02:59:08,848 - 10
2021-11-18 02:59:08,933 - 10
2021-11-18 02:59:08,995 - 20
2021-11-18 02:59:09,057 - 25
2021-11-18 02:59:09,120 - 22
2021-11-18 02:59:09,185 - 50
2021-11-18 02:59:09,247 - 40
2021-11-18 02:59:09,309 - 34
2021-11-18 02:59:09,371 - 80
2021-11-18 03:15:31,638 - 10
2021-11-18 03:15:31,736 - 10
2021-11-18 03:15:31,802 - 20
2021-11-18 03:15:31,866 - 25
2021-11-18 03:15:31,928 - 22
2021-11-18 03:15:31,994 - 50
2021-11-18 03:15:32,067 - 40
2021-11-18 03:15:32,130 - 34
2021-11-18 03:15:32,194 - 80
2021-11-18 03:16:17,972 - 10
2021-11-18 03:16:18,034 - 10
2021-11-18 03:16:18,102 - 20
2021-11-18 03:16:18,165 - 25
2021-11-18 03:16:18,228 - 22
2021-11-18 03:16:18,305 - 50
2021-11-18 03:16:18,372 - 40
2021-11-18 03:16:18,436 - 34
2021-11-18 03:16:18,498 - 80
2021-11-18 03:18:38,555 - 10
2021-11-18 03:18:38,623 - 10
2021-11-18 03:18:38,685 - 20
2021-11-18 03:18:38,746 - 25
2021-11-18 03:18:38,807 - 22
2021-11-18 03:18:38,869 - 50
2021-11-18 03:18:38,935 - 40
2021-11-18 03:18:38,997 - 34
2021-11-18 03:18:39,059 - 80
2021-11-18 03:19:17,583 - 10
2021-11-18 03:19:17,658 - 10
2021-11-18 03:19:17,733 - 20
2021-11-18 03:19:17,812 - 25
2021-11-18 03:19:17,888 - 22
2021-11-18 03:19:17,965 - 50
2021-11-18 03:19:18,034 - 40
2021-11-18 03:19:18,097 - 34
2021-11-18 03:19:18,159 - 80
2021-11-18 03:24:44,787 - 10
2021-11-18 03:24:44,879 - 10
2021-11-18 03:24:44,979 - 20
2021-11-18 03:24:45,046 - 25
2021-11-18 03:24:45,112 - 22
2021-11-18 03:24:45,173 - 50
2021-11-18 03:24:45,252 - 40
2021-11-18 03:24:45,330 - 34
2021-11-18 03:24:45,406 - 80
2021-11-18 03:25:30,373 - 10
2021-11-18 03:25:30,435 - 10
2021-11-18 03:25:30,502 - 20
2021-11-18 03:25:30,583 - 25
2021-11-18 03:25:30,646 - 22
2021-11-18 03:25:30,710 - 50
2021-11-18 03:25:30,777 - 40
2021-11-18 03:25:30,840 - 34
2021-11-18 03:25:30,903 - 80
2021-11-18 03:28:37,774 - 10
2021-11-18 03:28:37,860 - 10
2021-11-18 03:28:37,955 - 20
2021-11-18 03:28:38,035 - 25
2021-11-18 03:28:38,110 - 22
2021-11-18 03:28:38,191 - 50
2021-11-18 03:28:38,260 - 40
2021-11-18 03:28:38,330 - 34
2021-11-18 03:28:38,394 - 80
2021-11-18 03:38:03,279 - 10
2021-11-18 03:38:03,367 - 10
2021-11-18 03:38:03,430 - 20
2021-11-18 03:38:03,494 - 25
2021-11-18 03:38:03,556 - 22
2021-11-18 03:38:03,630 - 50
2021-11-18 03:38:03,698 - 40
2021-11-18 03:38:03,760 - 34
2021-11-18 03:38:03,823 - 80
2021-11-18 03:44:03,142 - 10
2021-11-18 03:44:03,248 - 10
2021-11-18 03:44:03,324 - 20
2021-11-18 03:44:03,389 - 25
2021-11-18 03:44:03,581 - 22
2021-11-18 03:44:04,108 - 50
2021-11-18 03:44:04,173 - 40
2021-11-18 03:44:04,301 - 34
2021-11-18 03:44:04,364 - 80
2021-11-18 04:02:10,541 - 10
2021-11-18 04:02:10,753 - 10
2021-11-18 04:02:12,095 - 20
2021-11-18 04:02:14,478 - 25
2021-11-18 04:02:14,677 - 22
2021-11-18 04:02:14,750 - 50
2021-11-18 04:02:14,821 - 40
2021-11-18 04:02:14,956 - 34
2021-11-18 04:02:15,028 - 80
2021-11-18 04:03:26,809 - 10
2021-11-18 04:03:26,884 - 10
2021-11-18 04:03:26,956 - 20
2021-11-18 04:03:27,028 - 25
2021-11-18 04:03:27,100 - 22
2021-11-18 04:03:27,170 - 50
2021-11-18 04:03:27,242 - 40
2021-11-18 04:03:27,314 - 34
2021-11-18 04:03:27,389 - 80
2021-11-18 04:03:40,825 - 10
2021-11-18 04:03:40,958 - 10
2021-11-18 04:03:41,037 - 20
2021-11-18 04:03:41,111 - 25
2021-11-18 04:03:41,178 - 22
2021-11-18 04:03:41,254 - 50
2021-11-18 04:03:41,366 - 40
2021-11-18 04:03:41,749 - 34
2021-11-18 04:03:41,812 - 80
2021-11-18 04:04:05,326 - 10
2021-11-18 04:04:05,511 - 10
2021-11-18 04:04:05,743 - 20
2021-11-18 04:04:05,805 - 25
2021-11-18 04:04:05,870 - 22
2021-11-18 04:04:05,940 - 50
2021-11-18 04:04:06,017 - 40
2021-11-18 04:04:06,089 - 34
2021-11-18 04:04:06,159 - 80
2021-11-18 04:04:27,390 - 10
2021-11-18 04:04:27,459 - 10
2021-11-18 04:04:27,533 - 20
2021-11-18 04:04:27,595 - 25
2021-11-18 04:04:27,657 - 22
2021-11-18 04:04:27,722 - 50
2021-11-18 04:04:27,790 - 40
2021-11-18 04:04:27,852 - 34
2021-11-18 04:04:27,914 - 80
2021-11-18 04:05:05,059 - 10
2021-11-18 04:05:05,134 - 10
2021-11-18 04:05:05,200 - 20
2021-11-18 04:05:05,265 - 25
2021-11-18 04:05:05,327 - 22
2021-11-18 04:05:05,388 - 50
2021-11-18 04:05:05,453 - 40
2021-11-18 04:05:05,515 - 34
2021-11-18 04:05:05,577 - 80
2021-11-18 04:07:59,759 - 10
2021-11-18 04:08:00,042 - 10
2021-11-18 04:08:00,113 - 20
2021-11-18 04:08:00,183 - 25
2021-11-18 04:08:00,258 - 22
2021-11-18 04:08:00,328 - 50
2021-11-18 04:08:00,419 - 40
2021-11-18 04:08:00,509 - 34
2021-11-18 04:08:00,581 - 80
2021-11-18 14:36:22,323 - 10
2021-11-18 14:36:22,466 - 10
2021-11-18 14:36:22,538 - 20
2021-11-18 14:36:22,612 - 25
2021-11-18 14:36:22,688 - 22
2021-11-18 14:36:22,762 - 50
2021-11-18 14:36:22,834 - 40
2021-11-18 14:36:22,912 - 34
2021-11-18 14:36:22,986 - 80
2021-11-18 17:38:00,513 - 10
2021-11-18 17:38:00,660 - 10
2021-11-18 17:38:01,044 - 20
2021-11-18 17:38:01,121 - 25
2021-11-18 17:38:01,197 - 22
2021-11-18 17:38:01,274 - 50
2021-11-18 17:38:01,347 - 40
2021-11-18 17:38:01,420 - 34
2021-11-18 17:38:01,492 - 80
56 changes: 56 additions & 0 deletions ref.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
global v
global n

with open("matrs.txt", "r") as f:

matrix1 = f.readline().strip()
matrix2 = f.readline().strip()



f.close()


prom_1 = []
prom_2 = []
d = []
v = 0
for i in matrix1:
if i == '[':
v += 1

n = v-1

for x in matrix1:
if x.isdigit() == True:
d.append(int(x))

for i in range(0, len(d), n):
prom_1.append(d[i:i + n])

d = []

for y in matrix2:
if y.isdigit() == True:
d.append(int(y))

for i in range(0, len(d), n):
prom_2.append(d[i:i + n])





mat1 = prom_1
mat2 = prom_2