Tuesday, May 8, 2007

OpenMP with Vc++

Microsoft Windows provides support for OpenMP standard. If you don't know what is OpenMP read this from wikipedia.

 " The OpenMP (Open Multi-Processing) is an application programming interface (API) that supports multi-platform shared memory multiprocessing programming in C/C++ and Fortran on many architectures, including Unix and Microsoft Windows platforms. It consists of a set of compiler directives, library routines, and environment variables that influence run-time behavior."

 In VC++ this OpenMP can be called using #pragma omp <> directvies.
 OpeMP is mainly used for parellel computing in the applications. Thread is created in openMp is like this
#pragma omp parallel num_threads(count ) , So the codes after this directive will be excuted in separte threads. count is the thread count.

For example
 #pragma omp parallel num_threads(3)

Here we can see 3 different message box while the running this program. it is not possible to "return" or "goto" from inside the omp blocks.
Another example is parallely computing the sum of numbers in an array. Like this

int arry[10] = {1,2,3,4,5,6,7,8,9,10};
#pragma omp parallel for

for(int i = 0; i < 10;i++)

Note:  For using OpenMp in you application , you should provide the switch /openmp in compiler options.
          If you need more information about OpenMp , please look the following links
         1 . http://en.wikipedia.org/wiki/OpenMP

1 comment:

Andrei said...

you probably need a "#pragma omp atomic" for that addition example.