OpenMP를 시작하며

OpenMP Directives
Directive Description

atomic

Specifies that a memory location that will be updated atomically.

barrier

Synchronizes all threads in a team; all threads pause at the barrier, until all threads execute the barrier.

critical

Specifies that code is only executed on one thread at a time.

flush (OpenMP)

Specifies that all threads have the same view of memory for all shared objects.

for (OpenMP)

Causes the work done in a for loop inside a parallel region to be divided among threads.

master

Specifies that only the master threadshould execute a section of the program.

ordered (OpenMP Directives)

Specifies that code under a parallelized for loop should be executed like a sequential loop.

parallel

Defines a parallel region, which is code that will be executed by multiple threads in parallel.

sections (OpenMP)

Identifies code sections to be divided among all threads.

single

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

threadprivate


예제
_tprintf(_T("Start OpenMP\r\n"));
omp_set_num_threads(10);
_tprintf(_T("omp_get_max_threads() : %d\r\n"), omp_get_max_threads());
#pragma omp parallel
{
for(int i=0 ; i< 10; i++)
{
_tprintf(_T("%d"), i);
}
}

output:
Start OpenMP
omp_get_max_threads() : 10
01000000000123411111111234567222222225678933333333894444444456785555555678966666
69777777898888899999


_tprintf(_T("Start OpenMP\r\n"));
omp_set_num_threads(10);
_tprintf(_T("omp_get_max_threads() : %d\r\n"), omp_get_max_threads());
#pragma omp parallel for
for(int i=0 ; i< 10; i++)
{
_tprintf(_T("%d"), i);
}

or


#pragma omp parallel
{
#pragma omp for
for(int i=0 ; i< 10; i++)
{
_tprintf(_T("%d"), i);
}
}



output:
Start OpenMP
omp_get_max_threads() : 10
0123456789


chaoskcuf
tags :
프로그래밍/TIP& Study 2006/11/07 22:52

트랙백 주소 : http://chaoskcuf.com/trackback/23

댓글을 달아 주세요

Powerd by Textcube, designed by criuce
rss