[petsc-users] MAT_REUSE_MATRIX
irfan.khan at gatech.edu
irfan.khan at gatech.edu
Mon May 10 12:20:33 CDT 2010
I get the following error at the call for MatMatMult(Mat A,Mat B,MatReuse scall, PetscReal fill,Mat *C).
Error: Container does not exit!
Is the probable cause of this error an invalid C matrix?. Can I use MAT_REUSE_MATRIX in MatMatMult() and use an existing C matrix. The call works fine when I use MAT_INITIAL_MATRIX and use a new matrix.
Here are the sequence of steps.
/* Generating A & B matrices by copying the global stiffness matrix */
ierr = MatConvert(global->Amat, MATSAME, MAT_INITIAL_MATRIX, &A);CHKERRQ(ierr);
ierr = MatConvert(global->Amat, MATSAME, MAT_INITIAL_MATRIX, &B);CHKERRQ(ierr);
/* Zero all the entries of the A matrix */
ierr = MatZeroEntries(A);CHKERRQ(ierr);
/* Fill in the diagonal entry and one off-diagonal entry of A matrix */
for(i = 0; i < bc.numPeriodic; i++){
if(bc.periodNode[i] > -1){
for(j = 0; j < dofn; j++){
row = local2Petsc[bc.periodNode[i]*dofn+j];
col = bc.periodPair[i]*dofn+j;
/* The diagonal Entry */
ierr =MatSetValue(A,row,row,1.0,ADD_VALUES);CHKERRQ(ierr);
/* The entry for periodic node */
ierr =MatSetValue(A,row,col,1.0,ADD_VALUES);CHKERRQ(ierr);
}
}
}
/* Assemble the new matrices */
ierr = MatAssemblyBegin(A, MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);
ierr = MatAssemblyEnd(A, MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);
ierr = MatAssemblyBegin(B, MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);
ierr = MatAssemblyEnd(B, MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);
/* Perform matrix multiplication of A and B(Amat) to add rows of periodic
* nodes. Save the new matrix in Amat */
ierr = MatMatMult(A,B,MAT_REUSE_MATRIX,PETSC_DEFAULT,&global->Amat);CHKERRQ(ierr);
ierr = MatDestroy(A);CHKERRQ(ierr);
ierr = MatDestroy(B);CHKERRQ(ierr);
Thank you
Irfan
----- Original Message -----
From: "Matthew Knepley" <knepley at gmail.com>
To: "PETSc users list" <petsc-users at mcs.anl.gov>
Sent: Monday, May 10, 2010 12:26:14 PM GMT -05:00 US/Canada Eastern
Subject: Re: [petsc-users] MAT_REUSE_MATRIX
On Mon, May 10, 2010 at 12:07 PM, < irfan.khan at gatech.edu > wrote:
Hi Petsc Team,
When using the subroutine MatMatMult(Mat A,Mat B,PetscReal fill,Mat *C) with option MAT_REUSE_MATRIX, Can the C matrix be any one of A or B?
I do not think that is safe. I believe C needs to be another matrix, but it can be
reused for successive multiplies.
Matt
Thank you
Irfan
----- Original Message -----
From: "Matthew Knepley" < knepley at gmail.com >
To: "PETSc users list" < petsc-users at mcs.anl.gov >
Sent: Friday, May 7, 2010 4:03:42 PM GMT -05:00 US/Canada Eastern
Subject: Re: [petsc-users] Adding MatAij rows
On Fri, May 7, 2010 at 3:57 PM, < irfan.khan at gatech.edu > wrote:
Petsc Team,
Is there a function that can be used to add two rows and put the results into a third row of the same parallel matrix (MPIAIJ)? i.e
A[k][l] = A[i][l] + A[j][l]
No, since it would entail messing with the nonzero structure. You could easily
use a second matrix to get this effect from subsequent MatMult() calls.
Matt
Thank you
Irfan
--
PhD Candidate
G.W. Woodruff School of Mechanical Engineering
Georgia Institute of Technology
Atlanta, GA (30332)
--
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
--
PhD Candidate
G.W. Woodruff School of Mechanical Engineering
Georgia Institute of Technology
Atlanta, GA (30332)
--
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
--
PhD Candidate
G.W. Woodruff School of Mechanical Engineering
Georgia Institute of Technology
Atlanta, GA (30332)
More information about the petsc-users
mailing list