Re: [f2py] Problem in calling MPI subroutine

Jaime Perea <[email protected]> Mon, 11 Feb 2013 16:50 +0100
Newsgroups gmane.comp.python.f2py.user
Message-ID <2415607.B6Ugc44nQW@cristina>
This is a multi-part message in MIME format.

--===============4090219711153273213==
Content-Type: multipart/alternative; boundary="nextPart24299589.aLO2QssMg3"
Content-Transfer-Encoding: 7Bit

This is a multi-part message in MIME format.

--nextPart24299589.aLO2QssMg3
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset="iso-8859-1"

El Lunes, 11 de febrero de 2013 04:45:56 Razibul Islam escribi=F3:

Hello,=20

          Hope everyone is doing fine. I am trying to use a MPI fortran=
 code=20
to call it from python.  First I have converted MPI code using f2py and=
 then=20
tried to use that one to call from python.  Konsole output is also adde=
d=20
below.=20

I am using openSUSE 12.2 and installed openMPI 1.5.4-4.1.4 from the sof=
tware management in opensuse. Any help or suggestions in this regard wo=
uld be very
 helpful.

BR
Razibul=20

------------------------ MPI------------------------
      subroutine simple()
      include 'mpif.h'
      integer numtasks, ranks, ierr, rc
      call MPI_INIT(ierr)
      if (ierr .ne. MPI_SUCCESS) then
          print *, 'Error starting MPI program. Terminating.'
          call MPI_ABORT(MPI_COMM_WORLD, rc, ierr)
      end if

      call MPI_COMM_RANK(MPI_COMM_WORLD, rank, ierr)
      call MPI_COMM_SIZE(MPI_COMM_WORLD, numtasks, ierr)
      print *, 'Number of tasks =3D ', numtasks, ' My Rank =3D', rank

      call MPI_FINALIZE(ierr)

      end subroutine
------------------------ END of MPI ------------------------

------------------------ F2PY Command ------------------------
f2py --fcompiler=3Dgnu95 --f77exec=3Dmpif90 -m simplesub -c simple.f90
-I/usr/lib/mpi/gcc/openmpi/include -L/usr/lib/mpi/gcc/openmpi/lib
-lmpi_f77

------------------------ Python Code ------------------------
#File Name : ptest.py
#!/usr/bin/env python
#-*- cpding: utf-8 -*-
import simplesub
print dir(simplesub)
simplesub.simple()
------------------------ End of Python Code ------------------------

------------------------ Error Text in Console ------------------------=


tamal@linux-p7k6:~/Dropbox/Thesis/2012/20130210/simple> mpiexec -n 4
python ptest.py

tamal@linux-p7k6:~/Dropbox/Thesis/2012/20130207> mpiexec -n 2 python
partest.py
python: symbol lookup error:
/usr/lib/mpi/gcc/openmpi/lib/openmpi/mca_paffinity_hwloc.so: undefined
symbol: mca_base_param_reg_int
python: symbol lookup error:
/usr/lib/mpi/gcc/openmpi/lib/openmpi/mca_paffinity_hwloc.so: undefined
symbol: mca_base_param_reg_int
-----------------------------------------------------------------------=
---
mpiexec noticed that the job aborted, but has no info as to the process=

that caused that situation.
-----------------------------------------------------------------------=
---







Hi, I found this problem some time ago, there are two options.

The easy way

Try to use some of the the mpi implementations in your python script. I=
 tried=20
with mpi4py.  An 'import mpi4py'  before calling simplesub can do the j=
ob.=20

The not so easy

Both python and mpi try to access the args command line, so some orderi=
ng it's=20
needed.  A small C program can manage this.=20

---------------
#include <Python.h>
#include <stdio.h>
#include <stdlib.h>
#include "mpi.h"
/*
py_mpi.c

Main program, it needs one file.py as first parameter, then the remaini=
ng are=20
passed to the script.
 */

int main(int argc, char *argv[])
{
  FILE *f;
  int new_argc,i;
  char **new_argv;
  /*
     argv[0] contains the exec file
  */
  if (argc < 2){
    printf("%i is invalid as number of params\n",argc);
    exit(1);
  }
  /*
     Init MPI, berfore calling python
  */
  MPI_Init(&argc,&argv);

  /*
     input file
  */
  f =3D fopen(argv[1], "r");
  if (f =3D=3D NULL){
    printf("invalid file\n");
    exit(1);
      }

  /*
   entering  python
  */
  Py_SetProgramName(argv[0]);
  Py_Initialize();
  new_argc =3D argc-1;
  new_argv =3D (char**) malloc((new_argc)*sizeof(char*));

  /*
 /*
    Changing command line
  */
  for (i=3D1; i<argc;i++) {
    new_argv[i-1]=3Dargv[i];
  }

  PySys_SetArgv(new_argc, new_argv);

  /*
  sending the script
  */

  PyRun_SimpleFile(f,argv[1]);

  /*
    bye bye, we close python and then mpi
  */

  Py_Finalize();
  MPI_Finalize();

  return 0;
}
---------------------

In this case the C program initializes mpi, so the mpi_init and mpi_fin=
alize=20
calls must be removed from your fortran code.      First solution is si=
mpler=20
but I'm not sure it will work always. For me (ubuntu 12.04, mpich2) it'=
s=20
working.

--nextPart24299589.aLO2QssMg3
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset="iso-8859-1"

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/=
REC-html40/strict.dtd">
<html><head><meta name=3D"qrichtext" content=3D"1" /><style type=3D"tex=
t/css">
p, li { white-space: pre-wrap; }
</style></head><body style=3D" font-family:'Droid Sans'; font-size:8pt;=
 font-weight:400; font-style:normal;">
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">El =
Lunes, 11 de febrero de 2013 04:45:56 Razibul Islam escribi=F3:<br /></=
p>
<p style=3D" margin-top:12px; margin-bottom:0px; margin-left:40px; marg=
in-right:40px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0; b=
ackground-color:#ffffff;"><span style=3D" font-family:'times new roman,=
new york,times,serif'; font-size:10pt; color:#000000;">Hello, <br /></s=
pan></p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:40px; margi=
n-right:40px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0; ba=
ckground-color:#000000;"><span style=3D" font-family:'times new roman,n=
ew york,times,serif'; font-size:10pt; color:#000000;">=A0=A0=A0=A0=A0=A0=
=A0=A0=A0 Hope everyone is doing fine. I am trying to use a MPI fortran=
 code to call it from python.=A0 First I have converted MPI code using =
f2py and then tried to use that one to call from python.=A0 Konsole out=
put is also added below. </span><span style=3D" font-family:'times new =
roman,new york,times,serif'; font-size:10pt; color:#000000;"><br /></sp=
an></p>
<pre style=3D" margin-top:12px; margin-bottom:0px; margin-left:40px; ma=
rgin-right:40px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;=
"><span style=3D" font-family:'times new roman,new york,times,serif'; f=
ont-size:10pt; color:#000000;">I am using openSUSE 12.2 and installed o=
penMPI 1.5.4-4.1.4 from the software management in opensuse. Any help o=
r suggestions in this regard would be very</span></pre>
<pre style=3D" margin-top:0px; margin-bottom:12px; margin-left:40px; ma=
rgin-right:40px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;=
"><span style=3D" font-family:'times new roman,new york,times,serif'; f=
ont-size:10pt; color:#000000;"> helpful.<br /><br />BR<br />Razibul</sp=
an><span style=3D" font-family:'times new roman,new york,times,serif'; =
font-size:10pt; color:#000000;"> </span><span style=3D" font-family:'Co=
urier New,courier'; font-size:10pt; color:#000000;"><br /></span></pre>=

<pre style=3D" margin-top:12px; margin-bottom:0px; margin-left:40px; ma=
rgin-right:40px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;=
"><span style=3D" font-family:'Courier New,courier'; font-size:10pt; co=
lor:#000000;">------------------------ MPI------------------------</spa=
n></pre>
<pre style=3D" margin-top:0px; margin-bottom:0px; margin-left:40px; mar=
gin-right:40px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"=
><span style=3D" font-family:'Courier New,courier'; font-size:10pt; col=
or:#000000;">      subroutine simple()</span></pre>
<pre style=3D" margin-top:0px; margin-bottom:0px; margin-left:40px; mar=
gin-right:40px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"=
><span style=3D" font-family:'Courier New,courier'; font-size:10pt; col=
or:#000000;">      include 'mpif.h'</span></pre>
<pre style=3D" margin-top:0px; margin-bottom:0px; margin-left:40px; mar=
gin-right:40px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"=
><span style=3D" font-family:'Courier New,courier'; font-size:10pt; col=
or:#000000;">      integer numtasks, ranks, ierr, rc</span></pre>
<pre style=3D" margin-top:0px; margin-bottom:0px; margin-left:40px; mar=
gin-right:40px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"=
><span style=3D" font-family:'Courier New,courier'; font-size:10pt; col=
or:#000000;">      call MPI_INIT(ierr)</span></pre>
<pre style=3D" margin-top:0px; margin-bottom:0px; margin-left:40px; mar=
gin-right:40px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"=
><span style=3D" font-family:'Courier New,courier'; font-size:10pt; col=
or:#000000;">      if (ierr .ne. MPI_SUCCESS) then</span></pre>
<pre style=3D" margin-top:0px; margin-bottom:0px; margin-left:40px; mar=
gin-right:40px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"=
><span style=3D" font-family:'Courier New,courier'; font-size:10pt; col=
or:#000000;">          print *, 'Error starting MPI program. Terminatin=
g.'</span></pre>
<pre style=3D" margin-top:0px; margin-bottom:0px; margin-left:40px; mar=
gin-right:40px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"=
><span style=3D" font-family:'Courier New,courier'; font-size:10pt; col=
or:#000000;">          call MPI_ABORT(MPI_COMM_WORLD, rc, ierr)</span><=
/pre>
<pre style=3D" margin-top:0px; margin-bottom:0px; margin-left:40px; mar=
gin-right:40px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"=
><span style=3D" font-family:'Courier New,courier'; font-size:10pt; col=
or:#000000;">      end if</span></pre>
<pre style=3D"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0=
px; margin-left:40px; margin-right:40px; -qt-block-indent:0; text-inden=
t:0px; -qt-user-state:0; font-family:'Courier New,courier'; font-size:1=
0pt; color:#000000;"><br /></pre>
<pre style=3D" margin-top:0px; margin-bottom:0px; margin-left:40px; mar=
gin-right:40px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"=
><span style=3D" font-family:'Courier New,courier'; font-size:10pt; col=
or:#000000;">      call MPI_COMM_RANK(MPI_COMM_WORLD, rank, ierr)</span=
></pre>
<pre style=3D" margin-top:0px; margin-bottom:0px; margin-left:40px; mar=
gin-right:40px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"=
><span style=3D" font-family:'Courier New,courier'; font-size:10pt; col=
or:#000000;">      call MPI_COMM_SIZE(MPI_COMM_WORLD, numtasks, ierr)</=
span></pre>
<pre style=3D" margin-top:0px; margin-bottom:0px; margin-left:40px; mar=
gin-right:40px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"=
><span style=3D" font-family:'Courier New,courier'; font-size:10pt; col=
or:#000000;">      print *, 'Number of tasks =3D ', numtasks, ' My Rank=
 =3D', rank</span></pre>
<pre style=3D"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0=
px; margin-left:40px; margin-right:40px; -qt-block-indent:0; text-inden=
t:0px; -qt-user-state:0; font-family:'Courier New,courier'; font-size:1=
0pt; color:#000000;"><br /></pre>
<pre style=3D" margin-top:0px; margin-bottom:0px; margin-left:40px; mar=
gin-right:40px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"=
><span style=3D" font-family:'Courier New,courier'; font-size:10pt; col=
or:#000000;">      call MPI_FINALIZE(ierr)</span></pre>
<pre style=3D"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0=
px; margin-left:40px; margin-right:40px; -qt-block-indent:0; text-inden=
t:0px; -qt-user-state:0; font-family:'Courier New,courier'; font-size:1=
0pt; color:#000000;"><br /></pre>
<pre style=3D" margin-top:0px; margin-bottom:0px; margin-left:40px; mar=
gin-right:40px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"=
><span style=3D" font-family:'Courier New,courier'; font-size:10pt; col=
or:#000000;">      end subroutine</span></pre>
<pre style=3D" margin-top:0px; margin-bottom:0px; margin-left:40px; mar=
gin-right:40px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"=
><span style=3D" font-family:'Courier New,courier'; font-size:10pt; col=
or:#000000;">------------------------ END of MPI ----------------------=
--</span></pre>
<pre style=3D"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0=
px; margin-left:40px; margin-right:40px; -qt-block-indent:0; text-inden=
t:0px; -qt-user-state:0; font-family:'Courier New,courier'; font-size:1=
0pt; color:#000000;"><br /></pre>
<pre style=3D" margin-top:0px; margin-bottom:0px; margin-left:40px; mar=
gin-right:40px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"=
><span style=3D" font-family:'Courier New,courier'; font-size:10pt; col=
or:#000000;">------------------------ F2PY Command --------------------=
----</span></pre>
<pre style=3D" margin-top:0px; margin-bottom:0px; margin-left:40px; mar=
gin-right:40px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"=
><span style=3D" font-family:'Courier New,courier'; font-size:10pt; col=
or:#000000;">f2py --fcompiler=3Dgnu95 --f77exec=3Dmpif90 -m simplesub -=
c simple.f90</span></pre>
<pre style=3D" margin-top:0px; margin-bottom:0px; margin-left:40px; mar=
gin-right:40px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"=
><span style=3D" font-family:'Courier New,courier'; font-size:10pt; col=
or:#000000;">-I/usr/lib/mpi/gcc/openmpi/include -L/usr/lib/mpi/gcc/open=
mpi/lib</span></pre>
<pre style=3D" margin-top:0px; margin-bottom:0px; margin-left:40px; mar=
gin-right:40px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"=
><span style=3D" font-family:'Courier New,courier'; font-size:10pt; col=
or:#000000;">-lmpi_f77</span></pre>
<pre style=3D"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0=
px; margin-left:40px; margin-right:40px; -qt-block-indent:0; text-inden=
t:0px; -qt-user-state:0; font-family:'Courier New,courier'; font-size:1=
0pt; color:#000000;"><br /></pre>
<pre style=3D" margin-top:0px; margin-bottom:0px; margin-left:40px; mar=
gin-right:40px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"=
><span style=3D" font-family:'Courier New,courier'; font-size:10pt; col=
or:#000000;">------------------------ Python Code ---------------------=
---</span></pre>
<pre style=3D" margin-top:0px; margin-bottom:0px; margin-left:40px; mar=
gin-right:40px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"=
><span style=3D" font-family:'Courier New,courier'; font-size:10pt; col=
or:#000000;">#File Name : ptest.py</span></pre>
<pre style=3D" margin-top:0px; margin-bottom:0px; margin-left:40px; mar=
gin-right:40px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"=
><span style=3D" font-family:'Courier New,courier'; font-size:10pt; col=
or:#000000;">#!/usr/bin/env python</span></pre>
<pre style=3D" margin-top:0px; margin-bottom:0px; margin-left:40px; mar=
gin-right:40px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"=
><span style=3D" font-family:'Courier New,courier'; font-size:10pt; col=
or:#000000;">#-*- cpding: utf-8 -*-</span></pre>
<pre style=3D" margin-top:0px; margin-bottom:0px; margin-left:40px; mar=
gin-right:40px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"=
><span style=3D" font-family:'Courier New,courier'; font-size:10pt; col=
or:#000000;">import simplesub</span></pre>
<pre style=3D" margin-top:0px; margin-bottom:0px; margin-left:40px; mar=
gin-right:40px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"=
><span style=3D" font-family:'Courier New,courier'; font-size:10pt; col=
or:#000000;">print dir(simplesub)</span></pre>
<pre style=3D" margin-top:0px; margin-bottom:0px; margin-left:40px; mar=
gin-right:40px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"=
><span style=3D" font-family:'Courier New,courier'; font-size:10pt; col=
or:#000000;">simplesub.simple()</span></pre>
<pre style=3D" margin-top:0px; margin-bottom:0px; margin-left:40px; mar=
gin-right:40px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"=
><span style=3D" font-family:'Courier New,courier'; font-size:10pt; col=
or:#000000;">------------------------ End of Python Code --------------=
----------</span></pre>
<pre style=3D"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0=
px; margin-left:40px; margin-right:40px; -qt-block-indent:0; text-inden=
t:0px; -qt-user-state:0; font-family:'Courier New,courier'; font-size:1=
0pt; color:#000000;"><br /></pre>
<pre style=3D" margin-top:0px; margin-bottom:0px; margin-left:40px; mar=
gin-right:40px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"=
><span style=3D" font-family:'Courier New,courier'; font-size:10pt; col=
or:#000000;">------------------------ Error Text in Console -----------=
-------------</span></pre>
<pre style=3D"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0=
px; margin-left:40px; margin-right:40px; -qt-block-indent:0; text-inden=
t:0px; -qt-user-state:0; font-family:'Courier New,courier'; font-size:1=
0pt; color:#000000;"><br /></pre>
<pre style=3D" margin-top:0px; margin-bottom:0px; margin-left:40px; mar=
gin-right:40px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"=
><span style=3D" font-family:'Courier New,courier'; font-size:10pt; col=
or:#000000;">tamal@linux-p7k6:~/Dropbox/Thesis/2012/20130210/simple&gt;=
 mpiexec -n 4</span></pre>
<pre style=3D" margin-top:0px; margin-bottom:0px; margin-left:40px; mar=
gin-right:40px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"=
><span style=3D" font-family:'Courier New,courier'; font-size:10pt; col=
or:#000000;">python ptest.py<br /></span></pre>
<pre style=3D" margin-top:0px; margin-bottom:0px; margin-left:40px; mar=
gin-right:40px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"=
><span style=3D" font-family:'Courier New,courier'; font-size:10pt; col=
or:#000000;">tamal@linux-p7k6:~/Dropbox/Thesis/2012/20130207&gt; mpiexe=
c -n 2 python</span></pre>
<pre style=3D" margin-top:0px; margin-bottom:0px; margin-left:40px; mar=
gin-right:40px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"=
><span style=3D" font-family:'Courier New,courier'; font-size:10pt; col=
or:#000000;">partest.py</span></pre>
<pre style=3D" margin-top:0px; margin-bottom:0px; margin-left:40px; mar=
gin-right:40px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"=
><span style=3D" font-family:'Courier New,courier'; font-size:10pt; col=
or:#000000;">python: symbol lookup error:</span></pre>
<pre style=3D" margin-top:0px; margin-bottom:0px; margin-left:40px; mar=
gin-right:40px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"=
><span style=3D" font-family:'Courier New,courier'; font-size:10pt; col=
or:#000000;">/usr/lib/mpi/gcc/openmpi/lib/openmpi/mca_paffinity_hwloc.s=
o: undefined</span></pre>
<pre style=3D" margin-top:0px; margin-bottom:0px; margin-left:40px; mar=
gin-right:40px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"=
><span style=3D" font-family:'Courier New,courier'; font-size:10pt; col=
or:#000000;">symbol: mca_base_param_reg_int</span></pre>
<pre style=3D" margin-top:0px; margin-bottom:0px; margin-left:40px; mar=
gin-right:40px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"=
><span style=3D" font-family:'Courier New,courier'; font-size:10pt; col=
or:#000000;">python: symbol lookup error:</span></pre>
<pre style=3D" margin-top:0px; margin-bottom:0px; margin-left:40px; mar=
gin-right:40px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"=
><span style=3D" font-family:'Courier New,courier'; font-size:10pt; col=
or:#000000;">/usr/lib/mpi/gcc/openmpi/lib/openmpi/mca_paffinity_hwloc.s=
o: undefined</span></pre>
<pre style=3D" margin-top:0px; margin-bottom:0px; margin-left:40px; mar=
gin-right:40px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"=
><span style=3D" font-family:'Courier New,courier'; font-size:10pt; col=
or:#000000;">symbol: mca_base_param_reg_int</span></pre>
<pre style=3D" margin-top:0px; margin-bottom:0px; margin-left:40px; mar=
gin-right:40px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"=
><span style=3D" font-family:'Courier New,courier'; font-size:10pt; col=
or:#000000;">----------------------------------------------------------=
----------------</span></pre>
<pre style=3D" margin-top:0px; margin-bottom:0px; margin-left:40px; mar=
gin-right:40px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"=
><span style=3D" font-family:'Courier New,courier'; font-size:10pt; col=
or:#000000;">mpiexec noticed that the job aborted, but has no info as t=
o the process</span></pre>
<pre style=3D" margin-top:0px; margin-bottom:0px; margin-left:40px; mar=
gin-right:40px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"=
><span style=3D" font-family:'Courier New,courier'; font-size:10pt; col=
or:#000000;">that caused that situation.</span></pre>
<pre style=3D" margin-top:0px; margin-bottom:0px; margin-left:40px; mar=
gin-right:40px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"=
><span style=3D" font-family:'Courier New,courier'; font-size:10pt; col=
or:#000000;">----------------------------------------------------------=
----------------</span></pre>
<pre style=3D"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0=
px; margin-left:40px; margin-right:40px; -qt-block-indent:0; text-inden=
t:0px; -qt-user-state:0; font-family:'Courier New,courier'; font-size:1=
0pt; color:#000000;"><br /></pre>
<pre style=3D"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0=
px; margin-left:40px; margin-right:40px; -qt-block-indent:0; text-inden=
t:0px; -qt-user-state:0; font-family:'Courier New,courier'; font-size:1=
0pt; color:#000000;"><br /></pre>
<pre style=3D" margin-top:0px; margin-bottom:12px; margin-left:40px; ma=
rgin-right:40px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;=
"><span style=3D" font-family:'Courier New,courier'; font-size:10pt; co=
lor:#000000;"><br /><br /><br /></span></pre>
<p style=3D"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px=
; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0p=
x; ">&nbsp;</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">Hi,=
 I found this problem some time ago, there are two options.</p>
<p style=3D"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px=
; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0p=
x; ">&nbsp;</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">The=
 easy way</p>
<p style=3D"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px=
; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0p=
x; ">&nbsp;</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">Try=
 to use some of the the mpi implementations in your python script. I tr=
ied with mpi4py.  An 'import mpi4py'  before calling simplesub can do t=
he job. </p>
<p style=3D"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px=
; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0p=
x; ">&nbsp;</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">The=
 not so easy</p>
<p style=3D"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px=
; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0p=
x; ">&nbsp;</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">Bot=
h python and mpi try to access the args command line, so some ordering =
it's needed.  A small C program can manage this. </p>
<p style=3D"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px=
; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0p=
x; ">&nbsp;</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">---=
------------</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">#in=
clude &lt;Python.h&gt;</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">#in=
clude &lt;stdio.h&gt;</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">#in=
clude &lt;stdlib.h&gt;</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">#in=
clude &quot;mpi.h&quot;</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">/*<=
/p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">py_=
mpi.c</p>
<p style=3D"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px=
; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0p=
x; ">&nbsp;</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">Mai=
n program, it needs one file.py as first parameter, then the remaining =
are passed to the script.</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> */=
</p>
<p style=3D"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px=
; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0p=
x; ">&nbsp;</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">int=
 main(int argc, char *argv[])</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">{</=
p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">  F=
ILE *f;</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">  i=
nt new_argc,i;</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">  c=
har **new_argv;</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">  /=
*</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">   =
  argv[0] contains the exec file</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">  *=
/</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">  i=
f (argc &lt; 2){</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">   =
 printf(&quot;%i is invalid as number of params\n&quot;,argc);</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">   =
 exit(1);</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">  }=
</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">  /=
*</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">   =
  Init MPI, berfore calling python</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">  *=
/</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">  M=
PI_Init(&amp;argc,&amp;argv);</p>
<p style=3D"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px=
; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0p=
x; ">&nbsp;</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">  /=
*</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">   =
  input file</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">  *=
/</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">  f=
 =3D fopen(argv[1], &quot;r&quot;);</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">  i=
f (f =3D=3D NULL){</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">   =
 printf(&quot;invalid file\n&quot;);</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">   =
 exit(1);</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">   =
   }</p>
<p style=3D"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px=
; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0p=
x; ">&nbsp;</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">  /=
*</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">   =
entering  python</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">  *=
/</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">  P=
y_SetProgramName(argv[0]);</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">  P=
y_Initialize();</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">  n=
ew_argc =3D argc-1;</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">  n=
ew_argv =3D (char**) malloc((new_argc)*sizeof(char*));</p>
<p style=3D"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px=
; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0p=
x; ">&nbsp;</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">  /=
*</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> /*=
</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">   =
 Changing command line</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">  *=
/</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">  f=
or (i=3D1; i&lt;argc;i++) {</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">   =
 new_argv[i-1]=3Dargv[i];</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">  }=
</p>
<p style=3D"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px=
; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0p=
x; ">&nbsp;</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">  P=
ySys_SetArgv(new_argc, new_argv);</p>
<p style=3D"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px=
; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0p=
x; ">&nbsp;</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">  /=
*</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">  s=
ending the script</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">  *=
/</p>
<p style=3D"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px=
; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0p=
x; ">&nbsp;</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">  P=
yRun_SimpleFile(f,argv[1]);</p>
<p style=3D"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px=
; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0p=
x; ">&nbsp;</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">  /=
*</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">   =
 bye bye, we close python and then mpi</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">  *=
/</p>
<p style=3D"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px=
; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0p=
x; ">&nbsp;</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">  P=
y_Finalize();</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">  M=
PI_Finalize();</p>
<p style=3D"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px=
; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0p=
x; ">&nbsp;</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">  r=
eturn 0;</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">}</=
p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">---=
------------------</p>
<p style=3D"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px=
; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0p=
x; ">&nbsp;</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">In =
this case the C program initializes mpi, so the mpi_init and mpi_finali=
ze calls must be removed from your fortran code.      First solution is=
 simpler but I'm not sure it will work always. For me (ubuntu 12.04, mp=
ich2) it's working.<br /></p></body></html>
--nextPart24299589.aLO2QssMg3--



--===============4090219711153273213==
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

--===============4090219711153273213==--