Browse Source

klasa liczaca czas + liczenie macierzy + omp

master
Piotr Dergun 8 years ago
parent
commit
27a482e8e8
2 changed files with 59 additions and 3 deletions
  1. +40
    -0
      DergunPiotr-WaskoDominik/zad1/Ttiming.h
  2. +19
    -3
      DergunPiotr-WaskoDominik/zad1/macierz_omp.cpp

+ 40
- 0
DergunPiotr-WaskoDominik/zad1/Ttiming.h View File

@ -0,0 +1,40 @@
#if !defined(DEF_TTIMING)
#define DEF_TTIMING
#include <sys/time.h>
class TTiming
{
protected:
struct timeval start;
struct timeval stop;
void getTime(timeval &tv);
public:
TTiming(void);
void Begin(void);
long End(void);
};
inline TTiming::TTiming(void)
{
}
inline void TTiming::Begin(void)
{
getTime(start);
}
inline long TTiming::End(void)
{
getTime(stop);
return ((stop.tv_sec-start.tv_sec) * 1000 + (stop.tv_usec-start.tv_usec)/1000.0) + 0.5;
}
inline void TTiming::getTime(timeval &tv)
{
gettimeofday(&tv,NULL);
}
#endif

+ 19
- 3
DergunPiotr-WaskoDominik/zad1/macierz_omp.cpp View File

@ -2,6 +2,7 @@
#include <cstdlib>
#include <cmath>
#include <omp.h>
#include "Ttiming.h"
using namespace std;
@ -37,6 +38,8 @@ int main(int argc, char *argv[])
long rozmiar=0;
char *endptr;
int threads_num=0;
TTiming tt;
long i, j;//,k;
if (argc < 3)
{
@ -89,10 +92,23 @@ int main(int argc, char *argv[])
for (long i=0; i<rozmiar; ++i)
for (long j=0; j<rozmiar; ++j)
B[i][j] = (long)(cos(j) *(i+j)) % 10; // postarac sie to zoptymalizowac!
//mnozenie macierzy - TO DO
tt.Begin();
//#pragma omp parallel for default(shared)
#pragma omp parallel for default(none) shared(A, B, C) firstprivate(rozmiar)private(i, j)
for (i=0; i<rozmiar; ++i)
for (j=0; j<rozmiar; ++j)
{
C[i][j] = 0;
for (long k=0; k<rozmiar; ++k)
C[i][j] += A[i][k]*B[k][j];
}
long elapsed = tt.End();
cout << "Time: " << elapsed << " ms" << endl;
array_destroy(A);
array_destroy(B);
array_destroy(C);

Loading…
Cancel
Save