LisaPizzoExercises/Sheet5/mainEx5.cpp
2025-12-04 12:07:13 +01:00

45 lines
1.2 KiB
C++

// 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 <iostream>
#include <vector>
#include <chrono>
#include <omp.h>
#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<double> 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<double>(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<double>(t1 - t0).count() << " s\n";
cout << "Done\n";
}