1
0

More work on parallel stuff

This commit is contained in:
Niklas Birk 2024-07-27 15:17:21 +02:00
parent 219570e4f1
commit 02263d602a
8 changed files with 123 additions and 4 deletions

View File

@ -12,7 +12,7 @@ comm = MPI.COMM_WORLD
size = comm.Get_size() size = comm.Get_size()
rank = comm.Get_rank() rank = comm.Get_rank()
n = 1_00 n = 1_000
h = 1 / (n - 1) h = 1 / (n - 1)
A = Matrix([-1, 2, -1], structure="tridiagonal", n=n) A = Matrix([-1, 2, -1], structure="tridiagonal", n=n)
@ -21,5 +21,5 @@ b = Vector([h**2 * 2] * n)
x = cg.cg(A, x0, b) x = cg.cg(A, x0, b)
if rank == 0: # if rank == 0:
print(x) # print(f"ranks = {size}: x = {x}")

27
src/main_cg_timeit.py Normal file
View File

@ -0,0 +1,27 @@
from mpi4py import MPI
import sys
import timeit
import cg
from matrix_mpi import MatrixMPI as Matrix
from vector_mpi import VectorMPI as Vector
# from matrix import Matrix
# from vector import Vector
comm = MPI.COMM_WORLD
size = comm.Get_size()
rank = comm.Get_rank()
n = int(sys.argv[1])
h = 1 / (n - 1)
A = Matrix([-1, 2, -1], structure="tridiagonal", n=n)
x0 = Vector([1] * n)
b = Vector([h**2 * 2] * n)
time = timeit.timeit(lambda: cg.cg(A, x0, b), number=1)
if rank == 0:
print(f"ranks = {size}: time = {time}")

21
src/main_diag_vec.py Normal file
View File

@ -0,0 +1,21 @@
from mpi4py import MPI
from matrix_mpi import MatrixMPI as Matrix
from vector_mpi import VectorMPI as Vector
# from matrix import Matrix
# from vector import Vector
comm = MPI.COMM_WORLD
size = comm.Get_size()
rank = comm.Get_rank()
n = 10_000
A = Matrix([3], structure="diagonal", offset=0, n=n)
v = Vector([7] * n)
x = A * v
# if rank == 0:
# print(f"ranks = {size}: x = {x}")

View File

@ -0,0 +1,23 @@
from mpi4py import MPI
import sys
import timeit
from matrix_mpi import MatrixMPI as Matrix
from vector_mpi import VectorMPI as Vector
# from matrix import Matrix
# from vector import Vector
comm = MPI.COMM_WORLD
size = comm.Get_size()
rank = comm.Get_rank()
n = int(sys.argv[1])
A = Matrix([3], structure="diagonal", offset=0, n=n)
v = Vector([7] * n)
time = timeit.timeit(lambda: A * v, number=1)
if rank == 0:
print(f"ranks = {size}: time = {time}s")

22
src/main_matrix_vec.py Normal file
View File

@ -0,0 +1,22 @@
from mpi4py import MPI
from matrix_mpi import MatrixMPI as Matrix
from vector_mpi import VectorMPI as Vector
# from matrix import Matrix
# from vector import Vector
comm = MPI.COMM_WORLD
size = comm.Get_size()
rank = comm.Get_rank()
n = 10_000
m_data = [(i / k) for i in range(1, n+1) for k in range(1, n+1)]
A = Matrix(m_data, (n, n))
v = Vector(list(range(1, n+1)))
x = A * v
# if rank == 0:
# print(f"ranks = {size}: x = {x}")

View File

@ -0,0 +1,24 @@
from mpi4py import MPI
import sys
import timeit
from matrix_mpi import MatrixMPI as Matrix
from vector_mpi import VectorMPI as Vector
# from matrix import Matrix
# from vector import Vector
comm = MPI.COMM_WORLD
size = comm.Get_size()
rank = comm.Get_rank()
n = int(sys.argv[1])
m_data = [(i / k) for i in range(1, n+1) for k in range(1, n+1)]
A = Matrix(m_data, (n, n))
v = Vector(list(range(1, n+1)))
time = timeit.timeit(lambda: A * v, number=1)
if rank == 0:
print(f"ranks = {size}: time = {time}s")

View File

@ -100,6 +100,9 @@ class MatrixMPI:
""" """
return self.transpose() return self.transpose()
def __str__(self):
return str(self.__data__)
def __eq__(self, other): def __eq__(self, other):
""" """
Return ``self==value`` Return ``self==value``

View File

@ -1,7 +1,6 @@
import math import math
import numpy import numpy
from mpi4py import MPI
from matrix_mpi import MatrixMPI from matrix_mpi import MatrixMPI
from vector import Vector from vector import Vector