lab2 by dandanhuanghuang

VIEWS: 6 PAGES: 2

									Uppsala University                                                                                        Programming of Parallel Computers
Department of Information Technology                                                                                             2004-11-16
Scientific Computing



                            Preparatory Computer Exercises 2
           Compiling and running OpenMP programs on a parallel computer

Getting started
1. Log in to the parallel computer Kredit by ssh kredit.it.uu.se

2. Three test programs are to be considered. The programs to test are, helloworld.c, pi.c, enumsort.cc,
   and can be downloaded from the course web-page together with a Makefile. Make a copy of all the files on the
   web-page into some of your directories.


Test 1: Running with different number of threads
1. Try the program helloworld, which is the very first step in using OpenMP. Compile by issuing the command
   make helloworld
   This will use the Makefile to build an executable file named helloworld.
   Run the program on one and more threads (processors) by setting the environment variable OMP_NUM_THREADS to
   the number of threads you want to run with. For example, export OMP_NUM_THREADS=4 (for four threads), and
   start running by giving the program name, helloworld, at the prompter.

2. Modify the program so that it reads in the number of threads from standard input (prompts for) and sets the number
   of threads at run-time by using the OpenMP function call omp_set_num_threads.


Test 2: Numerical integration, an example of a parallel algorithm
The program pi computes       using numerical integration. A known way to compute                         is the following:
                                                    ½
                                                                    Ü        Ö
Ø Ò´Üµ℄½
                                                                                      ¼
                                                        ½ · ܾ
                                                ¼


If we use the midpoint rule, we can compute the above integral as follows (see Figure 1):
                                   ½                        Ò                    Ò

                                                Ü
                               ¼
                                       ½ · ܾ
                                                                ½
                                                                    ½ · ܾ
                                                                                     ½
                                                                                         ½ · ´´    ½   ¾µ µ¾




                                                                         1
                                          f(x)
                                            1




                                                       h
                                            0                        1       x

                                 Figur 1: Numerical integration with the midpoint rule.


1. Parallelize the computations by inserting OpenMP directives in the code. Use PARALLEL DO with a reduction
   clause. (Compare with the effort of doing this in MPI.)


Test 3: Enumeration sort
The Enumeration-sort algorithm
For each element (j) count the number of elements (i) that are smaller (   ´ µ      ´ µ).   This gives the rank of a(j), i.e.
anew(rank(j))=a(j).
In this formulation equal elements get the same rank. Study the code in enumsort.cc and parallelize the algorithm
with OpenMP. Sort 20000 elements and measure speedup for your parallelization.


Requirements to pass
 After the lab hand in the following material or just discuss them with your teacher:
  1. Your program from Task 1.2
  2. Your parallel program from Task 2.1
  3. Your parallel program from Task 3
  4. A speedup graph from Task 3




                                                           2

								
To top