Hello,
Several projects (lla, blapack among them) link common lisp (cl) to fortran 77 (f77)code. Unfortunately, being totally unfamiliar with cffi, I was having trouble using those packages to learn how to link cl to other f77 code.
To learn more about calling f77 code from CL, I assembled a bunch of simple examples (using cygwin+clisp+gfortran).to show how to pass values of various types to f77.
I have put up the examples on https://github.com/mirkov/cffi-f77. I tried to add enough documentation to make the package easily understandable.
I hope this proves useful to others. I would appreciate comments regarding errors and improvements.
And, as always, thanks for cffi :-)
Mirko
On Fri, Dec 30, 2011 at 2:19 AM, Mirko Vukovic mirko.vukovic@gmail.com wrote:
To learn more about calling f77 code from CL, I assembled a bunch of simple examples (using cygwin+clisp+gfortran).to show how to pass values of various types to f77.
Cool. Thanks for sharing. Looking at the code, it seems like it'd be nice to have a DEFINE-FORTRAN-FUNCTION along with Fortran-specific type definitions.
Cheers
On Thu, 29 Dec 2011 21:19:15 -0500, Mirko Vukovic said:
Hello,
Several projects (lla, blapack among them) link common lisp (cl) to fortran 77 (f77)code. Unfortunately, being totally unfamiliar with cffi, I was having trouble using those packages to learn how to link cl to other f77 code.
To learn more about calling f77 code from CL, I assembled a bunch of simple examples (using cygwin+clisp+gfortran).to show how to pass values of various types to f77.
I have put up the examples on https://github.com/mirkov/cffi-f77. I tried to add enough documentation to make the package easily understandable.
I hope this proves useful to others. I would appreciate comments regarding errors and improvements.
I tested the code in LispWorks on 64-bit Linux and found the following changes useful.
Avoid hardwired paths:
diff --git a/library-ops.lisp b/library-ops.lisp index 63358e1..2c2e6b9 100755 --- a/library-ops.lisp +++ b/library-ops.lisp @@ -27,7 +27,7 @@ (defun link-lib () "Link to the foreign library" (setf *lib* - (load-foreign-library #P"/home/977315/my-software-add-ons/my-lisp/cffi+f77/library.dll"))) + (load-foreign-library (asdf:system-relative-pathname "cffi+f77" "library.dll"))))
(defun unlink-lib () "Unlink from the foreign library"
Need -fPIC for successful linking on 64-bit Linux:
diff --git a/makefile b/makefile index 3db9e80..1b542d6 100755 --- a/makefile +++ b/makefile @@ -3,7 +3,7 @@ fortran = gfortran objs = simple_example.o subroutines.o
%.o : %.f - $(fortran) -c $< -o $@ + $(fortran) -c -fPIC $< -o $@
special : clean clean :
Enhancement to the instructions:
diff --git a/readme.org b/readme.org index 9729387..b216a9d 100755 --- a/readme.org +++ b/readme.org @@ -73,5 +73,6 @@ make library.dll
The examples correctness can be verified by running unit tests: #+begin_src lisp +(in-package #:cffi+f77) (run-tests) #+end_src
__Martin
On Tue, Jan 3, 2012 at 2:10 PM, Martin Simmons martin@lispworks.com wrote:
On Thu, 29 Dec 2011 21:19:15 -0500, Mirko Vukovic said:
Hello,
Several projects (lla, blapack among them) link common lisp (cl) to
fortran
77 (f77)code. Unfortunately, being totally unfamiliar with cffi, I was having trouble using those packages to learn how to link cl to other f77 code.
To learn more about calling f77 code from CL, I assembled a bunch of
simple
examples (using cygwin+clisp+gfortran).to show how to pass values of various types to f77.
I have put up the examples on https://github.com/mirkov/cffi-f77. I
tried
to add enough documentation to make the package easily understandable.
I hope this proves useful to others. I would appreciate comments
regarding
errors and improvements.
I tested the code in LispWorks on 64-bit Linux and found the following changes useful.
Avoid hardwired paths:
diff --git a/library-ops.lisp b/library-ops.lisp index 63358e1..2c2e6b9 100755 --- a/library-ops.lisp +++ b/library-ops.lisp @@ -27,7 +27,7 @@ (defun link-lib () "Link to the foreign library" (setf *lib*
(load-foreign-library
#P"/home/977315/my-software-add-ons/my-lisp/cffi+f77/library.dll")))
(load-foreign-library (asdf:system-relative-pathname "cffi+f77"
"library.dll"))))
(defun unlink-lib () "Unlink from the foreign library"
Need -fPIC for successful linking on 64-bit Linux:
diff --git a/makefile b/makefile index 3db9e80..1b542d6 100755 --- a/makefile +++ b/makefile @@ -3,7 +3,7 @@ fortran = gfortran objs = simple_example.o subroutines.o
%.o : %.f
$(fortran) -c $< -o $@
$(fortran) -c -fPIC $< -o $@
special : clean clean :
Enhancement to the instructions:
diff --git a/readme.org b/readme.org index 9729387..b216a9d 100755 --- a/readme.org +++ b/readme.org @@ -73,5 +73,6 @@ make library.dll
The examples correctness can be verified by running unit tests: #+begin_src lisp +(in-package #:cffi+f77) (run-tests) #+end_src
__Martin
cffi-devel mailing list cffi-devel@common-lisp.net http://lists.common-lisp.net/cgi-bin/mailman/listinfo/cffi-devel
Cool, thank you. You removed at least one of my to-do items :-)
I am currently working on setting it up on 64-bit sbcl on redhat linux.
Mirko
Mirko,
Thank you for this work. I'm interested in building interfaces to Lapack etc. using Antik. In the foreign-array definitions, I have an option :linearization which can be either :row-major or :column-major; it defaults to the former. I even have make-fortran-arrayhttp://repo.or.cz/w/antik.git/blob/4d37965fa7712b968ac4d2d6dd743b1e707e47c1:/foreign-array/foreign-array.lisp#l206, but it's not built out closer to the user further than that. I will take a closer look at your code later (unfortunately, too busy with other things now), but if you have thoughts on how Antik should go, I'd be very interested to hear about them.
Thanks. Liam
On Thu, Dec 29, 2011 at 9:19 PM, Mirko Vukovic mirko.vukovic@gmail.comwrote:
Hello,
Several projects (lla, blapack among them) link common lisp (cl) to fortran 77 (f77)code. Unfortunately, being totally unfamiliar with cffi, I was having trouble using those packages to learn how to link cl to other f77 code.
To learn more about calling f77 code from CL, I assembled a bunch of simple examples (using cygwin+clisp+gfortran).to show how to pass values of various types to f77.
I have put up the examples on https://github.com/mirkov/cffi-f77. I tried to add enough documentation to make the package easily understandable.
I hope this proves useful to others. I would appreciate comments regarding errors and improvements.
And, as always, thanks for cffi :-)
Mirko
cffi-devel mailing list cffi-devel@common-lisp.net http://lists.common-lisp.net/cgi-bin/mailman/listinfo/cffi-devel
Liam,
I think Tamas Papp is much ahead of me in terms of linking cl to f77 arrays (especially on SBCL). Your best bet might be to somehow link to his LLA package (https://github.com/tpapp/lla). I suspect that his package also grovels through the f77 libraries, automatically generating CL defun's. But once I could not find what I was looking for, I stopped digging.
My work originates from the need to link to one or two subroutines for special functions that were note available via gsl (and gsll/antik).
Ideally, there would be a suite of four (or fewer) packages that provide - examples of linking (as the current package does) - automatic defun generation (something like defun-fortran-call ...) - groveller - interfaces to particular libraries (lapack, netlib, toms) Ideally those would be four packages, so that the user can choose which one suits him best.
It might be best to discuss with Tamas, and with his guidance extracts parts of LLA into separate packages, that he can then also use in LLA.
Mirko
On Tue, Jan 3, 2012 at 4:30 PM, Liam Healy lnp@healy.washington.dc.uswrote:
Mirko,
Thank you for this work. I'm interested in building interfaces to Lapack etc. using Antik. In the foreign-array definitions, I have an option :linearization which can be either :row-major or :column-major; it defaults to the former. I even have make-fortran-arrayhttp://repo.or.cz/w/antik.git/blob/4d37965fa7712b968ac4d2d6dd743b1e707e47c1:/foreign-array/foreign-array.lisp#l206, but it's not built out closer to the user further than that. I will take a closer look at your code later (unfortunately, too busy with other things now), but if you have thoughts on how Antik should go, I'd be very interested to hear about them.
Thanks. Liam
On Thu, Dec 29, 2011 at 9:19 PM, Mirko Vukovic mirko.vukovic@gmail.comwrote:
Hello,
Several projects (lla, blapack among them) link common lisp (cl) to fortran 77 (f77)code. Unfortunately, being totally unfamiliar with cffi, I was having trouble using those packages to learn how to link cl to other f77 code.
To learn more about calling f77 code from CL, I assembled a bunch of simple examples (using cygwin+clisp+gfortran).to show how to pass values of various types to f77.
I have put up the examples on https://github.com/mirkov/cffi-f77. I tried to add enough documentation to make the package easily understandable.
I hope this proves useful to others. I would appreciate comments regarding errors and improvements.
And, as always, thanks for cffi :-)
Mirko
cffi-devel mailing list cffi-devel@common-lisp.net http://lists.common-lisp.net/cgi-bin/mailman/listinfo/cffi-devel