[petsc-users] How can I update a global application vector with local petsc results?

Smith, Barry F. bsmith at mcs.anl.gov
Sun Dec 2 12:30:14 CST 2018



> On Dec 2, 2018, at 5:13 AM, Klaus Burkart via petsc-users <petsc-users at mcs.anl.gov> wrote:
> 
> Hello,
> 
> I use the following routine to transfer the petsc result back to my application which works fine using one core as the local parts of the linear system == global parts: 
> 
>     VecGetArray(petsc_x, &array);
>     for (i=rstart; i < rend; ++i) { 
>         application_x[i] = array[i];
>     }
>     VecRestoreArray(petsc_x, &array);
> 
     VecGetArray() (and VecGetArrayRead() which you could use in this case), return arrays that always begin at 0 on each process. So your loop should be 

> or (i=0; i < rend-rstart; ++i) { 
>         application_x[i] = array[i];
>     }


> As this updates only the local portion of x on each core but nowhere the entire/global application_x vector, multicore simulations don't work correctly.
> 
> How can I update the entire/global application_x vector with all local parts on all cores?

   I hope this resolves your difficulties, if not let us know what fails,

    Barry

> 
> Klaus



More information about the petsc-users mailing list