OpenMP API User's Guide

  • View
    227

  • Download
    0

Embed Size (px)

Text of OpenMP API User's Guide

  • 8/8/2019 OpenMP API User's Guide

    1/66

    Sun Microsystems, Inc.4150 Network CircleSanta Clara, CA 95054 U.S.A.650-960-1300

    Send comments about this document to: [email protected]

    OpenMP API Users Guide

    Forte Developer 7

    Part No. 816-2468-10May 2002, Revision A

  • 8/8/2019 OpenMP API User's Guide

    2/66

    PleaseRecycle

    Copyright 2002Sun Microsystems, Inc., 4150Network Circle, Santa Clara, California 95054, U.S.A.All rightsreserved.

    SunMicrosystems, Inc. hasintellectualproperty rightsrelatingto technology embodied in theproduct that is describedin this document.Inparticular, andwithout limitation, these intellectualpropertyrights mayinclude oneor more of theU.S. patents listedathttp://www.sun.com/patentsandoneor more additionalpatents or pending patentapplications in theU.S. andin other countries.

    This document andtheproduct to which it pertains aredistributedunder licenses restricting their use, copying, distribution, anddecompilation. No part of theproduct or of this document may be reproduced in any form by anymeans without prior writtenauthorization of

    Sunand itslicensors, if any.

    Third-party software, including font technology, is copyrighted and licensed fromSun suppliers.

    Parts of theproduct may be derived from Berkeley BSD systems, licensed from theUniversity of California. UNIX is a registered trademarkintheU.S. andin other countries, exclusively licensed through X/OpenCompany, Ltd.

    Sun, SunMicrosystems,the Sunlogo, Forte,Java, Solaris, iPlanet, NetBeans, anddocs.sun.comare trademarks or registered trademarks of SunMicrosystems, Inc. in theU.S. andother countries.

    AllSPARCtrademarks areused under license andaretrademarks or registered trademarks of SPARCInternational, Inc. in theU.S. andothercountries.Products bearing SPARC trademarks arebasedupon architecturedeveloped by Sun Microsystems, Inc.

    Netscape andNetscapeNavigatorare trademarks or registered trademarks of Netscape Communications Corporation in theUnited Statesandothercountries.

    Sun f90/f95 is derived in partfrom Cray CF90,aproductofCrayInc.

    libdwarfand lidredblackareCopyright 2000Silicon Graphics Inc. andareavailableunder theGNU LesserGeneral Public License fromhttp://www.sgi.com.

    Federal Acquisitions: Commercial SoftwareGovernmentUsersSubject to Standard License Terms and Conditions.

    DOCUMENTATION IS PROVIDED AS IS AND ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT,

    ARE DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD TO BE LEGALLY INVALID.

    Copyright 2002Sun Microsystems, Inc., 4150Network Circle, Santa Clara, California 95054, Etats-Unis. Tous droits rservs.

    SunMicrosystems, Inc. a les droitsde proprit intellectuelsrelatants la technologie incorpore dans le produit quiestdcritdans cedocument.En particulier, et sans la limitation, cesdroits de proprit intellectuelspeuvent inclure un ou plus des brevets amricains numrs http://www.sun.com/patentset un ou lesbrevets plus supplmentairesou lesapplicationsde brevet en attente dans les Etats - Unis etdans les autrespays.

    Ce produit ou document estprotgparun copyrightet distribuavec des licences quien restreignent lutilisation, la copie, la distribution, et ladcompilation. Aucunepartie de ce produit ou document ne peut tre reproduite sous aucuneforme, parquelque moyen quece soit, sanslautorisation pralable et critede Sunet de sesbailleursde licence, sil y en a.

    Le logiciel dtenupar destiers, et quicomprendla technologie relativeaux polices de caractres, estprotg par un copyrightet licenci par desfournisseurs de Sun.

    Desparties de ce produit pourronttre drives des systmes Berkeley BSDlicencispar lUniversitde Californie. UNIX estune marquedpose aux Etats-Unis et dans dautres pays et licencieexclusivement parX/OpenCompany, Ltd.

    Sun, SunMicrosystems,le logo Sun, Forte,Java, Solaris, iPlanet, NetBeans,et docs.sun.comsont des marques de fabrique ou des marquesdposes de SunMicrosystems, Inc. aux Etats-Unis et dans dautres pays.

    Toutes les marques SPARCsont utilisessous licence et sont desmarques de fabrique ou desmarques dposes de SPARCInternational, Inc.

    auxEtats-Unis et dans dautres pays. Les produitsprotant les marques SPARCsont bass surune architecture dveloppepar SunMicrosystems, Inc.

    Netscape et Netscape Navigator sont desmarques de fabrique ou desmarques dposes de Netscape Communications Corporation auxEtats-Unis et dans dautres pays.

    Sun f90/f95 estderive dune part de Cray CF90,unproduitdeCrayInc.

    libdwarfet lidredblacksont Copyright2000 Silicon Graphics Inc., et sont disponible surGNU General Public License http://www.sgi.com.

    LA DOCUMENTATION EST FOURNIE EN LTAT ET TOUTES AUTRES CONDITIONS, DECLARATIONS ET GARANTIES EXPRESSES

    OU TACITESSONT FORMELLEMENTEXCLUES, DANS LA MESUREAUTORISEE PAR LA LOIAPPLICABLE, Y COMPRIS NOTAMMENTTOUTE GARANTIE IMPLICITE RELATIVE A LA QUALITE MARCHANDE, A LAPTITUDE A UNE UTILISATION PARTICULIERE OU ALABSENCE DE CONTREFAON.

  • 8/8/2019 OpenMP API User's Guide

    3/66

    iii

    Contents

    Before You Begin ix

    Typographic Conventions ix

    Shell Prompts xi

    Accessing Forte Developer Development Tools and Man Pages xi

    Accessing Forte Developer Documentation xiii

    Accessing Related Solaris Documentation xvi

    Sending Your Comments xvi

    1. OpenMP API Summary 1-11.1 Where to Find the OpenMP Specifications 1-1

    1.2 Special Conventions Used Here 1-2

    1.3 Directive Formats 1-2

    1.4 Conditional Compilation 1-3

    1.5 PARALLEL - Parallel Region Construct 1-5

    1.6 Work-Sharing Constructs 1-6

    1.6.1 DO and for 1-6

    1.6.2 SECTIONS 1-7

    1.6.3 SINGLE 1-8

    1.6.4 Fortran WORKSHARE 1-9

  • 8/8/2019 OpenMP API User's Guide

    4/66

    iv OpenMP API Users Guide May 2002

    1.7 Combined Parallel Work-sharing Constructs 1-10

    1.7.1 PARALLEL DO and parallel for 1-10

    1.7.2 PARALLEL SECTIONS 1-11

    1.7.3 PARALLEL WORKSHARE 1-11

    1.8 Synchronization Constructs 1-12

    1.8.1 MASTER 1-12

    1.8.2 CRITICAL 1-13

    1.8.3 BARRIER 1-13

    1.8.4 ATOMIC 1-14

    1.8.5 FLUSH 1-15

    1.8.6 ORDERED 1-15

    1.9 Data Environment Directives 1-16

    1.9.1 THREADPRIVATE 1-16

    1.10 OpenMP Directive Clauses 1-17

    1.10.1 Data Scoping Clauses 1-17

    1.10.1.1 PRIVATE 1-17

    1.10.1.2 SHARED 1-171.10.1.3 DEFAULT 1-18

    1.10.1.4 FIRSTPRIVATE 1-18

    1.10.1.5 LASTPRIVATE 1-18

    1.10.1.6 COPYIN 1-18

    1.10.1.7 COPYPRIVATE 1-191.10.1.8 REDUCTION 1-19

    1.10.2 Scheduling Clauses 1-19

    1.10.2.1 STATIC Scheduling 1-20

    1.10.2.2 DYNAMIC Scheduling 1-20

    1.10.2.3 GUIDED Scheduling 1-201.10.2.4 RUNTIME Scheduling 1-20

  • 8/8/2019 OpenMP API User's Guide

    5/66

    Contents v

    1.10.3 NUM_THREADS Clause 1-21

    1.10.4 Placement of Clauses on Directives 1-22

    1.11 OpenMP Runtime Library Routines 1-23

    1.11.1 Fortran OpenMP Routines 1-23

    1.11.2 C/C++ OpenMP Routines 1-23

    1.11.3 Run-time Thread Management Routines 1-24

    1.11.3.1 OMP_SET_NUM_THREADS 1-24

    1.11.3.2 OMP_GET_NUM_THREADS 1-24

    1.11.3.3 OMP_GET_MAX_THREADS 1-24

    1.11.3.4 OMP_GET_THREAD_NUM 1-25

    1.11.3.5 OMP_GET_NUM_PROCS 1-25

    1.11.3.6 OMP_IN_PARALLEL 1-25

    1.11.3.7 OMP_SET_DYNAMIC 1-26

    1.11.3.8 OMP_GET_DYNAMIC 1-26

    1.11.3.9 OMP_SET_NESTED 1-26

    1.11.3.10 OMP_GET_NESTED 1-27

    1.11.4 Routines That Manage Synchronization Locks 1-27

    1.11.4.1 OMP_INIT_LOCK and OMP_INIT_NEST_LOCK 1-28

    1.11.4.2 OMP_DESTROY_LOCK andOMP_DESTROY_NEST_LOCK 1-28

    1.11.4.3 OMP_SET_LOCK and OMP_SET_NEST_LOCK 1-28

    1.11.4.4 OMP_UNSET_LOCK and OMP_UNSET_NEST_LOCK 1-29

    1.11.4.5 OMP_TEST_LOCK and OMP_TEST_NEST_LOCK 1-291.11.5 Timing Routines 1-30

    1.11.5.1 OMP_GET_WTIME 1-30

    1.11.5.2 OMP_GET_WTICK 1-30

  • 8/8/2019 OpenMP API User's Guide

    6/66

    vi OpenMP API Users Guide May 2002

    2. Implementation Dependent Issues 2-1

    3. Compiling for OpenMP 3-1

    3.1 Fortran 95 3-1

    3.1.1 Validation of OpenMP Directives with -XlistMP 3-2

    3.2 C and C++ 3-4

    3.3 OpenMP Environment Variables 3-6

    3.4 Stacks and Stack Sizes 3-7

    4. Converting to OpenMP 4-1

    4.1 Converting Legacy Fortran Directives 4-1

    4.1.1 Converting Sun-Style Directives 4-1

    4.1.1.1 Issues Between Sun-Style Directives and OpenMP 4-3

    4.1.2 Converting Cray-Style Directives 4-4

    4.1.2.1 Issues Between Cray-Style Directives and OpenMPDirectives 4-4

    4.2 Converting Legacy C Pragmas 4-5

    4.2.1 Issues Between Legacy C Pragmas and OpenMP 4-6

  • 8/8/2019 OpenMP API User's Guide

    7/66

    vii

    Tables

    TABLE 3-1 OpenMP Environment Variables: setenv VARIABLE value 3-6

    TABLE 3-2 Multiprocessing environment variables 3-7

    TABLE 4-1 Converting Sun Parallelization Directives to OpenMP 4-2

    TABLE 4-2 DOALL Qualifier Clauses and OpenMP Equivalent Clauses 4-2TABLE 4-3 SCHEDTYPE Scheduling and OpenMP schedule Equivalents 4-3

    TABLE 4-4 OpenMP Equivalents for Cray-Style DOALL Qualifier Clauses 4-4

    TABLE 4-5 Converting Legacy C Parallelization Pragmas to OpenMP 4-5

    TABLE 4-6 taskloop Optional Clauses and OpenMP Equivalents 4-5

    TABLE 4-7 SCHEDTYPE Scheduling and OpenMP schedule Equivalents 4-6

    http://-/?-http://-/?-
  • 8/8/2019 OpenMP API User's Guide

    8/66

    viii OpenMP API Users Guide May 2002

  • 8/8/2019 OpenMP API User's Guide

    9/66

    ix

    Before You Begin

    The OpenMP API Users Guide summarizes the OpenMP Fortran 95, C, and C++applicati