Skip to content

Latest commit

 

History

History
101 lines (84 loc) · 2.24 KB

File metadata and controls

101 lines (84 loc) · 2.24 KB
title single | Microsoft Docs
ms.custom
ms.date 11/04/2016
ms.reviewer
ms.suite
ms.technology
cpp-windows
ms.tgt_pltfrm
ms.topic article
f1_keywords
Single
dev_langs
C++
helpviewer_keywords
single OpenMP directive
ms.assetid 85cf94fb-cb9c-4d82-8609-adffa9f552e1
caps.latest.revision 11
author mikeblome
ms.author mblome
manager ghogen
translation.priority.ht
cs-cz
de-de
es-es
fr-fr
it-it
ja-jp
ko-kr
pl-pl
pt-br
ru-ru
tr-tr
zh-cn
zh-tw

single

Lets you specify that a section of code should be executed on a single thread, not necessarily the master thread.

Syntax

#pragma omp single [clauses]   
{  
   code_block   
}  

Parameters

clause (optional)
Zero or more clauses. See the Remarks section for a list of the clauses supported by single.

Remarks

The single directive supports the following OpenMP clauses:

The master directive lets you specify that a section of code should be executed only on the master thread.

For more information, see 2.4.3 single Construct.

Example

// omp_single.cpp  
// compile with: /openmp   
#include <stdio.h>  
#include <omp.h>  
  
int main() {  
   #pragma omp parallel num_threads(2)  
   {  
      #pragma omp single  
      // Only a single thread can read the input.  
      printf_s("read input\n");  
  
      // Multiple threads in the team compute the results.  
      printf_s("compute results\n");  
  
      #pragma omp single  
      // Only a single thread can write the output.  
      printf_s("write output\n");  
    }  
}  
read input  
compute results  
compute results  
write output  

See Also

Directives