Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <pthread.h>
- #include <stdlib.h>
- #include <stdio.h>
- struct v
- {
- int i ; /* row */
- int j ; /* column */
- };
- #define NUM_THREADS 10
- #define M 3
- #define K 2
- #define N 3
- int A [M] [K] = {{1,4}, {2,5}, {3,6}};
- int B [K] [N] = {{8,7,6}, {5,4,3}};
- int C [M] [N] ;
- void *runner(void *param);
- int main(int argc, char* argv[]){
- pthread_t workers[NUM_THREADS];
- for (int i = 0; i < M; i++){
- for (int j = 0; j < N; j++ ){
- struct v *data = (struct v *) malloc (sizeof (struct v)) ;
- data->i = i;
- data->j = j;
- pthread_create(&workers[j + M*i], NULL, runner, data);
- //pthread_join(workers[i], NULL);
- }
- }
- for (int i = 0; i < NUM_THREADS; i++)
- pthread_join(workers[i], NULL);
- for(int i = 0; i < M; ++i){
- for(int j = 0; j < N; ++j)
- printf("%d ",C[i][j]);
- printf("\n");
- }
- return 0;
- }
- void *runner(void *param){
- struct v *data = (struct v *)param;
- for(int x = 0; x < K; ++x)
- C[data->i][data->j] += A[data->i][x] * B[x][data->j];
- pthread_exit(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement