我正在尝试使用 pthreads 进行矩阵乘法,并为每行的每次计算而不是每个元素创建一个线程。假设有两个矩阵 A[M][K],B[K][N] 。我哪里错了?
int A[M][K];
int B[K][N];
int C[][];
void *runner (void *param);
struct v
{
int i;
int j;
};
pthread_t tid[M];
for (i = 0; i < M; i++) // It should create M threads
{
struct v *data = (struct v *) malloc (sizeof (struct v));
data->i = i;
data->j = j;
pthread_create (&tid[count], &attr, runner, data);
pthread_join (tid[count], NULL);
count++;
}
runner (void *param) //
{
struct v *test;
int t = 0;
test = (struct v *) param;
for (t = 0; t < K; t++) // I want to compute it for a row instead of an element
{
C[test->i][test->j] = C[test->i][test->j] + A[test->i][t] * B[t][test->j];
}
pthread_exit (0);
}