1、BSI Standards Publication PD ISO/IEC TS 19570:2015 Programming Languages Technical Specification for C+ Extensions for ParallelismPD ISO/IEC TS 19570:2015 PUBLISHED DOCUMENT National foreword This Published Document is the UK implementation of ISO/IEC TS 19570:2015. The UK participation in its prepa
2、ration was entrusted to Technical Committee IST/5, Programming languages, their environments and system software interfaces. A list of organizations represented on this committee can be obtained on request to its secretary. This publication does not purport to include all the necessary provisions of
3、 a contract. Users are responsible for its correct application. The British Standards Institution 2015. Published by BSI Standards Limited 2015 ISBN 978 0 580 87808 4 ICS 35.060 Compliance with a British Standard cannot confer immunity from legal obligations. This Published Document was published un
4、der the authority of the Standards Policy and Strategy Committee on 31 July 2015. Amendments/corrigenda issued since publication Date T e x t a f f e c t e dReference number ISO/IEC TS 19570:2015(E) ISO/IEC 2015 TECHNICAL SPECIFICATION ISO/IEC TS 19570 First edition 20 1 5 - 0 7 - 0 1 Programming La
5、nguages Technical Specification for C+ Extensions for Parallelism Langages de programmation Spcification technique pour les extensions C+ relatives au paralllisme PD ISO/IEC TS 19570:2015 ISO/IEC TS 19570:2015(E) COPYRIGHT PROTECTED DOCUMENT ISO/IEC 2015 All rights reserved. Unless otherwise specifi
6、ed, no part of this publication may be reproduced or utilized otherwise in any form or by any means, electronic or mechanical, including photocopying, or posting on the internet or an intranet, without prior written permission. Permission can be requested from either ISO at the address below or ISOs
7、 member body in the country of the requester. ISO copyright office Case postale 56 CH-1211 Geneva 20 Tel. + 41 22 749 01 11 Fax + 41 22 749 09 47 E-mail copyrightiso.org Web www.iso.org Published in Switzerland ii ISO/IEC 2015 All rights reservedPD ISO/IEC TS 19570:2015 ISO/IEC TS 19570:2015(E) ISO/
8、IEC 2015 All rights reserved iiiForeword ISO (the International Organization for Standardization) and IEC (the International Electrotechnical Commission) form the specialized system for worldwide standardization. National bodies that are members of ISO or IEC participate in the development of Intern
9、ational Standards through technical committees established by the respective organization to deal with particular fields of technical activity. ISO and IEC technical committees collaborate in fields of mutual interest. Other international organizations, governmental and non-governmental, in liaison
10、with ISO and IEC, also take part in the work. In the field of information technology, ISO and IEC have established a joint technical committee, ISO/IEC JTC 1. The procedures used to develop this document and those intended for its further maintenance are described in the ISO/IEC Directives, Part 1.
11、In particular the different approval criteria needed for the different types of document should be noted. This document was drafted in accordance with the editorial rules of the ISO/IEC Directives, Part 2 (see www.iso.org/directives). Attention is drawn to the possibility that some of the elements o
12、f this document may be the subject of patent rights. ISO and IEC shall not be held responsible for identifying any or all such patent rights. Details of any patent rights identified during the development of the document will be in the Introduction and/or on the ISO list of patent declarations recei
13、ved (see www.iso.org/patents). Any trade name used in this document is information given for the convenience of users and does not constitute an endorsement. For an explanation on the meaning of ISO specific terms and expressions related to conformity assessment, as well as information about ISOs ad
14、herence to the WTO principles in the Technical Barriers to Trade (TBT) see the following URL: Foreword - Supplementary information ISO/IEC TS 19570 was prepared by Joint Technical Committee ISO/IEC JTC 1, Information technology, Subcommittee SC 22, Programming languages, their environments and syste
15、m software interfaces. PD ISO/IEC TS 19570:2015 Contents 1 General . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 1.1 Scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 1.2 Normative references . . . . . . . . . . . . . . . . .
16、. . . . . . . . . . . . . . . . 4 1.3 Namespaces and headers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 1.4 Terms and definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 1.5 Feature-testing recommendations . . . . . . . . . . . . . . . . . . . . . . .
17、 . . . 5 2 Execution policies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 2.1 In general . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 2.2 Header synopsis . . . . . . . . . . . . . . . . . 6 2.3 Execution policy type trait . . . . . . . . .
18、 . . . . . . . . . . . . . . . . . . . . . 7 2.4 Sequential execution policy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 2.5 Parallel execution policy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 2.6 Parallel+Vector execution policy . . . . . . . . . . . . . . .
19、. . . . . . . . . . . . 7 2.7 Dynamic execution policy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 2.7.1execution_policy construct/assign . . . . . . . . . . . . . . . . . . . . . . . 8 2.7.2execution_policy object access . . . . . . . . . . . . . . . . . . . . . . . . 9 2.8 Exec
20、ution policy objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 3 Parallel exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 3.1 Exception reporting behavior . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 3.2 Header synopsis . . . . . .
21、. . . . . . . . . . . . . 10 4 Parallel algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 4.1 In general . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 4.1.1Requirements on user-provided function objects . . . . . . . . . . . . . . . 12 4
22、.1.2Effect of execution policies on algorithm execution . . . . . . . . . . . . . . 12 4.1.3ExecutionPolicy algorithm overloads . . . . . . . . . . . . . . . . . . . . . 14 4.2 Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 4.3 Non-Numeric Parallel Algorit
23、hms . . . . . . . . . . . . . . . . . . . . . . . . . . 15 4.3.1Header synopsis . . . . . . . . . . . . . . . . . 15 4.3.2For each . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 4.4 Numeric Parallel Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 4
24、.4.1Header synopsis . . . . . . . . . . . . . . . . . . 17 4.4.2Reduce . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 4.4.3Exclusive scan . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 4.4.4Inclusive scan . . . . . . . . . . . . . . . . . . . . . .
25、 . . . . . . . . . . . 21 4.4.5Transform reduce . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 4.4.6Transform exclusive scan . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 4.4.7Transform inclusive scan . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 ISO/IEC N4507
26、 3 PD ISO/IEC TS 19570:2015 ISO/IEC TS 19570:2015(E)PD ISO/IEC TS 19570:2015 parallel.general 1General parallel.general.scope 1.1Scope 1 This Technical Specification describes requirements for implementations of an interface that computer programs written in the C+ programming language may use to in
27、voke algorithms with parallel execution. The algorithms described by this Technical Specification are realizable across a broad class of computer architectures. 2 This Technical Specification is non-normative. Some of the functionality described by this Technical Specification may be considered for
28、standardization in a future version of C+, but it is not currently part of any C+ standard. Some of the functionality in this Technical Specification may never be standardized, and other functionality may be standardized in a substantially changed form. 3 The goal of this Technical Specification is
29、to build widespread existing practice for parallelism in the C+ standard algorithms library. It gives advice on extensions to those vendors who wish to provide them. parallel.general.references 1.2Normative references 1 The following referenced document is indispensable for the application of this d
30、ocument. For dated references, only the edition cited applies. For undated references, the latest edition of the referenced document (including any amendments) applies. ISO/IEC 14882: 1 ,Programming Languages C+ 2 ISO/IEC 14882: is herein called the C+ Standard . The library described in ISO/IEC 148
31、82: clauses 17-30 is herein called the C+ Standard Library . The C+ Standard Library components described in ISO/IEC 14882: clauses 25, 26.7 and 20.7.2 are herein called the C+ Standard Algorithms Library . 3 Unless otherwise specified, the whole of the C+ Standards Library introduction (C+1417) is
32、included into this Technical Specification by reference. parallel.general.namespaces 1.3Namespaces and headers 1 Since the extensions described in this Technical Specification are experimental and not part of the C+ Standard Library, they should not be declared directly within namespace std . Unless
33、 otherwise specified, all components described in this Technical Specification are declared in namespace std:experimental:parallel:v1 . Note: Once standardized, the components described by this Technical Specification are expected to be promoted to namespace std . end note 2 Unless otherwise specifi
34、ed, references to such entities described in this Technical Specification are assumed to be qualified with std:experimental:parallel:v1 , and references to entities described in the C+ Standard Library are assumed to be qualified with std: . 3 Extensions that are expected to eventually be added to a
35、n existing header are provided inside the header, which shall include the standard contents of as if by 1.To be published. Section references are relative to N3937. ISO/IEC N4507 1.3 4 PD ISO/IEC TS 19570:2015 ISO/IEC TS 19570:2015(E)PD ISO/IEC TS 19570:2015 #include parallel.general.defns 1.4Terms
36、and definitions 1 For the purposes of this document, the terms and definitions given in the C+ Standard and the following apply. 2 A parallel algorithm is a function template described by this Technical Specification declared in namespace std:experimental:parallel:v1 with a formal template parameter
37、 named ExecutionPolicy . 3 Parallel algorithms access objects indirectly accessible via their arguments by invoking the following functions: All operations of the categories of the iterators that the algorithm is instantiated with. Functions on those sequence elements that are required by its specif
38、ication. User-provided function objects to be applied during the execution of the algorithm, if required by the specification. Operations on those function objects required by the specification. Note: See clause 25.1 ofC+ Standard Algorithms Library . end note These functions are herein called eleme
39、nt access functions . Example: The sort function may invoke the following element access functions: Methods of the random-access iterator of the actual template argument, as per 24.2.7, as implied by the name of the template parameters RandomAccessIterator . The swap function on the elements of the
40、sequence (as per 25.4.1.1 sort/2). The user-provided Compare function object. end example parallel.general.features 1.5Feature-testing recommendations 1 An implementation that provides support for this Technical Specification shall define the feature test macro(s) in Table 1. Table 1 Feature Test Ma
41、cro(s) Name Value Header _cpp_lib_experimental_parallel_algorithm 201505 ISO/IEC N4507 1.5 5 PD ISO/IEC TS 19570:2015 ISO/IEC TS 19570:2015(E)PD ISO/IEC TS 19570:2015 parallel.execpol 2Execution policies parallel.execpol.general 2.1In general 1 This clause describes classes that are execution policy
42、 types. An object of an execution policy type indicates the kinds of parallelism allowed in the execution of an algorithm and expresses the consequent requirements on the element access functions. Example: std:vector v = . / standard sequential sort std:sort(v.begin(), v.end(); using namespace std:e
43、xperimental:parallel; / explicitly sequential sort sort(seq, v.begin(), v.end(); / permitting parallel execution sort(par, v.begin(), v.end(); / permitting vectorization as well sort(par_vec, v.begin(), v.end(); / sort with dynamically-selected execution size_t threshold = . execution_policy exec =
44、seq; if (v.size() threshold) exec = par; sort(exec, v.begin(), v.end(); end example Note: Because different parallel architectures may require idiosyncratic parameters for efficient execution, implementations of the Standard Library may provide additional execution policies to those described in thi
45、s Technical Specification as extensions. end note parallel.execpol.synopsis 2.2Header synopsis namespace std namespace experimental namespace parallel inline namespace v1 / 2.3, Execution policy type trait template struct is_execution_policy; template constexpr bool is_execution_policy_v = is_execut
46、ion_policy:value; ISO/IEC N4507 2.2 6 PD ISO/IEC TS 19570:2015 ISO/IEC TS 19570:2015(E)PD ISO/IEC TS 19570:2015 / 2.4, Sequential execution policy class sequential_execution_policy; / 2.5, Parallel execution policy class parallel_execution_policy; / 2.6, Parallel+Vector execution policy class parall
47、el_vector_execution_policy; / 2.7, Dynamic execution policy class execution_policy; parallel.execpol.type 2.3Execution policy type trait template struct is_execution_policy see below ; 1 is_execution_policy can be used to detect parallel execution policies for the purpose of excluding function signa
48、tures from otherwise ambiguous overload resolution participation. 2 is_execution_policy shall be a UnaryTypeTrait with a BaseCharacteristic of true_type if T is the type of a standard or implementation-defined execution policy, otherwise false_type . Note: This provision reserves the privilege of cr
49、eating non-standard execution policies to the library implementation. end note 3 The behavior of a program that adds specializations for is_execution_policy is undefined. parallel.execpol.seq 2.4Sequential execution policy class sequential_execution_policy unspecified ; 1 The class sequential_execution_policy is an execution policy type used as a unique type to disambiguate parallel algorithm overloading