26.06.2015 Views

Parallel Programming in Fortran 95 using OpenMP - People

Parallel Programming in Fortran 95 using OpenMP - People

Parallel Programming in Fortran 95 using OpenMP - People

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

4 1. <strong>OpenMP</strong> <strong>Fortran</strong> Application Program Interface<br />

1.2 The basics<br />

<strong>OpenMP</strong> represents a collection of compiler directives, library rout<strong>in</strong>es and environment<br />

variables meant for parallel programm<strong>in</strong>g <strong>in</strong> shared-memory mach<strong>in</strong>es. A chapter is go<strong>in</strong>g<br />

to be devoted to each of these elements, but before start<strong>in</strong>g with the review of the available<br />

compiler directives, it is necessary to have a look at some basic aspects of <strong>OpenMP</strong>.<br />

Although named as ”basic aspects”, the <strong>in</strong>formation presented <strong>in</strong> this section is the<br />

fundamental part of <strong>OpenMP</strong> which allows the <strong>in</strong>clusion of <strong>OpenMP</strong> commands <strong>in</strong> programs<br />

and the creation as well as destruction of parallel runn<strong>in</strong>g regions of code.<br />

1.2.1 The sent<strong>in</strong>els for <strong>OpenMP</strong> directives and conditional compilation<br />

One of the aims of the <strong>OpenMP</strong> standard is to offer the possibility of us<strong>in</strong>g the same<br />

source code l<strong>in</strong>es with an <strong>OpenMP</strong>-compliant compiler and with a normal compiler. This<br />

can only be achieved by hid<strong>in</strong>g the <strong>OpenMP</strong> directives and commands <strong>in</strong> such a way, that<br />

a normal compiler is unable to see them. For that purpose the follow<strong>in</strong>g two directive<br />

sent<strong>in</strong>els are <strong>in</strong>troduced:<br />

!$OMP<br />

!$<br />

S<strong>in</strong>ce the first character is an exclamation mark ”!”, a normal compiler will <strong>in</strong>terpret<br />

the l<strong>in</strong>es as comments and will neglect their content. But an <strong>OpenMP</strong>-compliant compiler<br />

will identify the complete sequences and will proceed as follows:<br />

!$OMP : the <strong>OpenMP</strong>-compliant compiler knows that the follow<strong>in</strong>g <strong>in</strong>formation <strong>in</strong> the<br />

l<strong>in</strong>e is an <strong>OpenMP</strong> directive. It is possible to extend an <strong>OpenMP</strong> directive over<br />

several l<strong>in</strong>es by plac<strong>in</strong>g the same sent<strong>in</strong>el <strong>in</strong> front of the follow<strong>in</strong>g l<strong>in</strong>es and us<strong>in</strong>g<br />

the standard <strong>Fortran</strong> <strong>95</strong> method of brak<strong>in</strong>g source code l<strong>in</strong>es:<br />

!$OMP PARALLEL DEFAULT(NONE) SHARED(A, B) PRIVATE(C, D) &<br />

!$OMP REDUCTION(+:A)<br />

It is mandatory to <strong>in</strong>clude a white space between the directive sent<strong>in</strong>el !$OMP and<br />

the follow<strong>in</strong>g <strong>OpenMP</strong> directive, otherwise the directive sent<strong>in</strong>el is not correctly<br />

identified and the l<strong>in</strong>e is treated as a comment.<br />

!$ : the correspond<strong>in</strong>g l<strong>in</strong>e is said to be affected by a conditional compilation. This<br />

means that its content will only be available to the compiler <strong>in</strong> case of be<strong>in</strong>g<br />

<strong>OpenMP</strong>-compliant. In such a case, the two characters of the sent<strong>in</strong>el are substituted<br />

by two white spaces so that the compiler is tak<strong>in</strong>g <strong>in</strong>to account the l<strong>in</strong>e.<br />

As <strong>in</strong> the previous case, it is possible to extend a source code l<strong>in</strong>e over several l<strong>in</strong>es<br />

as follows:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!