'OpenMP'에 해당되는 글 1건

320x100

병렬처리 방법 #2. 컴파일러가 지원하는 OpenMP !

Posted on 2009. 4. 28. 18:34
Filed Under Programming/Basic

2008/03/24
우연히 ZDNet에서 본 동영상: 프로그램 내에 병렬처리를 가능케 하기 위해 어떻게 해야 하는가?

 
 ▲ 아저씨 왜 그렇게 잘아셩~ *.*?

컴파일러가 지원하는 OpenMP < 이런게 있었단다 헐;
MSDN 검색해보니 'parallel OpenMP directive' 라고 있었다. 역시..

[CODE]
#include <windows.h>
#include <time.h>
#include <stdio.h>
#include <omp.h>
#include <conio.h>

int main()
{
 DWORD t1 = GetTickCount();
 
 struct tm  when;
 __time64_t before, after, result;

 time( &before );


 #pragma omp parallel for (i, j, k)
 {
  for( int i = 0; i < 100; i++ ) //int i = omp_get_thread_num();
  {
   printf_s("[i] Hello from thread %d\n", i);
   for( int j = 100; j < 150; j++ )
   {
    printf_s("\t[j] Hello from thread %d\n", j);
    for( int k = 1000; k < 1100; k++ )
    {
     printf_s("\t\t[k] Hello from thread %d\n", k);
    }
   }
  }

 }

 time( &after );
 result = after - before;
 _localtime64_s( &when, &result );
 
 DWORD t2 = GetTickCount();
 printf_s( "%d sec", when.tm_sec );

 _getch();
}
[/CODE]

돌려봤다;
27초 : 28초
밀리초 단위로 재봐야 확실히 나올듯하다.
아무튼 오늘은 컴파일러가 저런것도 지원한다는 것의 발견.. >_</

동영상 설명중 병렬처리 가장 많이 쓰는 방법: threading building blocks 는 아래 사이트 참조!
http://threadingbuildingblocks.org/


반응형

About

by 쑤기c

반응형