Wednesday, January 27, 2010

Think Parallel With Open MP

Ya pretty significant article this , due to the rapid development of MultiCore technologies , to take advantage of the multithreaded aspects of processes.

Open MP is a platform for writing parallel programs in C , C++ or Fortran in the form of library routines and environment variables.

The main advantage is the conversion of existing serialised code , into parallel codes. So , if we would like to use the multicore aspect of our processors , this platform is the place to start.

This platform is maintained by market leaders , such as AMD,Cray,HP,IBM,INTEL,Microsoft etc..

To find a list of supported compilers visit:

SUPPORTED COMPILERS

and for more info on the platform ,visit

http://openmp.org/

You can try this Simple Code Snippet :


// A program to test the working of open MP platform on fedora 12 (TRIED BY ME ELSE INSTALL IT ON YOUR PLATFORM)
// Author : Prashanth R
include omp.h and stdio.h
 

int main(){
int nthreads,tid;
omp_set_num_threads(3);
/*parallel code here*/

#pragma omp parallel
{
tid = omp_get_thread_num();
printf("Called by thread %d \n",tid);

if(tid==0){
nthreads = omp_get_num_threads();
printf("The number of threads is %d \n",nthreads);
}
}
return 0;
}


compile the following code as :
gcc -fopenmp filename.c

As usual feel free to comment .