Suppose I have the following Fortran subroutine:
subroutine f_test(n,x,value)
use iso_c_binding
implicit none
integer, intent(in) :: n
real(kind=8), intent(in) :: x(n)
real(kind=8), intent(out) :: value
integer(kind=c_int) :: n_
real(kind=c_double) :: value_,x_(n)
n_ = transfer( n, n_ )
x(1:n) = transfer( x(1:n), x_(1:n) )
call c_test(n_,x_,value_)
value = transfer( value_, value )
end subroutine f_test
and also suppose that c_test
is a pointer to a C routine that works over the vector x
and returns a result in value
variable.
This works perfectly, but I have a question about it:
The conversion of the vector x
can dramatically affect the complexity of an algorithm that calls the subroutine f_test
. I mean that, if a such algorithm calls f_test
n
times, the complexity of the algorithm will be quadratic, but without this conversion, it would be simply linear. So, this conversion made in this way is impracticable. Is there any reasonable way to work around this issue?