From 1c8ee8ae254bbdfa8be62be8d5d2aae14808ec3e Mon Sep 17 00:00:00 2001 From: "lisa.pizzo" Date: Thu, 4 Dec 2025 12:07:13 +0100 Subject: [PATCH] Main file - Exercise 5 --- Sheet5/mainEx5.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 Sheet5/mainEx5.cpp diff --git a/Sheet5/mainEx5.cpp b/Sheet5/mainEx5.cpp new file mode 100644 index 0000000..d713e88 --- /dev/null +++ b/Sheet5/mainEx5.cpp @@ -0,0 +1,45 @@ +// HOW TO COMPILE ON MACOS +// export CPPFLAGS="-I/opt/homebrew/opt/libomp/include" +// export LDFLAGS="-L/opt/homebrew/opt/libomp/lib" +// clang++ -std=c++17 -O3 -Xpreprocessor -fopenmp $CPPFLAGS main.cpp bench_funcs.cpp $LDFLAGS -lomp -o Ex5 +// ./Ex5 + +#include +#include +#include +#include +#include "bench_funcs.h" + +using namespace std; +using namespace std::chrono; + +int main() { + size_t n = 200000; // FEM system size + size_t maxit = 5000; + double omega = 1.0; + double tol = 1e-8; + + // show threads + #pragma omp parallel + { + #pragma omp single + cout << "Using " << omp_get_num_threads() << " OpenMP threads\n"; + } + + CSR K; + vector f, u; + + cout << "\nBuilding FEM system (parallel)\n"; + auto t0 = high_resolution_clock::now(); + build_fem_system(n, K, f); + auto t1 = high_resolution_clock::now(); + cout << "Assembly time = " << duration(t1 - t0).count() << " s\n"; + + cout << "\nRunning Jacobi solver (parallel)\n"; + t0 = high_resolution_clock::now(); + jacobi_csr_parallel(K, f, u, maxit, omega, tol); + t1 = high_resolution_clock::now(); + + cout << "Jacobi time = " << duration(t1 - t0).count() << " s\n"; + cout << "Done\n"; +}