Re: [f2py] - Multiple instance from a single so file
Pearu Peterson <[email protected]> Thu, 1 Dec 2011 16:07:01 +0200
| Newsgroups | gmane.comp.python.f2py.user |
|---|---|
| Message-ID | <CAPpwKcxZjpPkP=0-0OMLi-Cvy649caa8-hR2DkXuLZEZwiqv2Q@mail.gmail.com> |
--===============0067038750885541325== Content-Type: multipart/alternative; boundary=20cf3005dde6d0f97804b3085d9b --20cf3005dde6d0f97804b3085d9b 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 --20cf3005dde6d0f97804b3085d9b Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Hi,<br><br><div class=3D"gmail_quote">On Thu, Dec 1, 2011 at 3:03 PM, Cedri= c TAVE <span dir=3D"ltr"><<a href=3D"mailto:[email protected]">cedric.t= [email protected]</a>></span> wrote:<br><blockquote class=3D"gmail_quote" style= =3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"> <font face=3D"sans-serif" size=3D"2"><br> </font> <br><font face=3D"sans-serif" size=3D"2">Hello,</font> <br> <br> <br><font face=3D"sans-serif" size=3D"2">first of all, I would like to than= k you from the great work you have done on f2py. It =A0is of prime interest for me and the software I currently developping.</font> <br><font face=3D"sans-serif" size=3D"2">However, it has a limitative behav= ior that I can't solve or bypass. I hope you could help me...</font> <br> <br><font face=3D"sans-serif" size=3D"2">I use f2py to build a python-API t= o a huge F90 scientific software.</font> <br><font face=3D"sans-serif" size=3D"2">The tests I a am running now produ= ce good results and I really want to propose this API to my users.</font> <br> <br> <br><font face=3D"sans-serif" size=3D"2">--------------------- Description = ---------------------</font> <br> <br><font face=3D"sans-serif" size=3D"2">But for the needs of the end-users= , I need to create multiple instances of the program in the same python scrip= t (allowing sensitivity studies for example).</font> <br> <br></blockquote><div><br>Just to be sure, this need is raised because the = program is using global data (module data or common blocks) that will creat= e interference in between the two simultaneous runs of the program=A0 Right= ?<br> =A0</div><blockquote class=3D"gmail_quote" style=3D"margin: 0pt 0pt 0pt 0.8= ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><font fa= ce=3D"sans-serif" size=3D"2">The expected behavior could be :</font> <br> <br><font face=3D"sans-serif" size=3D"2">>> import program as program= 1 =A0 =A0 =A0 # I know this can't be the final solution, but I found it useful</font> <br><font face=3D"sans-serif" size=3D"2">>> import program as program= 2 =A0 =A0 =A0 # to write it like that (--> to improve understanding)</font= > <br> <br><font face=3D"sans-serif" size=3D"2">>> program1.init( 10 )</font= > <br><font face=3D"sans-serif" size=3D"2">>> program2.init( 1000 )</fo= nt> <br> <br><font face=3D"sans-serif" size=3D"2">>> program1.run()</font> <br><font face=3D"sans-serif" size=3D"2">>> program2.run()</font> <br> <br><font face=3D"sans-serif" size=3D"2">where program1 and program2 define= s 2 different instances from the same .so file.</font> <br> <br> <br><font face=3D"sans-serif" size=3D"2">--------------------- Investigatio= n ---------------------</font> <br> <br><font face=3D"sans-serif" size=3D"2">I found a thread on your mailing l= ist (from 2003 !) which seems to deal with this ( thread =3D " [f2py] mult= iple instances of same pyd file " ).</font> <br><font face=3D"sans-serif" size=3D"2">But I understand from it that no g= ood solution had been identified (I may be wrong). I'm wondering if, 8 year= s after, some new developpement (on f2py or Python itself) could help doing this.</font> <br> <br></blockquote><div><br>I have used the approach where two (or more) exte= nsion modules are generated via f2py having different names but exactly the= same source 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 ind= ented to do:<br>>>> import program1<br>>>> import program= 2<br>>>> <font face=3D"sans-serif" size=3D"2">program1.init( 10 )<= /font> <br>>>> <font face=3D"sans-serif" size=3D"2">program2.init( 1000 )= <br></font>>>> <font face=3D"sans-serif" size=3D"2">program1.run()= </font> <br> >>> <font face=3D"sans-serif" size=3D"2">program2.run()</font><br>= <br>If you are using signature file approach then you need to reorganize th= e pyf file as illustrated below:<br><br># File routines.pyf<br>subroutine i= nit(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>pyth= on 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 u= se them from Python as above.<br><br>HTH,<br>Pearu<br> </div></div> --20cf3005dde6d0f97804b3085d9b-- --===============0067038750885541325== 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 --===============0067038750885541325==--