Main file - Exercise 5
This commit is contained in:
parent
3a29f1c1a6
commit
1c8ee8ae25
1 changed files with 45 additions and 0 deletions
45
Sheet5/mainEx5.cpp
Normal file
45
Sheet5/mainEx5.cpp
Normal file
|
|
@ -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 <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";
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue