Compaq KAP Fortran/OpenMP
for Tru64 UNIX
User Guide


Previous Contents Index


Chapter 3
KAP Parallel Processing

3.1 Compaq KAP Parallel Processing

Compaq KAP transforms Fortran 90 source programs so that, when compiled and linked, they execute as multithreaded processes. These threads can run simultaneously --- that is, in parallel --- on symmetric multiprocessor (SMP) systems. The result is a program whose start-to-finish time is less than a Fortran 90 program that does not execute as a multithreaded process. More specifically, at run time the instructions from DO loops in a transformed Fortran 90 program execute in parallel mode. Parallelization is the process that transforms DO loops into instructions in an .EXE file that execute as multithreaded processes.

DO loops occur both explicitly and implicitly. The familiar sequence


DO 10 I = 
. 
. 
. 
10 CONTINUE 

forms an explicit DO loop that Compaq KAP views as a candidate for parallelization. A statement such as A = B * C, where A and B and C are arrays according to Fortran 90 syntax, is also viewed by Compaq KAP as a candidate for parallelization. Compaq KAP transforms this matrix multiplication statement into explicit DO loops. In general, any statement that Compaq KAP can transform into DO loops is an implicit DO loop.

Compaq KAP considers all DO loops in a program as candidates for parallelization. Each loop is or is not parallelized according to:

This chapter describes the three basic methods of controlling parallel processing (automatic, directed, and combination). It explains, for each method, how to:

3.1.1 Parallel Processing Methods

Compaq KAP provides three methods for programmers to control parallel processing. Their summaries follow:

Environment Variables to Set When -psyntax=openmp Is Selected


setenv OMP_SCHEDULE     (static,dynamic,guided,runtime) 
setenv OMP_DYNAMIC      (true,false) default is false. 
setenv OMP_NESTED       (true,false) default is false. 
setenv OMP_NUM_THREADS  (number) default value is the number of 
                        processors on the current system. 

For further information on environment variables read by the Compaq Fortran compiler, see your Fortran user's guide.

Environment Variables to Set When -psyntax=kap Is Selected


setenv KMP_SPINLOCKS on 
setenv KMP_STACKSIZE 1000000 
setenv PARALLEL 2 

(The value of PARALLEL must always be less than or equal to the number of processors.)

To execute the program, whose default file name is a.out, give this command:

a.out

Details of each method of parallelization, including corresponding switches for the kf90 command line, are in the method's description.

3.1.2 Parallel Processing Controls --- Summary

KAP provides the following parallel command switches, directives, and assertions for use with automatic parallel processing. Refer to the appropriate sections for explanations and code examples as follows:

Two types of command lines, kf90 and kapf90, invoke Compaq KAP software:

3.1.3 Parallel Processing Controls --- Interaction

As a programmer, you should always remember that you implement a parallel processing method (automatic, directed, or combination) by making choices from the previous command line options, directives, and assertions. Your choices affect the following actions:

For example, suppose you choose combination detection and parallelization for source program test_1.f90. This program contains some or none of the parallel processing directives, parallel processing assertions, and OpenMP directives. Consider the following command:


   kf90 -fkapargs='-concurrent -minconcurrent=1000 \
   -psyntax=openmp -directives=akpv' test_1.f90 

This command tells Compaq KAP to:

Compaq KAP parallel processing options, such as -concurrent, are enclosed in single quotation marks and are values of the -fkapargs option. The kf90 driver responds to the options enclosed in these single quotation marks by passing them as arguments to the kapf90 preprocessor (which actually transforms the source program file).

Note

Several switches used in this example, -psyntax, -directives, and -minconcurrent are set to their default values, and therefore you ordinarily have to set them explicitly to these values.

The default values of the parallel processing options also control Compaq KAP loop detections, loop transformations, calling of the compiler and linker, and runtime scheduling. They are:


  -directives=akpv 
  -minconcurrent=1000 
  -parallelio 
  -default=safe 
  -psyntax=openmp (parallel directives of type OpenMP are  generated) 
  -scheduling=e 
  -chunk=1 

Read the explanations of each of the three methods of parallelization in light of how your choices of options, directives, and assertions affect Compaq KAP detection of loops, changes to loops, compiler and linker behavior, and runtime behavior of executable file a.out.

3.2 Automatic Parallelization Using the kf90 Driver

Parallelization --- that is, creating an executable file that executes as a multithreaded application on symmetric multiprocessor systems --- via the automatic method, is most useful for large programs under the following circumstances:

For programs with loops that have not already been explicitly parallelized using OpenMP directives, Compaq recommends that you use automatic parallelization.

An example of using KAP automatic detection, selection, and transformation of loops is giving the following command line for Fortran source program my_prog.f:

kf90 -fkapargs='-concurrent' my_prog.f

The results include a transformed source program (my_prog.cmp.f) containing OpenMP directives around loops that KAP has decided to parallelize. and processing of the transformed source by the compiler and linker to create the executable file a.out.

3.2.1 Changing Source Programs

Compaq KAP cannot automatically parallelize loops with data dependencies between loop iterations and loops with calls to external routines. You can help Compaq KAP automatic detection of these loops by placing parallel processing assertions and parallel processing directives (each beginning with !*$*) in the source program. These assertions and directives are:


!*$* assert concurrent call 
!*$* assert do (concurrent) 
!*$* assert do (concurrent call) 
!*$* assert do (serial) 
!*$* assert do prefer (concurrent) 
!*$* assert do prefer (serial) 
!*$* [no]concurrent 
!*$* minconcurrent 

3.2.2 Giving Command Line Switches

Command line switches you can give to Compaq KAP that affect its transformation of DO loops under the automatic method are:

3.2.3 Directing the Compilation and Linking Process

To construct a program for parallel execution under the automatic method, you normally need to give only the -concurrent switch to the command, kf90, that invokes the kf90 driver software as follows:

kf90 -fkapargs='-concurrent' my_prog.f

The -concurrent (often abbreviated to -conc) switch tells KAP to automatically restructure the DO loops for parallel processing. The -conc switch also sets the compiler and linker switches correctly. DO loops are parallelized by insertion of OpenMP directives because -psyntax=openmp is the default. The Fortran 90 compiler will in turn process these directives and implement the parallelization.

Finally, you may want to create a completely non-parallelized program so you can compare its execution time with the times of programs that are parallelized in various ways (such as the automatic method and the directed method). The following command does this:

kf90 -fkapargs='-noconc -directives=ak' -noomp myprog.f90

The -noconc switch prevents automatic parallelization of DO loops and the absence of "p" from the string following -directives= prevents Compaq KAP from responding to any parallel directive statements. The -noomp switch prevents the Fortran compiler from responding to any OpenMP parallel directive statements in the transformed source file it receives.

3.3 Directed Parallelization Using the kf90 Driver and OpenMP Directives

Under the directed method, Compaq KAP does not do any automatic parallel detection. As always, any OpenMP directives in the original source program are passed to the Fortran 90 compiler for processing.

Parallelization --- that is, creating an executable file that executes as a multithreaded application on symmetric multiprocessor systems --- via inserting OpenMP directives is most useful for programs under the following circumstances:

The directed method applies only to DO loops with parallel directives. Consider a program with the following loops:


  C$OMP PARALLEL 
  DO WHILE (I ...               DO WHILE (J ... 
  ...                           ... 
  END DO                        END DO 
  C$OMP END PARALLEL 

Compaq KAP passes the OpenMP directives of the DO WHILE I loop onto the compiler for processing. Compaq KAP does not parallelize the DO WHILE J loop. So, "directed" means any loops not surrounded with parallel directive statements are not parallelized. If instead Compaq KAP were to attempt to transform both DO WHILE loops, then it would be running under the combination method.

An example of how to use KAP to process a program for which no automatic parallelization is desired is given below:


 
         kf90  -fkapargs='-noconc'  my_prog.f \
               -omp  -pthread  -call_shared 

The results include a transformed source program and its processing by the compiler and linker to create executable file a.out. Because of the -noconc switch, Compaq KAP does not automatically set compiler and linker switches related to parallel processing. Therefore the user must explicitly set the -omp and -pthread compiler and -call_shared linker switches.

3.3.1 Changing Source Programs

Insert OpenMP directives (beginning with C$OMP) only with loops that are safe to parallelize. When Compaq KAP sees a loop prefaced with OpenMP directives, it does not perform data dependence analysis on that loop and does not prevent you from using a parallel directive incorrectly. The OpenMP directives are described in the DIGITAL Fortran 90 User's Guide. For reference, the following table correlates OpenMP directives to Cray's CMIC parallel directives:
OpenMP Cray
Specifying Regions of Parallel Execution  
C$OMP PARALLEL CMIC$ PARALLEL
C$OMP END PARALLEL CMIC$ END PARALLEL
Specifying Parallel Loops  
C$OMP DO CMIC$ END DO
Specifying Synchronized Sections of Code  
C$OMP CRITICAL CMIC$ GUARD
C$OMP END CRITICAL CMIC$ END GUARD
C$OMP SINGLE (equivalent coded with guard flag)
C$OMP END SINGLE  
Specifying Sections of Code for Parallel Execution  
C$OMP SECTIONS CMIC$ CASE
C$OMP SECTION (before each section)  
C$OMP END SECTIONS CMIC$ END CASE
Controlling Subroutines Called within Parallel Regions  
C*$* ASSERT CONCURRENT CALL CMIC$ CONTINUE
Specifying Commons Local to each Thread  
C$OMP THREAD PRIVATE CMIC$ TASKCOMMON

3.3.2 Giving Command Line Switches

No Compaq KAP switches affect the processing by the compiler of OpenMP directives inserted by the user.

3.3.3 Directing the Compilation and Linking Process

To parallelize a program containing OpenMP directives, you normally need to give only the kf90 command with the -noconc KAP switch , the -omp and -pthread Fortran 90 compiler switches, and -call_shared linker switch.

An example follows:


   kf90  -fkapargs='-noconc'  myprog.f90 \
         -omp  -pthread  -call_shared 

Because of the -noconc switch, Compaq KAP does not automatically set the compiler and linker switches needed for parallelization. Correct ones appear here.

To parallelize a program containing PCF directives, you need to give the kf90 command with the -noconc KAP switch and a specification of the PCF library.

An example follows:


 kf90  -fkapargs='-noconc -psyntax=kap'  myprog.f90 \
       -lkmp_osfp10 -pthread -call_shared 

Finally, you may want to create a completely non-parallelized program so you can compare its execution time with the times of programs that are parallelized in various ways (such as the automatic method and the directed method). The following command does this:

kf90 -fkapargs='-noconc -directives=ak' -noomp myprog.f90

The -noconc switch prevents automatic parallelization of DO loops and the absence of "p" from the string following -directives= prevents Compaq KAP from responding to any PCF parallel directive statements (OpenMP directives are not processed by Compaq KAP). The -noomp switch prevents the Fortran 90 compiler from responding to any OpenMP directive statements in the transformed source file.


Previous Next Contents Index