DAS_2024_1/bondarenko_max_lab_5/matrix.worker.js

20 lines
548 B
JavaScript
Raw Normal View History

2024-12-13 23:51:05 +04:00
const { parentPort, workerData } = require('worker_threads');
function multiplyMatricesPart(A, B, start, end) {
const n = A.length;
const C = Array.from({ length: n }, () => Array(n).fill(0));
for (let i = start; i < end; ++i) {
for (let j = 0; j < n; ++j) {
for (let k = 0; k < n; ++k) {
C[i][j] += A[i][k] * B[k][j];
}
}
}
return C;
}
const { A, B, start, end } = workerData;
const result = multiplyMatricesPart(A, B, start, end);
parentPort.postMessage(result);