Skip to content
Snippets Groups Projects
Commit 90ca39c7 authored by Xin Li's avatar Xin Li
Browse files

updated intro_lab instruction

parent d65dd711
No related branches found
No related tags found
No related merge requests found
......@@ -94,7 +94,7 @@ Questions:
- How many different ways are there to change the number of threads? Which one are those?
- How can you make the output ordered from thread 0 to thread 4?
## Exercise 2 - Creating Threads: calculate π in parallel using only pragma omp parallel
## Exercise 2 - Creating Threads: calculate π in parallel using pragma omp parallel
_Concepts: Parallel, default data environment, runtime library calls_
......@@ -213,15 +213,15 @@ Questions:
- What would happen if you hadn’t used critical or atomic a shared variable?
- How does the execution time change varying the number of threads? Is it what
you expected?
- Do the two version of the codes differ in performance? If so, what do you
think it is the reason?
- Do the two versions of the code differ in performance? If so, what do you
think is the reason?
## Exercise 4 - Calculate π with a loop and a reduction
_Concepts: worksharing, parallel loop, schedule, reduction_
Here we are going to implement a fourth parallel version of the pi.c / pi.f90
code to calculate the value of π using omp for and reduction operations.
code to calculate the value of π using ``omp for`` and ``reduction`` operations.
Instructions: Create a new parallel versions of the pi.c / pi.f90 program using
the parallel construct ``#pragma omp for`` and ``reduction`` operation. Run the new
......@@ -231,7 +231,7 @@ the execution time for 1, 2, 4, 8, 16, 32 threads.
Hints:
To change the schedule, you can either change the environment variable with
- To change the schedule, you can either change the environment variable with
``export OMP_SCHEDULE=type`` where ``type`` can be any of static, dynamic, guided or in
the source code as ``omp parallel for schedule(type)``.
......@@ -239,5 +239,5 @@ Questions:
- What is the scheduling that provides the best performance? What is the reason for that?
- What is the fastest parallel implementation of pi.c / pi.f90 program? What is
the reason for being the fastest? What would be an even faster implementation
the reason for it being the fastest? What would be an even faster implementation
of pi.c / pi.f90 program?
#include <stdio.h>
int main ()
{
int ID = 0; // thread id
int thread_id = 0;
printf("Hello World from thread %d \n", ID);
printf("Hello World from thread %d \n", thread_id);
}
......@@ -13,10 +13,13 @@ from the OpenMP runtime library
History: Written by Tim Mattson, 11/99.
*/
#include <stdio.h>
#include <omp.h>
static long num_steps = 100000000;
double step;
int main ()
{
int i;
......@@ -25,7 +28,6 @@ int main ()
step = 1.0/(double) num_steps;
start_time = omp_get_wtime();
for (i=1;i<= num_steps; i++){
......@@ -37,8 +39,3 @@ int main ()
run_time = omp_get_wtime() - start_time;
printf("\n pi with %ld steps is %lf in %lf seconds\n ",num_steps,pi,run_time);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment