C. OpenMP C 和 C++ 文法

了解 C 和 C++ 中的文法規則和語法延伸,用於 OpenMP,一個平行程式設計框架。

C.1 表示法

文法規則包含非終端符號的名稱,接著冒號,然後是各行的替代選擇。

語法運算式字詞 opt 表示字詞在取代中是選擇性的。

語法表示式字詞optseq 相當於 term-seqopt,具有下列額外規則:

term-seq:
  術語
  term-seqterm
  term-seq,術語

C.2 規則

C 標準的第 6.1 節會說明標記法。 此語法附錄顯示 OpenMP C 和 C++ 指示的基礎語言語法延伸。

/* 在 C++ (ISO/IEC 14882:1998) */

statement-seq:
  陳述
  openmp-directive
  statement-seq 陳述式
  statement-seq openmp 指令

/* 在 C90 (ISO/IEC 9899:1990) */

statement-list :
  陳述
  openmp-directive
  語句列表語句
  statement-list OpenMP 指令

/* 在 C99 (ISO/IEC 9899:1999) */

block-item:
  宣告
  聲明
  openmp-directive

/* 標準陳述式 */

語句:
  openmp-construct

openmp-construct:
  parallel-construct
  for-construct
  章節構造
  單一結構
  parallel-for-construct
  平行區段構造
  master-construct
  critical-construct
  atomic-construct
  有序結構

openmp-directive:
  barrier-directive
  flush-directive

structured-block:
  陳述

parallel-construct:
  並行指令結構塊

parallel-directive:
  # pragma omp parallel 平行子句optseqnew-line

parallel-clause:
  獨特的並行子句
  data-clause

unique-parallel-clause:
  if ( 表達)
  num_threads ( 表達)

for-construct:
  for 迴圈指令語句

for-directive:
  # pragma omp for for子句optseq新行

for-clause:
  專用條件
  data-clause
  nowait

unique-for-clause:
  ordered
  schedule ( 日程類型)
  schedule ( 排程類型,表達)

排程類型:
  static
  dynamic
  guided
  runtime

sections-construct:
  部分-指令 部分範圍

sections-directive:
  # pragma omp sections sections-clauseoptseq換行符

sections-clause:
  data-clause
  nowait

section-scope:
  { 節序列 }

段落序列:
  段落指令選填結構區塊
  段落序列 指令節 結構化塊

section-directive:
  # pragma omp section 換行符

single-construct:
  單一指令結構模塊

single-directive:
  # pragma omp single 單子句optseq換行

single-clause:
  data-clause
  nowait

parallel-for-construct:
  平行 for 指令的迭代语句

parallel-for-directive:
  # pragma omp parallel for 平行子句optseq換行

parallel-for-clause:
  獨特的並行子句
  專用條件
  data-clause

parallel-sections-construct:
  平行段落指令 區段範圍

parallel-sections-directive:
  # pragma omp parallel sections parallel-sections-clauseoptseq換行

parallel-sections-clause:
  獨特的並行子句
  data-clause

master-construct:
  主指令結構化區塊

master-directive:
  # pragma omp master 換行符

critical-construct:
  關鍵指令 結構式區塊

critical-directive:
  # pragma omp critical region-phraseopt換行符

region-phrase:
  (識別元)

barrier-directive:
  # pragma omp barrier 換行符

atomic-construct:
  原子指令表達式-語句

atomic-directive:
  # pragma omp atomic 換行符

flush-directive:
  # pragma omp flush flush-vars選項新行

flush-vars:
  (variable-list)

ordered-construct:
  有序指令結構塊

有序指令:
  # pragma omp ordered 換行符

/* 標準宣告 */

declaration:
  threadprivate-directive

threadprivate-directive:
  # pragma omp threadprivate ( 變數清單)換行符

data-clause:
  private ( 變數清單)
  copyprivate ( 變數清單)
  firstprivate ( 變數清單)
  lastprivate ( 變數清單)
  shared ( 變數清單)
  default ( shared )
  default ( none )
  reduction ( 縮減運算子:變數清單)
  copyin ( 變數清單)

reduction-operator:
 其中一個:+ \* - & ^ | && ||

/* 在 C 程式中 */

variable-list:
  識別碼
  variable-list,標識碼

/* 在 C++ 語言中 */

variable-list:
  id-expression
  變數清單,id運算式