Calling PGI compiled code from a program compiled with the IBM xl compiler


we want to compile a CFD code on a Power9 machine. For some parts of the code we want to use the IBM xl compiler and for some other parts which include OpenACC code we want to use the PGI compiler.
Is it possible to compile the OpenACC code into a library using the PGI compiler and then call it from a program which was compiled using the IBM xl compiler? We are using FORTRAN as a programming language.

Thank you for your help

It might be tricky.

Generally, Fortran from one vendor can call/link with Fortran from another vendor if you stick to F77-style interfaces between subprograms. That means no assumed shape argument passing, no F90 pointers, nothing that requires you to pass a descriptor. And likely no sharing of Fortran modules between the two pieces of code.

To link, you will have to see what libraries the PGI compiler pulls in when linking with -ta=tesla (you can use -v here to see what we specify to “ld”, the linker). Then manually add those to your link line, along with the path to those specified with -L.

Thank you for the information! Does the descriptor restriction include MPI communicators?

Hi Peter,

A descriptor would only be used with allocatable arrays or Fortran pointers. MPI Communicators such as MPI_COMM_WORLD are handles so I don’t think would apply.

Though are you thinking of passing a communicator and then calling MPI APIs between the two compiled sections of code? I’ve not tried this myself so don’t know all the issues you may encounter but it may be tricky as well since you’ll need to make sure the same MPI is used for both. Also, you’ll need to include an MPI header rather than use the MPI interface module since modules are not compatible between compilers. Might be best to keep the MPI portion of the code in one compiled section (presumably the XL built part).

Any reason to not just use PGI for the entire project? Might make your life a lot easier.


Thank you for your answer! Yes thats sounds all very tricky. We wanted to use the IBM compiler because we observed slightly higher performance on the Power9 system. But the difference is not that big.
We will use the PGI compiler for the whole project.

I have a different question. The CFD code is written in FORTRAN but I want to add some new C++ files to the code which contain OpenACC and CUDA code. Later I want to call the C++ functions from the FORTRAN code, could this cause any problems with the PGI compiler?

Thank you for your help!

Later I want to call the C++ functions from the FORTRAN code, could this cause any problems with the PGI compiler?

Other than normal inter-language calling issues, it shouldn’t be an issue. Best to use Fortran ISO_C_BINDING features to make it easier and use a C interface layer (i.e. call routines decorated with extern “C”) to bridge the Fortran and C++.


Thank you for the information, I will try it!