forked from Alexey/DAS_2023_1
good start3
This commit is contained in:
parent
7cd2022236
commit
325d6f9bbb
@ -10,11 +10,11 @@ def submatrix(matrix, row, col):
|
|||||||
def determinant(matrix):
|
def determinant(matrix):
|
||||||
size = len(matrix)
|
size = len(matrix)
|
||||||
|
|
||||||
# Base case: determinant of a 1x1 matrix is the only element in it
|
# Простой случай: детерминант матрицы 1x1
|
||||||
if size == 1:
|
if size == 1:
|
||||||
return matrix[0][0]
|
return matrix[0][0]
|
||||||
|
|
||||||
# Base case: determinant of a 2x2 matrix
|
# Простой случай: детерминант матрицы 2x2
|
||||||
if size == 2:
|
if size == 2:
|
||||||
return matrix[0][0] * matrix[1][1] - matrix[0][1] * matrix[1][0]
|
return matrix[0][0] * matrix[1][1] - matrix[0][1] * matrix[1][0]
|
||||||
|
|
||||||
@ -36,8 +36,8 @@ def sequential_determinant_calculation(matrix_size, lower_limit, upper_limit):
|
|||||||
result = determinant(random_matrix)
|
result = determinant(random_matrix)
|
||||||
end_time = time.time()
|
end_time = time.time()
|
||||||
|
|
||||||
print(f"Sequential determinant: {result}")
|
print(f"Последовательный детерминант: {result}")
|
||||||
print(f"Sequential time: {end_time - start_time} seconds")
|
print(f"Последовательное время: {end_time - start_time} секунд")
|
||||||
|
|
||||||
|
|
||||||
def parallel_determinant_calculation(matrix_size, lower_limit, upper_limit, num_processes):
|
def parallel_determinant_calculation(matrix_size, lower_limit, upper_limit, num_processes):
|
||||||
@ -52,19 +52,19 @@ def parallel_determinant_calculation(matrix_size, lower_limit, upper_limit, num_
|
|||||||
result = sum(((-1) ** col) * random_matrix[0][col] * det for col, det in enumerate(determinants))
|
result = sum(((-1) ** col) * random_matrix[0][col] * det for col, det in enumerate(determinants))
|
||||||
end_time = time.time()
|
end_time = time.time()
|
||||||
|
|
||||||
print(f"Parallel determinant: {result}")
|
print(f"Параллельный детерминант: {result}")
|
||||||
print(f"Parallel time: {end_time - start_time} seconds")
|
print(f"Параллельное время: {end_time - start_time} секунд")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
matrix_size = 10 # You can change this to the desired size of the matrix
|
matrix_size = 10 # размер матрицы
|
||||||
lower_limit = 10 # You can change this to the lower limit of the random numbers
|
lower_limit = 10 # числа в матрице от
|
||||||
upper_limit = 1000 # You can change this to the upper limit of the random numbers
|
upper_limit = 1000 # и до
|
||||||
num_processes = 8 # You can change this to the desired number of parallel processes
|
num_processes = 8 # число потоков
|
||||||
|
|
||||||
# Sequential calculation
|
# последовательное вычисление
|
||||||
sequential_determinant_calculation(matrix_size, lower_limit, upper_limit)
|
sequential_determinant_calculation(matrix_size, lower_limit, upper_limit)
|
||||||
|
|
||||||
# Parallel calculation
|
# параллельное вычисление
|
||||||
parallel_determinant_calculation(matrix_size, lower_limit, upper_limit, num_processes)
|
parallel_determinant_calculation(matrix_size, lower_limit, upper_limit, num_processes)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user