diff --git a/intro_lab/solutions/hello_par.c b/intro_lab/solutions/hello_par.c deleted file mode 100755 index 93ae09f475a765875b5e76593f69e42589316340..0000000000000000000000000000000000000000 --- a/intro_lab/solutions/hello_par.c +++ /dev/null @@ -1,22 +0,0 @@ -#include <stdio.h> -#include <omp.h> - -int main () -{ - int nthreads = 4; - omp_set_num_threads(nthreads); - - #pragma omp parallel - { - int id = omp_get_thread_num(); - - printf("Hello World from thread = %d", id); - printf(" with %d threads\n",omp_get_num_threads()); - } - - printf("all done, with hopefully %d threads\n",nthreads); - -} - - - diff --git a/intro_lab/solutions/hello_par.f90 b/intro_lab/solutions/hello_par.f90 deleted file mode 100755 index 5a535ef4a8df73304a65281025f68c7c28b57e70..0000000000000000000000000000000000000000 --- a/intro_lab/solutions/hello_par.f90 +++ /dev/null @@ -1,22 +0,0 @@ -program hello_par - -use omp_lib - -implicit none - -integer :: num_threads = 4 -integer thread_id - -call OMP_SET_NUM_THREADS(num_threads) - -!$omp parallel private(thread_id) - - thread_id = OMP_GET_THREAD_NUM() - - print '("Hello World from thread = ", i0, " with ", i0, " threads")', thread_id, num_threads - -!$omp end parallel - -print '("all done, with hopefully ", i0, " threads")', num_threads - -end program diff --git a/intro_lab/solutions/pi_loop.c b/intro_lab/solutions/pi_loop.c deleted file mode 100755 index 4bac3891ecc6a493e74628e93b116f3186d34203..0000000000000000000000000000000000000000 --- a/intro_lab/solutions/pi_loop.c +++ /dev/null @@ -1,65 +0,0 @@ -/* - -This program will numerically compute the integral of - - 4/(1+x*x) - -from 0 to 1. The value of this integral is pi -- which -is great since it gives us an easy way to check the answer. - -The program was parallelized using OpenMP by adding just -four lines - -(1) A line to include omp.h -- the include file that -contains OpenMP's function prototypes and constants. - -(2) A pragma that tells OpenMP to create a team of threads - -(3) A pragma to cause one of the threads to print the -number of threads being used by the program. - -(4) A pragma to split up loop iterations among the team -of threads. This pragma includes 2 clauses to (1) create a -private variable and (2) to cause the threads to compute their -sums locally and then combine their local sums into a -single global value. - -History: Written by Tim Mattson, 11/99. - -*/ -#include <stdio.h> -#include <omp.h> -static long num_steps = 100000000; -double step; -int main () -{ - int i; - double x, pi, sum = 0.0; - double start_time, run_time; - - step = 1.0/(double) num_steps; - for (i=1;i<=4;i++){ - sum = 0.0; - omp_set_num_threads(i); - start_time = omp_get_wtime(); -#pragma omp parallel -{ -#pragma omp single - printf(" num_threads = %d",omp_get_num_threads()); - -#pragma omp for private(x) reduction(+:sum) - for (i=1;i<= num_steps; i++){ - x = (i-0.5)*step; - sum = sum + 4.0/(1.0+x*x); - } -} - pi = step * sum; - run_time = omp_get_wtime() - start_time; - printf("\n pi is %f in %f seconds and %d threads\n",pi,run_time,i); -} -} - - - - - diff --git a/intro_lab/solutions/pi_loop.f90 b/intro_lab/solutions/pi_loop.f90 deleted file mode 100755 index 286da8535e179eebc7d872625be114e741e92098..0000000000000000000000000000000000000000 --- a/intro_lab/solutions/pi_loop.f90 +++ /dev/null @@ -1,56 +0,0 @@ -! This program will numerically compute the integral of -! -! 4/(1+x*x) -! -! from 0 to 1. The value of this integral is pi -- which -! is great since it gives us an easy way to check the answer. - -program calc_pi - -use omp_lib - -implicit none - -integer, parameter :: MAX_THREADS = 4 - -integer(kind=8) :: num_steps = 100000000 - -real(kind=8) step - -integer i, num_threads -real(kind=8) x, pi, raw_sum -real(kind=8) start_time, run_time - -step = 1.0D0 / num_steps - -do num_threads = 1, MAX_THREADS - - call OMP_SET_NUM_THREADS(num_threads) - start_time = OMP_GET_WTIME() - - raw_sum = 0.0D0 - - !$omp parallel - - !$omp single - print '(" num_threads = ", i0)', num_threads - !$omp end single - - !$omp do private(x) reduction(+:raw_sum) - do i = 1, num_steps - x = (i-0.5D0)*step - raw_sum = raw_sum + 4.0D0/(1.0D0+x*x) - enddo - !$omp end do - - !$omp end parallel - - pi = step * raw_sum - - run_time = OMP_GET_WTIME() - start_time - print '(" pi is ", f12.6, " in ", f12.6, " seconds and ", i0, " threads. Error = ", e15.6)', & - pi, run_time, num_threads, abs(3.14159265358979323846D0 - pi) - -enddo - -end program diff --git a/intro_lab/solutions/pi_spmd_final.c b/intro_lab/solutions/pi_spmd_final.c deleted file mode 100755 index 59901fc3456d9b6f6e92e9f1e606ec40b43b5439..0000000000000000000000000000000000000000 --- a/intro_lab/solutions/pi_spmd_final.c +++ /dev/null @@ -1,94 +0,0 @@ -/* - -NAME: PI SPMD final version without false sharing - -This program will numerically compute the integral of - - 4/(1+x*x) - -from 0 to 1. The value of this integral is pi -- which -is great since it gives us an easy way to check the answer. - -The program was parallelized using OpenMP and an SPMD -algorithm. The following OpenMP specific lines were -added: - -(1) A line to include omp.h -- the include file that -contains OpenMP's function prototypes and constants. - -(2) A pragma that tells OpenMP to create a team of threads -with an integer variable i being created for each thread. - -(3) two function calls: one to get the thread ID (ranging -from 0 to one less than the number of threads), and the other -returning the total number of threads. - -(4) A "single" construct so only one thread prints the number -of threads. - -(5) A cyclic distribution of the loop by changing loop control -expressions to run from the thread ID incremented by the number -of threads. Local sums accumlated into sum[id]. - -(6) A barrier to make sure everyone's done. - -(7) A single construct so only one thread combines the local -sums into a single global sum. - -Note that this program avoids the false sharing problem -by storing partial sums into a private scalar. - -History: Written by Tim Mattson, 11/99. - -*/ - -#include <stdio.h> -#include <omp.h> - -#define MAX_THREADS 4 - -static long num_steps = 100000000; -double step; -int main () -{ - int i,j; - double pi, full_sum = 0.0; - double start_time, run_time; - double sum[MAX_THREADS]; - - step = 1.0/(double) num_steps; - - -for(j=1;j<=MAX_THREADS ;j++){ - omp_set_num_threads(j); - full_sum = 0.0; - start_time = omp_get_wtime(); -#pragma omp parallel private(i) -{ - int id = omp_get_thread_num(); - int numthreads = omp_get_num_threads(); - double x; - - double partial_sum = 0; - -#pragma omp single - printf(" num_threads = %d",numthreads); - - for (i=id;i< num_steps; i+=numthreads){ - x = (i+0.5)*step; - partial_sum += + 4.0/(1.0+x*x); - } -#pragma omp critical - full_sum += partial_sum; -} - - pi = step * full_sum; - run_time = omp_get_wtime() - start_time; - printf("\n pi is %f in %f seconds %d threds \n ",pi,run_time,j); -} -} - - - - - diff --git a/intro_lab/solutions/pi_spmd_final.f90 b/intro_lab/solutions/pi_spmd_final.f90 deleted file mode 100755 index 571a32dd0bcdb9441f48210db5785fb8dc890083..0000000000000000000000000000000000000000 --- a/intro_lab/solutions/pi_spmd_final.f90 +++ /dev/null @@ -1,66 +0,0 @@ -! NAME: PI SPMD final version without false sharing -! -! This program will numerically compute the integral of -! -! 4/(1+x*x) -! -! from 0 to 1. The value of this integral is pi -- which -! is great since it gives us an easy way to check the answer. -! -! The program was parallelized using OpenMP and an SPMD -! algorithm. - -program calc_pi - -use omp_lib - -implicit none - -integer, parameter :: MAX_THREADS = 4 - -integer(kind=8) :: num_steps = 100000000 -real(kind=8) step - -integer i, num_threads -real(kind=8) pi, full_sum, partial_sum -real(kind=8) start_time, run_time - -integer thread_id -real(kind=8) x - -step = 1.0D0 / num_steps - -do num_threads = 1, MAX_THREADS - - call OMP_SET_NUM_THREADS(num_threads) - start_time = OMP_GET_WTIME() - full_sum = 0.0D0 - - !$omp parallel private(thread_id, partial_sum, i, x) - - thread_id = OMP_GET_THREAD_NUM() + 1 - partial_sum = 0.0D0 - - !$omp single - print '(" num_threads = ", i0)', num_threads - !$omp end single - - do i = thread_id, num_steps, num_threads - x = (i-0.5D0)*step - partial_sum = partial_sum + 4.0D0/(1.0D0+x*x) - enddo - - !$omp critical - full_sum = full_sum + partial_sum - !$omp end critical - - !$omp end parallel - - pi = step * full_sum - run_time = OMP_GET_WTIME() - start_time - print '(" pi is ", f12.6, " in ", f12.6, " seconds and ", i0, " threads. Error = ", e15.6)', & - pi, run_time, num_threads, abs(3.14159265358979323846D0 - pi) - -enddo - -end program diff --git a/intro_lab/solutions/pi_spmd_simple.c b/intro_lab/solutions/pi_spmd_simple.c deleted file mode 100755 index ba0fe2c9e65829163028839b09f76644897cd4e6..0000000000000000000000000000000000000000 --- a/intro_lab/solutions/pi_spmd_simple.c +++ /dev/null @@ -1,92 +0,0 @@ -/* - -NAME: PI SPMD ... a simple version. - -This program will numerically compute the integral of - - 4/(1+x*x) - -from 0 to 1. The value of this integral is pi -- which -is great since it gives us an easy way to check the answer. - -The program was parallelized using OpenMP and an SPMD -algorithm. The following OpenMP specific lines were -added: - -(1) A line to include omp.h -- the include file that -contains OpenMP's function prototypes and constants. - -(2) A pragma that tells OpenMP to create a team of threads -with an integer variable i being created for each thread. - -(3) two function calls: one to get the thread ID (ranging -from 0 to one less than the number of threads), and the other -returning the total number of threads. - -(4) A cyclic distribution of the loop by changing loop control -expressions to run from the thread ID incremented by the number -of threads. Local sums accumlated into sum[id]. - -Note that this program will show low performance due to -false sharing. In particular, sum[id] is unique to each -thread, but adfacent values of this array share a cache line -causing cache thrashing as the program runs. - -History: Written by Tim Mattson, 11/99. - -*/ - -#include <stdio.h> -#include <omp.h> - -#define MAX_THREADS 4 - -static long num_steps = 100000000; -double step; -int main () -{ - int i,j; - double pi, full_sum = 0.0; - double start_time, run_time; - double sum[MAX_THREADS]; - - step = 1.0/(double) num_steps; - - - for (j=1;j<=MAX_THREADS ;j++) { - - omp_set_num_threads(j); - full_sum=0.0; - start_time = omp_get_wtime(); - - #pragma omp parallel - { - int i; - int id = omp_get_thread_num(); - int numthreads = omp_get_num_threads(); - double x; - - sum[id] = 0.0; - - if (id == 0) - printf(" num_threads = %d",numthreads); - - for (i=id;i< num_steps; i+=numthreads){ - x = (i+0.5)*step; - sum[id] = sum[id] + 4.0/(1.0+x*x); - } - } - - for(full_sum = 0.0, i=0;i<j;i++) - full_sum += sum[i]; - - pi = step * full_sum; - run_time = omp_get_wtime() - start_time; - printf("\n pi is %f in %f seconds %d thrds \n",pi,run_time,j); - } -} - - - - - diff --git a/intro_lab/solutions/pi_spmd_simple.f90 b/intro_lab/solutions/pi_spmd_simple.f90 deleted file mode 100755 index eb87ddf8206edc483083f1ec6ea8bc28f095575f..0000000000000000000000000000000000000000 --- a/intro_lab/solutions/pi_spmd_simple.f90 +++ /dev/null @@ -1,67 +0,0 @@ -! NAME: PI SPMD ... a simple version. -! -! This program will numerically compute the integral of -! -! 4/(1+x*x) -! -! from 0 to 1. The value of this integral is pi -- which -! is great since it gives us an easy way to check the answer. -! -! The program was parallelized using OpenMP and an SPMD -! algorithm. - -program calc_pi - -use omp_lib - -implicit none - -integer, parameter :: MAX_THREADS = 4 - -integer(kind=8) :: num_steps = 100000000 -real(kind=8) step - -integer i, num_threads -real(kind=8) pi, full_sum -real(kind=8) start_time, run_time -real(kind=8), dimension(1:MAX_THREADS) :: partial_sum - -integer thread_id -real(kind=8) x - -step = 1.0D0 / num_steps - -do num_threads = 1, MAX_THREADS - - call OMP_SET_NUM_THREADS(num_threads) - start_time = OMP_GET_WTIME() - - !$omp parallel private(thread_id, i, x) - - thread_id = OMP_GET_THREAD_NUM() + 1 - partial_sum(thread_id) = 0.0D0 - - if (thread_id == 1) then - print '(" num_threads = ", i0)', num_threads - endif - - do i = thread_id, num_steps, num_threads - x = (i-0.5D0)*step - partial_sum(thread_id) = partial_sum(thread_id) + 4.0D0/(1.0D0+x*x) - enddo - - !$omp end parallel - - full_sum = 0.0 - do thread_id = 1, num_threads - full_sum = full_sum + partial_sum(thread_id) - enddo - - pi = step * full_sum - run_time = OMP_GET_WTIME() - start_time - print '(" pi is ", f12.6, " in ", f12.6, " seconds and ", i0, " threads. Error = ", e15.6)', & - pi, run_time, num_threads, abs(3.14159265358979323846D0 - pi) - -enddo - -end program diff --git a/intro_lab/solutions/solutions.zip b/intro_lab/solutions/solutions.zip deleted file mode 100644 index 167225807dd6e5b5299f25763759f01bf22517c8..0000000000000000000000000000000000000000 Binary files a/intro_lab/solutions/solutions.zip and /dev/null differ