The -openmp flag in ifort does more than just enable the OpenMP directive. He also links to the appropriate libraries. Assuming you have already dealt with underscores in the naming routine, then if you add -openmp to the ifort link step, which takes care of the OpenMP libraries, and adding -lstdC ++ will handle C ++ links (e.g. __gxx_personality_v0).
Or you can use the options provided by ifort. A simple example:
$> cat a.f90
program a
print *, "calling C++ program"
call b()
end program a
$> cat b.cpp
#include <omp.h>
#include <stdio.h>
extern "C" {
void b_(void); }
void b_(void) {
int i;
#pragma omp parallel for
for (i = 0; i < 10; i++)
printf("t#: %i i: %i\n", omp_get_thread_num(), i);
}
$> g++ -fopenmp -c -o b.o b.cpp
$> ifort -g -O0 -c -o a.o a.f90
$> ifort -openmp -cxxlib -openmp-lib compat b.o a.o
$> export OMP_NUM_THREADS=4
$> a.out
calling C++ program
t#: 2 i: 6
t#: 2 i: 7
t#: 2 i: 8
t#: 3 i: 9
t#: 0 i: 0
t#: 0 i: 1
t#: 0 i: 2
t#: 1 i: 3
t#: 1 i: 4
t#: 1 i: 5
You must tell ifort to use OpenMP (-openmp), be compatible with the GNU OpenMP runtime library libgomp (-openmp-lib compat), and link using the C ++ runtime libraries provided by g ++ (- cxxlib).
source
share