73 lines
2.1 KiB
C++
73 lines
2.1 KiB
C++
#include "bsp_5_2_lib.h"
|
|
#include <iostream>
|
|
#include <algorithm>
|
|
using namespace std;
|
|
// BSP 5_2
|
|
|
|
int main()
|
|
{
|
|
const string name1("data_1.txt"); // name of input file
|
|
const string name2("out.txt"); // name of output file
|
|
vector<int> v;
|
|
|
|
read_vector_from_file(name1, v);
|
|
|
|
float a, g, h, d, aex, gex, hex, dex, minvex, maxvex, control1(0);
|
|
int minvp, maxvp, control2(0);
|
|
|
|
int NLOOPS = 100000;
|
|
|
|
// testing parallel
|
|
double tstart1 = omp_get_wtime();
|
|
for(int i=0; i<NLOOPS; ++i)
|
|
{
|
|
meandevvec(v,a,g,h,d);
|
|
minmaxvec(v,minvp,maxvp);
|
|
control1 += a;
|
|
control2 += minvp;
|
|
}
|
|
double t1all = omp_get_wtime() - tstart1;
|
|
double t1 = t1all/NLOOPS;
|
|
|
|
// testing execution policies
|
|
double tstart2 = omp_get_wtime();
|
|
for(int i=0; i<NLOOPS; ++i)
|
|
{
|
|
meandevmaxminvec(v,aex,gex,hex,dex,minvex,maxvex);
|
|
control1 += aex;
|
|
control2 += minvex;
|
|
}
|
|
double t2all = omp_get_wtime() - tstart2;
|
|
double t2 = t2all/NLOOPS;
|
|
|
|
cout << "\nTiming for parallel\n";
|
|
cout << "Timing NLOOPS: " << t1all << endl;
|
|
cout << "Timing per it. (sec): " << t1 << endl;
|
|
|
|
cout << "\n\nTiming for execution policies\n";
|
|
cout << "Timing NLOOPS: " << t2all << endl;
|
|
cout << "Timing per it. (sec): " << t2 << endl;
|
|
|
|
|
|
cout << "\n\nAuswertung (parallel)" << endl;
|
|
cout << "arithmetisches Mittel: " << a << endl;
|
|
cout << "geometrisches Mittel: " << g << endl;
|
|
cout << "harmonisches Mittel: " << h << endl;
|
|
cout << "standard deviation: " << d << endl;
|
|
cout << "Minimum: " << minvp << endl;
|
|
cout << "Maximum: " << maxvp << endl;
|
|
|
|
cout << endl;
|
|
cout << "\nAuswertung (execution policies)" << endl;
|
|
cout << "arithmetisches Mittel: " << aex << endl;
|
|
cout << "geometrisches Mittel: " << gex << endl;
|
|
cout << "harmonisches Mittel: " << hex << endl;
|
|
cout << "standard deviation: " << dex << endl;
|
|
cout << "Minimum: " << minvex << endl;
|
|
cout << "Maximum: " << maxvex << endl;
|
|
|
|
vector<float> ve{a,g,h,d,minvp,maxvp};
|
|
write_vector_to_file(name2, ve);
|
|
|
|
return 0;
|
|
}
|