11 int gResult
[MATRIX_SIZE
][MATRIX_SIZE
];
13 void mult_entry(void *ptr
) {
15 struct point
*deref_pt
= (struct point
*) ptr
;
17 gResult
[deref_pt
->r
][deref_pt
->c
] = matrix_multiply(deref_pt
->r
, deref_pt
->c
);
20 int main(int argc
, char* argv
[])
23 int left
[MATRIX_SIZE
][MATRIX_SIZE
];
24 int right
[MATRIX_SIZE
][MATRIX_SIZE
];
25 pthread_t threads
[100];
27 for(row
= 0; row
< MATRIX_SIZE
; ++row
)
29 for(col
= 0; col
< MATRIX_SIZE
; ++col
)
31 left
[row
][col
] = (rand() % 2) + 1;
32 right
[row
][col
] = (rand() % 3) + 1;
36 // this causes setleft and setright to operate in parallel
38 pthread_t init_thread
;
39 pthread_create(&init_thread
, NULL
,
41 void* setleft(void* arg
) { set_left(left
); return NULL
; }
46 pthread_join(init_thread
, NULL
);
49 /* change this loop to execute on 100 different threads (each thread does 1 row) */
50 for(row
= 0; row
< MATRIX_SIZE
; ++row
)
52 for(col
= 0; col
< MATRIX_SIZE
; ++col
)
55 struct point curPoint
= { row
, col
};
57 pthread_create(&threads
[(row
* 10) + col
], NULL
, mult_entry
, (void *) &curPoint
);
60 /* make the above line run in parallel */
62 print_matrix(gResult
);