Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ff5ec85747 | ||
|
|
4bc2574c03 | ||
|
|
d3ce2aa5f8 |
No files matched your search
@@ -19,8 +19,6 @@ set(SRC_FILES
|
|||||||
${CMAKE_CURRENT_LIST_DIR}/src/main.cpp
|
${CMAKE_CURRENT_LIST_DIR}/src/main.cpp
|
||||||
${CMAKE_CURRENT_LIST_DIR}/src/gamecube.cpp
|
${CMAKE_CURRENT_LIST_DIR}/src/gamecube.cpp
|
||||||
src/gamematrix.cpp
|
src/gamematrix.cpp
|
||||||
parallel/parallel_measurements.cpp
|
|
||||||
parallel/matrizenmultiplikation.cpp
|
|
||||||
)
|
)
|
||||||
|
|
||||||
##Tom: prev: ${CMAKE_CURRENT_LIST_DIR}/linux -> now /include
|
##Tom: prev: ${CMAKE_CURRENT_LIST_DIR}/linux -> now /include
|
||||||
@@ -52,4 +50,3 @@ if (APPLE)
|
|||||||
target_link_libraries(Prog3B "-framework Cocoa")
|
target_link_libraries(Prog3B "-framework Cocoa")
|
||||||
target_link_libraries(Prog3B "-framework OpenGL")
|
target_link_libraries(Prog3B "-framework OpenGL")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
========================================================
|
||||||
|
Projekt: gamematrix (C++ Library)
|
||||||
|
Rolle: Projektleiter
|
||||||
|
Datei: requirements.txt
|
||||||
|
Datum: 3.11.2025
|
||||||
|
Team: Thomas und Co
|
||||||
|
========================================================
|
||||||
|
|
||||||
|
# ----------------------------
|
||||||
|
# 1. Projektziel
|
||||||
|
# ----------------------------
|
||||||
|
Beschreiben Sie hier kurz das Ziel des Projekts:
|
||||||
|
|
||||||
|
Ziel: Implementierung der Matrixmulitplikation, -Rotation, -Verschiebung und anschließendes Testen
|
||||||
|
|
||||||
|
# ----------------------------
|
||||||
|
# 2. Funktionale Anforderungen
|
||||||
|
# ----------------------------
|
||||||
|
Listen Sie alle Funktionen auf, die die Bibliothek bereitstellen soll.
|
||||||
|
Tragen Sie ein: Funktion, Eingabe, Ausgabe, kurze Beschreibung
|
||||||
|
|
||||||
|
| Funktion | Eingabe | Ausgabe | Kurzbeschreibung |
|
||||||
|
|---------------|------------------------------------|-----------------------|----------------------------------------|
|
||||||
|
| matmul | 4x4 Matrix A, 4x4 Matrix B | 4x4 Matrix | Multiplikation zweier Matrizen wie in Mathe gelernt
|
||||||
|
| translate | 3D Vektor | 4x4 Matrix | Verschiebung
|
||||||
|
| rot3D | Winkel in °, Rotationsachse (x/y/z)| 4x4 Matrix | Rotation
|
||||||
|
| identity (optional)| --- | 4x4 Matrix | _____________________________________ |
|
||||||
|
| _____________ | __________________________________ | ____________________ | ______________________________ |
|
||||||
|
| _____________ | __________________________________ | ____________________ | ______________________________ |
|
||||||
|
|
||||||
|
# ----------------------------
|
||||||
|
# 3. Nicht-funktionale Anforderungen
|
||||||
|
# ----------------------------
|
||||||
|
(z. B. Performance, Lesbarkeit, Wartbarkeit, Python-Kompatibilität via pybind11)
|
||||||
|
|
||||||
|
- Lesbarkeit nach Coding Guidelines: https://elearning.ohmportal.de/pluginfile.php/395279/mod_page/content/5/Coding_Guidelines.pdf
|
||||||
|
|
||||||
|
|
||||||
|
# ----------------------------
|
||||||
|
# 4. Annahmen / Einschränkungen
|
||||||
|
# ----------------------------
|
||||||
|
(z. B. alle Matrizen sind 4x4, Winkel in Grad, nur double)
|
||||||
|
|
||||||
|
- alle Matrizen sind 4x4
|
||||||
|
- Winkel in Grad
|
||||||
|
- nur double
|
||||||
|
|
||||||
|
# ----------------------------
|
||||||
|
# 5. Abnahmekriterien
|
||||||
|
# ----------------------------
|
||||||
|
Wie soll geprüft werden, dass die Anforderungen erfüllt sind?
|
||||||
|
(z. B. Unit-Tests, Beispielrotationen, Matrizenmultiplikation)
|
||||||
|
|
||||||
|
- Tests von Marco müssen fehlerfrei verlaufen
|
||||||
|
|
||||||
|
========================================================
|
||||||
|
Hinweis:
|
||||||
|
- Diese Datei wird vom Projektleiter erstellt und gepflegt.
|
||||||
|
- Jede Phase des Projekts soll hier dokumentiert werden.
|
||||||
|
========================================================
|
||||||
@@ -1,91 +0,0 @@
|
|||||||
#include <iostream>
|
|
||||||
#include <vector>
|
|
||||||
#include <chrono>
|
|
||||||
#include <omp.h>
|
|
||||||
|
|
||||||
|
|
||||||
// Funktion erzeugt zwei Matrizen A und B der Größe n x n mit Zufallswerten
|
|
||||||
void generateRandomMatrices(int n,
|
|
||||||
std::vector<std::vector<double>>& A,
|
|
||||||
std::vector<std::vector<double>>& B,
|
|
||||||
double min_val = 0.0,
|
|
||||||
double max_val = 10.0)
|
|
||||||
{
|
|
||||||
// Zufallsgenerator initialisieren
|
|
||||||
std::srand(static_cast<unsigned int>(std::time(nullptr)));
|
|
||||||
|
|
||||||
A.resize(n, std::vector<double>(n));
|
|
||||||
B.resize(n, std::vector<double>(n));
|
|
||||||
|
|
||||||
for (int i = 0; i < n; ++i)
|
|
||||||
for (int j = 0; j < n; ++j)
|
|
||||||
{
|
|
||||||
double r1 = static_cast<double>(std::rand()) / RAND_MAX; // 0..1
|
|
||||||
double r2 = static_cast<double>(std::rand()) / RAND_MAX; // 0..1
|
|
||||||
A[i][j] = min_val + r1 * (max_val - min_val);
|
|
||||||
B[i][j] = min_val + r2 * (max_val - min_val);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<std::vector<double>> matmul_serial(
|
|
||||||
const std::vector<std::vector<double>>& A,
|
|
||||||
const std::vector<std::vector<double>>& B)
|
|
||||||
{
|
|
||||||
int n = A.size();
|
|
||||||
int m = B[0].size();
|
|
||||||
int p = B.size();
|
|
||||||
|
|
||||||
std::vector<std::vector<double>> C(n, std::vector<double>(m, 0.0));
|
|
||||||
|
|
||||||
for (int i = 0; i < n; ++i)
|
|
||||||
for (int j = 0; j < m; ++j)
|
|
||||||
for (int k = 0; k < p; ++k)
|
|
||||||
C[i][j] += A[i][k] * B[k][j];
|
|
||||||
|
|
||||||
return C;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<std::vector<double>> matmul_parallel(
|
|
||||||
const std::vector<std::vector<double>>& A,
|
|
||||||
const std::vector<std::vector<double>>& B)
|
|
||||||
{
|
|
||||||
int n = A.size();
|
|
||||||
int m = B[0].size();
|
|
||||||
int p = B.size();
|
|
||||||
|
|
||||||
std::vector<std::vector<double>> C(n, std::vector<double>(m, 0.0));
|
|
||||||
|
|
||||||
#pragma omp parallel for
|
|
||||||
for (int i = 0; i < n; ++i)
|
|
||||||
for (int j = 0; j < m; ++j)
|
|
||||||
for (int k = 0; k < p; ++k)
|
|
||||||
C[i][j] += A[i][k] * B[k][j];
|
|
||||||
|
|
||||||
return C;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
int N = 500;
|
|
||||||
|
|
||||||
std::vector<std::vector<double>> A, B;
|
|
||||||
generateRandomMatrices(N, A, B);
|
|
||||||
|
|
||||||
// Serielle Version
|
|
||||||
auto start = std::chrono::high_resolution_clock::now();
|
|
||||||
auto C_serial = matmul_serial(A, B);
|
|
||||||
auto end = std::chrono::high_resolution_clock::now();
|
|
||||||
std::cout << "Serielle Laufzeit: "
|
|
||||||
<< std::chrono::duration<double>(end - start).count()
|
|
||||||
<< " Sekunden\n";
|
|
||||||
|
|
||||||
// Parallele Version
|
|
||||||
start = std::chrono::high_resolution_clock::now();
|
|
||||||
auto C_parallel = matmul_parallel(A, B);
|
|
||||||
end = std::chrono::high_resolution_clock::now();
|
|
||||||
std::cout << "Parallele Laufzeit: "
|
|
||||||
<< std::chrono::duration<double>(end - start).count()
|
|
||||||
<< " Sekunden\n";
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
File diff suppressed because it is too large.
Load diff
@@ -1,83 +0,0 @@
|
|||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <fstream>
|
|
||||||
#include <vector>
|
|
||||||
#include <thread>
|
|
||||||
#include <chrono>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
void readFile(const std::string& filename, std::vector<int>& data) {
|
|
||||||
std::ifstream file(filename);
|
|
||||||
if (!file) {
|
|
||||||
std::cerr << "Fehler: Datei '" << filename << "' konnte nicht geöffnet werden!\n";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
int v;
|
|
||||||
while (file >> v) data.push_back(v);
|
|
||||||
}
|
|
||||||
|
|
||||||
int countIncreasesSerial(const std::vector<int>& data) {
|
|
||||||
if (data.size() < 2) return 0;
|
|
||||||
int increases = 0;
|
|
||||||
for (size_t i = 1; i < data.size(); ++i)
|
|
||||||
if (data[i] > data[i - 1]) ++increases;
|
|
||||||
return increases;
|
|
||||||
}
|
|
||||||
|
|
||||||
int countIncreasesParallel(const std::vector<int>& messungen, int numThreads = 4) {
|
|
||||||
int totalComparisons = static_cast<int>(messungen.size()) - 1;
|
|
||||||
if (totalComparisons <= 0) return 0;
|
|
||||||
|
|
||||||
std::vector<int> results(numThreads, 0);
|
|
||||||
std::vector<std::thread> threads;
|
|
||||||
threads.reserve(numThreads);
|
|
||||||
|
|
||||||
int base = totalComparisons / numThreads;
|
|
||||||
int remainder = totalComparisons % numThreads;
|
|
||||||
|
|
||||||
int idx = 1;
|
|
||||||
for (int t = 0; t < numThreads; t++) {
|
|
||||||
int startIdx = idx;
|
|
||||||
int count = base + (t < remainder ? 1 : 0);
|
|
||||||
int endIdx = idx + count - 1;
|
|
||||||
idx = endIdx + 1;
|
|
||||||
|
|
||||||
if (count <= 0) {
|
|
||||||
results[t] = 0;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
threads.emplace_back([&, t, startIdx, endIdx]() {
|
|
||||||
int localCount = 0;
|
|
||||||
for (int i = startIdx; i <= endIdx; ++i)
|
|
||||||
if (messungen[i] > messungen[i - 1])
|
|
||||||
++localCount;
|
|
||||||
results[t] = localCount;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto& th : threads) th.join();
|
|
||||||
|
|
||||||
int total = 0;
|
|
||||||
for (int r : results) total += r;
|
|
||||||
return total;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
std::vector<int> messungen;
|
|
||||||
readFile("parallel/measurements.txt", messungen);
|
|
||||||
std::cout << "Gelesene Werte: " << messungen.size() << "\n";
|
|
||||||
|
|
||||||
auto t0 = std::chrono::steady_clock::now();
|
|
||||||
int s = countIncreasesSerial(messungen);
|
|
||||||
auto t1 = std::chrono::steady_clock::now();
|
|
||||||
|
|
||||||
auto p0 = std::chrono::steady_clock::now();
|
|
||||||
int p = countIncreasesParallel(messungen, 4);
|
|
||||||
auto p1 = std::chrono::steady_clock::now();
|
|
||||||
|
|
||||||
std::cout << "Seriell: " << s << " Dauer: " << std::chrono::duration<double>(t1 - t0).count() << "s\n";
|
|
||||||
std::cout << "Parallel: " << p << " Dauer: " << std::chrono::duration<double>(p1 - p0).count() << "s\n";
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
Reference in new issue
Block a user