Download PGI User's Guide
Transcript
Chapter 3. Using Optimization & Parallelization • Tune selected routines or loops based on your knowledge or on information obtained through profiling. Chapter 6, “Using Directives and Pragmas” provides details on how to add directives and pragmas to your source files. Execution Timing and Instruction Counting As this chapter describes, once you have a program that compiles, executes and gives correct results, you may optimize your code for execution efficiency. Selecting the correct optimization level requires some thought and may require that you compare several optimization levels before arriving at the best solution. To compare optimization levels, you need to measure the execution time for your program. There are several approaches you can take for timing execution. You can use shell commands that provide execution time statistics, you can include function calls in your code that provide timing information, or you can profile sections of code. Timing functions available with the PGI compilers include 3F timing routines, the SECNDS pre-declared function in PGF77 or PGF95, or the SYSTEM_CLOCK or CPU_CLOCK intrinsics in PGF95 or PGHPF. In general, when timing a program, you should try to eliminate or reduce the amount of system level activities such as program loading, I/O and task switching. The following example shows a fragment that indicates how to use SYSTEM_CLOCK effectively within an F90, F95 or HPF program unit. Example 3.4. Using SYSTEM_CLOCK code fragment . . . integer :: nprocs, hz, clock0, clock1 real :: time integer, allocatable :: t(:) !hpf$ distribute t(cyclic) #if defined (HPF) allocate (t(number_of_processors())) #elif defined (_OPENMP) allocate (t(OMP_GET_NUM_THREADS())) #else allocate (t(1)) #endif call system_clock (count_rate=hz) ! call system_clock(count=clock0) < do work> call system_clock(count=clock1) ! t = (clock1 - clock0) time = real (sum(t)) / (real(hz) * size(t)) . . . Portability of Multi-Threaded Programs on Linux PGI has created two libraries - libpgbind and libnuma - to handle the variations between various implementations of Linux. Some older versions of Linux are lacking certain features that support multi-processor and multi-core systems, in particular, the system call 'sched_setaffinity' and the numa library libnuma. The PGI run-time library uses these features to implement some –Mconcur and –mp operations. 43