Right way to build Fortran 90 module using numpy.distutils
I'm having some problems to properly build a module written in Fortran 90 using numpy.distutils. It only contains one subroutine, but: * If I write a .f90 file with the single subroutine (no module .. contains), then f2py tries to compile it using a f77 compiler, and that's not what I want. * If I put it inside a module definition, then at the final compilation stage modulef2pywrapper.c is missing the corresponding .mod file and I have to make the build fail, then copy the .mod from the temp directory and rebuild. Weird. On the other hand, with the second approach f2py creates a unnecessary level of nesting in the corresponding python module and I don't feel quite ok with that. What is the right way to do this? I find the documentation on numpy.distutils a bit lacking, I almost always find the solution by trial and error. I can push the code, it's a short file (part of the rewrite of odeint I'm doing in SciPy). Regards Juan Luis Cano
On Tue, Aug 27, 2013 at 6:46 AM, Juan Luis Cano
I'm having some problems to properly build a module written in Fortran 90 using numpy.distutils. It only contains one subroutine, but:
* If I write a .f90 file with the single subroutine (no module .. contains), then f2py tries to compile it using a f77 compiler, and that's not what I want. * If I put it inside a module definition, then at the final compilation stage modulef2pywrapper.c is missing the corresponding .mod file and I have to make the build fail, then copy the .mod from the temp directory and rebuild. Weird.
On the other hand, with the second approach f2py creates a unnecessary level of nesting in the corresponding python module and I don't feel quite ok with that.
What is the right way to do this? I find the documentation on numpy.distutils a bit lacking, I almost always find the solution by trial and error. I can push the code, it's a short file (part of the rewrite of odeint I'm doing in SciPy).
Regards
Juan Luis Cano _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
You should be able to specify the compiler when invoking f2py, something like: f2py --fcompiler=$COMPILER -m $MODULE_NAME -c $SOURCE_FILE Kyle
El 27/08/2013 17:27, "Kyle Mandli"
On Tue, Aug 27, 2013 at 6:46 AM, Juan Luis Cano
I'm having some problems to properly build a module written in Fortran 90 using numpy.distutils. It only contains one subroutine, but:
* If I write a .f90 file with the single subroutine (no module .. contains), then f2py tries to compile it using a f77 compiler, and that's not what I want. * If I put it inside a module definition, then at the final compilation stage modulef2pywrapper.c is missing the corresponding .mod file and I have to make the build fail, then copy the .mod from the temp directory and rebuild. Weird.
On the other hand, with the second approach f2py creates a unnecessary level of nesting in the corresponding python module and I don't feel quite ok with that.
What is the right way to do this? I find the documentation on numpy.distutils a bit lacking, I almost always find the solution by trial and error. I can push the code, it's a short file (part of the rewrite of odeint I'm doing in SciPy).
Regards
Juan Luis Cano _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
You should be able to specify the compiler when invoking f2py, something
wrote: like:
f2py --fcompiler=$COMPILER -m $MODULE_NAME -c $SOURCE_FILE
That won't work since gfortran is used for both F77 and F90. If you look on rules.py in f2py F77 wrappers are generated if the subroutine is not inside a module, and then the compilation fails because it contains invalid statements for F77. Bug? Any other suggestions?
Kyle
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
On Tue, Aug 27, 2013 at 1:26 PM, Juan Luis Cano
El 27/08/2013 17:27, "Kyle Mandli"
escribió: On Tue, Aug 27, 2013 at 6:46 AM, Juan Luis Cano
I'm having some problems to properly build a module written in Fortran 90 using numpy.distutils. It only contains one subroutine, but:
* If I write a .f90 file with the single subroutine (no module .. contains), then f2py tries to compile it using a f77 compiler, and that's not what I want. * If I put it inside a module definition, then at the final compilation stage modulef2pywrapper.c is missing the corresponding .mod file and I have to make the build fail, then copy the .mod from the temp directory and rebuild. Weird.
On the other hand, with the second approach f2py creates a unnecessary level of nesting in the corresponding python module and I don't feel quite ok with that.
What is the right way to do this? I find the documentation on numpy.distutils a bit lacking, I almost always find the solution by trial and error. I can push the code, it's a short file (part of the rewrite of odeint I'm doing in SciPy).
Regards
Juan Luis Cano _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
You should be able to specify the compiler when invoking f2py, something
wrote: like:
f2py --fcompiler=$COMPILER -m $MODULE_NAME -c $SOURCE_FILE
That won't work since gfortran is used for both F77 and F90. If you look on rules.py in f2py F77 wrappers are generated if the subroutine is not inside a module, and then the compilation fails because it contains invalid statements for F77. Bug?
Any other suggestions?
Kyle
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Can you post your fortran source code? The other key would be see what f2py thinks it's doing, for instance in the output of f2py there two lines that read: ``` Reading fortran codes... Reading file 'test_file.f90' (format:free) ``` For the following source code: ``` subroutine my_func(a, b) implicit none integer, intent(in) :: a real(kind=8), intent(out) :: b b = real(a, kind=8) * 5.d0 end subroutine my_func ``` compiled with `f2py -c test_file.f90 -m my_module`
El 27/08/2013 21:21, "Kyle Mandli"
On Tue, Aug 27, 2013 at 1:26 PM, Juan Luis Cano
El 27/08/2013 17:27, "Kyle Mandli"
escribió: On Tue, Aug 27, 2013 at 6:46 AM, Juan Luis Cano
wrote:
I'm having some problems to properly build a module written in Fortran 90 using numpy.distutils. It only contains one subroutine, but:
* If I write a .f90 file with the single subroutine (no module .. contains), then f2py tries to compile it using a f77 compiler, and that's not what I want. * If I put it inside a module definition, then at the final compilation stage modulef2pywrapper.c is missing the corresponding .mod file and I have to make the build fail, then copy the .mod from the temp directory and rebuild. Weird.
On the other hand, with the second approach f2py creates a unnecessary level of nesting in the corresponding python module and I don't feel quite ok with that.
What is the right way to do this? I find the documentation on numpy.distutils a bit lacking, I almost always find the solution by trial and error. I can push the code, it's a short file (part of the rewrite of odeint I'm doing in SciPy).
Regards
Juan Luis Cano _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
You should be able to specify the compiler when invoking f2py, something like:
f2py --fcompiler=$COMPILER -m $MODULE_NAME -c $SOURCE_FILE
That won't work since gfortran is used for both F77 and F90. If you look on rules.py in f2py F77 wrappers are generated if the subroutine is not inside a module, and then the compilation fails because it contains invalid statements for F77. Bug?
Any other suggestions?
Kyle
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Can you post your fortran source code? The other key would be see what f2py thinks it's doing, for instance in the output of f2py there two lines
wrote: that read:
``` Reading fortran codes... Reading file 'test_file.f90' (format:free) ```
For the following source code:
``` subroutine my_func(a, b)
implicit none
integer, intent(in) :: a real(kind=8), intent(out) :: b
b = real(a, kind=8) * 5.d0
end subroutine my_func ```
compiled with `f2py -c test_file.f90 -m my_module`
Solved! It was as easy as adding both the .pyf and the .f90 to sources, I was having a silly name conflict. I will push the source next week. Thanks!
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
participants (2)
-
Juan Luis Cano
-
Kyle Mandli