Re: [f2py] OpenMP - again
Pearu Peterson <[email protected]> Sat, 4 Sep 2010 16:24:34 +0300
| Newsgroups | gmane.comp.python.f2py.user |
|---|---|
| Message-ID | <[email protected]> |
On Sat, Sep 4, 2010 at 2:51 PM, Paul Anton Letnes <[email protected]> wrote: > Hi again! > > On 4. sep. 2010, at 12.30, Pearu Peterson wrote: > >> Hi! >> >> On Sat, Sep 4, 2010 at 12:31 PM, Paul Anton Letnes >> <[email protected]> wrote: >>> Dear f2py fans. >>> >>> I finally got an OpenMP example up and running. It even gives a decent speedup (1.8-ish) on my 2-core laptop! The only disadvantage is that I have not managed to pass the "-fopenmp" flag to the final compile-and-link command, meaning that if I simply run "make" (Makefile included, of course) the resulting python module is not linked to libopenmp. I managed to fix this by manually copying the final build command and adding the "-fopenmp" flag by hand - see detailed instructions in the Makefile. >>> >>> Can anyone please tell me how I can "automagically" get the -fopenmp flag into the final build command? I believe that will make this example more complete. Also, feel free to suggest improvements to this example! >> >> Isn't -fopenmp the flag for the compiler, not for the linker? >> f2py has --opt, --f90flags, and --f77flags switches that can be used for >> specifying extra options to fortran compiler. Note that when >> using these switches then their default values defined >> by numpy.distutils.fcompiler will be overwritten. So, always >> remember specifying these default values in the switches >> as some of them might be required. Redefining --opt might >> be the safest way as then one would loose only optimization >> flags. > > As far as I understand, -fopenmp includes -lgomp or similar flag which will tell the compiler to link to the OpenMP library. From my experience, it makes no difference if you include -lgomp or -fopenmp, as long as one of them are present, in the last (linking) stage. > > I have tried setting --opt='-fopenmp' but that does not help, either. I just want to insert that flag into the final linking stage, because it demonstrably helps. I do not, however, understand why setting --f90flags or --opt does not help? These switches are used for compilation, not for linkage. I'll look into how to add flags to linking command. Afaik, distutils does not have switches for that. Specifying LDFLAGS might help, though. Pearu