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

using gsl from fortran

jft27
Beginner
1,874 Views
Hi,

I'm trying to make use of a gsl function to compute wigner 3j symbols within a fortran program.

I'm having a problem that my program works when I pass constants to the c function but not when I pass variables (the gsl function raises an exception). I have included a simple test case
which was compiled with the command

ifort test_gsl.f90 -lgsl -lgslcblas

the program code is

program test_gsl

use iso_c_binding

implicit none


interface
real(c_double) function gsl_sf_coupling_3j&
(l1, l2, l3, m1, m2, m3) bind(c)
use iso_c_binding
integer(c_int) :: l1, l2, l3, m1, m2, m3
end function gsl_sf_coupling_3j
end interface


real(c_double) :: wigner3j
integer(c_int) :: j



!this bit works
wigner3j = gsl_sf_coupling_3j(4, 4, 4, 0, 0, 0)

print*, wigner3j


!this bit doesn't work
j = 4_c_int

wigner3j = gsl_sf_coupling_3j(j, j, j, 0, 0, 0)

print*, wigner3j


end program test_gsl


thanks in advance for any suggestions!
Jeremy



0 Kudos
2 Replies
reinhold-bader
New Contributor II
1,874 Views
Hello,

the interface is not correctly specified; according to the GSL reference manual the integer arguments are passed by value. ifort supports this, so you need to declare:

integer(c_int), value :: l1, l2, l3, m1, m2, m3


[I suspect the compiler assumes intent(inout) for your code and hence performs
copy-in if constants are provided].

While we're at it, I guess I can now shamelessly plug FGSL:

http://www.lrz-muenchen.de/services/software/mathematik/gsl/fortran/index.html

Regards

0 Kudos
jft27
Beginner
1,874 Views
Great, that works.

I found fgsl about 5 minutes after posting my original message. It's an interesting project.

Unfortunately I needed to compute wigner 3j symbols and it turns out the gsl code isn't great at this; overflows for large angular momenta.

many thanks
Jeremy

0 Kudos
Reply