Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
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.
#pragma omp [parallel] sections [clauses]
{
#pragma omp section
{
code_block
}
}
where,
clause
(optional)
Zero or more clauses. See the Remarks section for a list of the clauses supported by sections.
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.
// 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