Skip to content

Commit e21a086

Browse files
committed
Fill with zero one-by-one block when needed
1 parent 5890a4b commit e21a086

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

plugin/mpi/PETSc-code.hpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2097,6 +2097,27 @@ namespace PETSc {
20972097
}
20982098
}
20992099
}
2100+
auto maybeCreateDense = [&](int i, int j) {
2101+
int t = t_M[i][j];
2102+
if ((t != 0 && t != 7) || a[i * M + j]) return;
2103+
bool rowHasMat = false, colHasMat = false;
2104+
for (int k = 0; k < M && !rowHasMat; ++k)
2105+
rowHasMat = static_cast<bool>(a[i * M + k]);
2106+
for (int k = 0; k < N && !colHasMat; ++k)
2107+
colHasMat = static_cast<bool>(a[k * M + j]);
2108+
if (!rowHasMat || !colHasMat) {
2109+
MatCreateDense(comm1 != MPI_COMM_NULL ? comm1 : PETSC_COMM_WORLD,
2110+
PETSC_DECIDE, PETSC_DECIDE,
2111+
1, 1, NULL,
2112+
a + i * M + j);
2113+
}
2114+
};
2115+
for (int i = std::min(N, M) - 1; i >= 0; --i)
2116+
maybeCreateDense(i, i);
2117+
for (int i = N - 1; i >= 0; --i)
2118+
for (int j = M - 1; j >= 0; --j)
2119+
if (i != j)
2120+
maybeCreateDense(i, j);
21002121
Result sparse_mat = GetAny< Result >((*emat)(s));
21012122
if (sparse_mat->_petsc) sparse_mat->dtor( );
21022123
MatCreateNest(comm1 != MPI_COMM_NULL ? comm1 : PETSC_COMM_WORLD, N, NULL, M, NULL, a, &sparse_mat->_petsc);

0 commit comments

Comments
 (0)