c - 对主要 Fortran 程序的 undefined reference

标签 c fortran fortran90 hpc intel-fortran

我正在编写用于对三个循环内核进行基准测试的 Fortran 代码:

       program Kernel_benchmark

       implicit none

       double precision,dimension (:),save,allocatable:: a,b,c,d,x,y
       double precision s
       double precision,dimension (:,:),save,allocatable:: mat
       double precision wcs,wce,ct,runtime, total
       integer k,iter,r,i,j,N


       do k = 3, 20
          N = INT(2.5**k)
          allocate (a(N),b(N),c(N),d(N))
          do i=1,N
             a(i) = 1.2
             b(i) = 1.2
             c(i) = 1.2
             d(i) = 1.2
          end do
          iter = 1
          runtime = 0.0
          do while(runtime < 0.2)
            call timing(wcs,ct)
            do r =0, iter
                    do i=1,N
                            a(i) = b(i) + c(i) * d(i)
                    end do
                    if(a(ISHFT(N,-1)) < 0.0) then
                             call dummy(a)
                    end if
            end do
            call timing(wce,ct)
            runtime = wce - wcs
            iter = iter * 2
        end do
        iter = iter / 2
        open(unit=1, file = 'vector_triad.dat',status = 'unknown')
        write(1,*) N, (N * iter* 2) / (runtime * 1e-6)
        close(1)
        deallocate(a,b,c,d)
     end do

     do k = 3, 20
       N = INT(2.5**k)
       allocate(a(N))
       do i = 1, N
            a(i) = 1.2
       end do
       s = 2.2
       iter = 1
       runtime = 0.0
    do while(runtime < 0.2)
            call timing(wcs,ct)
            do r = 0, iter
                    do i = 1, N
                            a(i) = s * a(i)
                    end do
                    if(a(ISHFT(N,-1)) < 0.0) then
                             call dummy(a)
                    end if
            end do
            call timing(wce,ct)
            runtime = wce - wcs
            iter = iter * 2
    end do
    iter = iter / 2
    open (unit = 2, file = 'vector_update.txt', status = 'unknown' )
    write(2,*) N, (N * iter) / (runtime * 1e-6)
    close(2)
    deallocate(a)
  end do

  do k = 10, 22
      N = INT(1.5**k)
      allocate (mat(N,N),x(N),y(N))
      do i = 1, N
            do j = 1, N
                    mat(i,j) = 1.2
            end do
            y(i) = 1.2
            x(i) = 1.2
      end do
      iter = 1
      runtime = 0.0
      do while(runtime < 0.2)
            call timing(wcs,ct)
            do r = 0, iter
                    do i = 1, N
                            y(i) = 0.0      
                            do j = 1, N
                                    y(i)     = y(i) + (mat(i,j) * x(i))
                            end do
                    end do
                    if(y(ISHFT(N,-1))< 0.0) then
                            call  dummy(y)
                    end if
            end do
            call timing(wce,ct)
            runtime = wce - wcs
            iter = iter * 2
      end do
      iter = iter / 2
      open (unit = 3, file = 'matrix_vector.txt', status ='unknown')
      write(3,*) N, (2 * N * N * iter) / (runtime * 1e-6)
      close(3)
      deallocate(mat,x,y)
    end do

end program Kernel_benchmark

我在C源文件中编写的虚拟函数如下

#include "dummy.h"

void  dummy(double *array){
    printf ("Well if its printing this then you're pretty much screwed.");
}

dummy.h 只包含函数原型(prototype)。

我制作了一个 dummy.o 目标文件,并尝试使用 intel ifort 编译器将它与我的 Fortran 源代码链接起来。不幸的是,我收到一个错误 在函数 MAIN__':bench.f90:(.text+0x8ca): undefined reference todummy_'

每次调用虚拟函数时。有什么建议吗?提前致谢。

最佳答案

与 Fortran 接口(interface)的现代方式是与 C 和 iso_c_binding 模块的互操作性,正如本网站多次讨论的那样。

Calling a FORTRAN subroutine from C

https://stackoverflow.com/search?tab=votes&q=iso_c_binding

关于c - 对主要 Fortran 程序的 undefined reference ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16284383/

相关文章:

c - 在没有 malloc 的情况下在 C 中实现一个简单的链表

gdb - 使用 gdb 和 gfortran 进行调试 - FPE

pointers - 类型声明的 Fortran 指针属性

fortran - 使用 Fortran FMZM 多精度库中的 IM_FORM 显示任意长度格式化字符串

fortran - 使用隐式 do 循环写入文件

c - 删除C中的特殊字符

c - 在c程序中执行一条Linux命令

c++ - 为什么 Direct3D 没有自己的顶点结构?

fortran - 从 Fortran 中的特定行号开始读取

c - 如何确定 C 与数组的互操作性