All of the interesting technological, artistic or just plain fun subjects I'd investigate if I had an infinite number of lifetimes. In other words, a dumping ground...

Friday 24 April 2009

OpenMP programming

OpenMP

g++ -Wall -o opm opm.cc -fopenmp

#include <stdio.h>
#include <omp.h>

int main ()  {

int nthreads, tid;



/* Fork a team of threads with each thread having a private tid variable */
#pragma omp parallel private(tid)
  {

  /* Obtain and print thread id */
  tid = omp_get_thread_num();
  printf("Hello World from thread = %d\n", tid);

  /* Only master thread does this */
  if (tid == 0)
    {
    nthreads = omp_get_num_threads();
    printf("Number of threads = %d\n", nthreads);
    }

  }  /* All threads join master thread and terminate */

}

No comments:

tim's shared items

Add to Google Reader or Homepage