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

Using ifort to link .o files compiled with ifort & nvcc

Emec71LOp
Novice
1,271 Views

Hello,

I have a big(ish) fluids simulation code written in fortran which is compiled with ifort to run on 2 Xeon v4s. I am also trying gpu acceleration using C  interface routines (with iso C bindings) and of late I am trying to use a couple nvidia teslas for acceleration.

When compiling the C part of the code with gcc, ifort will link with the object files and nvidia libraries (cufft, cublas).  But having to write my own kernels it is necessary to be able compiling with nvcc. When doing so,  ifort cannot find any of the C routines.

A search for similar queries  produced no recent posts on the subject and the older suggestions seem not to work. It seems odd that this issue may be  unresolved given the dominance intel processors. A similar question on the nvidia site produced a wave of apathy.

 

Any suggestions?

Thanks.

--

0 Kudos
1 Solution
Emec71LOp
Novice
1,239 Views

This did the trick. Thank you v much.

==

View solution in original post

0 Kudos
5 Replies
Mark_Lewy
Valued Contributor I
1,257 Views

Without seeing an example of your code (perhaps a small reproducer?), it is difficult to say what might be going wrong.  We have CFD code that uses Fortran and CUDA (and hence nvcc) that builds fine on Windows and Linux, but we don't use ISO C binding (because the code predated Fortran 2003 support).

0 Kudos
Emec71LOp
Novice
1,251 Views

Thanks for the quick answer. Files anything.c  and anything.cu are identical. No specific cuda routines are invoked. Just simple C code. The last screenshot shows what happens.

0 Kudos
Mark_Lewy
Valued Contributor I
1,244 Views

CUDA code behaves like C++ by default, so you need to declare your functions with extern "C", i.e.

#include <stdio.h>
#include <cuda.h>
#include <cuda_runtime_api.h>

extern "C" void anything_( double A[], int *Nin )
{
int i;

   for( i=1; i<*Nin; i++ ) {
    printf("\n  i, A(i) = %d  %f ", i, A[i] );
   }
}
0 Kudos
Emec71LOp
Novice
1,238 Views

Thanks again. Flagged my post as solution instead of yours. Dimnation.

0 Kudos
Emec71LOp
Novice
1,240 Views

This did the trick. Thank you v much.

==

0 Kudos
Reply