chundoong-lab-ta/SamsungDS22/HW3/mat_mul.cpp

29 lines
615 B
C++

#include "mat_mul.h"
#include <cstdlib>
#include <cstdio>
static float *A, *B, *C;
static int M, N, K;
static int num_threads;
static void mat_mul_omp() {
// TODO: parallelize & optimize matrix multiplication
#pragma omp parallel for
for (int i = 0; i < M; ++i) {
for (int j = 0; j < N; ++j) {
for (int k = 0; k < K; ++k) {
C[i * N + j] += A[i * K + k] * B[k * N + j];
}
}
}
}
void mat_mul(float *_A, float *_B, float *_C, int _M, int _N, int _K, int _num_threads) {
A = _A, B = _B, C = _C;
M = _M, N = _N, K = _K;
num_threads = _num_threads;
mat_mul_omp();
}