Hi,
I am trying to call the FORTRAN routine ILAENV in LAPACK [1] from CL, using CFFI. It has CHARACTER*(*) arguments, and I am not sure how to handle these. I found a lot of conflicting information on the web, including examples which used C-style zero-terminated strings [2], and others which mention string length as an extra argument to the function.
Any kind of guidance on how to do this would be appreciated.
Thanks,
Tamas
[1] http://www.netlib.org/lapack/util/ilaenv.f [2] http://www.ualberta.ca/AICT/RESEARCH/LinuxClusters/doc/acml350/ ILAENV_002dILAENVSET.html
CHARACTERs in Fortran are just pointers of type char*, just like in C, and just like any other fortran array. There is no terminating null and the fortran functions get the length either from some argument or because they assume a given size (for instance in Lapack it is a one-character string what the function expects)
On Sat, Jun 5, 2010 at 12:45 PM, Tamas K Papp tkpapp@gmail.com wrote:
Hi,
I am trying to call the FORTRAN routine ILAENV in LAPACK [1] from CL, using CFFI. It has CHARACTER*(*) arguments, and I am not sure how to handle these. I found a lot of conflicting information on the web, including examples which used C-style zero-terminated strings [2], and others which mention string length as an extra argument to the function.
Any kind of guidance on how to do this would be appreciated.
Thanks,
Tamas
[1] http://www.netlib.org/lapack/util/ilaenv.f [2] http://www.ualberta.ca/AICT/RESEARCH/LinuxClusters/doc/acml350/ ILAENV_002dILAENVSET.html
cffi-devel mailing list cffi-devel@common-lisp.net http://common-lisp.net/cgi-bin/mailman/listinfo/cffi-devel
On Sat, 5 Jun 2010 16:12:58 +0200, Juan Jose Garcia-Ripoll said:
CHARACTERs in Fortran are just pointers of type char*, just like in C, and just like any other fortran array. There is no terminating null and the fortran functions get the length either from some argument or because they assume a given size (for instance in Lapack it is a one-character string what the function expects)
Are you sure about? I think the lengths are passed as implicit arguments at the end of the argumwnt list.
On Mon, Jun 7, 2010 at 10:56, Martin Simmons martin@lispworks.com wrote:
On Sat, 5 Jun 2010 16:12:58 +0200, Juan Jose Garcia-Ripoll said:
CHARACTERs in Fortran are just pointers of type char*, just like in C, and just like any other fortran array. There is no terminating null and the fortran functions get the length either from some argument or because they assume a given size (for instance in Lapack it is a one-character string what the function expects)
Are you sure about? I think the lengths are passed as implicit arguments at the end of the argumwnt list.
Not on any Fortran compilers I've seen, at least when dealing with LAPACK. Replacing CHARACTER*(*) with "char* const" when calling LAPACK routines that take CHARACTER*(*) arguments works perfectly fine with all the Fortran compilers I've encountered (e.g., gfortran, Intel Fortran compiler, IBM's xlf).
mfh
On Mon, 7 Jun 2010 11:12:47 -0600, Mark Hoemmen said:
On Mon, Jun 7, 2010 at 10:56, Martin Simmons martin@lispworks.com wrote:
> On Sat, 5 Jun 2010 16:12:58 +0200, Juan Jose Garcia-Ripoll said:
CHARACTERs in Fortran are just pointers of type char*, just like in C, and just like any other fortran array. There is no terminating null and the fortran functions get the length either from some argument or because they assume a given size (for instance in Lapack it is a one-character string what the function expects)
Are you sure about? I think the lengths are passed as implicit arguments at the end of the argumwnt list.
Not on any Fortran compilers I've seen, at least when dealing with LAPACK. Replacing CHARACTER*(*) with "char* const" when calling LAPACK routines that take CHARACTER*(*) arguments works perfectly fine with all the Fortran compilers I've encountered (e.g., gfortran, Intel Fortran compiler, IBM's xlf).
Maybe LAPACK is compiled with options that make this work (or nothing looks at the length arguments), but when I compile the code below with gfortran it clearly passes the string lengths 4 and 3 as extra arguments.
INTEGER FUNCTION ILAENV( NAME , NN ) CHARACTER*( * ) NAME, NN ILAENV = ICHAR( NAME( 1: 1 ) ) RETURN END
INTEGER FUNCTION ZZZ( ) ZZZ = ILAENV("fooo", "bar") RETURN END
movl $3, %ecx movl $4, %edx movl $.LC0, %esi movl $.LC1, %edi call ilaenv_
We were talking about Fortran. I do not know about Fortran90. Lapack is definitely Fortran77 and is compiled as such. In any case I would recommend linking against cblas and clapack, the C bindings that are also available for the most useful libraries -- atlas, Intel's, IBM's. There is no ambiguity there.
Juanjo
On Mon, Jun 7, 2010 at 8:38 PM, Martin Simmons martin@lispworks.com wrote:
On Mon, 7 Jun 2010 11:12:47 -0600, Mark Hoemmen said:
On Mon, Jun 7, 2010 at 10:56, Martin Simmons martin@lispworks.com
wrote:
>> On Sat, 5 Jun 2010 16:12:58 +0200, Juan Jose Garcia-Ripoll said:
CHARACTERs in Fortran are just pointers of type char*, just like in C,
and
just like any other fortran array. There is no terminating null and
the
fortran functions get the length either from some argument or because
they
assume a given size (for instance in Lapack it is a one-character
string
what the function expects)
Are you sure about? I think the lengths are passed as implicit
arguments at
the end of the argumwnt list.
Not on any Fortran compilers I've seen, at least when dealing with LAPACK. Replacing CHARACTER*(*) with "char* const" when calling LAPACK routines that take CHARACTER*(*) arguments works perfectly fine with all the Fortran compilers I've encountered (e.g., gfortran, Intel Fortran compiler, IBM's xlf).
Maybe LAPACK is compiled with options that make this work (or nothing looks at the length arguments), but when I compile the code below with gfortran it clearly passes the string lengths 4 and 3 as extra arguments.
INTEGER FUNCTION ILAENV( NAME , NN ) CHARACTER*( * ) NAME, NN ILAENV = ICHAR( NAME( 1: 1 ) ) RETURN END INTEGER FUNCTION ZZZ( ) ZZZ = ILAENV("fooo", "bar") RETURN END movl $3, %ecx movl $4, %edx movl $.LC0, %esi movl $.LC1, %edi call ilaenv_
-- Martin Simmons LispWorks Ltd http://www.lispworks.com/
cffi-devel mailing list cffi-devel@common-lisp.net http://common-lisp.net/cgi-bin/mailman/listinfo/cffi-devel