From: Mirko
Subject: linking to fortran routines
Date: 
Message-ID: <59cb8c8f-19af-49b0-a774-ff24cb7db045@j35g2000yqh.googlegroups.com>
Hello,

I would like to use some of the lapack routines (namely cgtsv) from
lisp to solve a complex tridiagonal system.

(I could implement this particular solver in lisp since it is a fairly
simple algorithm, but this is a good excuse to try to link to fortran
libraries that may prove needed in the future).

So, does anyone (Tamas?) have a simple example of how to do it?  I use
mainly sbcl (at work), but will also try to make it work on clisp (on
my windows+cygwin at home).

Thanks,

Mirko

From: Tamas K Papp
Subject: Re: linking to fortran routines
Date: 
Message-ID: <71r8s0FmrhvfU1@mid.individual.net>
On Wed, 11 Mar 2009 18:34:03 -0700, Mirko wrote:

> Hello,
> 
> I would like to use some of the lapack routines (namely cgtsv) from lisp
> to solve a complex tridiagonal system.
> 
> (I could implement this particular solver in lisp since it is a fairly
> simple algorithm, but this is a good excuse to try to link to fortran
> libraries that may prove needed in the future).
> 
> So, does anyone (Tamas?) have a simple example of how to do it?  I use
> mainly sbcl (at work), but will also try to make it work on clisp (on my
> windows+cygwin at home).

Nope, nothing simple.  I usually use one of these options for Fortran
code:

1) translation to Lisp via f2cl.  This works for minpack etc, but not
something I would use for lapack routines.

2) find a C equivalent or an already written wrapper.  For a lot of
BLAS/LAPACK, this is a good option, eg see cblas/clapack.  But of course 
not for cgtsv.

3) write a wrapper myself.  I thought of automating this, but balked
at the thought of writing a Fortran parser (unfortunately, so did the
authors of SWIG :-).  The only thing that you have to take care of are
atoms (numbers, chars), for these you have to pass their address to
the Fortran routine.

In theory, one can write a Lisp/CFFI wrapper macro that would put
values on the stack (see with-foreign-object), copy the value and pass
the resulting pointer to the Fortran routine.  The Matlisp sources
have examples on how to deal with name mangling, and of course on
directly calling Fortran (eg def-fortran-routine in src/ffi-*.lisp).

On a related note, in case you would like FFA to handle complex
numbers, let me know, it should be fairly easy to do but I never got
around to it.  Unfortunately, I will be mostly offline for two weeks
from tomorrow, so I can't do it immediately - but patches are welcome :-)

Calling Fortran functions is becoming enough of a PITA for me that I
am strongly motivated to deal with it as neatly as possible in a
library written specifically for the purpose, but at the moment I only
have a vague idea how to do it.  Suggestions are appreciated...

HTH,

Tamas
From: Raymond Toy
Subject: Re: linking to fortran routines
Date: 
Message-ID: <sxd4oxyltuz.fsf@rtp.ericsson.se>
>>>>> "Mirko" == Mirko  <·············@gmail.com> writes:

    Mirko> Hello,
    Mirko> I would like to use some of the lapack routines (namely cgtsv) from
    Mirko> lisp to solve a complex tridiagonal system.

Searching for lapack on cliki.net gives 3 hits:  matlisp, clem, and
bindings for libraries.

Perhaps one of these will work for you.

Linking to Fortran isn't all that hard if you know how to link to C.
The hardest part is figuring out the naming convention and calling
convention of the Fortran compiler you want to use.

Ray
From: Mirko
Subject: Re: linking to fortran routines
Date: 
Message-ID: <b0d550ea-8c0e-4a09-a5ad-0f4a81b4fb87@d19g2000yqb.googlegroups.com>
On Mar 12, 10:05 am, Raymond Toy <···········@stericsson.com> wrote:
> >>>>> "Mirko" == Mirko  <·············@gmail.com> writes:
>
>     Mirko> Hello,
>     Mirko> I would like to use some of the lapack routines (namely cgtsv) from
>     Mirko> lisp to solve a complex tridiagonal system.
>
> Searching for lapack on cliki.net gives 3 hits:  matlisp, clem, and
> bindings for libraries.
>
> Perhaps one of these will work for you.
>
> Linking to Fortran isn't all that hard if you know how to link to C.
> The hardest part is figuring out the naming convention and calling
> convention of the Fortran compiler you want to use.
>
> Ray

Thank you to both.  Found matlisp.  I'll take a look at cliki.