Stumbling through getting an OpenMPI app compiling and linking with (and without) NetBeans on Fedora


Fedora 14
Netbeans 6.9 + g++ 4.5.1 and MPICH2


I wanted to play around with OpenMP and C++ and I wanted to use the NetBeans IDE but had no luck compiling and/or linking.

Naively I did this:

  • installed MPICH2 packages using the package manager (I tried first with yum but that didn’t work at all…could be a red herring but be warned, see end notes.) 
  • openend up NetBeans, created a C++ app project and wrote a little Hello World program with a simple #pragma omp parallel section
  • I hit compile and…naturally, it just compiles a standard single-threaded app (ignoring the unrecognized pragma)
  • So, I tried to compile the program on the command line using the mpic++ compiler/linker wrapper which is installed with openmpi-devel
    • It failed with the errors about not finding -lmpichcxx, -lpmipch and -lopa (again, see end notes)


  1. mpic++ for some reason or other produces the wrong (???) command line;
    1. it typically looks like this: 
      1. c++ -m32 -O2 -Wl,-z,noexecstack -I/usr/include/mpich2-i386 -L/usr/lib/mpich2/lib -L/usr/lib/mpich2/lib -lmpichcxx -lmpich -lopa -lpthread -lrt
    2. but it should look like this (highlighting changes from above only):
      1. c++ -fopenmp -m32 -O2 -Wl,-z,noexecstack -I/usr/include/mpich2-i386 -L/usr/lib/mpich2/lib -L/usr/lib/mpich2/lib -lmpichcxx -lmpich -lgomp -lpthread -lrt
  2. Therefore, in the properties of your NetBeans project, under C++ Compiler::Additional Options you set the command line to
    1.  -fopenmp -m32 -O2 -Wl,-z,noexecstack -I/usr/include/mpich2-i386 -L/usr/lib/mpich2/lib -L/usr/lib/mpich2/lib -lmpichcxx -lmpich -lgomp -lpthread -lrt
    2. Alternatively you can of course use that as-is on the command line
  3. ..and compile…and it runs, and according to my perf monitor it uses more than one thread. Perfect.


libgomp is the GNU OpenMP library and it is part of the gcc 4.5.x install (and possibly earlier, but I haven’t checked/tested this). I don’t know what “libopa” was/is (can’t find anything about it) so it might even be a typo (although this would be horrendous and hopefully not the case) – If anybody reading this can shed some light….?

I tried with c++ and g++ both in the project settings in NetBeans but it doesn’t matter which one you use, as long as the command line is correct as in step 2 above.

The issue alluded to concerning installing OpenMPI using Yum; I did this first #yum install openmpi openmpi-devel but it seems that this, although it installed the libraries, did not create appropriate symlinks to them so that ld could find them (see note about ld failing at the top of this post.) I therefore manually created these and it fixed the linking, but as I subsequently did an install of MPICH2 using the package manager before I got the app running properly I can’t verify exactly if this had a positive effect overall or if it was a red herring. If anybody can recreate this and confirm then that would be great.

Btw, here are some great links for some OpenMP examples and tutorials: