<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Feb 28, 2017 at 6:17 PM, Rodrigo Felicio <span dir="ltr"><<a href="mailto:Rodrigo.Felicio@iongeo.com" target="_blank">Rodrigo.Felicio@iongeo.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Dear All,<br>
<br>
I am new to both pestc (petsc4py) and MPI. I am prototyping an application that acts on data belonging to thousands of different spatial locations, so I decided to use mpi4py to parallelize my computations over said set of points. At each point, however, I have to solve linear systems of the type A x = b, using least-squares. As matrices A are sparse and large, I would like use petsc LSQR solver to obtain x. Trouble is that I cannot get mpi4py to work with petsc4py when using MPI.Spawn(), so that I could solve those linear systems using threads spawned from my main algorithm. I am not sure if this is a problem with my petsc/mpi installation, or if there is some inherent incompatibility between mpi4py and petsc4py on spawned threads. Anyway, I would be really thankful to anyone who could shed some light on this issue. For illustration, the child and parent codes found on the pestc4py spawning demo folder fail for me if I just include the petsc4py initialization in either of them. In fact, just the introduction of the line " from petsc4py import PETSc" is enough to make the code to hang and issue, upon keyboard termination, error msgs of the type "spawned process group was unable to connect back to parent port" .<br></blockquote><div><br></div><div>MPI is really an SPMD framework, so it does not make sense to me that you separate the codes here. Normally</div><div>you would designate one rank (say 0) to be the master, and then the others are the children. Also, startup is</div><div>collective, so everyone must call it at the same time.</div><div><br></div><div> Matt</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Kind regards<br>
Rodrigo<br>
<br>
------------------------<br>
CHILD code:<br>
-------------------------<br>
<br>
# inclusion of petsc4py lines causes code to hang<br>
import petsc4py<br>
petsc4py.init(sys.argv)<br>
from petsc4py import PETSc<br>
from mpi4py import MPI<br>
from array import array<br>
<br>
master = MPI.Comm.Get_parent()<br>
nprocs = master.Get_size()<br>
myrank = master.Get_rank()<br>
<br>
n = array('i', [0])<br>
master.Bcast([n, <a href="http://MPI.INT" rel="noreferrer" target="_blank">MPI.INT</a>], root=0)<br>
n = n[0]<br>
<br>
h = 1.0 / n<br>
s = 0.0<br>
for i in range(myrank+1, n+1, nprocs):<br>
x = h * (i - 0.5)<br>
s += 4.0 / (1.0 + x**2)<br>
pi = s * h<br>
<br>
pi = array('d', [pi])<br>
master.Reduce(sendbuf=[pi, MPI.DOUBLE],<br>
recvbuf=None,<br>
op=MPI.SUM, root=0)<br>
<br>
master.Disconnect()<br>
<br>
<br>
---------------------<br>
MASTER CODE:<br>
----------------------<br>
from mpi4py import MPI<br>
from array import array<br>
from math import pi as PI<br>
from sys import argv<br>
<br>
cmd = 'cpi-worker-py.exe'<br>
if len(argv) > 1: cmd = argv[1]<br>
print("%s -> %s" % (argv[0], cmd))<br>
<br>
worker = MPI.COMM_SELF.Spawn(cmd, None, 5)<br>
<br>
n = array('i', [100])<br>
worker.Bcast([n,<a href="http://MPI.INT" rel="noreferrer" target="_blank">MPI.INT</a>], root=MPI.ROOT)<br>
<br>
pi = array('d', [0.0])<br>
worker.Reduce(sendbuf=None,<br>
recvbuf=[pi, MPI.DOUBLE],<br>
op=MPI.SUM, root=MPI.ROOT)<br>
pi = pi[0]<br>
<br>
worker.Disconnect()<br>
<br>
print('pi: %.16f, error: %.16f' % (pi, abs(PI-pi)))<br>
<br>
<br>
<br>
<br>
<br>
______________________________<wbr>__<br>
<br>
<br>
This email and any files transmitted with it are confidential and are intended solely for the use of the individual or entity to whom they are addressed. If you are not the original recipient or the person responsible for delivering the email to the intended recipient, be advised that you have received this email in error, and that any use, dissemination, forwarding, printing, or copying of this email is strictly prohibited. If you received this email in error, please immediately notify the sender and delete the original.<br>
<br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>-- Norbert Wiener</div>
</div></div>