Main.cpp wurde angepasst
This commit is contained in:
parent
bedc65ed34
commit
6d084c7d88
@ -5,9 +5,9 @@
|
||||
#include <chrono>
|
||||
#include <omp.h>
|
||||
|
||||
// =====================
|
||||
|
||||
// Matrizen erzeugen
|
||||
// =====================
|
||||
|
||||
void generateRandomMatrices(int n,
|
||||
std::vector<std::vector<double>>& A,
|
||||
std::vector<std::vector<double>>& B,
|
||||
@ -28,9 +28,9 @@ void generateRandomMatrices(int n,
|
||||
}
|
||||
}
|
||||
|
||||
// =====================
|
||||
|
||||
// Serielle Multiplikation
|
||||
// =====================
|
||||
|
||||
std::vector<std::vector<double>> matmul_serial(const std::vector<std::vector<double>>& A,
|
||||
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;
|
||||
}
|
||||
|
||||
// =====================
|
||||
|
||||
// Parallele Zeilenzerlegung
|
||||
// =====================
|
||||
|
||||
std::vector<std::vector<double>> matmul_row_parallel(const std::vector<std::vector<double>>& A,
|
||||
const std::vector<std::vector<double>>& B,
|
||||
int numThreads)
|
||||
@ -72,9 +72,9 @@ std::vector<std::vector<double>> matmul_row_parallel(const std::vector<std::vect
|
||||
return C;
|
||||
}
|
||||
|
||||
// =====================
|
||||
|
||||
// Parallele Spaltenzerlegung
|
||||
// =====================
|
||||
|
||||
std::vector<std::vector<double>> matmul_col_parallel(const std::vector<std::vector<double>>& A,
|
||||
const std::vector<std::vector<double>>& B,
|
||||
int numThreads)
|
||||
@ -96,9 +96,9 @@ std::vector<std::vector<double>> matmul_col_parallel(const std::vector<std::vect
|
||||
return C;
|
||||
}
|
||||
|
||||
// =====================
|
||||
|
||||
// Parallele Blockzerlegung
|
||||
// =====================
|
||||
|
||||
std::vector<std::vector<double>> matmul_block_parallel(const std::vector<std::vector<double>>& A,
|
||||
const std::vector<std::vector<double>>& B,
|
||||
int blockSize,
|
||||
@ -123,9 +123,9 @@ std::vector<std::vector<double>> matmul_block_parallel(const std::vector<std::ve
|
||||
return C;
|
||||
}
|
||||
|
||||
// =====================
|
||||
|
||||
// Main
|
||||
// =====================
|
||||
|
||||
int main()
|
||||
{
|
||||
int N = 500; // Matrixgröße anpassen
|
||||
@ -135,25 +135,25 @@ int main()
|
||||
std::vector<std::vector<double>> A, B;
|
||||
generateRandomMatrices(N, A, B);
|
||||
|
||||
// ---------- Seriell ----------
|
||||
// Seriell
|
||||
auto start = std::chrono::steady_clock::now();
|
||||
auto C_serial = matmul_serial(A, B);
|
||||
auto end = std::chrono::steady_clock::now();
|
||||
std::cout << "Seriell: " << std::chrono::duration<double>(end-start).count() << " s\n";
|
||||
|
||||
// ---------- Zeilenparallel ----------
|
||||
// Zeilenparallel
|
||||
start = std::chrono::steady_clock::now();
|
||||
auto C_row = matmul_row_parallel(A, B, numThreads);
|
||||
end = std::chrono::steady_clock::now();
|
||||
std::cout << "Zeilenparallel: " << std::chrono::duration<double>(end-start).count() << " s\n";
|
||||
|
||||
// ---------- Spaltenparallel ----------
|
||||
// Spaltenparallel
|
||||
start = std::chrono::steady_clock::now();
|
||||
auto C_col = matmul_col_parallel(A, B, numThreads);
|
||||
end = std::chrono::steady_clock::now();
|
||||
std::cout << "Spaltenparallel: " << std::chrono::duration<double>(end-start).count() << " s\n";
|
||||
|
||||
// ---------- Blockparallel ----------
|
||||
// Blockparallel
|
||||
start = std::chrono::steady_clock::now();
|
||||
auto C_block = matmul_block_parallel(A, B, blockSize, numThreads);
|
||||
end = std::chrono::steady_clock::now();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user