Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <pthread.h>
- struct poz {
- int row, col;
- };
- void *prod(void *param);
- int m, n, p;
- int A[100][100];
- int B[100][100];
- int C[100][100];
- int main(int argc, char *argv[]) {
- /// Citire
- FILE *fA = fopen(argv[1], "r");
- fscanf(fA, "%d %d", &m, &p);
- for(int i = 0; i < m; i++) {
- for(int j = 0; j < p; j++) {
- fscanf(fA, "%d", &(A[i][j]));
- }
- }
- FILE *fB = fopen(argv[2], "r");
- fscanf(fB, "%d %d", &p, &n);
- for(int i = 0; i < p; i++) {
- for(int j = 0; j < n; j++) {
- fscanf(fB, "%d", &(B[i][j]));
- }
- }
- pthread_attr_t attr;
- pthread_t workers[100][100];
- pthread_attr_init(&attr);
- for(int i = 0; i < m; i++) {
- for(int j = 0; j < n; j++) {
- poz param;
- param.row = i;
- param.col = j;
- pthread_create(&(workers[i][j]), &attr, prod, ¶m);
- }
- }
- for(int i = 0; i < m; i++) {
- for(int j = 0; j < n; j++) {
- pthread_join(&(workers[i][j]), NULL);
- }
- }
- }
- void *prod(void *param) {
- int row = (*poz)(param) -> row;
- int col = (*poz)(param) -> col;
- C[row][col] = 0;
- for(int i = 0; i < p; i++) {
- C[row][col] += A[row][p] * B[p][col];
- }
- pthread_exit(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement