<html lang="en"> <head> <title>OpenMP - The GNU Fortran Compiler</title> <meta http-equiv="Content-Type" content="text/html"> <meta name="description" content="The GNU Fortran Compiler"> <meta name="generator" content="makeinfo 4.13"> <link title="Top" rel="start" href="index.html#Top"> <link rel="up" href="Extensions-implemented-in-GNU-Fortran.html#Extensions-implemented-in-GNU-Fortran" title="Extensions implemented in GNU Fortran"> <link rel="prev" href="CONVERT-specifier.html#CONVERT-specifier" title="CONVERT specifier"> <link rel="next" href="Argument-list-functions.html#Argument-list-functions" title="Argument list functions"> <link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage"> <!-- Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with the Invariant Sections being ``Funding Free Software'', the Front-Cover Texts being (a) (see below), and with the Back-Cover Texts being (b) (see below). A copy of the license is included in the section entitled ``GNU Free Documentation License''. (a) The FSF's Front-Cover Text is: A GNU Manual (b) The FSF's Back-Cover Text is: You have freedom to copy and modify this GNU Manual, like GNU software. Copies published by the Free Software Foundation raise funds for GNU development.--> <meta http-equiv="Content-Style-Type" content="text/css"> <style type="text/css"><!-- pre.display { font-family:inherit } pre.format { font-family:inherit } pre.smalldisplay { font-family:inherit; font-size:smaller } pre.smallformat { font-family:inherit; font-size:smaller } pre.smallexample { font-size:smaller } pre.smalllisp { font-size:smaller } span.sc { font-variant:small-caps } span.roman { font-family:serif; font-weight:normal; } span.sansserif { font-family:sans-serif; font-weight:normal; } --></style> </head> <body> <div class="node"> <a name="OpenMP"></a> <p> Next: <a rel="next" accesskey="n" href="Argument-list-functions.html#Argument-list-functions">Argument list functions</a>, Previous: <a rel="previous" accesskey="p" href="CONVERT-specifier.html#CONVERT-specifier">CONVERT specifier</a>, Up: <a rel="up" accesskey="u" href="Extensions-implemented-in-GNU-Fortran.html#Extensions-implemented-in-GNU-Fortran">Extensions implemented in GNU Fortran</a> <hr> </div> <h4 class="subsection">6.1.16 OpenMP</h4> <p><a name="index-OpenMP-319"></a> OpenMP (Open Multi-Processing) is an application programming interface (API) that supports multi-platform shared memory multiprocessing programming in C/C++ and Fortran on many architectures, including Unix and Microsoft Windows platforms. It consists of a set of compiler directives, library routines, and environment variables that influence run-time behavior. <p>GNU Fortran strives to be compatible to the <a href="http://www.openmp.org/mp-documents/spec30.pdf">OpenMP Application Program Interface v3.0</a>. <p>To enable the processing of the OpenMP directive <code>!$omp</code> in free-form source code; the <code>c$omp</code>, <code>*$omp</code> and <code>!$omp</code> directives in fixed form; the <code>!$</code> conditional compilation sentinels in free form; and the <code>c$</code>, <code>*$</code> and <code>!$</code> sentinels in fixed form, <samp><span class="command">gfortran</span></samp> needs to be invoked with the <samp><span class="option">-fopenmp</span></samp>. This also arranges for automatic linking of the GNU OpenMP runtime library <a href="../libgomp/index.html#Top">libgomp</a>. <p>The OpenMP Fortran runtime library routines are provided both in a form of a Fortran 90 module named <code>omp_lib</code> and in a form of a Fortran <code>include</code> file named <samp><span class="file">omp_lib.h</span></samp>. <p>An example of a parallelized loop taken from Appendix A.1 of the OpenMP Application Program Interface v2.5: <pre class="smallexample"> SUBROUTINE A1(N, A, B) INTEGER I, N REAL B(N), A(N) !$OMP PARALLEL DO !I is private by default DO I=2,N B(I) = (A(I) + A(I-1)) / 2.0 ENDDO !$OMP END PARALLEL DO END SUBROUTINE A1 </pre> <p>Please note: <ul> <li><samp><span class="option">-fopenmp</span></samp> implies <samp><span class="option">-frecursive</span></samp>, i.e., all local arrays will be allocated on the stack. When porting existing code to OpenMP, this may lead to surprising results, especially to segmentation faults if the stacksize is limited. <li>On glibc-based systems, OpenMP enabled applications cannot be statically linked due to limitations of the underlying pthreads-implementation. It might be possible to get a working solution if <samp><span class="command">-Wl,--whole-archive -lpthread -Wl,--no-whole-archive</span></samp> is added to the command line. However, this is not supported by <samp><span class="command">gcc</span></samp> and thus not recommended. </ul> </body></html>