[petsc-users] 3-dimension to matrix

Jed Brown jedbrown at mcs.anl.gov
Fri May 17 16:05:12 CDT 2013


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