15. March, 2006
11. September, 2007
in by Michael Neumann

OpenMP works fine with GCC 4.2. I tried it with the following hello world example:

/* hello.c */
#include <stdio.h>
int main(int argc, char** argv)
{
  int myid, numprocs;

  #pragma omp parallel private(myid, numprocs)
  {
    myid = omp_get_thread_num();
    numprocs = omp_get_num_threads();

    printf("Hello, I'm thread %d of %d\n", myid, numprocs);
  }

  return 0;
}

Now lets produce an executable:

gcc42 -fopenmp -c hello.c
gcc42 hello.o -lgomp -lpthread -o hello

And execute it with 4 threads:

export OMP_NUM_THREADS=4
./hello

What you get will look like:

Hello, I'm 0 of 4
Hello, I'm 1 of 4
Hello, I'm 2 of 4
Hello, I'm 3 of 4

This is great news! Now looking forward to try out OpenMPI, not to be confused with OpenMP!!! It’s message passing and not shared memory, completely different thingy. Harder to program with (hmm, not always), but much more scalable, as you can distribute the paralellel programs on your very own computer cluster (take 4 PCs and connect via Ethernet and your done). Quite a lot cheaper than SMP systems, but of course performs not that good for a low number of processors. If you have more than 64 processors in an SMP system, it’s probably better to switch to message passing :). But if you’ve so many processors, you should be a lucky man, don’t you?