Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <omp.h>
- #include <ctime>
- #include <fstream>
- #include <time.h>
- #include <cstdlib>
- using namespace std;
- int main()
- {
- omp_set_num_threads(8);
- srand (time(NULL));
- ofstream zapis("wynik.txt");
- int x = 750;
- int A[x][x];
- int B[x][x];
- int C[x][x];
- int c = 0;
- int i, j, k;
- int alpha = 3;
- int beta = 2;
- for(int i = 0 ; i < x ; i++) {
- for(int j = 0 ; j < x ; j++) {
- A[i][j] = rand() % 100; //liczby z zakresu 0-99
- B[i][j] = rand() % 100;
- C[i][j] = rand() % 100;
- }
- }
- double pocz = omp_get_wtime();
- #pragma omp parallel for shared(x,A,B,C) private(i,j,k,c)
- for(i = 0 ; i < x ; i++) {
- for(j = 0 ; j < x ; j++) {
- c = 0;
- for(k = 0 ; k < x ; k++) {
- c = c + A[k][i]*B[j][k];
- }
- C[j][i] = alpha*c + beta*C[j][i];
- }
- }
- double koniec = omp_get_wtime();
- cout<<"Time: "<<koniec-pocz<<endl;
- zapis<<"Time: "<<koniec-pocz<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement