[petsc-users] local Vec to global Vec and global 3-D array

Barry Smith bsmith at mcs.anl.gov
Wed May 15 11:40:03 CDT 2013


On May 15, 2013, at 10:19 AM, Roc Wang <pengxwang at hotmail.com> wrote:

>  Hello, 
> 
>  1. I am trying to save the solution of a PDE for a 3-D geometry domain.  I used DM to manage the matrix and vector.
>   The solution vector was converted to local 3D arrays on each process successfully. But there was errors when the functions DMLocalToGlobalBegin() and DMLocalToGlobalEnd() were called.
>   
>   I built the code by following the example in /petsc-3.3-p6/src/dm/examples/tutorials/ex3.c. The codes for this are as followings :
> 
>   /*Get the solution vec */
>   ierr = KSPSolve(ksp,PETSC_NULL,PETSC_NULL);CHKERRQ(ierr);
>   ierr = KSPGetSolution(ksp,&x);CHKERRQ(ierr);
>   
>   /* local 3d arrays */ 
>   ierr = DMDAVecGetArray(da, x, &localArray3d ); CHKERRQ(ierr);
> 
>   /* global 3d array */ 
>   ierr = DMCreateGlobalVector(da,&gsol3d);CHKERRQ(ierr);
>   ierr = DMLocalToGlobalBegin(da,x,INSERT_VALUES,gsol3d);CHKERRQ(ierr);
>   ierr = DMLocalToGlobalEnd(da,x,INSERT_VALUES,gsol3d);CHKERRQ(ierr);

   The x here must not have been obtained from this da. You need to have obtained the x somewhere before with DMCreateLocalVector(da,&x) or with a VecDuplicate from such a vector. Likely the vector put into the KSP is not from this da.
>  
>  
>  2.   I am trying to visualize the solution in a 3-D domain by using some software such as Tecplot. To my understand, I need to output the solution in the format of 3-D array. The vectors of KSP solution in PETSc are local vectors on each process. So they have to be assembled to a global vector and then converted to a 3-D global array.  I am not sure if my approach is a good way and if there is some functions in PETSc to output the global solutions directly?

   Yes. VecView() on DMDA vectors automatically reorders the entries on the file to use the natural ordering. There are variety of possible viewers you can use including binary, ASCII (no good for anything but tiny problems), VTK, HDF5 

   Barry

>       
> Part of the error information when DMLocalToGlobalBegin() and DMLocalToGlobalEnd() were called 
>   
> [0]PETSC ERROR: [1]PETSC ERROR: [2]PETSC ERROR: --------------------- Error Message ------------------------------------
> [3]PETSC ERROR: --------------------- Error Message ------------------------------------
> [2]PETSC ERROR: [3]PETSC ERROR: --------------------- Error Message ------------------------------------
> Nonconforming object sizes!
> Nonconforming object sizes!
> [2]PETSC ERROR: [3]PETSC ERROR: Vector wrong size 30 for scatter 60 (scatter forward and vector from != ctx from size)!
> Vector wrong size 20 for scatter 45 (scatter forward and vector from != ctx from size)!



More information about the petsc-users mailing list