hey
This commit is contained in:
63
.vscode/settings.json
vendored
Normal file
63
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
{
|
||||
"files.associations": {
|
||||
"fstream": "cpp",
|
||||
"iosfwd": "cpp",
|
||||
"atomic": "cpp",
|
||||
"bit": "cpp",
|
||||
"cctype": "cpp",
|
||||
"charconv": "cpp",
|
||||
"chrono": "cpp",
|
||||
"clocale": "cpp",
|
||||
"cmath": "cpp",
|
||||
"compare": "cpp",
|
||||
"concepts": "cpp",
|
||||
"cstddef": "cpp",
|
||||
"cstdint": "cpp",
|
||||
"cstdio": "cpp",
|
||||
"cstdlib": "cpp",
|
||||
"cstring": "cpp",
|
||||
"ctime": "cpp",
|
||||
"cwchar": "cpp",
|
||||
"exception": "cpp",
|
||||
"format": "cpp",
|
||||
"forward_list": "cpp",
|
||||
"initializer_list": "cpp",
|
||||
"iomanip": "cpp",
|
||||
"ios": "cpp",
|
||||
"iostream": "cpp",
|
||||
"istream": "cpp",
|
||||
"iterator": "cpp",
|
||||
"limits": "cpp",
|
||||
"locale": "cpp",
|
||||
"memory": "cpp",
|
||||
"new": "cpp",
|
||||
"optional": "cpp",
|
||||
"ostream": "cpp",
|
||||
"ratio": "cpp",
|
||||
"sstream": "cpp",
|
||||
"stdexcept": "cpp",
|
||||
"streambuf": "cpp",
|
||||
"string": "cpp",
|
||||
"system_error": "cpp",
|
||||
"tuple": "cpp",
|
||||
"type_traits": "cpp",
|
||||
"typeinfo": "cpp",
|
||||
"utility": "cpp",
|
||||
"vector": "cpp",
|
||||
"xfacet": "cpp",
|
||||
"xiosbase": "cpp",
|
||||
"xlocale": "cpp",
|
||||
"xlocbuf": "cpp",
|
||||
"xlocinfo": "cpp",
|
||||
"xlocmes": "cpp",
|
||||
"xlocmon": "cpp",
|
||||
"xlocnum": "cpp",
|
||||
"xloctime": "cpp",
|
||||
"xmemory": "cpp",
|
||||
"xstring": "cpp",
|
||||
"xtr1common": "cpp",
|
||||
"xutility": "cpp",
|
||||
"stop_token": "cpp",
|
||||
"thread": "cpp"
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ def read_csv_pandas(filename):
|
||||
return df.values.flatten().astype(float) # Konvertiert in flaches NumPy-Array (float, um Fehler zu vermeiden)
|
||||
|
||||
# Daten einlesen
|
||||
data = read_csv_pandas("output.csv")
|
||||
data = read_csv_pandas("outcomes-100-1000000.csv")
|
||||
|
||||
# Plot erstellen
|
||||
plt.figure(figsize=(8, 5))
|
||||
|
||||
34
lab02/optimized.cpp
Normal file
34
lab02/optimized.cpp
Normal file
@@ -0,0 +1,34 @@
|
||||
#include "matrix.h"
|
||||
#include <cmath>
|
||||
int fib(int n)
|
||||
{
|
||||
if (n < 2)
|
||||
return n;
|
||||
|
||||
int a = 0;
|
||||
int b = 1;
|
||||
|
||||
for (int i = 2; i <= n; ++i)
|
||||
{
|
||||
int temp = a + b;
|
||||
a = b;
|
||||
b = temp;
|
||||
}
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
Matrix compute(const Matrix &s, const std::vector<int> &v)
|
||||
{
|
||||
Matrix m(s.dim());
|
||||
const int n = v.size();
|
||||
for (int j = 0; j < n; ++j)
|
||||
{
|
||||
for (int i = 0; i < n; ++i)
|
||||
{
|
||||
double val = static_cast<double>(fib(v[j] % 256));
|
||||
m(j, i) = s(j, i) * (sin(val) * tan(val) / sqrt(cos(val) + 2));
|
||||
}
|
||||
}
|
||||
return m;
|
||||
}
|
||||
1
lab02/outcomes-100-1000000.csv
Normal file
1
lab02/outcomes-100-1000000.csv
Normal file
File diff suppressed because one or more lines are too long
@@ -2,6 +2,8 @@
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <thread>
|
||||
|
||||
std::vector<double> B(1000000, 1);
|
||||
std::vector<double> C(1000000, 2);
|
||||
@@ -9,12 +11,11 @@ std::vector<double> D(1000000, 3);
|
||||
|
||||
static double ownMethod(int n) {
|
||||
std::vector<double> A(n, 0);
|
||||
|
||||
std::chrono::duration<double, std::milli> sumTime;
|
||||
for (int i = 0; i < 20; ++i) {
|
||||
auto startTime = std::chrono::system_clock::now();
|
||||
for (int i = 0; i < n; ++i) {
|
||||
A[i] = B[i] + C[i] * D[i];
|
||||
for (int j = 0; j < n; ++j) {
|
||||
A[j] = B[j] + C[j] * D[j];
|
||||
}
|
||||
// prevent the compiler from optimizing everything away
|
||||
volatile double dummy = A[0];
|
||||
@@ -25,14 +26,39 @@ static double ownMethod(int n) {
|
||||
return averageTime;
|
||||
}
|
||||
|
||||
int main() {
|
||||
static void workerThread(int start, int end) {
|
||||
std::vector<double> outcomes;
|
||||
for (int i = 100; i < 1000000; i+=10) {
|
||||
for (int i = start; i < end; i+=10) {
|
||||
outcomes.push_back(ownMethod(i));
|
||||
}
|
||||
std::ofstream MyFile("outcomes.csv");
|
||||
std::stringstream fileName;
|
||||
fileName << "outcomes-" << start << "-" << end << ".csv";
|
||||
std::ofstream MyFile(fileName.str());
|
||||
for (int j = 0; j < outcomes.size(); j++) {
|
||||
MyFile << outcomes[j] << ",";
|
||||
}
|
||||
MyFile.close();
|
||||
}
|
||||
|
||||
int main() {
|
||||
int range_start = 100;
|
||||
int range_end = 1'000'000;
|
||||
int num_threads = std::thread::hardware_concurrency(); // use system's core count
|
||||
|
||||
int total = range_end - range_start;
|
||||
int chunk_size = total / num_threads;
|
||||
|
||||
std::vector<std::thread> threads;
|
||||
|
||||
for (int i = 0; i < num_threads; ++i) {
|
||||
int start = range_start + i * chunk_size;
|
||||
int end = (i == num_threads - 1) ? range_end : start + chunk_size;
|
||||
|
||||
threads.emplace_back(workerThread, start, end);
|
||||
}
|
||||
|
||||
for (auto& t : threads) t.join();
|
||||
|
||||
std::cout << "All threads finished.\n";
|
||||
return 0;
|
||||
}
|
||||
BIN
lab02/triad_bench.exe
Normal file
BIN
lab02/triad_bench.exe
Normal file
Binary file not shown.
Reference in New Issue
Block a user