forked from Alexey/DAS_2023_1
44 lines
1.1 KiB
Python
44 lines
1.1 KiB
Python
|
from flask import Flask, render_template, request
|
||
|
import numpy as np
|
||
|
import concurrent.futures
|
||
|
|
||
|
app = Flask(__name__)
|
||
|
|
||
|
|
||
|
def multiply_matrices(matrix_a, matrix_b):
|
||
|
result = np.dot(matrix_a, matrix_b)
|
||
|
return result
|
||
|
|
||
|
|
||
|
def multiply_matrices_parallel(matrix_a, matrix_b):
|
||
|
with concurrent.futures.ThreadPoolExecutor() as executor:
|
||
|
result = executor.submit(np.dot, matrix_a, matrix_b)
|
||
|
return result.result()
|
||
|
|
||
|
|
||
|
@app.route('/')
|
||
|
def index():
|
||
|
return render_template('index.html')
|
||
|
|
||
|
|
||
|
@app.route('/multiply', methods=['POST'])
|
||
|
def multiply():
|
||
|
n = int(request.form.get('matrix_a'))
|
||
|
matrix_a = np.random.randint(10, size=(n, n))
|
||
|
matrix_b = np.random.randint(10, size=(n, n))
|
||
|
|
||
|
operation_type = request.form.get('operation_type')
|
||
|
|
||
|
if operation_type == 'sequential':
|
||
|
result = multiply_matrices(matrix_a, matrix_b)
|
||
|
elif operation_type == 'parallel':
|
||
|
result = multiply_matrices_parallel(matrix_a, matrix_b)
|
||
|
else:
|
||
|
return "Invalid operation type"
|
||
|
|
||
|
return render_template('result.html', matrix_a=matrix_a, matrix_b=matrix_b, result=result)
|
||
|
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
app.run(debug=True)
|