"Ferdig" med øving 2

This commit is contained in:
2024-03-05 10:35:30 +01:00
parent 42176e4c76
commit 7b40a4243d
7 changed files with 74 additions and 4 deletions

View File

@@ -6,7 +6,7 @@ run: $(binary)
./$(binary) 7 100000000
$(binary): $(objects)
g++ -o $@ $^
g++ -Ofast -march=native -flto -fno-signed-zeros -fno-trapping-math -o $@ $^
clean:
rm -f *.o

View File

@@ -1,6 +1,7 @@
#include <cassert>
#include <cstdlib>
#include <ctime>
#include <fstream>
#include "chain-random-walk.h"
@@ -61,6 +62,11 @@ int main(int argc, char** argv)
el_avg = el_sum / (i + 1.0);
}
crw::output(steps, size, present_configuration, extreme_configuration, el_avg);
std::ofstream myfile;
myfile.open ("elongation.csv", std::ios::app);
myfile << size << ", " << el_avg << ", " << crw::elongation(size, extreme_configuration) << "\n";
myfile.close();
delete[] present_configuration;
}

View File

@@ -0,0 +1,30 @@
import matplotlib.pyplot as plt
import matplotlib.cbook as cbook
import numpy as np
import pandas as pd
f = open('elongation.csv', 'r')
x = []
y_average = []
y_extreme = []
for l in f.readlines():
l = l.split(',')
x.append(l[0])
y_average.append(float(l[1]))
y_extreme.append(float(l[2]))
plt.plot(x, y_average, label = 'average')
plt.plot(x, y_extreme, label = 'extreme')
for i in range(len(x)):
plt.text(i,y_average[i],f'{y_average[i]:.2f}', color="blue")
for i in range(len(x)):
plt.text(i,y_extreme[i],f'{y_extreme[i]:.2f}', color="orange")
plt.title('Speedup after optimization')
plt.xlabel('N')
plt.ylabel('elongation')
plt.grid()
plt.legend()
plt.show()