diff --git a/src/mat/impls/aij/seq/seqcusparse/aijcusparse.cu b/src/mat/impls/aij/seq/seqcusparse/aijcusparse.cu index 0bbb96a..ffee6fd 100644 --- a/src/mat/impls/aij/seq/seqcusparse/aijcusparse.cu +++ b/src/mat/impls/aij/seq/seqcusparse/aijcusparse.cu @@ -37,6 +37,7 @@ static PetscErrorCode MatMultTransposeAdd_SeqAIJCUSPARSE(Mat,Vec,Vec,Vec); static PetscErrorCode CsrMatrix_Destroy(CsrMatrix**); static PetscErrorCode MatSeqAIJCUSPARSEMultStruct_Destroy(Mat_SeqAIJCUSPARSETriFactorStruct**); static PetscErrorCode MatSeqAIJCUSPARSEMultStruct_Destroy(Mat_SeqAIJCUSPARSEMultStruct**,MatCUSPARSEStorageFormat); +static PetscErrorCode MatSeqAIJCUSPARSETriFactors_Reset(Mat_SeqAIJCUSPARSETriFactors**); static PetscErrorCode MatSeqAIJCUSPARSETriFactors_Destroy(Mat_SeqAIJCUSPARSETriFactors**); static PetscErrorCode MatSeqAIJCUSPARSE_Destroy(Mat_SeqAIJCUSPARSE**); @@ -449,6 +450,7 @@ static PetscErrorCode MatSeqAIJCUSPARSEILUAnalysisAndCopyToGPU(Mat A) PetscInt n = A->rmap->n; PetscFunctionBegin; + ierr = MatSeqAIJCUSPARSETriFactors_Reset(&cusparseTriFactors);CHKERRQ(ierr); ierr = MatSeqAIJCUSPARSEBuildILULowerTriMatrix(A);CHKERRQ(ierr); ierr = MatSeqAIJCUSPARSEBuildILUUpperTriMatrix(A);CHKERRQ(ierr); @@ -644,6 +646,7 @@ static PetscErrorCode MatSeqAIJCUSPARSEICCAnalysisAndCopyToGPU(Mat A) PetscInt n = A->rmap->n; PetscFunctionBegin; + ierr = MatSeqAIJCUSPARSETriFactors_Reset(&cusparseTriFactors);CHKERRQ(ierr); ierr = MatSeqAIJCUSPARSEBuildICCTriMatrices(A);CHKERRQ(ierr); cusparseTriFactors->workVector = new THRUSTARRAY(n); cusparseTriFactors->nnz=(a->nz-n)*2 + n; @@ -678,6 +681,7 @@ static PetscErrorCode MatLUFactorNumeric_SeqAIJCUSPARSE(Mat B,Mat A,const MatFac PetscFunctionBegin; ierr = MatLUFactorNumeric_SeqAIJ(B,A,info);CHKERRQ(ierr); + B->offloadmask = PETSC_OFFLOAD_CPU; /* determine which version of MatSolve needs to be used. */ ierr = ISIdentity(isrow,&row_identity);CHKERRQ(ierr); ierr = ISIdentity(iscol,&col_identity);CHKERRQ(ierr); @@ -707,7 +711,7 @@ static PetscErrorCode MatCholeskyFactorNumeric_SeqAIJCUSPARSE(Mat B,Mat A,const PetscFunctionBegin; ierr = MatCholeskyFactorNumeric_SeqAIJ(B,A,info);CHKERRQ(ierr); - + B->offloadmask = PETSC_OFFLOAD_CPU; /* determine which version of MatSolve needs to be used. */ ierr = ISIdentity(ip,&perm_identity);CHKERRQ(ierr); if (perm_identity) { @@ -1948,11 +1952,8 @@ static PetscErrorCode MatSeqAIJCUSPARSEMultStruct_Destroy(Mat_SeqAIJCUSPARSEMult PetscFunctionReturn(0); } -static PetscErrorCode MatSeqAIJCUSPARSETriFactors_Destroy(Mat_SeqAIJCUSPARSETriFactors** trifactors) +static PetscErrorCode MatSeqAIJCUSPARSETriFactors_Reset(Mat_SeqAIJCUSPARSETriFactors** trifactors) { - cusparseHandle_t handle; - cusparseStatus_t stat; - PetscFunctionBegin; if (*trifactors) { MatSeqAIJCUSPARSEMultStruct_Destroy(&(*trifactors)->loTriFactorPtr); @@ -1962,6 +1963,21 @@ static PetscErrorCode MatSeqAIJCUSPARSETriFactors_Destroy(Mat_SeqAIJCUSPARSETriF delete (*trifactors)->rpermIndices; delete (*trifactors)->cpermIndices; delete (*trifactors)->workVector; + (*trifactors)->rpermIndices = 0; + (*trifactors)->cpermIndices = 0; + (*trifactors)->workVector = 0; + } + PetscFunctionReturn(0); +} + +static PetscErrorCode MatSeqAIJCUSPARSETriFactors_Destroy(Mat_SeqAIJCUSPARSETriFactors** trifactors) +{ + cusparseHandle_t handle; + cusparseStatus_t stat; + + PetscFunctionBegin; + if (*trifactors) { + MatSeqAIJCUSPARSETriFactors_Reset(trifactors); if (handle = (*trifactors)->handle) { stat = cusparseDestroy(handle);CHKERRCUSPARSE(stat); }