Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Error when mixing ifort / c++ / python

Ekaterina_M_
Beginner
1,544 Views

Dear all, 

I am facing issues I don't seem able to resolve. Hopefully someone here will have an answer or a hint.

Here's the context. I have to couple two software pieces via Python:

Piece 1:

  • fortran 90 code built into shared libraries
  • built with openmpi 1.6.4 / ifort 15.0.2
  • uses mpi, openmp and some legacy libs that can not be rebuilt
  • a python interface to the main routine is created via f2py

Piece 2:

  • C++ code with Python interface generated by Swig
  • uses mpi and some routines from Pièce 1's shared libraries
  • compiled with distutils => the default linker is g++ as Python has been compiled with

Python:

  • python 2.7, built with GNU (no intel C/C++ compiler on my machine)
  • the main script must execute some ops from "Piece 2" then some ops from "Piece 1"

Today, I am able to execute Piece 1 or Piece 2 code through a python script. However the environment is different. My problem is to be able to call both in the same script. I have read here that I have to link everythin with ifort. Well, as Python has been compiled with GNU, it'll need a hack to change the linker but I am not even sure it is the solution.

What would be your roadmap if you had to set up a coupling like this?

Best regards,

Ekaterina.

 

 

0 Kudos
4 Replies
Steven_L_Intel1
Employee
1,544 Views

No, you don't have to link everything with ifort. If you are mixing Fortran and C++ code, it's best if you link with ifort but you could link with gcc if you get the libraries right.

Since you seem to have two executables being called from Python, I don't see what the problem is. Are you having a problem?

0 Kudos
Ekaterina_M_
Beginner
1,544 Views

Hello Steve and thanks a lot for your answer. Surely, I am not getting the libraries right. Maybe I should give more details on my "pieces".

Piece 1

---------------------------------------
#if defined (LIBRARY)
   subroutine main()
#else
   program main
#endif
   integer i
#if defined (LIBRARY)
   call get_piece2(i)
#else
   call read_file(i)
#endif
   call compute(i)
   end

---------------------------------------

   subroutine read_file (i)
   [read data from file]
   end

---------------------------------------

Static library lib1.a (external) defines compute(), I have no source code for it.

---------------------------------------

I generate:

  • without -DLIBRARY: lib2.a (main + file) + executable linked to both lib1.a and lib2.a
  • with -DLIBRARY: lib3.so (main)
  • lib1.a converted to lib1.so (extract with ar + build lib with ld)
  • python interface uses lib3.so

Piece 2

I generate:

  • lib4.so: a shared library using get (=> link to lib2 is required for read_file)
  • lib5.so: another shared library defining get_piece2

Triggering script

from piece2 import lib4

[initialize piece2 data using lib4]

[launch piece1 via lib3]

 

When importing lib4, I get unresolved symbol errors (mpi, openmp, intel, ... ), symbols coming from lib1 and lib3. I have tried to resolve them by adding libs to the piece 2 library generation step (like -lirc), I have stopped at _f90_dope_vector_init saying myself it was probably not a good way to go.

Ekaterina.

0 Kudos
Steven_L_Intel1
Employee
1,544 Views

It's difficult to provide the best advice when you are not showing actual code or commands. Adding libraries with -l when building a .a is not helpful, as that doesn't do anything.

You will not only need to add the appropriate libraries -lifcore -lirc, -letc., -liomp5, but also add -L to give the path to where the Intel Fortran libraries are provided. 

0 Kudos
Ekaterina_M_
Beginner
1,544 Views

Hello!

Thanks for your help, I have finally redone the whole legacy compilation process and now mixing goes well. The issue is resolved.

Regards.

 

0 Kudos
Reply