단일

코드 섹션을 마스터 스레드가 아닌 단일 스레드에서 실행 되도록 지정할 수 있습니다.

#pragma omp single [clauses] 
{
   code_block 
}

매개 변수

  • clause(선택적 요소)
    0 개 이상의 절입니다.목록에 대 한 설명 부분에서 지원 절을 참조 하십시오. 단일.

설명

해당 단일 지시문 다음 OpenMP 절을 지원 합니다.

마스터 지시문을 사용 하면 코드 부분 마스터 스레드에서만 실행 되도록 지정 합니다.

자세한 내용은 2.4.3 단일 구문를 참조하십시오.

예제

// 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");
    }
}
  

참고 항목

참조

OpenMP 지시문