Main.cpp wurde angepasst

This commit is contained in:
Jaroslav Rotormel 2025-12-15 14:32:43 +01:00
parent bedc65ed34
commit 6d084c7d88

View File

@ -5,9 +5,9 @@
#include <chrono> #include <chrono>
#include <omp.h> #include <omp.h>
// =====================
// Matrizen erzeugen // Matrizen erzeugen
// =====================
void generateRandomMatrices(int n, void generateRandomMatrices(int n,
std::vector<std::vector<double>>& A, std::vector<std::vector<double>>& A,
std::vector<std::vector<double>>& B, std::vector<std::vector<double>>& B,
@ -28,9 +28,9 @@ void generateRandomMatrices(int n,
} }
} }
// =====================
// Serielle Multiplikation // Serielle Multiplikation
// =====================
std::vector<std::vector<double>> matmul_serial(const std::vector<std::vector<double>>& A, std::vector<std::vector<double>> matmul_serial(const std::vector<std::vector<double>>& A,
const std::vector<std::vector<double>>& B) const std::vector<std::vector<double>>& B)
{ {
@ -48,9 +48,9 @@ std::vector<std::vector<double>> matmul_serial(const std::vector<std::vector<dou
return C; return C;
} }
// =====================
// Parallele Zeilenzerlegung // Parallele Zeilenzerlegung
// =====================
std::vector<std::vector<double>> matmul_row_parallel(const std::vector<std::vector<double>>& A, std::vector<std::vector<double>> matmul_row_parallel(const std::vector<std::vector<double>>& A,
const std::vector<std::vector<double>>& B, const std::vector<std::vector<double>>& B,
int numThreads) int numThreads)
@ -72,9 +72,9 @@ std::vector<std::vector<double>> matmul_row_parallel(const std::vector<std::vect
return C; return C;
} }
// =====================
// Parallele Spaltenzerlegung // Parallele Spaltenzerlegung
// =====================
std::vector<std::vector<double>> matmul_col_parallel(const std::vector<std::vector<double>>& A, std::vector<std::vector<double>> matmul_col_parallel(const std::vector<std::vector<double>>& A,
const std::vector<std::vector<double>>& B, const std::vector<std::vector<double>>& B,
int numThreads) int numThreads)
@ -96,9 +96,9 @@ std::vector<std::vector<double>> matmul_col_parallel(const std::vector<std::vect
return C; return C;
} }
// =====================
// Parallele Blockzerlegung // Parallele Blockzerlegung
// =====================
std::vector<std::vector<double>> matmul_block_parallel(const std::vector<std::vector<double>>& A, std::vector<std::vector<double>> matmul_block_parallel(const std::vector<std::vector<double>>& A,
const std::vector<std::vector<double>>& B, const std::vector<std::vector<double>>& B,
int blockSize, int blockSize,
@ -123,9 +123,9 @@ std::vector<std::vector<double>> matmul_block_parallel(const std::vector<std::ve
return C; return C;
} }
// =====================
// Main // Main
// =====================
int main() int main()
{ {
int N = 500; // Matrixgröße anpassen int N = 500; // Matrixgröße anpassen
@ -135,25 +135,25 @@ int main()
std::vector<std::vector<double>> A, B; std::vector<std::vector<double>> A, B;
generateRandomMatrices(N, A, B); generateRandomMatrices(N, A, B);
// ---------- Seriell ---------- // Seriell
auto start = std::chrono::steady_clock::now(); auto start = std::chrono::steady_clock::now();
auto C_serial = matmul_serial(A, B); auto C_serial = matmul_serial(A, B);
auto end = std::chrono::steady_clock::now(); auto end = std::chrono::steady_clock::now();
std::cout << "Seriell: " << std::chrono::duration<double>(end-start).count() << " s\n"; std::cout << "Seriell: " << std::chrono::duration<double>(end-start).count() << " s\n";
// ---------- Zeilenparallel ---------- // Zeilenparallel
start = std::chrono::steady_clock::now(); start = std::chrono::steady_clock::now();
auto C_row = matmul_row_parallel(A, B, numThreads); auto C_row = matmul_row_parallel(A, B, numThreads);
end = std::chrono::steady_clock::now(); end = std::chrono::steady_clock::now();
std::cout << "Zeilenparallel: " << std::chrono::duration<double>(end-start).count() << " s\n"; std::cout << "Zeilenparallel: " << std::chrono::duration<double>(end-start).count() << " s\n";
// ---------- Spaltenparallel ---------- // Spaltenparallel
start = std::chrono::steady_clock::now(); start = std::chrono::steady_clock::now();
auto C_col = matmul_col_parallel(A, B, numThreads); auto C_col = matmul_col_parallel(A, B, numThreads);
end = std::chrono::steady_clock::now(); end = std::chrono::steady_clock::now();
std::cout << "Spaltenparallel: " << std::chrono::duration<double>(end-start).count() << " s\n"; std::cout << "Spaltenparallel: " << std::chrono::duration<double>(end-start).count() << " s\n";
// ---------- Blockparallel ---------- // Blockparallel
start = std::chrono::steady_clock::now(); start = std::chrono::steady_clock::now();
auto C_block = matmul_block_parallel(A, B, blockSize, numThreads); auto C_block = matmul_block_parallel(A, B, blockSize, numThreads);
end = std::chrono::steady_clock::now(); end = std::chrono::steady_clock::now();