[petsc-users] A Beginner Question

Matthew Knepley knepley at gmail.com
Tue Jul 5 12:29:31 CDT 2011


On Tue, Jul 5, 2011 at 2:04 PM, Stefan Kolb <skolb at rocketmail.com> wrote:

> Hi all,
> i have written a littel test program, to check how PETSc stores a matrix
> across two processes.
>
> static char help[] = "PETSc test";
>
> #include "stdio.h"
>
> #include "petscksp.h"
>
> int main(int argc,char **args)
> {
>        Mat                             A;
>        PetscInt                        N=100,M=100, row_start = 0,
> column_start = 0, row_end = 0, column_end = 0, rank = 0, local_rows = 0,
> local_columns = 0,nproc=0;
>        PetscErrorCode          ierr;
>        PetscScalar             value =0.;
>
>        PetscInitialize(&argc,&args,(char *)0,help);
>
>        MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
>        MPI_Comm_size(PETSC_COMM_WORLD,&nproc);
>
>        ierr = PetscPrintf(PETSC_COMM_WORLD,"Number of Processes
> %d\n",nproc);CHKERRQ(ierr);
>        ierr = MatCreate(PETSC_COMM_WORLD,&A); CHKERRQ(ierr);
>        ierr = MatSetSizes(A,PETSC_DECIDE, PETSC_DECIDE,N,M); CHKERRQ(ierr);
>        ierr = MatSetFromOptions(A);CHKERRQ(ierr);
>        ierr = MatGetOwnershipRange(A,&row_start,&row_end);CHKERRQ(ierr);
>        ierr =
> MatGetOwnershipRangeColumn(A,&column_start,&column_end);CHKERRQ(ierr);
>        ierr = MatGetLocalSize(A,&local_rows,&local_columns);CHKERRQ(ierr);
>
>        printf("process=%d \t row_start=%d \t row_end=%d \t column_start=%d
> \t column_end=%d \t local_rows=%d \t
> local_columns=%d\n",rank,row_start,row_end,column_start,column_end,local_rows,local_columns);
>
>        ierr = MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);
>        ierr = MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);
>
>        ierr = MatDestroy(A); CHKERRQ(ierr);
>
>        ierr = PetscFinalize();CHKERRQ(ierr);
>        return 0;
> }
>
> The output of the program (using 2 processes) is:
> Number of Processes 2
> process=0        row_start=0     row_end=50      column_start=0
>  column_end=50   local_rows=50   local_columns=50
> process=1        row_start=50    row_end=100     column_start=50
> column_end=100          local_rows=50   local_columns=50
>
> So if the output of my program is right the process with rank=0 owns a
> matrix with 50 rows and 50 columns in the same way the process with rank=1.
> This cant be right because on both processes only one half of the global
> matrix is stored. Wat is the error in my test programm?
> I tried to set the local size of the matrix by hand with the command
> MatSetSizes(A,50, 100,N,M) but then i get an error from PETSc. How can i
> tell PETSc to store the first 50 rows on process 0 and the next 50 rows on
> process 1?
>

All matrix formats store by row. The column ownership is only used to
determine compatibility with vector it might act on.

  Thanks,

     Matt


> Regards,
> Stefan
>



-- 
What most experimenters take for granted before they begin their experiments
is infinitely more interesting than any results to which their experiments
lead.
-- Norbert Wiener
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20110705/7d965ae6/attachment.htm>


More information about the petsc-users mailing list