Commits

BarryFSmith committed a825bcd

MatHeaderCopy() is very very dangerous; it did not destroy the attached viewer 2 hours debugging

Comments (0)

Files changed (3)

src/mat/utils/gcreate.c

   PetscCheckSameComm(A,1,C,2);
   if (((PetscObject)C)->refct != 1) SETERRQ1(PetscObjectComm((PetscObject)C),PETSC_ERR_ARG_WRONGSTATE,"Object C has refct %D > 1, would leave hanging reference",((PetscObject)C)->refct);
 
+  ierr = PetscViewerDestroy(&A->viewonassembly);CHKERRQ(ierr);
   /* free all the interior data structures from mat */
   ierr = (*A->ops->destroy)(A);CHKERRQ(ierr);
   ierr = PetscHeaderDestroy_Private((PetscObject)A);CHKERRQ(ierr);

src/sys/objects/destroy.c

 {
   PetscFunctionBegin;
   PetscValidHeader(obj,1);
-  if (PetscObjectRegisterDestroy_Count < MAXREGDESOBJS) 
-    PetscObjectRegisterDestroy_Objects[PetscObjectRegisterDestroy_Count++] = obj;
+  if (PetscObjectRegisterDestroy_Count < MAXREGDESOBJS) PetscObjectRegisterDestroy_Objects[PetscObjectRegisterDestroy_Count++] = obj;
   else SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_PLIB,"No more room in array, limit %d \n recompile src/sys/objects/destroy.c with larger value for MAXREGDESOBJS\n",MAXREGDESOBJS);
   PetscFunctionReturn(0);
 }

src/ts/examples/tutorials/advection-diffusion-reaction/ex10.c

 
 /*    Hard wire the number of cluster sizes for He, V, and I, and He-V */
 #define  NHe          9
-#define  NV           50
+#define  NV           10   /* 50 */
 #define  NI           2
-#define  MHeV         50   /* maximum V size in He-V */
+#define  MHeV         10  /* 50 */  /* maximum V size in He-V */
 PetscInt NHeV[MHeV+1];     /* maximum He size in an He-V with given V */
-#define  MNHeV        6778
+#define  MNHeV        451  /* 6778 */
 #define  DOF          (NHe + NV + NI + MNHeV)
 
 /*
     ierr = MatAssemblyEnd(*J,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);
     ierr = MatSetOption(*J,MAT_NEW_NONZERO_LOCATIONS,PETSC_FALSE);CHKERRQ(ierr);
     ierr = MatStoreValues(*J);CHKERRQ(ierr);
+    MatSetFromOptions(*J);
     initialized = PETSC_TRUE;
   } else {
     ierr = MatRetrieveValues(*J);CHKERRQ(ierr);
     ierr = MatAssemblyBegin(*A,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);
     ierr = MatAssemblyEnd(*A,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);
   }
-  MatSetFromOptions(*J);
   PetscFunctionReturn(0);
 }
 
     ierr = PetscStrchr(buff,'#',&sharp);CHKERRQ(ierr);
     if (!sharp) {
       sscanf(buff,"%d %d %d %s %s %s %s",&He,&V,&I,Hebindstr,Vbindstr,Ibindstr,trapbindstr);
-      if (lc++ > DOF) SETERRQ4(PETSC_COMM_WORLD,PETSC_ERR_SUP,"Recompile with correct NHe %d NV %d NI %d MNHeV %",NHe,NV,NI,MNHeV);
       Hebind = strtod(Hebindstr,NULL);
       Vbind = strtod(Vbindstr,NULL);
       Ibind = strtod(Ibindstr,NULL);
       trapbind = strtod(trapbindstr,NULL);
-      if (He > NHe && V == 0 && I == 0) SETERRQ2(PETSC_COMM_WORLD,PETSC_ERR_SUP,"Recompile with correct NHe %d %d",He,NHe);
-      if (He == 0  && V > NV && I == 0) SETERRQ2(PETSC_COMM_WORLD,PETSC_ERR_SUP,"Recompile with correct V %d %d",V,NV);
-      if (He == 0  && V == 0 && I > NI) SETERRQ2(PETSC_COMM_WORLD,PETSC_ERR_SUP,"Recompile with correct NI %d %d",I,NI);
-      if (He > 0 && V > 0) {  /* assumes the He are sorted in increasing order */
-        NHeV[V] = He;
+      if (V <= NV) {
+        if (He > NHe && V == 0 && I == 0) SETERRQ2(PETSC_COMM_WORLD,PETSC_ERR_SUP,"Recompile with correct NHe %d %d",He,NHe);
+        if (He == 0  && V > NV && I == 0) SETERRQ2(PETSC_COMM_WORLD,PETSC_ERR_SUP,"Recompile with correct V %d %d",V,NV);
+        if (He == 0  && V == 0 && I > NI) SETERRQ2(PETSC_COMM_WORLD,PETSC_ERR_SUP,"Recompile with correct NI %d %d",I,NI);
+        if (lc++ > DOF) SETERRQ4(PETSC_COMM_WORLD,PETSC_ERR_SUP,"Recompile with correct NHe %d NV %d NI %d MNHeV %",NHe,NV,NI,MNHeV);
+        if (He > 0 && V > 0) {  /* assumes the He are sorted in increasing order */
+          NHeV[V] = He;
+        }
       }
     }
     ierr = PetscSynchronizedFGets(comm,fp,256,buff);CHKERRQ(ierr);