Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <time.h>
- #include "omp.h"
- #include <stdlib.h>
- #include <math.h>
- using namespace std;
- int main()
- {
- int n = 2000,j,k,i;
- double** matrica1 = new double* [n];
- double** matrica2 = new double* [n];
- double** matricaFinal = new double* [n];
- double StartTime, EndTime, mflop, threads[4] = {};
- double realcpu = 0;
- for (int i = 0; i < n; i++) {
- matrica1[i] = new double[n];
- matrica2[i] = new double[n];
- matricaFinal[i] = new double[n];
- }
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < n; j++) {
- matricaFinal[i][j] = 0;
- matrica1[i][j] = (double)1;
- matrica2[i][j] = (double)2;
- }
- }
- omp_set_num_threads(4);
- StartTime = omp_get_wtime();
- #pragma omp parallel private (i,j,k)
- {
- #pragma omp for nowait
- for (int i = 0; i < n; i++) {
- for (j = 0; j < n; j++) {
- matricaFinal[i][j] = 0;
- for (k = 0; k < n; k++)
- {
- matricaFinal[i][j] += matrica1[i][k] * matrica2[k][j];
- }
- }
- }
- threads [omp_get_thread_num()] = omp_get_wtime() - StartTime;
- }
- EndTime = omp_get_wtime();
- double cputime = EndTime - StartTime;
- cout << "user cpu time" << cputime <<endl;
- for (i = 0; i < 4; i++)
- {
- cout << " kraj !! " << threads[i] << endl;
- realcpu += threads[i];
- }
- cout << "real cpu time :" << realcpu << endl;
- mflop = pow(n, 3) * 2;
- cout << "mflops" << (mflop / (cputime * 1000000)) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement