<div dir="ltr"><div>Dear all</div><div><br></div><div>In my problem, I know the ghost vertices in each partition since I have used metis to partition my unstructured grid. I want to get a vector ul with ghosts, from a global vector ug.</div><div><br></div><div>I will use ul to assemble my non-linear rhs vector.</div><div><br></div><div>Is the following approach optimal for this purpose ?</div><div><br></div>PetscInt nvar; // number of variables at each vertex<div>PetscInt nvl; // number of local vertices in this partition</div><div>PetscInt nvg; // number of ghost vertices for this partition</div><div>PetscInt *vghost; // global index of ghost vertices for this partition</div><div>PetscReal **u; // size u[nvl+nvg][nvar]</div><div>Vec ul; // vector with ghosts</div><div>Vec ug; // global vector without ghosts</div><div><br></div><div><div>   VecCreate(PETSC_COMM_WORLD, &ug);</div><div>   VecSetSizes(ug, nvar*nvl, PETSC_DECIDE);</div><div>   VecSetFromOptions(ug);</div></div><div><br></div><div><div>   VecCreateGhostBlockWithArray(PETSC_COMM_WORLD, nvar, nvar*nvl,</div><div>                                       PETSC_DECIDE, nvg, vghost,</div><div>                                       &u, ul);</div></div><div><br></div><div>// Following would be inside RHSFunction</div><div><div>   double **array;</div><div>   VecGetArray2d(ug, nvl, nvar, 0, 0, &array);</div><div>   for(unsigned int i=0; i<nvl; ++i)</div><div>      for(unsigned int j=0; j<nvar; ++j)</div><div>         u[i][j] = array[i][j];</div><div>   VecRestoreArray2d(ug, nvl, nvar, 0, 0, &array);</div><div><br></div><div>   // Fill ghost values</div><div>   VecGhostUpdateBegin(ul, INSERT_VALUES, SCATTER_FORWARD);</div><div>   VecGhostUpdateEnd  (ul, INSERT_VALUES, SCATTER_FORWARD);</div></div><div><br></div><div>// now use u[][] to compute local part of rhs vector</div><div><br></div><div>Thanks</div><div>praveen</div></div>