Skip to content

Commit f6b81de

Browse files
committed
Better handling of MatShell with no domain decomposition
1 parent 56a41c2 commit f6b81de

1 file changed

Lines changed: 26 additions & 17 deletions

File tree

plugin/mpi/PETSc-code.hpp

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3946,7 +3946,7 @@ namespace PETSc {
39463946
DistributedCSR< HpddmType >* ptC = GetAny< DistributedCSR< HpddmType >* >((*C)(stack));
39473947
Matrice_Creuse< upscaled_type<PetscScalar> >* ptK =
39483948
(c == 0 || c == 3 ? GetAny< Matrice_Creuse< upscaled_type<PetscScalar> >* >((*K)(stack)) : nullptr);
3949-
if (ptB->_A && ptC->_A) {
3949+
if (ptB->_petsc && ptC->_petsc) {
39503950
ptA->_first = ptB->_first;
39513951
ptA->_last = ptB->_last;
39523952
ptA->_cfirst = ptC->_first;
@@ -3963,7 +3963,7 @@ namespace PETSc {
39633963
PetscInt* ja = nullptr;
39643964
PetscScalar* a = nullptr;
39653965
bool free = true;
3966-
if (ptK->A) {
3966+
if (ptK && ptK->A) {
39673967
MatriceMorse< upscaled_type<PetscScalar> >* mA = static_cast< MatriceMorse< upscaled_type<PetscScalar> >* >(&(*ptK->A));
39683968
ff_HPDDM_MatrixCSR< PetscScalar > dA(mA);
39693969
ptA->_num = new PetscInt[mA->n + (ptC->_A && ptC->_A->getMatrix() ? ptC->_A->getMatrix()->HPDDM_m : mA->m)];
@@ -4013,24 +4013,33 @@ namespace PETSc {
40134013
MatShellSetOperation(ptA->_petsc, MATOP_DESTROY, (void (*)(void))ShellDestroy< LinearSolver< Dmat > >);
40144014
}
40154015
MatSetUp(ptA->_petsc);
4016-
MatSetOption(ptA->_petsc, MAT_NO_OFF_PROC_ENTRIES, PETSC_TRUE);
4017-
if(ptB->_A->getMatrix() && ptC->_A->getMatrix()) {
4018-
ptA->_num = new PetscInt[ptB->_A->getMatrix( )->HPDDM_n + ptC->_A->getMatrix( )->HPDDM_m];
4019-
ptA->_cnum = ptA->_num + ptB->_A->getMatrix( )->HPDDM_n;
4020-
std::copy_n(ptB->_num, ptB->_A->getMatrix( )->HPDDM_n, ptA->_num);
4021-
std::copy_n(ptC->_num, ptC->_A->getMatrix( )->HPDDM_m, ptA->_cnum);
4016+
if(ptB->_A && ptC->_A) {
4017+
MatSetOption(ptA->_petsc, MAT_NO_OFF_PROC_ENTRIES, PETSC_TRUE);
4018+
if(ptB->_A->getMatrix() && ptC->_A->getMatrix()) {
4019+
ptA->_num = new PetscInt[ptB->_A->getMatrix( )->HPDDM_n + ptC->_A->getMatrix( )->HPDDM_m];
4020+
ptA->_cnum = ptA->_num + ptB->_A->getMatrix( )->HPDDM_n;
4021+
std::copy_n(ptB->_num, ptB->_A->getMatrix( )->HPDDM_n, ptA->_num);
4022+
std::copy_n(ptC->_num, ptC->_A->getMatrix( )->HPDDM_m, ptA->_cnum);
4023+
} else {
4024+
ptA->_num = new PetscInt[ptB->_A->getDof() + ptC->_A->getDof()];
4025+
ptA->_cnum = ptA->_num + ptB->_A->getDof();
4026+
std::copy_n(ptB->_num, ptB->_A->getDof(), ptA->_num);
4027+
std::copy_n(ptC->_num, ptC->_A->getDof(), ptA->_cnum);
4028+
}
40224029
} else {
4023-
ptA->_num = new PetscInt[ptB->_A->getDof() + ptC->_A->getDof()];
4024-
ptA->_cnum = ptA->_num + ptB->_A->getDof();
4025-
std::copy_n(ptB->_num, ptB->_A->getDof(), ptA->_num);
4026-
std::copy_n(ptC->_num, ptC->_A->getDof(), ptA->_cnum);
4030+
ptA->_num = new PetscInt[ptB->_last - ptB->_first + ptC->_last - ptC->_first];
4031+
ptA->_cnum = ptA->_num + ptB->_last - ptB->_first;
4032+
std::copy_n(ptB->_num, ptB->_last - ptB->_first, ptA->_num);
4033+
std::copy_n(ptC->_num, ptC->_last - ptC->_first, ptA->_cnum);
40274034
}
40284035
}
4029-
ptA->_exchange = new HPDDM::template Subdomain< PetscScalar >*[2];
4030-
ptA->_exchange[0] = new HPDDM::template Subdomain< PetscScalar >(*ptB->_A);
4031-
ptA->_exchange[0]->setBuffer( );
4032-
ptA->_exchange[1] = new HPDDM::template Subdomain< PetscScalar >(*ptC->_A);
4033-
ptA->_exchange[1]->setBuffer( );
4036+
if(ptB->_A && ptC->_A) {
4037+
ptA->_exchange = new HPDDM::template Subdomain< PetscScalar >*[2];
4038+
ptA->_exchange[0] = new HPDDM::template Subdomain< PetscScalar >(*ptB->_A);
4039+
ptA->_exchange[0]->setBuffer( );
4040+
ptA->_exchange[1] = new HPDDM::template Subdomain< PetscScalar >(*ptC->_A);
4041+
ptA->_exchange[1]->setBuffer( );
4042+
} else ptA->_exchange = nullptr;
40344043
}
40354044
if (c == 0 && nargs[0] && GetAny< bool >((*nargs[0])(stack))) ptK->destroy( );
40364045
if (c != 3)

0 commit comments

Comments
 (0)