From: Robert D. <rob...@gm...> - 2006-01-22 18:01:51
|
Hello, I'm trying to translate a program which has a named common block. I'm using current cvs version of f2cl with clisp 2.34. A simple example which shows the problem is PROGRAM FOO INTEGER BAR COMMON /MYCOMN/BAR BAR=3D12345 WRITE(6,10)BAR 10 FORMAT('BAR IS ', I5) RETURN END g77 compiles this program and when executed it yields BAR IS 12345. I translate this with (f2cl::f2cl "tmp.f" :declare-common t) (same problem with (f2cl::f2cl "tmp.f" :declare-common t :common-as-array t= ) by the way). The translation is apparently successful. However, (load "tmp.lisp") complains "undefined function FORTRAN-TO-LISP::MAKE-MYCOMN". I looked at f2cl5.lisp and it looks like the stuff in create-sym-macros-arr= ay is relevant in the :common-as-array case. However it appears that the make-array at line 774 is never executed. I couldn't figure out anything el= se. I searched the clocc-list and clocc-devel archives and checked the bug reports (open and closed) but I didn't see anything about this problem. Hopefully there is something simple I'm overlooking. Thanks for your help. Robert Dodier PS. Here is the f2cl output of tmp.f: ;;; Compiled by f2cl version 2.0 beta Date: 2006/01/11 22:57:58 ;;; Using Lisp CLISP 2.34 (2005-07-20) (built 3332957838) (memory 333907137= 5) ;;; Options: ((:prune-labels nil) (:auto-save t) (:relaxed-array-decls t) (:coerce-assigns :as-needed) ;;; (:array-type ':array) (:array-slicing t) (:declare-common t) (:float-format single-float)) (in-package :common-lisp-user) (|COMMON-LISP|::|DEFSTRUCT| (|FORTRAN-TO-LISP|::|MYCOMN| (:|PREDICATE| |FORTRAN-TO-LISP|::|IS-MYCOMN-P= |)) (|FORTRAN-TO-LISP|::|PART-0| (|COMMON-LISP|::|MAKE-ARRAY| 1. :|ELEMENT-TYPE| '|F2CL-LIB|::|INTEGER4|) :|TYPE| (|COMMON-LISP|::|SIMPLE-ARRAY| |F2CL-LIB|::|INTEGER4| (1.)))) (|COMMON-LISP|::|LET*| |COMMON-LISP|::|NIL| (|COMMON-LISP|::|DEFPARAMETER| |FORTRAN-TO-LISP|::|*MYCOMN-COMMON-BLOCK*| (|FORTRAN-TO-LISP|::|MAKE-MYCOMN|))) (|COMMON-LISP|::|DEFUN| |FORTRAN-TO-LISP|::|FOO| |COMMON-LISP|::|NIL| (|COMMON-LISP|::|LET| |COMMON-LISP|::|NIL| (|COMMON-LISP|::|SYMBOL-MACROLET| ((|FORTRAN-TO-LISP|::|BAR| (|COMMON-LISP|::|AREF| (|FORTRAN-TO-LISP|::|MYCOMN-PART-0| |FORTRAN-TO-LISP|::|*MYCOMN-COMMON-BLOCK*|) 0.))) (|F2CL-LIB|::|WITH-MULTI-ARRAY-DATA| |COMMON-LISP|::|NIL| (|COMMON-LISP|::|PROG| |COMMON-LISP|::|NIL| (|COMMON-LISP|::|DECLARE|) (|COMMON-LISP|::|SETF| |FORTRAN-TO-LISP|::|BAR| 12345.) (|F2CL-LIB|::|FFORMAT| 6. ("BAR IS " 1. (("~5D")) "~%") |FORTRAN-TO-LISP|::|BAR|) (|COMMON-LISP|::|GO| |FORTRAN-TO-LISP|::|END_LABEL|) |FORTRAN-TO-LISP|::|END_LABEL| (|COMMON-LISP|::|RETURN| |COMMON-LISP|::|NIL|)))))) |
From: Raymond T. <ray...@er...> - 2006-01-23 14:05:52
|
>>>>> "Robert" == Robert Dodier <rob...@gm...> writes: Hello, Robert! Robert> g77 compiles this program and when executed it yields BAR IS 12345. Robert> I translate this with (f2cl::f2cl "tmp.f" :declare-common t) Robert> (same problem with (f2cl::f2cl "tmp.f" :declare-common t :common-as-array t) Robert> by the way). The translation is apparently successful. Robert> However, (load "tmp.lisp") complains "undefined function Robert> FORTRAN-TO-LISP::MAKE-MYCOMN". Does the result work? I also get these warnings when I compile the lisp code with cmucl. But the resulting compiled code does work. Robert> I looked at f2cl5.lisp and it looks like the stuff in create-sym-macros-array Robert> is relevant in the :common-as-array case. However it appears that the Robert> make-array at line 774 is never executed. I couldn't figure out anything else. The generated code looks the same as that generated by cmucl. Ray |
From: Robert D. <rob...@gm...> - 2006-01-26 15:27:34
|
Hi Ray, thanks for your help. On 1/23/06, Raymond Toy <ray...@er...> wrote: > Robert> g77 compiles this program and when executed it yields BAR IS = 12345. > Robert> I translate this with (f2cl::f2cl "tmp.f" :declare-common t) > Robert> (same problem with (f2cl::f2cl "tmp.f" :declare-common t :com= mon-as-array t) > Robert> by the way). The translation is apparently successful. > Robert> However, (load "tmp.lisp") complains "undefined function > Robert> FORTRAN-TO-LISP::MAKE-MYCOMN". > > Does the result work? I also get these warnings when I compile the > lisp code with cmucl. But the resulting compiled code does work. When I try (load "tmp.lisp") in Clisp, I get the error message, it dumps me into the debugger. If I skip over the offending form, there aren't any more errors, but then if I try (FORTRAN-TO-LISP::FOO) to run the program I get "undefined function FORTRAN-TO-LISP::MYCOMN-PART-0". Examining tmp.lisp, I don't see a definition for MYCOMN-PART-0. SBCL doesn't get that far; FOO is undefined. GCL fails to load f2cl1.l so that's not in the running. Are there some examples (containing common blocks or not) which are known to work? I looked around in the cvs repository but I didn't find anything like that. Thanks for your help, Robert Dodier |
From: Raymond T. <ray...@er...> - 2006-01-26 15:37:50
|
>>>>> "Robert" == Robert Dodier <rob...@gm...> writes: Robert> When I try (load "tmp.lisp") in Clisp, Robert> I get the error message, it dumps me into the debugger. Ok. I'll try with clisp. Robert> SBCL doesn't get that far; FOO is undefined. Hmm. How can FOO be undefined? Robert> GCL fails to load f2cl1.l so that's not in the running. I haven't tried gcl with f2cl in ages. But can gcl load the lisp file? Robert> Are there some examples (containing common blocks or not) Robert> which are known to work? I looked around in the cvs In packages/minpack, there are some common blocks. These work for me with cmucl, but I haven't tried anything else. Ray |
From: Robert D. <rob...@gm...> - 2006-01-26 15:57:58
|
Hi Ray, > Robert> GCL fails to load f2cl1.l so that's not in the running. > > I haven't tried gcl with f2cl in ages. But can gcl load the lisp > file? (load "tmp.lisp") =3D> There is no package with the name FORTRAN-TO-LISP. Maybe I'm not understanding how f2cl is supposed to work. I try loading "tmp.lisp" (with clisp, sbcl, or gcl) and I get a complaint about the package FORTRAN-TO-LISP being undefined. OK, maybe I'm supposed to (load "macros.l") and then (load "tmp.lisp"). Nope, complaints about F2CL-LIB. OK, I'll try loading f2cl0.l through f2cl8.l and then macros.l. Well, clisp is happy with that, sbcl complains a lot but apparently succeeds, and gcl can't get through f2cl1.l. I looked at f2cl/NOTES but it doesn't seem to have any instructions or examples. I looked for other README-type files but I didn't see any. How is this supposed to work? > Robert> Are there some examples (containing common blocks or not) > Robert> which are known to work? I looked around in the cvs > > In packages/minpack, there are some common blocks. These work for me > with cmucl, but I haven't tried anything else. Thanks for the pointer, I'll take a look. best, Robert |
From: Raymond T. <ray...@er...> - 2006-01-26 18:43:17
|
>>>>> "Robert" == Robert Dodier <rob...@gm...> writes: Robert> Hi Ray, Robert> GCL fails to load f2cl1.l so that's not in the running. >> >> I haven't tried gcl with f2cl in ages. But can gcl load the lisp >> file? Robert> (load "tmp.lisp") => There is no package with the name FORTRAN-TO-LISP. Robert> Maybe I'm not understanding how f2cl is supposed to work. Robert> I try loading "tmp.lisp" (with clisp, sbcl, or gcl) and I get a Robert> complaint about the package FORTRAN-TO-LISP being Robert> undefined. OK, maybe I'm supposed to (load "macros.l") Robert> and then (load "tmp.lisp"). Nope, complaints about F2CL-LIB. Robert> OK, I'll try loading f2cl0.l through f2cl8.l and then macros.l. Robert> Well, clisp is happy with that, sbcl complains a lot but Robert> apparently succeeds, and gcl can't get through f2cl1.l. Ok. It's certainly a problem that there's no file describing what to do. My fault. I'll add a README file that explains some of this. So, if you want to do a conversion, you need to load all of the files, of course. Use the f2cl/f2cl.system or f2cl/f2cl.asd file to load f2cl via mk:defsys or asdf. Once a conversion is done, you don't need to load all of f2cl. You basically just need f2cl0.l to define the packages needed, and macros.l to define the stuff that f2cl-lib needs. Ray |
From: Raymond T. <ray...@er...> - 2006-01-26 19:45:29
|
>>>>> "Robert" == Robert Dodier <rob...@gm...> writes: Robert> I try loading "tmp.lisp" (with clisp, sbcl, or gcl) and I get a Robert> complaint about the package FORTRAN-TO-LISP being Robert> undefined. OK, maybe I'm supposed to (load "macros.l") Got a chance to try this with clisp (2.35). Something is broken in either clisp or f2cl (more likely). The generated code seems wrong. However, when I use cmucl to generate the code, clisp compiles and loads the code just find and (foo) produces the expected output. Is it important for you to be able to generate the code via clisp? I usually use cmucl for that. In any case, I'll look into making f2cl work with clisp. I'm pretty sure this used to work, but I haven't tried clisp in a long time. GCl 2.7.0 ansi from 11/2004 compiles, loads, and runs the cmucl-generated lisp file just fine. This gcl seems incapable of generating the lisp file, but it does load the f2cl*.l files just fine. Ray |
From: Robert D. <rob...@gm...> - 2006-01-27 15:50:23
|
Ray, thanks for your help. I've made some progress. (1) SBCL loads f2cl successfully (although with many complaints), and f2cl::f2cl executes successfully, and SBCL loads the resulting translation successfully. Terrific! (2) Variables mentioned in DATA statements within BLOCK DATA aren't initialized. A function named /BLOCKDATA-<WHATEVER>/ is defined to initialize the data, but it is not automatically called; if I call the block data function by hand, then the variables are initializ= ed. (3) The program of interest at the moment is LBFGS, a minimization program. If I call the blockdata function to initialize the common variables, the LBFGS test program runs successfully. That's really good news. Here is an example which exhibits the problem with initializing common variables. After loading tmp2.lisp, (foo) =3D> OUTPUT 1: BAR IS 0 OUTPUT 2: BAR IS 12345 However, I can force BAR to get initialized -- (/blockdata-mybloc/) Then (foo) =3D> OUTPUT 1: BAR IS 98765 OUTPUT 2: BAR IS 12345 Thanks a lot for your help, Robert Dodier PS. ------------------------------------ tmp2.f -------------------------------= ----- PROGRAM FOO INTEGER BAR COMMON /MYCOMN/BAR WRITE(6,10)BAR 10 FORMAT('OUTPUT 1: BAR IS ',I5) BAR=3D12345 WRITE(6,20)BAR 20 FORMAT('OUTPUT 2: BAR IS ',I5) RETURN END BLOCK DATA MYBLOC INTEGER BAR COMMON /MYCOMN/BAR DATA BAR/98765/ END ----------------------------------- tmp2.lisp -----------------------------= ----- ;;; Compiled by f2cl version 2.0 beta Date: 2006/01/11 22:57:58 ;;; Using Lisp SBCL 0.9.4 ;;; ;;; Options: ((:prune-labels nil) (:auto-save t) (:relaxed-array-decls t) ;;; (:coerce-assigns :as-needed) (:array-type ':array) ;;; (:array-slicing t) (:declare-common t) ;;; (:float-format single-float)) (in-package :common-lisp-user) (defstruct (mycomn (:predicate is-mycomn-p)) (part-0 (make-array 1 :element-type 'f2cl-lib:integer4) :type (simple-array f2cl-lib:integer4 (1)))) (let* () (defparameter *mycomn-common-block* (make-mycomn))) (defun foo () (let () (symbol-macrolet ((bar (aref (mycomn-part-0 *mycomn-common-block*) 0))) (f2cl-lib:with-multi-array-data nil (prog () (declare) (f2cl-lib:fformat 6 ("OUTPUT 1: BAR IS " 1 (("~5D")) "~%") bar) (setf bar 12345) (f2cl-lib:fformat 6 ("OUTPUT 2: BAR IS " 1 (("~5D")) "~%") bar) (go end_label) end_label (return nil)))))) ;;; Compiled by f2cl version 2.0 beta Date: 2006/01/11 22:57:58 ;;; Using Lisp SBCL 0.9.4 ;;; ;;; Options: ((:prune-labels nil) (:auto-save t) (:relaxed-array-decls t) ;;; (:coerce-assigns :as-needed) (:array-type ':array) ;;; (:array-slicing t) (:declare-common t) ;;; (:float-format single-float)) (in-package :common-lisp-user) (defun /blockdata-mybloc/ () (let () (symbol-macrolet ((bar (aref (mycomn-part-0 *mycomn-common-block*) 0))) (setf bar 98765)))) |
From: Raymond T. <ray...@er...> - 2006-01-27 16:20:25
|
>>>>> "Robert" == Robert Dodier <rob...@gm...> writes: Robert> Ray, thanks for your help. I've made some progress. Robert> (1) SBCL loads f2cl successfully (although with many complaints), Robert> and f2cl::f2cl executes successfully, and SBCL loads the Robert> resulting translation successfully. Terrific! I've checked in a change for clisp. Clisp (2.35) works fine for me with your test case now. I also get quite a few errors from cmucl, but I'm too lazy to fix them, because I think they're harmless. Robert> (2) Variables mentioned in DATA statements within Robert> BLOCK DATA aren't initialized. A function named Robert> /BLOCKDATA-<WHATEVER>/ is defined Robert> to initialize the data, but it is not automatically called; Robert> if I call the block data function by hand, then the variables are initialized. Yes, that's a problem, but I'm not sure what the right solution is. Currently, it's expected that you know what you're doing and how the Fortran code works so that you call the block data initializer as needed. With Fortran, it's pretty easy to do this automatically at "load" time because programs run just once. But with Lisp, it's not so clear when you have a repl and the program can be run many times. I tend to put wrappers around stuff as needed, so that the block data is initialized everytime I run the main program. Since f2cl may not know about the block data when it's compiling the main program, there's no way for f2cl to call the initializer automatically. Robert> (3) The program of interest at the moment is LBFGS, Robert> a minimization program. If I call the blockdata function to Robert> initialize the common variables, the LBFGS test program Robert> runs successfully. That's really good news. Cool! If you look in the packages directory, you'll find quite a few other packages, including minpack and hompack. These were used a tests for f2cl because they exposed various bugs. They should work. Since f2cl seems to have converted LBFGS correctly without tweaking on your part, it doesn't really expose any regressions in f2cl. But if you like, I can add that to the packages as a kind of "supported" regression test, especially if it comes with a test program. Ray |
From: Robert D. <rob...@gm...> - 2006-01-28 01:26:21
|
Hi Ray, > Yes, that's a problem, but I'm not sure what the right solution is. > Currently, it's expected that you know what you're doing and how the > Fortran code works so that you call the block data initializer as > needed. I think the current policy should be mentioned in the comment for :DECLARE-COMMON in F2CL-COMPILE (f2cl1.l), and elsewhere if there is somewhere else to put it. About LBFGS, I'm not seeing a need to include it in the f2cl test suite. Thanks a lot for your help -- I'll probably commit lbfgs.lisp to Maxima sometime soon ... Robert Dodier |