Re: [f2py] OpenMP - again
Paul Anton Letnes <[email protected]> Sun, 5 Sep 2010 12:55:54 +0200
| Newsgroups | gmane.comp.python.f2py.user |
|---|---|
| Message-ID | <[email protected]> |
Hi again!
On 4. sep. 2010, at 15.48, Pearu Peterson wrote:
> Here follows a solution when using setup.py file.
> So, create a setup.py file containing
>
> #!/usr/bin/env python
> def configuration(parent_package='',top_path=None):
> from numpy.distutils.misc_util import Configuration
> config = Configuration(None,parent_package,top_path)
> config.add_extension('wrapper',
> ['fortranmodule.f95','wrapper.f95'],
> libraries = ['gomp','blas'],
> library_dirs = ['/opt/local/lib/gcc44'],
> f2py_options = [],
> define_macros = [('F2PY_REPORT_ON_ARRAY_COPY','1')],
> extra_link_args = ['-fopenmp']
> )
>
> return config
>
> if __name__ == "__main__":
> from numpy.distutils.core import setup
> setup(configuration=configuration)
> #eof
>
> and then run
>
> python setup.py build_ext --inplace --fcompiler=gnu95
>
> HTH,
> Pearu
Thanks for your help there - I am closer to a workable solution now. There are still a few quirks, however. I attach my source files and the output (in output.txt) I get when running "make clean; make test" in the terminal.
Questions:
Why do I get this warning? fortranmodule.f95 is a pure fortran module, and can be compiled as such; hence, real(wp) should work (fortranmodule.f95 line 8 and 9).
Warning:
getctype: "real(kind=wp)" not supported (use .f2py_f2cmap).
Your setup.py lets the program compile and run nicely. However, there is no speedup and only 1 OMP thread running when using your setup.py. When calling setup.py with the env variable F90FLAGS=-fopenmp set, however, I do get several threads and a close to optimal speedup - see this line in Makefile:
env F90FLAGS=-fopenmp python setup.py build_ext --inplace --fcompiler=gnu95
Finally, something which might be related to gfortran performance rather than f2py: I notice that on the Linux desktop which I've also been running this program, the program runs essentially only half as fast as on my laptop. CPUs are core 2 duo 2.4 GHz on my laptop and a more recent core 2 quad 2.83 GHz on the desktop. This seems rather odd to me - the desktop should be roughly as fast "per core".
If you find this example interesting enough to use in some f2py documentation, please feel free to. I guess other people might be trying to use OpenMP with fortran as well, as it's a rather simple way of parallelizing fortran code.
Thanks again for all your help, Pearu!
-Paul
_______________________________________________
f2py-users mailing list
f2py-users-Y4l6ocDipWCuvFJfX82//[email protected]
http://cens.ioc.ee/mailman/listinfo/f2py-users
Archive.zip
(application/zip, 3.4 KB) - not displayed