f2py and Fortran90 gfortran_filename error
Hello All: I was suggested to post this question here with the f2py experts from comp.lang.python. I have been able to use the example F77 files suggested in the f2py User Manual, but the problems happened when I tried my own F90 file (attached below. I am able to create a <module_name>.so file using the following method: (1) Created a Fortran90 program matsolve.f90 Note: The program compiles fine and prints the proper output for the simple matrix specified. (2) f2py matsolve.f90 -m matsolve2 -h matsolve2.pyf This created the matsolve2.pyf fine (3) f2py -c matsolve2.pyf --f90exec=/usr/bin/gfortran matsolve.f90 Note: I had to specify the f90exec path as f2py did not automatically find it. This was the only way I could generate a *.so file. The rub: When I import it into Python, I receive the following message:
import matsolve2
Traceback (most recent call last): File "<stdin>", line 1, in ? ImportError: ./matsolve2.so: undefined symbol: _gfortran_filename Any suggestions are greatly appreciated. (I almost started smoking again last night! ARGH!) Cheers, t. PS - Below I have attached the F90 program for LU decomposition with a simple test case. ! MATSOLVE.f90 ! ! Start main program PROGRAM MATSOLVE IMPLICIT NONE INTEGER,PARAMETER :: n=3 INTEGER :: i,j REAL,DIMENSION(n) :: x,b REAL,DIMENSION(n,n) :: A,L,U ! Initialize the vectors and matrices with a test case from text ! Using the one given in Appendix A from Thompson. ! Known vector "b" b(1) = 12. b(2) = 11. b(3) = 2. ! Known coefficient matrix "A", and initialize L and U DO i=1,n DO j=1,n L(i,j) = 0. U(i,j) = 0. END DO END DO ! Create matrix A A(1,1) = 3. A(1,2) = -1. A(1,3) = 2. A(2,1) = 1. A(2,2) = 2. A(2,3) = 3. A(3,1) = 2. A(3,2) = -2. A(3,3) = -1. ! Call subroutine to create L and U matrices from A CALL lumake(L,U,A,n) ! Print results PRINT *, '-----------------------' DO i=1,n DO j=1,n PRINT *, i, j, A(i,j), L(i,j), U(i,j) END DO END DO PRINT *, '-----------------------' ! Call subroutine to solve for "x" using L and U CALL lusolve(x,L,U,b,n) ! Print results PRINT *, '-----------------------' DO i=1,n PRINT *, i, x(i) END DO PRINT *, '-----------------------' END PROGRAM MATSOLVE ! Create subroutine to make L and U matrices SUBROUTINE lumake(LL,UU,AA,n1) IMPLICIT NONE INTEGER,PARAMETER :: n=3 INTEGER :: i,j,k REAL :: LUSUM INTEGER,INTENT(IN) :: n1 REAL,DIMENSION(n,n),INTENT(IN) :: AA REAL,DIMENSION(n,n),INTENT(OUT) :: LL,UU ! We first note that the diagonal in our UPPER matrix is ! going to be UU(j,j) = 1.0, this allows us to initialize ! the first set of expressions UU(1,1) = 1. ! Find first column of LL DO i = 1,n1 LL(i,1) = AA(i,1)/UU(1,1) END DO ! Now find first row of UU DO j = 2,n1 UU(1,j) = AA(1,j)/LL(1,1) END DO ! Now find middle LL elements DO j = 2,n1 DO i = j,n1 LUSUM = 0. DO k = 1,j-1 LUSUM = LUSUM + LL(i,k)*UU(k,j) END DO LL(i,j) = AA(i,j) - LUSUM END DO ! Set Diagonal UU UU(j,j) = 1. ! Now find middle UU elements DO i = j+1,n1 LUSUM = 0. DO k = 1,j-1 LUSUM = LUSUM + LL(j,k)*UU(k,i) END DO UU(j,i) = (AA(j,i) - LUSUM)/LL(j,j) END DO END DO END SUBROUTINE lumake ! Make subroutine to solve for x SUBROUTINE lusolve(xx,L2,U2,bb,n2) IMPLICIT NONE INTEGER,PARAMETER :: n=3 INTEGER :: i,j,k REAL :: LYSUM,UXSUM REAL,DIMENSION(n):: y INTEGER,INTENT(IN) :: n2 REAL,DIMENSION(n),INTENT(IN) :: bb REAL,DIMENSION(n,n),INTENT(IN) :: L2,U2 REAL,DIMENSION(n),INTENT(OUT) :: xx ! Initialize DO i=1,n2 y(i) = 0. xx(i) = 0. END DO ! Solve L.y = b y(1) = bb(1)/L2(1,1) DO i = 2,n2 LYSUM = 0. DO k = 1,i-1 LYSUM = LYSUM + L2(i,k)*y(k) END DO y(i) = (bb(i) - LYSUM)/L2(i,i) END DO ! Now do back subsitution for U.x = y xx(n2) = y(n2)/U2(n2,n2) DO j = n2-1,1,-1 UXSUM = 0. DO k = j+1,n2 UXSUM = UXSUM + U2(j,k)*xx(k) END DO xx(j) = y(j) - UXSUM END DO END SUBROUTINE lusolve -- Tyler Joseph Hayes 600 Talbot St. -- Apt. 812 London, Ontario N6A 5L9 Tel : 519.435.0967 Fax : 519.661.3198 Cell : 416.655.7897 email: thayes@uwo.ca GPG Key ID# 0x3AE05130
Hello All:
I was suggested to post this question here with the f2py experts from comp.lang.python.
I have been able to use the example F77 files suggested in the f2py User Manual, but the problems happened when I tried my own F90 file (attached below.
I am able to create a <module_name>.so file using the following method:
(1) Created a Fortran90 program matsolve.f90
Note: The program compiles fine and prints the proper output for the simple matrix specified.
(2) f2py matsolve.f90 -m matsolve2 -h matsolve2.pyf
This created the matsolve2.pyf fine
(3) f2py -c matsolve2.pyf --f90exec=/usr/bin/gfortran matsolve.f90
Use f2py -c --fcompiler=gnu95 matsolve2.pyf matsolve.f90 HTH, Pearu
Thanks for helping out Pearu, But it won't even create the .so file using that command. Using what you suggested, seems to work as it goes through many of the processes but then f2py stops at: error: don't know how to compile Fortran code on platform 'posix' with 'gnu95' compiler. Supported compilers are: compaq,absoft,intel,gnu,sun,f,vast,ibm,lahey,intelv,intele,pg,compaqv,mips,hpux,intelev,nag) Even more weird is on my laptop the situation is even worse. Check out this error which I seem to get regardless of whether I use the gnu95 line like you suggested on the --f90exec option. thayes@seneca:~/fortran90/am562b/misc_finite$ f2py -c --fcompiler=gnu95 matsolve2.pyf matsolve.f90 Unknown vendor: "gnu95" numpy_info: FOUND: define_macros = [('NUMERIC_VERSION', '"\\"24.2\\""')] include_dirs = ['/usr/include/python2.4'] Traceback (most recent call last): File "/usr/bin/f2py", line 4, in ? f2py2e.main() File "/usr/lib/python2.4/site-packages/f2py2e/f2py2e.py", line 677, in main run_compile() File "/usr/lib/python2.4/site-packages/f2py2e/f2py2e.py", line 650, in run_compile ext = Extension(**ext_args) File "/usr/lib/python2.4/site-packages/scipy_distutils/extension.py", line 45, in __init__ export_symbols) File "/usr/lib/python2.4/distutils/extension.py", line 106, in __init__ assert type(name) is StringType, "'name' must be a string" AssertionError: 'name' must be a string Thanks for the help anyways. Cheers, t. -- Tyler Joseph Hayes GPG Key ID# 0x3AE05130
Thanks for helping out Pearu,
But it won't even create the .so file using that command. Using what you suggested, seems to work as it goes through many of the processes but then f2py stops at:
error: don't know how to compile Fortran code on platform 'posix' with 'gnu95' compiler. Supported compilers are: compaq,absoft,intel,gnu,sun,f,vast,ibm,lahey,intelv,intele,pg,compaqv,mips,hpux,intelev,nag)
Even more weird is on my laptop the situation is even worse. Check out this error which I seem to get regardless of whether I use the gnu95 line like you suggested on the --f90exec option.
thayes@seneca:~/fortran90/am562b/misc_finite$ f2py -c --fcompiler=gnu95 matsolve2.pyf matsolve.f90 Unknown vendor: "gnu95" numpy_info: FOUND: define_macros = [('NUMERIC_VERSION', '"\\"24.2\\""')] include_dirs = ['/usr/include/python2.4']
The problem is that you are using Numeric and f2py2e combination that do not have gfortran support (in f2py2e, to be specific). You can either switch to Numpy (that includes f2py with gfortran support) or use your original command line with -lgfortran specified: f2py -c matsolve2.pyf --f90exec=/usr/bin/gfortran matsolve.f90 -lgfortran If you get more undefined symbol errors then find out which libraries define these symbols and include the corresponding -l<libname> switches. Note that it is recommended to switch using to numpy as f2py has better F90 support there. Pearu
Hi Pearu: Well, the -l option worked!!! (May you live to be one thousand.) To be honest though, I had thought I was using NumPy (I even purchased the NumPy manual). How do I switch f2py to always use NumPy? Either way, it now works.... Cheers, t. On 28/02/07, pearu@cens.ioc.ee <pearu@cens.ioc.ee> wrote:
Thanks for helping out Pearu,
But it won't even create the .so file using that command. Using what you suggested, seems to work as it goes through many of the processes but then f2py stops at:
error: don't know how to compile Fortran code on platform 'posix' with 'gnu95' compiler. Supported compilers are: compaq,absoft,intel,gnu,sun,f,vast,ibm,lahey,intelv,intele,pg,compaqv,mips,hpux,intelev,nag)
Even more weird is on my laptop the situation is even worse. Check out this error which I seem to get regardless of whether I use the gnu95 line like you suggested on the --f90exec option.
thayes@seneca:~/fortran90/am562b/misc_finite$ f2py -c --fcompiler=gnu95 matsolve2.pyf matsolve.f90 Unknown vendor: "gnu95" numpy_info: FOUND: define_macros = [('NUMERIC_VERSION', '"\\"24.2\\""')] include_dirs = ['/usr/include/python2.4']
The problem is that you are using Numeric and f2py2e combination that do not have gfortran support (in f2py2e, to be specific). You can either switch to Numpy (that includes f2py with gfortran support) or use your original command line with -lgfortran specified:
f2py -c matsolve2.pyf --f90exec=/usr/bin/gfortran matsolve.f90 -lgfortran
If you get more undefined symbol errors then find out which libraries define these symbols and include the corresponding -l<libname> switches.
Note that it is recommended to switch using to numpy as f2py has better F90 support there.
Pearu
_______________________________________________ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
-- Tyler Joseph Hayes GPG Key ID# 0x3AE05130
Hi Pearu:
Well, the -l option worked!!! (May you live to be one thousand.)
To be honest though, I had thought I was using NumPy (I even purchased the NumPy manual). How do I switch f2py to always use NumPy?
Well, it depends how did you installed numpy, before or after installing f2py2e. Both install f2py scripts. So, just make sure that f2py script is from numpy installation, for example, reinstalling numpy should be sufficient (you don't need to rebuild numpy for that). Also, you can safely remove f2py2e from your system if you are going to use numpy. HTH, Pearu
Well, I removed the f2py2e directory and reinstalled numpy as you suggested. Now, I still use the -lgfortran option and the --f90exec option, but am no longer getting the "NUMERIC" version. Thank you for the help. You have been more than patient with me :-) Now all I have to do is get my laptop to also behave the same way. f2py creates the .pyf file fine, but balks at the following command. thayes@seneca$ f2py -c --f90exec=/usr/bin/gfortran matsolve2.pyf -lgfortran matsolve.f90 /usr/lib/python2.4/site-packages/numpy/ctypeslib.py:12: UserWarning: All features of ctypes interface may not work with ctypes < 1.0.1 warnings.warn("All features of ctypes interface may not work with " \ Traceback (most recent call last): File "/usr/bin/f2py", line 26, in ? main() File "/usr/lib/python2.4/site-packages/numpy/f2py/f2py2e.py", line 552, in main run_compile() File "/usr/lib/python2.4/site-packages/numpy/f2py/f2py2e.py", line 528, in run_compile ext = Extension(**ext_args) File "/usr/lib/python2.4/site-packages/numpy/distutils/extension.py", line 45, in __init__ export_symbols) File "/usr/lib/python2.4/distutils/extension.py", line 106, in __init__ assert type(name) is StringType, "'name' must be a string" AssertionError: 'name' must be a string However, I can save this for another day..... Thanks again, Tyler -- Tyler Joseph Hayes GPG Key ID# 0x3AE05130
Well, I removed the f2py2e directory and reinstalled numpy as you suggested. Now, I still use the -lgfortran option and the --f90exec option, but am no longer getting the "NUMERIC" version.
Thank you for the help. You have been more than patient with me :-)
Now all I have to do is get my laptop to also behave the same way. f2py creates the .pyf file fine, but balks at the following command.
thayes@seneca$ f2py -c --f90exec=/usr/bin/gfortran matsolve2.pyf -lgfortran matsolve.f90
You should use f2py -c --fcompiler=gnu95 matsolve2.pyf matsolve.f90 no need to specify --f90exec or -lgfortran if you specify the gnu95 compiler. Pearu
Hi again Pearu: As you suggested, the gnu95 option works fine on my desktop without calling the other options, but I think I may have to reinstall everything from scratch on my laptop as I keep getting that "'name' must be a string" error message (which doesn't show up on my desktop). Like I said, I think I'll save that for another day. I really should get back to coding my assignment now :-) Anyways, you have been more than helpful, and if you are ever in London, Ontario, I owe you a drink. Thanks again. Cheers, t, -- Tyler Joseph Hayes GPG Key ID# 0x3AE05130
Ok, so I'm a total nutcase and couldn't let the laptop thing go. So, I reinstalled everything from source, and Voila!, it worked. You have been a huge help Pearu. Cheers, t.
participants (3)
-
pearu@cens.ioc.ee -
Tyler Hayes -
Tyler J Hayes