More work on parallel stuff
This commit is contained in:
parent
219570e4f1
commit
02263d602a
@ -12,7 +12,7 @@ comm = MPI.COMM_WORLD
|
||||
size = comm.Get_size()
|
||||
rank = comm.Get_rank()
|
||||
|
||||
n = 1_00
|
||||
n = 1_000
|
||||
h = 1 / (n - 1)
|
||||
|
||||
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)
|
||||
|
||||
if rank == 0:
|
||||
print(x)
|
||||
# if rank == 0:
|
||||
# print(f"ranks = {size}: x = {x}")
|
27
src/main_cg_timeit.py
Normal file
27
src/main_cg_timeit.py
Normal 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
21
src/main_diag_vec.py
Normal 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}")
|
23
src/main_diag_vec_timeit.py
Normal file
23
src/main_diag_vec_timeit.py
Normal 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
22
src/main_matrix_vec.py
Normal 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}")
|
24
src/main_matrix_vec_timeit.py
Normal file
24
src/main_matrix_vec_timeit.py
Normal 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")
|
@ -100,6 +100,9 @@ class MatrixMPI:
|
||||
"""
|
||||
return self.transpose()
|
||||
|
||||
def __str__(self):
|
||||
return str(self.__data__)
|
||||
|
||||
def __eq__(self, other):
|
||||
"""
|
||||
Return ``self==value``
|
||||
|
@ -1,7 +1,6 @@
|
||||
import math
|
||||
|
||||
import numpy
|
||||
from mpi4py import MPI
|
||||
|
||||
from matrix_mpi import MatrixMPI
|
||||
from vector import Vector
|
||||
|
Loading…
Reference in New Issue
Block a user