<html dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style id="owaParaStyle" type="text/css">P {margin-top:0;margin-bottom:0;}</style>
</head>
<body ocsi="0" fpstyle="1">
<div style="direction: ltr;font-family: Tahoma;color: #000000;font-size: 10pt;">Hello all,<br>
<br>
Sorry for the newbie question, but is there a way of making petsc4py work with an MPI group or subcommunicator? I saw a solution posted back in 2010 (<a href="http://lists.mcs.anl.gov/pipermail/petsc-users/2010-May/006382.html" target="_blank">http://lists.mcs.anl.gov/pipermail/petsc-users/2010-May/006382.html</a>),
but it does not work for me. Indeed, if I try to use petsc4py.init(comm=newcom), then my sample code prints a msg "Attempting to use an MPI routine before initializing MPI". Below I attach both the output and the source of the python code.<br>
<br>
kind regards<br>
Rodrigo<br>
<br>
<br>
time mpirun -n 5 python split_comm_ex2.py <br>
Global: rank 0 of 5. New comm : rank 0 of 3<br>
Global: rank 1 of 5. New comm : rank 0 of 2<br>
Global: rank 2 of 5. New comm : rank 1 of 3<br>
Global: rank 3 of 5. New comm : rank 1 of 2<br>
Global: rank 4 of 5. New comm : rank 2 of 3<br>
Attempting to use an MPI routine before initializing MPI<br>
Attempting to use an MPI routine before initializing MPI<br>
<br>
real 0m0.655s<br>
user 0m1.122s<br>
sys 0m1.047s<br>
<br>
And the python code:<br>
<br>
from mpi4py import MPI<br>
<br>
comm = MPI.COMM_WORLD<br>
world_rank = comm.rank<br>
world_size = comm.size<br>
<br>
color = world_rank % 2<br>
<br>
newcomm = comm.Split(color)<br>
newcomm_rank = newcomm.rank<br>
newcomm_size = newcomm.size<br>
<br>
for i in range(world_size):<br>
comm.Barrier()<br>
if (world_rank == i):<br>
print ("Global: rank %d of %d. New comm : rank % d of %d" % <br>
(world_rank, world_size, newcomm_rank, newcomm_size))<br>
<br>
if newcomm.rank == 0:<br>
import petsc4py<br>
petsc4py.init(comm=newcomm)<br>
from petsc4py import PETSc<br>
<br>
pcomm = PETSc.COMM_WORLD<br>
print('pcomm size is {}/{}'.format(pcomm.rank, pcomm.size))<br>
<br>
newcomm.Free()<br>
</div>
<br>
<hr>
<font face="Arial" color="Gray" size="1"><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>
</font>
</body>
</html>