Re: [f2py] RE Re: - Multiple instance from a single so file
Pearu Peterson <[email protected]> Mon, 5 Dec 2011 16:07:45 +0200
| Newsgroups | gmane.comp.python.f2py.user |
|---|---|
| Message-ID | <CAPpwKcyv4E=yeatuvLgLXt47z7bJs-BsBngPcaL2SS3aFO3-uA@mail.gmail.com> |
--===============8050637834158258344== Content-Type: multipart/alternative; boundary=bcaec52c5ea98fc27904b358d9e1 --bcaec52c5ea98fc27904b358d9e1 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 2011/12/5 Cedric TAVE <[email protected]> > 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. > > As Gaetan pointed out, an equivalent solution that copies the shared files in runtime, exists. I have created the corresponding entry in a new f2py FAQ page in http://code.google.com/p/f2py/wiki/FAQ2ed (hopefully I will have more time update the page with more entries..). I have not tested the other approach myself but it sounds more elegant and robust (no need to reorganize pyf files and there is no limit in the depth of recursive calls). If this approach will work in all platforms then it would be nice to provide the corresponding extension module copier via numpy (or numpy.f2py). Best regards, Pearu > > 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=3D > 0-0OMLi-Cvy649caa8-hR2DkXuLZEZwiqv2Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> > Content-Type: text/plain; charset=3D"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 do= ne > > 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 =3D " [f2py] multiple instances of same pyd file " )= . > > But I understand from it that no good solution had been identified (I m= ay > > 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/att= achment-0001.htm > > ------------------------------ > > > > > Ce message et toutes les pi=E8ces jointes (ci-apr=E8s le 'Message') sont > =E9tablis =E0 l'intention exclusive des destinataires et les informations= qui y > figurent sont strictement confidentielles. Toute utilisation de ce Messag= e > non conforme =E0 sa destination, toute diffusion ou toute publication tot= ale > ou partielle, est interdite sauf autorisation expresse. > > Si vous n'=EAtes 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=E7u ce Message par erreur, merci de le supprimer = de > votre syst=E8me, ainsi que toutes ses copies, et de n'en garder aucune tr= ace > sur quelque support que ce soit. Nous vous remercions =E9galement d'en > avertir imm=E9diatement l'exp=E9diteur par retour du message. > > Il est impossible de garantir que les communications par messagerie > =E9lectronique arrivent en temps utile, sont s=E9curis=E9es ou d=E9nu=E9e= s de toute > erreur ou virus. > ____________________________________________________ > > This message and any attachments (the 'Message') are intended solely for > the addressees. The information contained in this Message is confidential= . > Any use of information contained in this Message not in accord with its > purpose, 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 > any 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 > virus-free. > > _______________________________________________ > f2py-users mailing list > f2py-users-Y4l6ocDipWCuvFJfX82//[email protected] > http://cens.ioc.ee/mailman/listinfo/f2py-users > > --bcaec52c5ea98fc27904b358d9e1 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable <br><br><div class=3D"gmail_quote">2011/12/5 Cedric TAVE <span dir=3D"ltr">= <<a href=3D"mailto:[email protected]">[email protected]</a>></span>= <br><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-lef= t:1px #ccc solid;padding-left:1ex;"> <tt><font size=3D"2">Hi,</font></tt> <br> <br> <br><tt><font size=3D"2">you're right. I have a huge number of global a= rrays in a module data (and it would be a hard task to change that !).</font></tt= > <br> <br><tt><font size=3D"2">I've just tried the solution you gave to me an= d it works fine. I use the "signature approach" and it is quite elegan= t to produce multiple so-files from a unique signature file (using include statement).</font></tt> <br><tt><font size=3D"2">Many thanks, I think I will reach my goal by proce= eding like this.</font></tt> <br> <br><tt><font size=3D"2">The only thing which is annoying for me, as a prod= uct 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></blockquote><div><br>As Gaetan pointed out, an equivalent solution tha= t copies the shared files in runtime, exists.<br>I have created the corresp= onding entry in a new f2py FAQ page in<br><br>=A0 <a href=3D"http://code.go= ogle.com/p/f2py/wiki/FAQ2ed">http://code.google.com/p/f2py/wiki/FAQ2ed</a><= br> <br>(hopefully I will have more time update the page with more entries..).<= br>I have not tested the other approach myself but it sounds more elegant a= nd robust (no need to reorganize pyf files and there is no limit in the dep= th of recursive calls). If this approach will work in all platforms then it= would be nice to provide the corresponding extension module copier via num= py (or numpy.f2py).<br> <br>Best regards,<br>Pearu<br><br>=A0</div><blockquote class=3D"gmail_quote= " style=3D"margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, = 204); padding-left: 1ex;"> <br><tt><font size=3D"2">Thank you for your availability. Thank you, again, for your great work.</font></tt> <br><tt><font size=3D"2">Cedric TAVE.</font></tt> <br> <br> <br> <br> <br><tt><font size=3D"2">--------------------------------------------------= -- PREVIOUS MESSAGE</font></tt> <br> <br><tt><font size=3D"2">Message: 2<br> Date: Thu, 1 Dec 2011 16:07:01 +0200<br> From: Pearu Peterson <<a href=3D"mailto:[email protected]" target=3D"_blank= ">[email protected]</a>><br> Subject: Re: [f2py] - Multiple instance from a single so file<br> To: For users of the f2py program <<a href=3D"mailto:[email protected]= .ee" target=3D"_blank">f2py-users-Y4l6ocDipWCuvFJfX82//[email protected]</a>><br> Message-ID:<br> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <CAPpwKcxZjpPkP=3D<a href=3D"mailto:0-0OMLi-Cvy649caa8-hR2DkXuLZEZwiqv2Q= @mail.gmail.com" target=3D"_blank">0-0OMLi-Cvy649caa8-hR2DkXuLZEZwiqv2Q@mai= l.gmail.com</a>><br> Content-Type: text/plain; charset=3D"iso-8859-1"<br> <br> Hi,<br> <br> On Thu, Dec 1, 2011 at 3:03 PM, Cedric TAVE <<a href=3D"mailto:cedric.ta= [email protected]" target=3D"_blank">[email protected]</a>> 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 =A0is of prime interest for me and the software I currentl= y<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 instance= s 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 =A0Right?<br> <br> <br> > The expected behavior could be :<br> ><br> > >> import program as program1 =A0 =A0 =A0 # I know this can't be the final<br> > solution, but I found it useful<br> > >> import program as program2 =A0 =A0 =A0 # 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 =3D " [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> =A0! f2py specs<br> end subroutine init<br> subroutine run()<br> =A0! 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=3D"http://cens.ioc.ee/pipermail/f2py-users/attachm= ents/20111201/7b277418/attachment-0001.htm" target=3D"_blank"><tt><font siz= e=3D"2">http://cens.ioc.ee/pipermail/f2py-users/attachments/20111201/7b2774= 18/attachment-0001.htm</font></tt></a><tt><font size=3D"2"> <br> <br> ------------------------------<br> </font></tt><br><br> <br> <br> Ce message et toutes les pi=E8ces jointes (ci-apr=E8s le 'Message')= sont =E9tablis =E0 l'intention exclusive des destinataires et les info= rmations qui y figurent sont strictement confidentielles. Toute utilisation= de ce Message non conforme =E0 sa destination, toute diffusion ou toute pu= blication totale ou partielle, est interdite sauf autorisation expresse.<br= > <br> Si vous n'=EAtes pas le destinataire de ce Message, il vous est interdi= t de le copier, de le faire suivre, de le divulguer ou d'en utiliser to= ut ou partie. Si vous avez re=E7u ce Message par erreur, merci de le suppri= mer de votre syst=E8me, ainsi que toutes ses copies, et de n'en garder = aucune trace sur quelque support que ce soit. Nous vous remercions =E9galem= ent d'en avertir imm=E9diatement l'exp=E9diteur par retour du messa= ge.<br> <br> Il est impossible de garantir que les communications par messagerie =E9lect= ronique arrivent en temps utile, sont s=E9curis=E9es ou d=E9nu=E9es de tout= e erreur ou virus.<br> ____________________________________________________<br> <br> This message and any attachments (the 'Message') are intended solel= y for the addressees. The information contained in this Message is confiden= tial. Any use of information contained in this Message not in accord with i= ts purpose, any dissemination or disclosure, either whole or partial, is pr= ohibited except formal approval.<br> <br> 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.<br> <br> E-mail communication cannot be guaranteed to be timely secure, error or vir= us-free.<br> <br>_______________________________________________<br> f2py-users mailing list<br> <a href=3D"mailto:f2py-users-Y4l6ocDipWCuvFJfX82//[email protected]">f2py-users-Y4l6ocDipWCuvFJfX82//[email protected]</a><br> <a href=3D"http://cens.ioc.ee/mailman/listinfo/f2py-users" target=3D"_blank= ">http://cens.ioc.ee/mailman/listinfo/f2py-users</a><br> <br></blockquote></div><br> --bcaec52c5ea98fc27904b358d9e1-- --===============8050637834158258344== 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 --===============8050637834158258344==--