chundoong-lab-ta/SamsungDS23/HW2/mat_mul.cpp

36 lines
828 B
C++

#include "mat_mul.h"
#include <pthread.h>
#include <immintrin.h>
static float *A, *B, *C;
static int M, N, K;
static int num_threads;
static int min(int x, int y) {
return x < y ? x : y;
}
static void* mat_mul_thread(void *data) {
int tid = (long)data;
int is = M / num_threads * tid + min(tid, M % num_threads);
int ie = M / num_threads * (tid + 1) + min(tid + 1, M % num_threads);
// TODO
return NULL;
}
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;
pthread_t threads[num_threads];
for (long i = 0; i < num_threads; ++i) {
pthread_create(&threads[i], NULL, mat_mul_thread, (void*)i);
}
for (long i = 0; i < num_threads; ++i) {
pthread_join(threads[i], NULL);
}
}