### Merge branch 'master' of gitlab.ethz.ch:hpcse_hs16/lecture

parents 3f9f1c3e c396e4f5
 // Example codes for HPC course // (c) 2012 Matthias Troyer, ETH Zurich #include "simpson.hpp" #include #include #include // The function to integrate double func(double x) { return x * std::sin(x); } int main() { double a; // lower bound of integration double b; // upper bound of integration unsigned int nsteps; // number of subintervals for integration // read the parameters std::cin >> a >> b >> nsteps; double result=0.; #pragma omp parallel shared(result) { #pragma omp sections reduction(+:result) { #pragma omp section { result = simpson(func,a,a+0.5*(b-a),nsteps/2); } #pragma omp section { result = simpson(func,a+0.5*(b-a),b,nsteps/2); } } } std::cout << result << std::endl; return 0; } \ No newline at end of file
 // Example codes for HPC course // (c) 2012 Matthias Troyer, ETH Zurich #include #include int main() { #pragma omp parallel #pragma omp single std::cout << "Only thread " << omp_get_thread_num() << " of " << omp_get_num_threads() << " is printing.\n"; return 0; }
 // Example codes for HPC course // (c) 2012 Matthias Troyer, ETH Zurich #include #include "mutex.hpp" int main() { mutex m; #pragma omp parallel for for (int i=0; i < 100; ++i) { { lock_guard lock(m); std::cout << "Hello from the " << i << "-th iteration\n"; } } }
 // Example codes for HPC course // (c) 2012 Matthias Troyer, ETH Zurich #include int main() { #pragma omp parallel for for (int i=0; i < 100; ++i) { // do some (fake) work int j=i; #pragma omp critical std::cout << "Hello from the " << j << "-th iteration\n"; } } \ No newline at end of file
 all: integral_seq integral_mt integral_seq: integral_seq.cpp g++ -Wall -O3 --std=c++11 -o integral_seq integral_seq.cpp integral_mt: integral_mt.cpp g++ -Wall -O3 --std=c++11 -pthread -o integral_mt integral_mt.cpp clean: rm -f integral_seq integral_mt