Skip to content

Commit 6c5cb1a

Browse files
committed
Merge branch 'barry/2025-10-18/optimize-matzeroentries-seqaijcusparse' into 'main'
MatZeroEntries_SeqAIJCUSPARSE() was zeroing both the CPU and GPU array.... See merge request petsc/petsc!8796
2 parents 4b0a549 + f5d0f30 commit 6c5cb1a

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/mat/impls/aij/seq/seqcusparse/aijcusparse.cu

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3924,16 +3924,16 @@ static PetscErrorCode MatScale_SeqAIJCUSPARSE(Mat Y, PetscScalar a)
39243924

39253925
static PetscErrorCode MatZeroEntries_SeqAIJCUSPARSE(Mat A)
39263926
{
3927-
PetscBool both = PETSC_FALSE;
3928-
Mat_SeqAIJ *a = (Mat_SeqAIJ *)A->data;
3927+
PetscBool gpu = PETSC_FALSE;
3928+
Mat_SeqAIJ *a = (Mat_SeqAIJ *)A->data;
39293929

39303930
PetscFunctionBegin;
39313931
if (A->factortype == MAT_FACTOR_NONE) {
39323932
Mat_SeqAIJCUSPARSE *spptr = (Mat_SeqAIJCUSPARSE *)A->spptr;
39333933
if (spptr->mat) {
39343934
CsrMatrix *matrix = (CsrMatrix *)spptr->mat->mat;
39353935
if (matrix->values) {
3936-
both = PETSC_TRUE;
3936+
gpu = PETSC_TRUE;
39373937
thrust::fill(thrust::device, matrix->values->begin(), matrix->values->end(), 0.);
39383938
}
39393939
}
@@ -3942,10 +3942,12 @@ static PetscErrorCode MatZeroEntries_SeqAIJCUSPARSE(Mat A)
39423942
if (matrix->values) thrust::fill(thrust::device, matrix->values->begin(), matrix->values->end(), 0.);
39433943
}
39443944
}
3945-
PetscCall(PetscArrayzero(a->a, a->i[A->rmap->n]));
3945+
if (gpu) A->offloadmask = PETSC_OFFLOAD_GPU;
3946+
else {
3947+
PetscCall(PetscArrayzero(a->a, a->i[A->rmap->n]));
3948+
A->offloadmask = PETSC_OFFLOAD_CPU;
3949+
}
39463950
PetscCall(MatSeqAIJInvalidateDiagonal(A));
3947-
if (both) A->offloadmask = PETSC_OFFLOAD_BOTH;
3948-
else A->offloadmask = PETSC_OFFLOAD_CPU;
39493951
PetscFunctionReturn(PETSC_SUCCESS);
39503952
}
39513953

0 commit comments

Comments
 (0)