ready for parralization

This commit is contained in:
2025-09-12 22:58:52 +02:00
parent cb825aec40
commit 320436ce98
14 changed files with 920 additions and 294 deletions
+42
View File
@@ -0,0 +1,42 @@
#ifndef _matmul_n_
#define _matmul_n_
#include "./utils/matrix.h"
namespace numerics{
template <typename T>
utils::Matrix<T> matmul(const utils::Matrix<T>& A, const utils::Matrix<T>& B){
if(A.cols() != B.rows()){
throw std::runtime_error("matmul: dimension mismatch");
}
const uint64_t m = A.rows();
const uint64_t n = A.cols(); // also B.rows()
const uint64_t p = B.cols();
T tmp;
utils::Matrix<T> C(m, n, T{0});
//#pragma omp parallel for collapse(2) schedule(static)
#pragma omp parallel for
for (uint64_t i = 0; i < m; ++i){
for (uint64_t j = 0; j < n; ++j){
tmp = A(i,j);
for (uint64_t k = 0; k < p; ++k){
C(i,k) += tmp * B(j,k);
}
}
}
return C;
}
} // namespace numerics
#endif // _matmul_n_