[petsc-dev] MatMatMult gives different results

Alexander Grayver agrayver at gfz-potsdam.de
Tue Feb 7 04:03:07 CST 2012


Dear Hong,

You can get matrices here:
http://dl.dropbox.com/u/60982984/A.dat
http://dl.dropbox.com/u/60982984/B.dat

I wrote simple testing application for that problem (it looks ugly, but 
allows to reproduce the problem):

   Mat            A,AT,B,C;
   PetscInt       M,N;

   PetscInitialize(&argc,&args,(char *)0,help);

   ierr = 
PetscViewerBinaryOpen(PETSC_COMM_WORLD,"A.dat",FILE_MODE_READ,&viewer);CHKERRQ(ierr);
   ierr = MatCreate(PETSC_COMM_WORLD,&A);CHKERRQ(ierr);
   ierr = MatSetType(A,MATMPIAIJ);CHKERRQ(ierr);
   ierr = MatLoad(A,viewer);CHKERRQ(ierr);
   ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr);

   ierr = 
PetscViewerBinaryOpen(PETSC_COMM_WORLD,"B.dat",FILE_MODE_READ,&viewer);CHKERRQ(ierr);
   ierr = MatCreate(PETSC_COMM_WORLD,&B);CHKERRQ(ierr);
   ierr = MatSetType(B,MATMPIDENSE);CHKERRQ(ierr);
   ierr = MatLoad(B,viewer);CHKERRQ(ierr);
   ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr);

   MatGetSize(A,&M,&N);
   MatCreateMPIAIJ(PETSC_COMM_WORLD, PETSC_DECIDE, PETSC_DECIDE, N, M, 
12, PETSC_NULL, 12, PETSC_NULL, &AT);

   MatTranspose(A,MAT_IGNORE_MATRIX,&AT);
   MatMatMult(AT,B,MAT_INITIAL_MATRIX,PETSC_DEFAULT,&C);

   ierr = 
PetscViewerBinaryOpen(PETSC_COMM_WORLD,"C.dat",FILE_MODE_WRITE,&viewer);CHKERRQ(ierr);
   ierr = PetscViewerSetFormat(viewer,PETSC_VIEWER_NATIVE);CHKERRQ(ierr);
   ierr = MatView(C,viewer);CHKERRQ(ierr);
   ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr);

   ierr = PetscFinalize();
   return 0;

To compare results I use following Matlab script:

A = PetscBinaryRead('A.dat','complex',true);
B = PetscBinaryRead('B.dat','complex',true);
Cm = A.'*B;
C = PetscBinaryRead('C.dat','complex',true);

Matrix C is different depending on number of cores I use.
My PETSc is:
Using Petsc Development HG revision: 
876c894d95f4fa6561d0a91310ca914592527960  HG Date: Tue Jan 10 19:27:14 
2012 +0100

On 06.02.2012 17:13, Hong Zhang wrote:
> MatMatMult() in petsc is not well-tested for complex - could be buggy.
> Can you send us the matrices A and B in petsc binary format for 
> investigation?
>
> Hong
>
> On Mon, Feb 6, 2012 at 5:55 AM, Alexander Grayver 
> <agrayver at gfz-potsdam.de <mailto:agrayver at gfz-potsdam.de>> wrote:
>
>     Dear PETSc team,
>
>     I try to use:
>     call
>     MatMatMult(A,B,MAT_INITIAL_MATRIX,PETSC_DEFAULT_DOUBLE_PRECISION,C,ierr);CHKERRQ(ierr)
>
>     Where both A and B are rectangular, but A is sparse and B is
>     dense. Both are double complex and distributed.
>     The product PETSc gives me contains some errors in some part of
>     the matrix.
>     I output A, B and C then computed product in matlab.
>
>     Attached you see figure plotted as:
>     imagesc(log10(abs(C-Cm)))
>
>     Where Cm -- product computed in matlab.
>
>     The pattern and amplitude vary depending on the number of cores I
>     use. This picture is obtained for 48 cores (I've tried 12, 64
>     cores as well).
>
>     Where should I look for possible explanation?
>
>     -- 
>     Regards,
>     Alexander
>
>


-- 
Regards,
Alexander

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-dev/attachments/20120207/f9b04f7a/attachment.html>


More information about the petsc-dev mailing list