Hi All,

A matrix is created with the right preallocation, and then MatAssembly is
called. The preallocation info will be removed. We insert any values then,
and will encounter an malloc error.

My question is that we was intending to design like this way? Attached
simple example demonstrates what I am talking about.



Fande,
/*
 * ex4.c
 *
 *  Created on: Sep 25, 2017
 *      Author: Fande Kong
 */

static char help[] = "MatAssemblyBegin destroy preallocation info.\n";

#include "petscmat.h"

int main(int argc,char **argv)
{
  Mat             A;
  MPI_Comm        comm;
  PetscErrorCode  ierr;


  ierr = PetscInitialize(&argc,&argv,0,help);if (ierr) return ierr;
  comm = MPI_COMM_WORLD;
  ierr = MatCreateSeqAIJ(comm,10,10,4,NULL,&A);CHKERRQ(ierr);

  /*Assembly matrix before we actually do anything */
  ierr = MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);
  ierr = MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);

  /* Insert a value after the matrix is assembled.
   * Causes a malloc error because the preallocation is destroyed
   * */
  ierr = MatSetValue(A,6,6,1.0,INSERT_VALUES);CHKERRQ(ierr);

  ierr = MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);
  ierr = MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);
  ierr = MatDestroy(&A);CHKERRQ(ierr);
  ierr = PetscFinalize();
}


Reply via email to