我有两个f90源代码,并希望将它们组合起来构建一个动态库供以后使用(可能从其他语言调用)。问题是当我在Visual Studio中使用英特尔Fortran编译器2015编译它们时,会出现一些错误。源代码为mandel.f90
和mandel_wrap.f90
! Calculates the Mandelbrot set
module mandel
implicit none
integer, parameter :: dp=kind(0.d0) ! double precision
contains
pure function mandel_frac(z, c) result(out)
! The Mandelbrot map: z -> z^2 + c
complex(dp), intent(in):: z, c
complex(dp):: out
out = z**2 + c
end function mandel_frac
function calc_num_iter(re, im, itermax, escape) result(out)
! Iterates on mandel_frac
! Input:
! - re/im: vector of real/imaginary values of grid
! - itermax: maximum of iterations done
! - escape: stops if abs(z)>escape, for Mandelbrot escape=2
! Output:
! - number of iterations until abs(z)>escape
real(dp), intent(in):: re(:), im(:), escape
integer, intent(in):: itermax
integer:: out(size(re), size(im))
integer:: ii, jj, kk, itt
complex(dp):: zz, cc
!$OMP PARALLEL PRIVATE(jj, zz, cc, itt, kk)
!$OMP DO
do jj=1,size(im)
do ii=1,size(re)
zz = 0
cc = cmplx(re(ii), im(jj), dp)
do kk=1,itermax
zz = mandel_frac(zz, cc)
if (abs(zz)>escape) then
exit
end if
end do
if (kk>=itermax) then
out(ii,jj) = -1
else
out(ii,jj) = kk
end if
end do
end do
!$OMP END PARALLEL
end function calc_num_iter
end module mandel
和
module mandel_wrap
! To wrap calc_num_iter for use in C using iso_c_binding
use iso_c_binding, only: c_double, c_int
use mandel, only: calc_num_iter
implicit none
contains
! need to make a subroutine as only scalars can be returned
subroutine c_calc_num_iter(nre, re, nim, im, itermax, escape, out) bind(c)
real(c_double), intent(in):: re(nre), im(nim)
real(c_double), intent(in), value:: escape
integer(c_int), intent(in), value:: itermax, nre, nim
integer(c_int), intent(out):: out(nim, nre) ! note that in C the indices will be reversed!
out = transpose(calc_num_iter(re, im, itermax, escape)) ! thus the transpose here!
end subroutine c_calc_num_iter
subroutine c_calc_num_iter2(re, im, itermax, escape, out) bind(c)
real(c_double), intent(in):: re(:), im(:)
real(c_double), intent(in), value:: escape
integer(c_int), intent(in), value:: itermax
integer(c_int), intent(out):: out(size(im), size(re)) ! note that in C the indices will be reversed!
out = transpose(calc_num_iter(re, im, itermax, escape)) ! thus the transpose here!
end subroutine c_calc_num_iter2
end module mandel_wrap
错误消息是
error #8520: An array dummy argument of a BIND(C) procedure must be an explicit shape or assumed size array. [RE]
error #8520: An array dummy argument of a BIND(C) procedure must be an explicit shape or assumed size array. [IM]
此外,当我尝试使用 gfortran 编译它们时,它给了我不同的错误消息
subroutine c_calc_num_iter2(re,im,itermax,escape,out) bind(c)
2 1
Error: Assumed-shape array 're' at (1) cannot be an argument to the procedure 'c_calc_num_iter2' at (2) because the procedure is BIND(C) mandel_wrap.f90