Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
55 Views

Intel MPI Fortran & Intel C++ Coupling Error

Hello, I am trying to compile a simple just to check mpi fortran is working well with C++ but for some reason, I keep getting compiling errors or an executable which gives segmentation fault. 

Environment:

  • CentOS 6.7
  • ifort (IFORT) 19.0.1.144 20181018
  • GCC 4.4.7
  • Not using openmp

testf.f

      PROGRAM hello

      include 'mpif.h'
      integer :: PETOT, my_rank, ierr
      integer :: af, bf, cf
      CALL MPI_INIT (ierr)
      CALL MPI_COMM_SIZE (MPI_COMM_WORLD, PETOT, ierr)
      CALL MPI_COMM_RANK (MPI_COMM_WORLD, my_rank, ierr)
      
      write(*,'(a,2i8)') 'Hello World Fortran', my_rank, PETOT
      
      CALL MPI_FINALIZE (ierr)
      
      af=2
      bf=3
      
      CALL runc(af,bf,cf)
      
      write(*,*) cf
      STOP
      END

testc.cc

#include <stdio.h>

extern "C" {
      int runc_(int &a, int &b, int&c);
}

int runc_(int &a, int &b, int&c) {
      c=a+b;
            
      printf("Hello world\n");
      return 0;
}

At first I tried using GCC instead of icpc and everything went well with the compiling and execution.

mpiifort  -c -fpp testf.f -o testf.o
gcc -c -W -Wall testc.cc -o testc.o
mpiifort  testf.o testc.o  -fpp -o test.exe

However when I tried to use icpc using the exact same commands I get this error: testc.o:(.eh_frame+0x11): undefined reference to `__gxx_personality_v0' 

By the end I managed to compile it with this sequence of commands only to get a segmentation fault at the executable.

mpiifort -c -fpp -shared -fpic testf.f -o testf.o
icpc -c -W -Wall -shared -fpic testc.cc  -o testc.o
mpiifort  testf.o testc.o -fpp -shared -fpic -o test.exe

I really appreciate any kind of help here. Pretty much my first time compiling fortran/c++ together and cannot understand why there is this error with icpc but not with gcc (library linking problem?). Thanks in advance.

0 Kudos
1 Reply
Highlighted
55 Views

RE: gcc link

From one of the other forums:

You're probably using gcc for linking c++ code. Change it to g++ and it will work.

I cannot test this here...

RE: Segfault

Assure that you properly sourced both the ifort and intel MPI environments.

Jim Dempsey

0 Kudos