<div dir="ltr">Thank you Barry.<div>Is there a way to reuse the vector x? I don't want to gather the vector in each iteration, I'd rather replicate the vector x in each process.</div><div><br></div><div>Thanks in advance.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Feb 8, 2015 at 7:17 PM, Barry Smith <span dir="ltr"><<a href="mailto:bsmith@mcs.anl.gov" target="_blank">bsmith@mcs.anl.gov</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><br>
> On Feb 8, 2015, at 5:41 PM, Ronal Celaya <<a href="mailto:ronalcelayavzla@gmail.com">ronalcelayavzla@gmail.com</a>> wrote:<br>
><br>
> Hello<br>
> If I have a MatMult operation inside a for loop (e. g. CG algorithm), and the matrix A is MPIAIJ, vector x is gathered to local process in every loop?<br>
<br>
</span>  Yes, internal to MatMult() it calls MatMult_MPIAIJ() which is in src/mat/impls/aij/mpi/mpiaij,c which has the following code:<br>
<br>
PetscErrorCode MatMult_MPIAIJ(Mat A,Vec xx,Vec yy)<br>
{<br>
  Mat_MPIAIJ     *a = (Mat_MPIAIJ*)A->data;<br>
  PetscErrorCode ierr;<br>
  PetscInt       nt;<br>
<br>
  PetscFunctionBegin;<br>
  ierr = VecGetLocalSize(xx,&nt);CHKERRQ(ierr);<br>
  if (nt != A->cmap->n) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_ARG_SIZ,"Incompatible partition of A (%D) and xx (%D)",A->cmap->n,nt);<br>
  ierr = VecScatterBegin(a->Mvctx,xx,a->lvec,INSERT_VALUES,SCATTER_FORWARD);CHKERRQ(ierr);<br>
  ierr = (*a->A->ops->mult)(a->A,xx,yy);CHKERRQ(ierr);<br>
  ierr = VecScatterEnd(a->Mvctx,xx,a->lvec,INSERT_VALUES,SCATTER_FORWARD);CHKERRQ(ierr);<br>
  ierr = (*a->B->ops->multadd)(a->B,a->lvec,yy,yy);CHKERRQ(ierr);<br>
  PetscFunctionReturn(0);<br>
<br>
The needed values of x are communicated in the VecScatterBegin() to VecScatterEnd(). Note only exactly those values needed by each process are communicated in the scatter so not all values are communicated to all processes. Since the matrix is very sparse (normally) only a small percentage of the values need to be communicated.<br>
<span class="HOEnZb"><font color="#888888"><br>
  Barry<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
><br>
> I'm sorry for my English.<br>
><br>
> Regards,<br>
><br>
> --<br>
> Ronal Celaya<br>
<br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr">Ronal Celaya<br></div></div>
</div>