Shouldn't PetscCheckSameType compare type_name instead of type? #define PetscCheckSameType(a,arga,b,argb) \ if (((PetscObject)a)->type != ((PetscObject)b)->type) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_ARG_NOTSAMETYPE,"Objects not of same type: Argument # %d and %d",arga,argb);