[petsc-users] 3-dimension to matrix

Joon hee Choi choi240 at purdue.edu
Fri May 17 21:28:59 CDT 2013


Thank you for your reply. Yes. I think so now. If I have slow result in spite of applying MatCreateAIJ, then I reply it again. Thank you very much again.

Sincerely,
Joon

----- Original Message -----
From: "Jed Brown" <jedbrown at mcs.anl.gov>
To: "Peter Lichtner" <peter.lichtner at gmail.com>, petsc-users at mcs.anl.gov
Sent: Friday, May 17, 2013 5:05:12 PM
Subject: Re: [petsc-users] 3-dimension to matrix

Peter Lichtner <peter.lichtner at gmail.com> writes:

> I found a similar problem solving Laplace's equation: using MatCreate
> took forever, whereas using MatCreateAIJ instead the time for
> MatSetValues was essentially negligible. I set up MatCreate with a
> call to MatSetSizes.

This is almost certainly caused by bad preallocation information, or
from that information not being used.  The complete implementation of
MatCreateAIJ is:

PetscErrorCode  MatCreateAIJ(MPI_Comm comm,PetscInt m,PetscInt n,PetscInt M,PetscInt N,PetscInt d_nz,const PetscInt d_nnz[],PetscInt o_nz,const PetscInt o_nnz[],Mat *A)
{
  PetscErrorCode ierr;
  PetscMPIInt    size;

  PetscFunctionBegin;
  ierr = MatCreate(comm,A);CHKERRQ(ierr);
  ierr = MatSetSizes(*A,m,n,M,N);CHKERRQ(ierr);
  ierr = MPI_Comm_size(comm,&size);CHKERRQ(ierr);
  if (size > 1) {
    ierr = MatSetType(*A,MATMPIAIJ);CHKERRQ(ierr);
    ierr = MatMPIAIJSetPreallocation(*A,d_nz,d_nnz,o_nz,o_nnz);CHKERRQ(ierr);
  } else {
    ierr = MatSetType(*A,MATSEQAIJ);CHKERRQ(ierr);
    ierr = MatSeqAIJSetPreallocation(*A,d_nz,d_nnz);CHKERRQ(ierr);
  }
  PetscFunctionReturn(0);
}



More information about the petsc-users mailing list