다음을 통해 공유


sections (OpenMP)

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

Identifies code sections to be divided among all threads.

Syntax

#pragma omp [parallel] sections [clauses]  
{  
   #pragma omp section  
   {  
      code_block   
   }   
}  

Remarks

where,

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

Remarks

The sections directive can contain zero or more section directives.

The sections directive supports the following OpenMP clauses:

If parallel is also specified, clause can be any clause accepted by the parallel or sections directives, except nowait.

For more information, see 2.4.2 sections Construct.

Example

// omp_sections.cpp  
// compile with: /openmp   
#include <stdio.h>  
#include <omp.h>  
  
int main() {  
    #pragma omp parallel sections num_threads(4)  
    {  
        printf_s("Hello from thread %d\n", omp_get_thread_num());  
        #pragma omp section  
        printf_s("Hello from thread %d\n", omp_get_thread_num());  
    }  
}  
Hello from thread 0  
Hello from thread 0  

See Also

Directives