Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // prir lab2.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #define LOOPS 50
- double** StworzMacierz(int rows, int columns)
- {
- double **macierz;
- macierz = (double**)malloc(rows * sizeof(double*));
- for (int i = 0; i < rows; i++)
- macierz[i] = (double*)malloc(columns * sizeof(double));
- return macierz;
- }
- int _tmain(int argc, _TCHAR* argv[])
- {
- double **macierz;
- double *v1, *v2;
- long rows = 5000, columns = 5000;
- time_t begin_t, end_t;
- long i, j, k;
- v1 = (double*)malloc(columns * sizeof(double));
- v2 = (double*)malloc(rows * sizeof(double));
- macierz = StworzMacierz(rows,columns);
- for (i = 0; i < columns; i++)
- {
- v1[i] = (double)(i / 1000.0f);
- v2[i] = (double)(i / 1000.0f);
- for ( j = 0; j < rows; j++ )
- macierz[j][i] = (double)(i * j / 1000.0f);
- }
- begin_t = time(NULL);
- for (k = 0; k < LOOPS; k++)
- {
- #pragma omp parallel for shared(macierz, v1, v2, rows, columns) private(i, j)
- for (i = 0; i < rows; i++)
- {
- // v2[i] = 0.0f;
- for (j = 0; j < columns; j++)
- v2[i] = macierz[i][j] * v1[j];
- }
- }
- end_t = time(NULL);
- printf("Czas obliczen: %f.\n", difftime(end_t, begin_t));
- free(v1);
- free(v2);
- for (i = 0; i < rows; i++)
- free(macierz[i]);
- free(macierz);
- return 0;
- }
Advertisement