Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- matrix multiplication
- */
- #include <omp.h>
- #include <stdio.h>
- #include <stdlib.h>
- #ifndef DEBUG
- #define printf(fmt,...) (0)
- #endif
- #ifndef MROW
- #define MROW 300
- #endif
- #ifndef MCOL
- #define MCOL 300
- #endif
- int A[MROW][MCOL];
- int B[MROW][MCOL];
- int C[MROW][MCOL];
- void printMatrix(int m[MROW][MCOL])
- {
- printf("\n");
- for (int i = 0; i < MROW; ++i)
- {
- printf("|");
- for (int j = 0; j < MCOL; ++j)
- {
- printf("%d|", m[i][j] );
- }
- printf("\n");
- }
- }
- void fillMatrix(int matrix[MROW][MCOL])
- {
- for(int i=0; i<MROW; i++)
- {
- for (int j = 0; j < MCOL; j++)
- {
- matrix[i][j]= rand()%(MCOL);
- matrix[i][j]= rand()%(MROW);
- }
- }
- }
- int main(int argc, char const *argv[])
- {
- printf("Starting with %d,%d\n",MROW,MCOL);
- fillMatrix(A);
- fillMatrix(B);
- printf("Starting multiplication\n");
- #pragma omp parallel for schedule(dynamic) collapse(2)
- for (int i = 0; i < MROW; i++)
- {
- for (int j = 0; j < MCOL; j++)
- {
- int cellResult=0;
- int k,h;
- for (k=0; k<MCOL; k++)
- {
- for(h=0; h < MROW; h++)
- {
- cellResult = cellResult + (A[i][k] * B[h][j]) ;
- }
- }
- C[i][j] = cellResult;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement