Commits

Hong Zhang committed 17803ae

bugfix for seqsbaij with USESHORT - when matrix data structure is changed, previous jshort must be replaced

Hg-commit: cdeadfe75d9385ee75e1b3b6997e8a07e011691d

  • Participants
  • Parent commits 2e14765

Comments (0)

Files changed (1)

src/mat/impls/sbaij/seq/sbaij.c

   a->idiagvalid = PETSC_FALSE;
 
   if (A->cmap->n < 65536 && A->cmap->bs == 1) {
-    if (!a->jshort) {
-      ierr = PetscMalloc(a->i[A->rmap->n]*sizeof(unsigned short),&a->jshort);CHKERRQ(ierr);
-      ierr = PetscLogObjectMemory(A,a->i[A->rmap->n]*sizeof(unsigned short));CHKERRQ(ierr);
-      for (i=0; i<a->i[A->rmap->n]; i++) a->jshort[i] = a->j[i];
-      A->ops->mult  = MatMult_SeqSBAIJ_1_ushort;
-      A->ops->sor = MatSOR_SeqSBAIJ_ushort;
-      a->free_jshort = PETSC_TRUE;
+    if (a->jshort){ 
+      /* when matrix data structure is changed, previous jshort must be replaced */
+      ierr = PetscFree(a->jshort);CHKERRQ(ierr);
     }
+    ierr = PetscMalloc(a->i[A->rmap->n]*sizeof(unsigned short),&a->jshort);CHKERRQ(ierr);
+    ierr = PetscLogObjectMemory(A,a->i[A->rmap->n]*sizeof(unsigned short));CHKERRQ(ierr);
+    for (i=0; i<a->i[A->rmap->n]; i++) a->jshort[i] = a->j[i];
+    A->ops->mult  = MatMult_SeqSBAIJ_1_ushort;
+    A->ops->sor = MatSOR_SeqSBAIJ_ushort;
+    a->free_jshort = PETSC_TRUE;
   }
   PetscFunctionReturn(0);
 }