Commits

BarryFSmith committed 231ec94

fix for ISToGeneral_Block for a block size of 1

Reported-by: Lisandro Dalcin <dalcinl@gmail.com>

  • Participants
  • Parent commits a6c8f22

Comments (0)

Files changed (1)

File src/vec/is/is/impls/block/block.c

   PetscFunctionReturn(0);
 }
 
+#undef __FUNCT__
+#define __FUNCT__ "ISToGeneral_Block"
+static PetscErrorCode ISToGeneral_Block(IS inis)
+{
+  IS_Block       *sub   = (IS_Block*)inis->data;
+  PetscInt       bs,n;
+  const PetscInt *idx;
+  PetscErrorCode ierr;
+
+  PetscFunctionBegin;
+  ierr = ISGetBlockSize(inis,&bs);CHKERRQ(ierr);
+  ierr = ISGetLocalSize(inis,&n);CHKERRQ(ierr);
+  ierr = ISGetIndices(inis,&idx);CHKERRQ(ierr);
+  if (bs == 1) {
+    PetscCopyMode mode = sub->borrowed_indices ? PETSC_USE_POINTER : PETSC_OWN_POINTER;
+    sub->borrowed_indices = PETSC_TRUE; /* prevent deallocation when changing the subtype*/
+    ierr = ISSetType(inis,ISGENERAL);CHKERRQ(ierr);
+    ierr = ISGeneralSetIndices(inis,n,idx,mode);CHKERRQ(ierr);
+  } else {
+    ierr = ISSetType(inis,ISGENERAL);CHKERRQ(ierr);
+    ierr = ISGeneralSetIndices(inis,n,idx,PETSC_OWN_POINTER);CHKERRQ(ierr);
+  }
+  PetscFunctionReturn(0);
+}
+
 
 static struct _ISOps myops = { ISGetSize_Block,
                                ISGetLocalSize_Block,
                                ISLoad_Default,
                                ISIdentity_Block,
                                ISCopy_Block,
-                               0,
+                               ISToGeneral_Block,
                                ISOnComm_Block,
                                ISSetBlockSize_Block,
                                0};
 }
 
 #undef __FUNCT__
-#define __FUNCT__ "ISToGeneral_Block"
-PetscErrorCode  ISToGeneral_Block(IS inis)
-{
-  PetscErrorCode ierr;
-  const PetscInt *idx;
-  PetscInt       n;
-
-  PetscFunctionBegin;
-  ierr = ISGetLocalSize(inis,&n);CHKERRQ(ierr);
-  ierr = ISGetIndices(inis,&idx);CHKERRQ(ierr);
-  ierr = ISSetType(inis,ISGENERAL);CHKERRQ(ierr);
-  ierr = ISGeneralSetIndices(inis,n,idx,PETSC_OWN_POINTER);CHKERRQ(ierr);
-  PetscFunctionReturn(0);
-}
-
-#undef __FUNCT__
 #define __FUNCT__ "ISCreate_Block"
 PETSC_EXTERN PetscErrorCode ISCreate_Block(IS is)
 {