<div class="gmail_quote">On Sun, Nov 28, 2010 at 21:11, Rongliang Chen <span dir="ltr"><<a href="mailto:rongliang.chan@gmail.com">rongliang.chan@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div id=":128">The format of the matrix A is AIJ and is obtained by function SNESDefaultComputeJacobian.<br>
I compute A*x in Matlab with the following A and x and compare it with Ax.<br><br> .......................<br> ierr = MatMult(*A, x, Ax);CHKERRQ(ierr);<br><br> sprintf(filename,"x.m");<br> ierr = PetscViewerASCIIOpen(PETSC_COMM_WORLD,filename,&view->viewer);CHKERRQ(ierr);<br>
ierr = PetscViewerSetFormat(view->viewer, PETSC_VIEWER_ASCII_MATLAB);CHKERRQ(ierr); <br> ierr = VecView(x, view->viewer);CHKERRQ(ierr);<br><br> sprintf(filename,"Ax.m");<br> ierr = PetscViewerASCIIOpen(PETSC_COMM_WORLD,filename,&view->viewer);CHKERRQ(ierr);<br>
ierr = PetscViewerSetFormat(view->viewer, PETSC_VIEWER_ASCII_MATLAB);CHKERRQ(ierr); <br> ierr = VecView(Ax, view->viewer);CHKERRQ(ierr); </div></blockquote></div><br><div>Are the vectors and matrices obtained from a DA (DACreateGlobalVector, DAGetMatrix)? How are you comparing the matrix that PETSc sees with the matrix that Matlab sees? I suggest writing the matrix and both vectors to a PETSc binary file</div>
<div><br></div><div> PetscViewer viewer = PETSC_VIEWER_BINARY(PETSC_COMM_WORLD);</div><div> MatView(A,viewer);</div><div> VecView(x,viewer);</div><div> MatMult(A,x,y);</div><div> VecView(y,viewer);</div><div><br></div>
<div>and read them into Matlab with</div><div><br></div><div> [A,x,y] = PetscBinaryRead('binaryoutput')</div><div> norm(A*x - y) % This should be small</div><div><br></div><div>Jed</div>