Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <omp.h>
- #include <time.h>
- #include <stdlib.h>
- #include <string.h>
- #define N 723
- int main(void) {
- int matA[N][N], matB[N][N], matC[N][N], matC_MP[N][N];
- srand((unsigned int) time(NULL));
- for (int i = 0; i < N; i++)
- for (int j = 0; j < N; j++)
- matA[i][j] = rand() % 10;
- for (int i = 0; i < N; i++)
- for (int j = 0; j < N; j++)
- matB[i][j] = rand() % 10;
- double timer = omp_get_wtime();
- for (int i = 0; i < N; i++)
- for (int j = 0; j < N; j++) {
- matC[i][j] = 0;
- for (int k = 0; k < N; k++)
- matC[i][j] += matA[i][k] * matB[k][j];
- }
- printf("non-omp time: %.5lf\n", omp_get_wtime() - timer);
- timer = omp_get_wtime();
- #pragma omp parallel num_threads(16)
- {
- #pragma omp for ordered
- for (int i = 0; i < N; i++)
- for (int j = 0; j < N; j++) {
- int sum = 0;
- for (int k = 0; k < N; k++)
- sum += matA[i][k] * matB[k][j];
- matC_MP[i][j] = sum;
- }
- }
- printf("omp time: %.5lf\n", omp_get_wtime() - timer);
- int count = 0;
- for (int i = 0; i < N; i++)
- for (int j = 0; j < N; j++)
- if (matC[i][j] == matC_MP[i][j]) count++;
- printf("Match: %d\n", count);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement