Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Fanny_D_
Beginner
97 Views

Gcc compiler and openmp linking

Hi,

I have a problem with the gcc compiler (version Red Hat 5.3.1-2) and the linking of openmp libraries.

My code includes both some OpenMP directives (so I have to compile with -fopenmp) and some MKL functions (so I link with -liomp5 -lpthread (composer_xe_2013) to use the multithreading).

So my executable is linked with both libgomp.so and libiomp5.so.

The multi-threading in the MKL functions works fine but the OpenMP directives (#pragma ...) are not taken into account.

Why do these two links prevent the OpenMP directives?

Below is a simple code which illustrates the problem.

#include <cstdio>
#include "omp.h"

int main(int argc, char *argv[])
{

omp_set_num_threads(4);
    
#pragma omp parallel
       {
         printf("number of threads = %d \n", omp_get_num_threads());
       }
            
return 0;
}

When I compile with "/usr/bin/c++ OpenMP_test.cpp -o OpenMP_test -fopenmp" the OpenMP directives work.

When I compile with "/usr/bin/c++ OpenMP_test.cpp -o OpenMP_test -fopenmp -L/opt/intel/lib/intel64 -liomp5 -lpthread"  the OpenMP directives don't work.
 
Thanks for your help

0 Kudos
1 Reply
TimP
Black Belt
97 Views

It's just plain wrong to link both libgomp and libiomp5, as the latter supports libgomp compatibility on Linux. You may need to separate your compile and link steps so as to avoid fopenmp in the latter. You might succeed in getting the link step to ignore fopenmp if you would give a more reasonable order in your command line.

Reply