[f2py] RE Re: - Multiple instance from a single so file
Cedric TAVE <[email protected]> Mon, 5 Dec 2011 13:40:27 +0100
| Newsgroups | gmane.comp.python.f2py.user |
|---|---|
| Message-ID | <OFA6D0BE29.30DD8AB2-ONC125795D.00357443-C125795D.00459F23@notes.edfgdf.fr> |
--===============1092775466== MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="=_alternative 00459EACC125795D_=" --=_alternative 00459EACC125795D_= Content-Type: text/plain; charset="US-ASCII" Hi, you're right. I have a huge number of global arrays in a module data (and it would be a hard task to change that !). I've just tried the solution you gave to me and it works fine. I use the "signature approach" and it is quite elegant to produce multiple so-files from a unique signature file (using include statement). Many thanks, I think I will reach my goal by proceeding like this. The only thing which is annoying for me, as a product manager, is that I have to produce multiple so-files (may be 10 or more) to deliver this feature to users... but I guess this is the unique solution. Thank you for your availability. Thank you, again, for your great work. Cedric TAVE. ---------------------------------------------------- PREVIOUS MESSAGE Message: 2 Date: Thu, 1 Dec 2011 16:07:01 +0200 From: Pearu Peterson <[email protected]> Subject: Re: [f2py] - Multiple instance from a single so file To: For users of the f2py program <f2py-users-Y4l6ocDipWCuvFJfX82//[email protected]> Message-ID: <CAPpwKcxZjpPkP=0-0OMLi-Cvy649caa8-hR2DkXuLZEZwiqv2Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> Content-Type: text/plain; charset="iso-8859-1" Hi, On Thu, Dec 1, 2011 at 3:03 PM, Cedric TAVE <[email protected]> wrote: > > > Hello, > > > first of all, I would like to thank you from the great work you have done > on f2py. It is of prime interest for me and the software I currently > developping. > However, it has a limitative behavior that I can't solve or bypass. I hope > you could help me... > > I use f2py to build a python-API to a huge F90 scientific software. > The tests I a am running now produce good results and I really want to > propose this API to my users. > > > --------------------- Description --------------------- > > But for the needs of the end-users, I need to create multiple instances of > the program in the same python script (allowing sensitivity studies for > example). > > Just to be sure, this need is raised because the program is using global data (module data or common blocks) that will create interference in between the two simultaneous runs of the program Right? > The expected behavior could be : > > >> import program as program1 # I know this can't be the final > solution, but I found it useful > >> import program as program2 # to write it like that (--> to > improve understanding) > > >> program1.init( 10 ) > >> program2.init( 1000 ) > > >> program1.run() > >> program2.run() > > where program1 and program2 defines 2 different instances from the same > .so file. > > > --------------------- Investigation --------------------- > > I found a thread on your mailing list (from 2003 !) which seems to deal > with this ( thread = " [f2py] multiple instances of same pyd file " ). > But I understand from it that no good solution had been identified (I may > be wrong). I'm wondering if, 8 years after, some new developpement (on f2py > or Python itself) could help doing this. > > I have used the approach where two (or more) extension modules are generated via f2py having different names but exactly the same source content. For example, f2py -c -m program1 source.f90 f2py -c -m program2 source.f90 and in Python you can do what you indented to do: >>> import program1 >>> import program2 >>> program1.init( 10 ) >>> program2.init( 1000 ) >>> program1.run() >>> program2.run() If you are using signature file approach then you need to reorganize the pyf file as illustrated below: # File routines.pyf subroutine init(n) ! f2py specs end subroutine init subroutine run() ! f2py specs end subroutine run # EOF routines.pyf # File program1.pyf python module program1 interface include "routines.pyf" end interface end python module program1 # EOF program1.pyf # File program2.pyf python module program2 interface include "routines.pyf" end interface end python module program2 # EOF program2.pyf and then build the extension modules: f2py -c program1.pyf source.f90 f2py -c program2.pyf source.f90 and use them from Python as above. HTH, Pearu -------------- next part -------------- An HTML attachment was scrubbed... URL: http://cens.ioc.ee/pipermail/f2py-users/attachments/20111201/7b277418/attachment-0001.htm ------------------------------ --=_alternative 00459EACC125795D_= Content-Type: text/html; charset="US-ASCII" <tt><font size=2>Hi,</font></tt> <br> <br> <br><tt><font size=2>you're right. I have a huge number of global arrays in a module data (and it would be a hard task to change that !).</font></tt> <br> <br><tt><font size=2>I've just tried the solution you gave to me and it works fine. I use the "signature approach" and it is quite elegant to produce multiple so-files from a unique signature file (using include statement).</font></tt> <br><tt><font size=2>Many thanks, I think I will reach my goal by proceeding like this.</font></tt> <br> <br><tt><font size=2>The only thing which is annoying for me, as a product manager, is that I have to produce multiple so-files (may be 10 or more) to deliver this feature to users... but I guess this is the unique solution.</font></tt> <br> <br> <br><tt><font size=2>Thank you for your availability. Thank you, again, for your great work.</font></tt> <br><tt><font size=2>Cedric TAVE.</font></tt> <br> <br> <br> <br> <br><tt><font size=2>---------------------------------------------------- PREVIOUS MESSAGE</font></tt> <br> <br><tt><font size=2>Message: 2<br> Date: Thu, 1 Dec 2011 16:07:01 +0200<br> From: Pearu Peterson <[email protected]><br> Subject: Re: [f2py] - Multiple instance from a single so file<br> To: For users of the f2py program <f2py-users-Y4l6ocDipWCuvFJfX82//[email protected]><br> Message-ID:<br> <CAPpwKcxZjpPkP=0-0OMLi-Cvy649caa8-hR2DkXuLZEZwiqv2Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org><br> Content-Type: text/plain; charset="iso-8859-1"<br> <br> Hi,<br> <br> On Thu, Dec 1, 2011 at 3:03 PM, Cedric TAVE <[email protected]> wrote:<br> <br> ><br> ><br> > Hello,<br> ><br> ><br> > first of all, I would like to thank you from the great work you have done<br> > on f2py. It is of prime interest for me and the software I currently<br> > developping.<br> > However, it has a limitative behavior that I can't solve or bypass. I hope<br> > you could help me...<br> ><br> > I use f2py to build a python-API to a huge F90 scientific software.<br> > The tests I a am running now produce good results and I really want to<br> > propose this API to my users.<br> ><br> ><br> > --------------------- Description ---------------------<br> ><br> > But for the needs of the end-users, I need to create multiple instances of<br> > the program in the same python script (allowing sensitivity studies for<br> > example).<br> ><br> ><br> Just to be sure, this need is raised because the program is using global<br> data (module data or common blocks) that will create interference in<br> between the two simultaneous runs of the program Right?<br> <br> <br> > The expected behavior could be :<br> ><br> > >> import program as program1 # I know this can't be the final<br> > solution, but I found it useful<br> > >> import program as program2 # to write it like that (--> to<br> > improve understanding)<br> ><br> > >> program1.init( 10 )<br> > >> program2.init( 1000 )<br> ><br> > >> program1.run()<br> > >> program2.run()<br> ><br> > where program1 and program2 defines 2 different instances from the same<br> > .so file.<br> ><br> ><br> > --------------------- Investigation ---------------------<br> ><br> > I found a thread on your mailing list (from 2003 !) which seems to deal<br> > with this ( thread = " [f2py] multiple instances of same pyd file " ).<br> > But I understand from it that no good solution had been identified (I may<br> > be wrong). I'm wondering if, 8 years after, some new developpement (on f2py<br> > or Python itself) could help doing this.<br> ><br> ><br> I have used the approach where two (or more) extension modules are<br> generated via f2py having different names but exactly the same source<br> content.<br> For example,<br> <br> f2py -c -m program1 source.f90<br> f2py -c -m program2 source.f90<br> <br> and in Python you can do what you indented to do:<br> >>> import program1<br> >>> import program2<br> >>> program1.init( 10 )<br> >>> program2.init( 1000 )<br> >>> program1.run()<br> >>> program2.run()<br> <br> If you are using signature file approach then you need to reorganize the<br> pyf file as illustrated below:<br> <br> # File routines.pyf<br> subroutine init(n)<br> ! f2py specs<br> end subroutine init<br> subroutine run()<br> ! f2py specs<br> end subroutine run<br> # EOF routines.pyf<br> <br> # File program1.pyf<br> python module program1<br> interface<br> include "routines.pyf"<br> end interface<br> end python module program1<br> # EOF program1.pyf<br> <br> # File program2.pyf<br> python module program2<br> interface<br> include "routines.pyf"<br> end interface<br> end python module program2<br> # EOF program2.pyf<br> <br> and then build the extension modules:<br> <br> f2py -c program1.pyf source.f90<br> f2py -c program2.pyf source.f90<br> <br> and use them from Python as above.<br> <br> HTH,<br> Pearu<br> -------------- next part --------------<br> An HTML attachment was scrubbed...<br> URL: </font></tt><a href="http://cens.ioc.ee/pipermail/f2py-users/attachments/20111201/7b277418/attachment-0001.htm"><tt><font size=2>http://cens.ioc.ee/pipermail/f2py-users/attachments/20111201/7b277418/attachment-0001.htm</font></tt></a><tt><font size=2> <br> <br> ------------------------------<br> </font></tt> --=_alternative 00459EACC125795D_=-- --===============1092775466== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Ce message et toutes les pi=C3=A8ces jointes (ci-apr=C3=A8s le 'Message') s= ont =C3=A9tablis =C3=A0 l'intention exclusive des destinataires et les info= rmations qui y figurent sont strictement confidentielles. Toute utilisation= de ce Message non conforme =C3=A0 sa destination, toute diffusion ou toute= publication totale ou partielle, est interdite sauf autorisation expresse. Si vous n'=C3=AAtes pas le destinataire de ce Message, il vous est interdit= de le copier, de le faire suivre, de le divulguer ou d'en utiliser tout ou= partie. Si vous avez re=C3=A7u ce Message par erreur, merci de le supprime= r de votre syst=C3=A8me, ainsi que toutes ses copies, et de n'en garder auc= une trace sur quelque support que ce soit. Nous vous remercions =C3=A9galem= ent d'en avertir imm=C3=A9diatement l'exp=C3=A9diteur par retour du message. Il est impossible de garantir que les communications par messagerie =C3=A9l= ectronique arrivent en temps utile, sont s=C3=A9curis=C3=A9es ou d=C3=A9nu= =C3=A9es de toute erreur ou virus. ____________________________________________________ This message and any attachments (the 'Message') are intended solely for th= e addressees. The information contained in this Message is confidential. An= y use of information contained in this Message not in accord with its purpo= se, any dissemination or disclosure, either whole or partial, is prohibited= except formal approval. If you are not the addressee, you may not copy, forward, disclose or use an= y part of it. If you have received this message in error, please delete it = and all copies from your system and notify the sender immediately by return= message. E-mail communication cannot be guaranteed to be timely secure, error or vir= us-free. --===============1092775466== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ f2py-users mailing list f2py-users-Y4l6ocDipWCuvFJfX82//[email protected] http://cens.ioc.ee/mailman/listinfo/f2py-users --===============1092775466==--