Task 5, 5* some fixes and cleanup

This commit is contained in:
Markus Schmidt 2025-12-09 23:33:08 +01:00
commit c8bf307391
154 changed files with 214851 additions and 93 deletions

View file

@ -10,7 +10,7 @@
#include <cmath>
using namespace std;
void benchmark(vector<double> &x, vector<double> &y, unsigned int N, unsigned int NLOOPS)
void benchmark(vector<double> &x, vector<double> &y, unsigned int NLOOPS)
{
double sk = 0.0;
for (int i = 0; i < NLOOPS; ++i)
@ -92,8 +92,7 @@ int main(int argc, char const *argv[])
for (int i = 0; i < NLOOPS; ++i)
{
sk = scalar(x, y);
sk = scalar_trans(x, y);
//sk = norm(x);
sk = norm(x);
}
double t1 = omp_get_wtime() - tstart; // OpenMP
@ -124,7 +123,7 @@ int main(int argc, char const *argv[])
cout << "done\n";
cout << vr << endl;
N=2;
N=200;
//Data (re-)inizialiion
for (unsigned int i = 0; i < N; ++i)
{
@ -147,9 +146,9 @@ int main(int argc, char const *argv[])
omp_set_schedule(omp_sched_static, 0);
tstart = omp_get_wtime();
benchmark(x, y, N, NLOOPS);
t1 = omp_get_wtime()/NLOOPS;
cout << "static (chunk 0) "<< (t1-tstart) << endl;
benchmark(x, y, NLOOPS);
t1 = (omp_get_wtime()-tstart)/NLOOPS;
cout << "static (chunk 0) "<< t1 << endl;
for(int i=0; i<= 5; i++)
{
@ -159,30 +158,30 @@ int main(int argc, char const *argv[])
// STATIC
omp_set_schedule(omp_sched_static, chunk);
tstart = omp_get_wtime();
benchmark(x, y, N, NLOOPS);
t1 = omp_get_wtime()/NLOOPS;
std::cout << "static: " << (t1 - tstart) << " s\n";
benchmark(x, y, NLOOPS);
t1 = (omp_get_wtime()-tstart)/NLOOPS;
std::cout << "static: "<< t1 << " s\n";
// DYNAMIC
omp_set_schedule(omp_sched_dynamic, chunk);
tstart = omp_get_wtime();
benchmark(x, y, N, NLOOPS);
t1 = omp_get_wtime()/NLOOPS;
std::cout << "dynamic: " << (t1 - tstart) << " s\n";
benchmark(x, y, NLOOPS);
t1 = (omp_get_wtime()-tstart)/NLOOPS;
std::cout << "dynamic: "<< t1 << " s\n";
// GUIDED
omp_set_schedule(omp_sched_guided, chunk);
tstart = omp_get_wtime();
benchmark(x, y, N, NLOOPS);
t1 = omp_get_wtime()/NLOOPS;
std::cout << "guided: " << (t1 - tstart) << " s\n";
benchmark(x, y, NLOOPS);
t1 = (omp_get_wtime()-tstart)/NLOOPS;
std::cout << "guided: "<< t1 << " s\n";
// AUTO
omp_set_schedule(omp_sched_auto, chunk);
tstart = omp_get_wtime();
benchmark(x, y, N, NLOOPS);
t1 = omp_get_wtime()/NLOOPS;
std::cout << "auto: " << (t1 - tstart) << " s\n";
benchmark(x, y, NLOOPS);
t1 = (omp_get_wtime()-tstart)/NLOOPS;
std::cout << "auto: "<< t1 << " s\n";
cout << endl;
}
cout << endl;
@ -194,7 +193,9 @@ int main(int argc, char const *argv[])
vector<int> vec = reduction_vec_append(N);
for(int i=0; i< N; i++)
unsigned int n = vec.size();
cout << "vec.size() = " << n << "\n";
for(int i=0; i< n; i++)
{
cout << vec[i] << ", ";
}