13bf14a46SMatthew Knepley /* 23bf14a46SMatthew Knepley Provides an interface to the PaStiX sparse solver 33bf14a46SMatthew Knepley */ 4c6db04a5SJed Brown #include <../src/mat/impls/aij/seq/aij.h> 5c6db04a5SJed Brown #include <../src/mat/impls/aij/mpi/mpiaij.h> 6c6db04a5SJed Brown #include <../src/mat/impls/sbaij/seq/sbaij.h> 7c6db04a5SJed Brown #include <../src/mat/impls/sbaij/mpi/mpisbaij.h> 83bf14a46SMatthew Knepley 95ec454cfSSatish Balay #if defined(PETSC_USE_COMPLEX) && defined(__cplusplus) 105ec454cfSSatish Balay #define _H_COMPLEX 115ec454cfSSatish Balay #endif 125ec454cfSSatish Balay 133bf14a46SMatthew Knepley EXTERN_C_BEGIN 14c6db04a5SJed Brown #include <pastix.h> 153bf14a46SMatthew Knepley EXTERN_C_END 163bf14a46SMatthew Knepley 17519f805aSKarl Rupp #if defined(PETSC_USE_COMPLEX) 18519f805aSKarl Rupp #if defined(PETSC_USE_REAL_SINGLE) 195ec454cfSSatish Balay #define PASTIX_CALL c_pastix 205ec454cfSSatish Balay #define PASTIX_CHECKMATRIX c_pastix_checkMatrix 215ec454cfSSatish Balay #define PastixScalar COMPLEX 225ec454cfSSatish Balay #else 235ec454cfSSatish Balay #define PASTIX_CALL z_pastix 245ec454cfSSatish Balay #define PASTIX_CHECKMATRIX z_pastix_checkMatrix 255ec454cfSSatish Balay #define PastixScalar DCOMPLEX 265ec454cfSSatish Balay #endif 27d41469e0Sxavier lacoste 28d41469e0Sxavier lacoste #else /* PETSC_USE_COMPLEX */ 29d41469e0Sxavier lacoste 30519f805aSKarl Rupp #if defined(PETSC_USE_REAL_SINGLE) 315ec454cfSSatish Balay #define PASTIX_CALL s_pastix 325ec454cfSSatish Balay #define PASTIX_CHECKMATRIX s_pastix_checkMatrix 335ec454cfSSatish Balay #define PastixScalar float 345ec454cfSSatish Balay #else 355ec454cfSSatish Balay #define PASTIX_CALL d_pastix 365ec454cfSSatish Balay #define PASTIX_CHECKMATRIX d_pastix_checkMatrix 375ec454cfSSatish Balay #define PastixScalar double 385ec454cfSSatish Balay #endif 39d41469e0Sxavier lacoste 40d41469e0Sxavier lacoste #endif /* PETSC_USE_COMPLEX */ 41d41469e0Sxavier lacoste 423bf14a46SMatthew Knepley typedef struct Mat_Pastix_ { 433bf14a46SMatthew Knepley pastix_data_t *pastix_data; /* Pastix data storage structure */ 443bf14a46SMatthew Knepley MatStructure matstruc; 453bf14a46SMatthew Knepley PetscInt n; /* Number of columns in the matrix */ 463bf14a46SMatthew Knepley PetscInt *colptr; /* Index of first element of each column in row and val */ 473bf14a46SMatthew Knepley PetscInt *row; /* Row of each element of the matrix */ 483bf14a46SMatthew Knepley PetscScalar *val; /* Value of each element of the matrix */ 493bf14a46SMatthew Knepley PetscInt *perm; /* Permutation tabular */ 503bf14a46SMatthew Knepley PetscInt *invp; /* Reverse permutation tabular */ 513bf14a46SMatthew Knepley PetscScalar *rhs; /* Rhight-hand-side member */ 523bf14a46SMatthew Knepley PetscInt rhsnbr; /* Rhight-hand-side number (must be 1) */ 533bf14a46SMatthew Knepley PetscInt iparm[64]; /* Integer parameters */ 543bf14a46SMatthew Knepley double dparm[64]; /* Floating point parameters */ 553bf14a46SMatthew Knepley MPI_Comm pastix_comm; /* PaStiX MPI communicator */ 563bf14a46SMatthew Knepley PetscMPIInt commRank; /* MPI rank */ 573bf14a46SMatthew Knepley PetscMPIInt commSize; /* MPI communicator size */ 58ace3abfcSBarry Smith PetscBool CleanUpPastix; /* Boolean indicating if we call PaStiX clean step */ 593bf14a46SMatthew Knepley VecScatter scat_rhs; 603bf14a46SMatthew Knepley VecScatter scat_sol; 61f31ce8a6SBarry Smith Vec b_seq; 62ace3abfcSBarry Smith PetscBool isAIJ; 63bf0cc555SLisandro Dalcin PetscErrorCode (*Destroy)(Mat); 643bf14a46SMatthew Knepley } Mat_Pastix; 653bf14a46SMatthew Knepley 6609573ac7SBarry Smith extern PetscErrorCode MatDuplicate_Pastix(Mat,MatDuplicateOption,Mat*); 673bf14a46SMatthew Knepley 68eb1f6c34SBarry Smith #undef __FUNCT__ 69eb1f6c34SBarry Smith #define __FUNCT__ "MatConvertToCSC" 703bf14a46SMatthew Knepley /* 713bf14a46SMatthew Knepley convert Petsc seqaij matrix to CSC: colptr[n], row[nz], val[nz] 723bf14a46SMatthew Knepley 733bf14a46SMatthew Knepley input: 743bf14a46SMatthew Knepley A - matrix in seqaij or mpisbaij (bs=1) format 753bf14a46SMatthew Knepley valOnly - FALSE: spaces are allocated and values are set for the CSC 763bf14a46SMatthew Knepley TRUE: Only fill values 773bf14a46SMatthew Knepley output: 783bf14a46SMatthew Knepley n - Size of the matrix 793bf14a46SMatthew Knepley colptr - Index of first element of each column in row and val 803bf14a46SMatthew Knepley row - Row of each element of the matrix 813bf14a46SMatthew Knepley values - Value of each element of the matrix 823bf14a46SMatthew Knepley */ 83ace3abfcSBarry Smith PetscErrorCode MatConvertToCSC(Mat A,PetscBool valOnly,PetscInt *n,PetscInt **colptr,PetscInt **row,PetscScalar **values) 8441c8de11SBarry Smith { 853bf14a46SMatthew Knepley Mat_SeqAIJ *aa = (Mat_SeqAIJ*)A->data; 863bf14a46SMatthew Knepley PetscInt *rowptr = aa->i; 873bf14a46SMatthew Knepley PetscInt *col = aa->j; 883bf14a46SMatthew Knepley PetscScalar *rvalues = aa->a; 893bf14a46SMatthew Knepley PetscInt m = A->rmap->N; 90745c78f7SBarry Smith PetscInt nnz; 913bf14a46SMatthew Knepley PetscInt i,j, k; 923bf14a46SMatthew Knepley PetscInt base = 1; 933bf14a46SMatthew Knepley PetscInt idx; 943bf14a46SMatthew Knepley PetscErrorCode ierr; 953bf14a46SMatthew Knepley PetscInt colidx; 963bf14a46SMatthew Knepley PetscInt *colcount; 97ace3abfcSBarry Smith PetscBool isSBAIJ; 98ace3abfcSBarry Smith PetscBool isSeqSBAIJ; 99ace3abfcSBarry Smith PetscBool isMpiSBAIJ; 100ace3abfcSBarry Smith PetscBool isSym; 101d41469e0Sxavier lacoste PetscBool flg; 102d41469e0Sxavier lacoste PetscInt icntl; 103d41469e0Sxavier lacoste PetscInt verb; 104d41469e0Sxavier lacoste PetscInt check; 1053bf14a46SMatthew Knepley 1063bf14a46SMatthew Knepley PetscFunctionBegin; 10741c8de11SBarry Smith ierr = MatIsSymmetric(A,0.0,&isSym);CHKERRQ(ierr); 108251f4c67SDmitry Karpeev ierr = PetscObjectTypeCompare((PetscObject)A,MATSBAIJ,&isSBAIJ);CHKERRQ(ierr); 109251f4c67SDmitry Karpeev ierr = PetscObjectTypeCompare((PetscObject)A,MATSEQSBAIJ,&isSeqSBAIJ);CHKERRQ(ierr); 110251f4c67SDmitry Karpeev ierr = PetscObjectTypeCompare((PetscObject)A,MATMPISBAIJ,&isMpiSBAIJ);CHKERRQ(ierr); 1113bf14a46SMatthew Knepley 112745c78f7SBarry Smith *n = A->cmap->N; 113745c78f7SBarry Smith 114745c78f7SBarry Smith /* PaStiX only needs triangular matrix if matrix is symmetric 115745c78f7SBarry Smith */ 1162205254eSKarl Rupp if (isSym && !(isSBAIJ || isSeqSBAIJ || isMpiSBAIJ)) nnz = (aa->nz - *n)/2 + *n; 1172205254eSKarl Rupp else nnz = aa->nz; 1183bf14a46SMatthew Knepley 1193bf14a46SMatthew Knepley if (!valOnly) { 1203bf14a46SMatthew Knepley ierr = PetscMalloc(((*n)+1) *sizeof(PetscInt) ,colptr);CHKERRQ(ierr); 1213bf14a46SMatthew Knepley ierr = PetscMalloc(nnz *sizeof(PetscInt) ,row);CHKERRQ(ierr); 122785e854fSJed Brown ierr = PetscMalloc1(nnz ,values);CHKERRQ(ierr); 1233bf14a46SMatthew Knepley 12441c8de11SBarry Smith if (isSBAIJ || isSeqSBAIJ || isMpiSBAIJ) { 12541c8de11SBarry Smith ierr = PetscMemcpy (*colptr, rowptr, ((*n)+1)*sizeof(PetscInt));CHKERRQ(ierr); 1262205254eSKarl Rupp for (i = 0; i < *n+1; i++) (*colptr)[i] += base; 12741c8de11SBarry Smith ierr = PetscMemcpy (*row, col, (nnz)*sizeof(PetscInt));CHKERRQ(ierr); 1282205254eSKarl Rupp for (i = 0; i < nnz; i++) (*row)[i] += base; 12941c8de11SBarry Smith ierr = PetscMemcpy (*values, rvalues, (nnz)*sizeof(PetscScalar));CHKERRQ(ierr); 13041c8de11SBarry Smith } else { 131785e854fSJed Brown ierr = PetscMalloc1((*n),&colcount);CHKERRQ(ierr); 13241c8de11SBarry Smith 133f31ce8a6SBarry Smith for (i = 0; i < m; i++) colcount[i] = 0; 1343bf14a46SMatthew Knepley /* Fill-in colptr */ 135f31ce8a6SBarry Smith for (i = 0; i < m; i++) { 136f31ce8a6SBarry Smith for (j = rowptr[i]; j < rowptr[i+1]; j++) { 137f31ce8a6SBarry Smith if (!isSym || col[j] <= i) colcount[col[j]]++; 138f31ce8a6SBarry Smith } 139f31ce8a6SBarry Smith } 140745c78f7SBarry Smith 1413bf14a46SMatthew Knepley (*colptr)[0] = base; 1423bf14a46SMatthew Knepley for (j = 0; j < *n; j++) { 1433bf14a46SMatthew Knepley (*colptr)[j+1] = (*colptr)[j] + colcount[j]; 144745c78f7SBarry Smith /* in next loop we fill starting from (*colptr)[colidx] - base */ 1453bf14a46SMatthew Knepley colcount[j] = -base; 1463bf14a46SMatthew Knepley } 1473bf14a46SMatthew Knepley 1483bf14a46SMatthew Knepley /* Fill-in rows and values */ 1493bf14a46SMatthew Knepley for (i = 0; i < m; i++) { 1503bf14a46SMatthew Knepley for (j = rowptr[i]; j < rowptr[i+1]; j++) { 15141c8de11SBarry Smith if (!isSym || col[j] <= i) { 1523bf14a46SMatthew Knepley colidx = col[j]; 1533bf14a46SMatthew Knepley idx = (*colptr)[colidx] + colcount[colidx]; 1543bf14a46SMatthew Knepley (*row)[idx] = i + base; 1553bf14a46SMatthew Knepley (*values)[idx] = rvalues[j]; 1563bf14a46SMatthew Knepley colcount[colidx]++; 1573bf14a46SMatthew Knepley } 1583bf14a46SMatthew Knepley } 1593bf14a46SMatthew Knepley } 16041c8de11SBarry Smith ierr = PetscFree(colcount);CHKERRQ(ierr); 161745c78f7SBarry Smith } 16241c8de11SBarry Smith } else { 163745c78f7SBarry Smith /* Fill-in only values */ 1643bf14a46SMatthew Knepley for (i = 0; i < m; i++) { 1653bf14a46SMatthew Knepley for (j = rowptr[i]; j < rowptr[i+1]; j++) { 1663bf14a46SMatthew Knepley colidx = col[j]; 1672205254eSKarl Rupp if ((isSBAIJ || isSeqSBAIJ || isMpiSBAIJ) ||!isSym || col[j] <= i) { 168745c78f7SBarry Smith /* look for the value to fill */ 169f31ce8a6SBarry Smith for (k = (*colptr)[colidx] - base; k < (*colptr)[colidx + 1] - base; k++) { 170eb1f6c34SBarry Smith if (((*row)[k]-base) == i) { 1713bf14a46SMatthew Knepley (*values)[k] = rvalues[j]; 1723bf14a46SMatthew Knepley break; 1733bf14a46SMatthew Knepley } 1743bf14a46SMatthew Knepley } 175f31ce8a6SBarry Smith /* data structure of sparse matrix has changed */ 176e32f2f54SBarry Smith if (k == (*colptr)[colidx + 1] - base) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_PLIB,"overflow on k %D",k); 1773bf14a46SMatthew Knepley } 1783bf14a46SMatthew Knepley } 1793bf14a46SMatthew Knepley } 180745c78f7SBarry Smith } 181d41469e0Sxavier lacoste 182d41469e0Sxavier lacoste icntl =-1; 183d41469e0Sxavier lacoste check = 0; 184*952ee8f4SMatthew G. Knepley ierr = PetscOptionsGetInt(((PetscObject) A)->prefix, "-mat_pastix_check", &icntl, &flg);CHKERRQ(ierr); 1852205254eSKarl Rupp if ((flg && icntl >= 0) || PetscLogPrintInfo) check = icntl; 1862205254eSKarl Rupp 187d41469e0Sxavier lacoste if (check == 1) { 18870fe17b1SSatish Balay PetscScalar *tmpvalues; 18970fe17b1SSatish Balay PetscInt *tmprows,*tmpcolptr; 1900f11a792SBarry Smith tmpvalues = (PetscScalar*)malloc(nnz*sizeof(PetscScalar)); if (!tmpvalues) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_MEM,"Unable to allocate memory"); 1910f11a792SBarry Smith tmprows = (PetscInt*) malloc(nnz*sizeof(PetscInt)); if (!tmprows) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_MEM,"Unable to allocate memory"); 1920f11a792SBarry Smith tmpcolptr = (PetscInt*) malloc((*n+1)*sizeof(PetscInt)); if (!tmpcolptr) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_MEM,"Unable to allocate memory"); 19343801a69SSatish Balay 19470fe17b1SSatish Balay ierr = PetscMemcpy(tmpcolptr,*colptr,(*n+1)*sizeof(PetscInt));CHKERRQ(ierr); 19570fe17b1SSatish Balay ierr = PetscMemcpy(tmprows,*row,nnz*sizeof(PetscInt));CHKERRQ(ierr); 19670fe17b1SSatish Balay ierr = PetscMemcpy(tmpvalues,*values,nnz*sizeof(PetscScalar));CHKERRQ(ierr); 19743801a69SSatish Balay ierr = PetscFree(*row);CHKERRQ(ierr); 19843801a69SSatish Balay ierr = PetscFree(*values);CHKERRQ(ierr); 19943801a69SSatish Balay 200d41469e0Sxavier lacoste icntl=-1; 201d41469e0Sxavier lacoste verb = API_VERBOSE_NOT; 202*952ee8f4SMatthew G. Knepley /* "iparm[IPARM_VERBOSE] : level of printing (0 to 2)" */ 203*952ee8f4SMatthew G. Knepley ierr = PetscOptionsGetInt(((PetscObject) A)->prefix, "-mat_pastix_verbose", &icntl, &flg);CHKERRQ(ierr); 204*952ee8f4SMatthew G. Knepley if ((flg && icntl >= 0) || PetscLogPrintInfo) verb = icntl; 2055ec454cfSSatish Balay PASTIX_CHECKMATRIX(MPI_COMM_WORLD,verb,((isSym != 0) ? API_SYM_YES : API_SYM_NO),API_YES,*n,&tmpcolptr,&tmprows,(PastixScalar**)&tmpvalues,NULL,1); 20643801a69SSatish Balay 20770fe17b1SSatish Balay ierr = PetscMemcpy(*colptr,tmpcolptr,(*n+1)*sizeof(PetscInt));CHKERRQ(ierr); 208785e854fSJed Brown ierr = PetscMalloc1(((*colptr)[*n]-1),row);CHKERRQ(ierr); 20970fe17b1SSatish Balay ierr = PetscMemcpy(*row,tmprows,((*colptr)[*n]-1)*sizeof(PetscInt));CHKERRQ(ierr); 210785e854fSJed Brown ierr = PetscMalloc1(((*colptr)[*n]-1),values);CHKERRQ(ierr); 21170fe17b1SSatish Balay ierr = PetscMemcpy(*values,tmpvalues,((*colptr)[*n]-1)*sizeof(PetscScalar));CHKERRQ(ierr); 212be76a908SBarry Smith free(tmpvalues); 213be76a908SBarry Smith free(tmprows); 214be76a908SBarry Smith free(tmpcolptr); 215be76a908SBarry Smith 21643801a69SSatish Balay } 2173bf14a46SMatthew Knepley PetscFunctionReturn(0); 2183bf14a46SMatthew Knepley } 2193bf14a46SMatthew Knepley 2203bf14a46SMatthew Knepley 2213bf14a46SMatthew Knepley 2223bf14a46SMatthew Knepley #undef __FUNCT__ 2233bf14a46SMatthew Knepley #define __FUNCT__ "MatDestroy_Pastix" 2243bf14a46SMatthew Knepley /* 2253bf14a46SMatthew Knepley Call clean step of PaStiX if lu->CleanUpPastix == true. 2263bf14a46SMatthew Knepley Free the CSC matrix. 2273bf14a46SMatthew Knepley */ 2283bf14a46SMatthew Knepley PetscErrorCode MatDestroy_Pastix(Mat A) 2293bf14a46SMatthew Knepley { 2303bf14a46SMatthew Knepley Mat_Pastix *lu=(Mat_Pastix*)A->spptr; 2313bf14a46SMatthew Knepley PetscErrorCode ierr; 2323bf14a46SMatthew Knepley PetscMPIInt size=lu->commSize; 233745c78f7SBarry Smith 2343bf14a46SMatthew Knepley PetscFunctionBegin; 235bf0cc555SLisandro Dalcin if (lu && lu->CleanUpPastix) { 2363bf14a46SMatthew Knepley /* Terminate instance, deallocate memories */ 2373bf14a46SMatthew Knepley if (size > 1) { 2386bf464f9SBarry Smith ierr = VecScatterDestroy(&lu->scat_rhs);CHKERRQ(ierr); 2396bf464f9SBarry Smith ierr = VecDestroy(&lu->b_seq);CHKERRQ(ierr); 2406bf464f9SBarry Smith ierr = VecScatterDestroy(&lu->scat_sol);CHKERRQ(ierr); 2413bf14a46SMatthew Knepley } 2423bf14a46SMatthew Knepley 2433bf14a46SMatthew Knepley lu->iparm[IPARM_START_TASK]=API_TASK_CLEAN; 2443bf14a46SMatthew Knepley lu->iparm[IPARM_END_TASK] =API_TASK_CLEAN; 2453bf14a46SMatthew Knepley 246d41469e0Sxavier lacoste PASTIX_CALL(&(lu->pastix_data), 2473bf14a46SMatthew Knepley lu->pastix_comm, 248d41469e0Sxavier lacoste lu->n, 249d41469e0Sxavier lacoste lu->colptr, 250d41469e0Sxavier lacoste lu->row, 2515ec454cfSSatish Balay (PastixScalar*)lu->val, 252d41469e0Sxavier lacoste lu->perm, 253d41469e0Sxavier lacoste lu->invp, 2545ec454cfSSatish Balay (PastixScalar*)lu->rhs, 255d41469e0Sxavier lacoste lu->rhsnbr, 256d41469e0Sxavier lacoste lu->iparm, 2573bf14a46SMatthew Knepley lu->dparm); 2583bf14a46SMatthew Knepley 2593bf14a46SMatthew Knepley ierr = PetscFree(lu->colptr);CHKERRQ(ierr); 2603bf14a46SMatthew Knepley ierr = PetscFree(lu->row);CHKERRQ(ierr); 2613bf14a46SMatthew Knepley ierr = PetscFree(lu->val);CHKERRQ(ierr); 2623bf14a46SMatthew Knepley ierr = PetscFree(lu->perm);CHKERRQ(ierr); 2633bf14a46SMatthew Knepley ierr = PetscFree(lu->invp);CHKERRQ(ierr); 2643bf14a46SMatthew Knepley ierr = MPI_Comm_free(&(lu->pastix_comm));CHKERRQ(ierr); 2653bf14a46SMatthew Knepley } 266bf0cc555SLisandro Dalcin if (lu && lu->Destroy) { 267bf0cc555SLisandro Dalcin ierr = (lu->Destroy)(A);CHKERRQ(ierr); 268bf0cc555SLisandro Dalcin } 269bf0cc555SLisandro Dalcin ierr = PetscFree(A->spptr);CHKERRQ(ierr); 2703bf14a46SMatthew Knepley PetscFunctionReturn(0); 2713bf14a46SMatthew Knepley } 2723bf14a46SMatthew Knepley 2733bf14a46SMatthew Knepley #undef __FUNCT__ 2743bf14a46SMatthew Knepley #define __FUNCT__ "MatSolve_PaStiX" 2753bf14a46SMatthew Knepley /* 2763bf14a46SMatthew Knepley Gather right-hand-side. 2773bf14a46SMatthew Knepley Call for Solve step. 2783bf14a46SMatthew Knepley Scatter solution. 2793bf14a46SMatthew Knepley */ 2803bf14a46SMatthew Knepley PetscErrorCode MatSolve_PaStiX(Mat A,Vec b,Vec x) 2813bf14a46SMatthew Knepley { 2823bf14a46SMatthew Knepley Mat_Pastix *lu=(Mat_Pastix*)A->spptr; 2833bf14a46SMatthew Knepley PetscScalar *array; 2843bf14a46SMatthew Knepley Vec x_seq; 2853bf14a46SMatthew Knepley PetscErrorCode ierr; 2863bf14a46SMatthew Knepley 2873bf14a46SMatthew Knepley PetscFunctionBegin; 2883bf14a46SMatthew Knepley lu->rhsnbr = 1; 2893bf14a46SMatthew Knepley x_seq = lu->b_seq; 2903bf14a46SMatthew Knepley if (lu->commSize > 1) { 2913bf14a46SMatthew Knepley /* PaStiX only supports centralized rhs. Scatter b into a seqential rhs vector */ 2923bf14a46SMatthew Knepley ierr = VecScatterBegin(lu->scat_rhs,b,x_seq,INSERT_VALUES,SCATTER_FORWARD);CHKERRQ(ierr); 2933bf14a46SMatthew Knepley ierr = VecScatterEnd(lu->scat_rhs,b,x_seq,INSERT_VALUES,SCATTER_FORWARD);CHKERRQ(ierr); 294b5e56a35SBarry Smith ierr = VecGetArray(x_seq,&array);CHKERRQ(ierr); 29541c8de11SBarry Smith } else { /* size == 1 */ 2963bf14a46SMatthew Knepley ierr = VecCopy(b,x);CHKERRQ(ierr); 2973bf14a46SMatthew Knepley ierr = VecGetArray(x,&array);CHKERRQ(ierr); 2983bf14a46SMatthew Knepley } 2993bf14a46SMatthew Knepley lu->rhs = array; 3003bf14a46SMatthew Knepley if (lu->commSize == 1) { 3013bf14a46SMatthew Knepley ierr = VecRestoreArray(x,&array);CHKERRQ(ierr); 3023bf14a46SMatthew Knepley } else { 3033bf14a46SMatthew Knepley ierr = VecRestoreArray(x_seq,&array);CHKERRQ(ierr); 3043bf14a46SMatthew Knepley } 3053bf14a46SMatthew Knepley 3063bf14a46SMatthew Knepley /* solve phase */ 3073bf14a46SMatthew Knepley /*-------------*/ 3083bf14a46SMatthew Knepley lu->iparm[IPARM_START_TASK] = API_TASK_SOLVE; 3093bf14a46SMatthew Knepley lu->iparm[IPARM_END_TASK] = API_TASK_REFINE; 310745c78f7SBarry Smith lu->iparm[IPARM_RHS_MAKING] = API_RHS_B; 3113bf14a46SMatthew Knepley 312d41469e0Sxavier lacoste PASTIX_CALL(&(lu->pastix_data), 313d41469e0Sxavier lacoste lu->pastix_comm, 314d41469e0Sxavier lacoste lu->n, 315d41469e0Sxavier lacoste lu->colptr, 316d41469e0Sxavier lacoste lu->row, 3175ec454cfSSatish Balay (PastixScalar*)lu->val, 318d41469e0Sxavier lacoste lu->perm, 319d41469e0Sxavier lacoste lu->invp, 3205ec454cfSSatish Balay (PastixScalar*)lu->rhs, 321d41469e0Sxavier lacoste lu->rhsnbr, 322d41469e0Sxavier lacoste lu->iparm, 323d41469e0Sxavier lacoste lu->dparm); 3243bf14a46SMatthew Knepley 32565e19b50SBarry Smith if (lu->iparm[IPARM_ERROR_NUMBER] < 0) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"Error reported by PaStiX in solve phase: lu->iparm[IPARM_ERROR_NUMBER] = %d\n",lu->iparm[IPARM_ERROR_NUMBER]); 3263bf14a46SMatthew Knepley 3273bf14a46SMatthew Knepley if (lu->commSize == 1) { 3283bf14a46SMatthew Knepley ierr = VecRestoreArray(x,&(lu->rhs));CHKERRQ(ierr); 3293bf14a46SMatthew Knepley } else { 3303bf14a46SMatthew Knepley ierr = VecRestoreArray(x_seq,&(lu->rhs));CHKERRQ(ierr); 3313bf14a46SMatthew Knepley } 3323bf14a46SMatthew Knepley 3333bf14a46SMatthew Knepley if (lu->commSize > 1) { /* convert PaStiX centralized solution to petsc mpi x */ 3343bf14a46SMatthew Knepley ierr = VecScatterBegin(lu->scat_sol,x_seq,x,INSERT_VALUES,SCATTER_FORWARD);CHKERRQ(ierr); 3353bf14a46SMatthew Knepley ierr = VecScatterEnd(lu->scat_sol,x_seq,x,INSERT_VALUES,SCATTER_FORWARD);CHKERRQ(ierr); 3363bf14a46SMatthew Knepley } 3373bf14a46SMatthew Knepley PetscFunctionReturn(0); 3383bf14a46SMatthew Knepley } 3393bf14a46SMatthew Knepley 3403bf14a46SMatthew Knepley /* 3413bf14a46SMatthew Knepley Numeric factorisation using PaStiX solver. 3423bf14a46SMatthew Knepley 3433bf14a46SMatthew Knepley */ 3443bf14a46SMatthew Knepley #undef __FUNCT__ 34553c77d0aSJed Brown #define __FUNCT__ "MatFactorNumeric_PaStiX" 3463bf14a46SMatthew Knepley PetscErrorCode MatFactorNumeric_PaStiX(Mat F,Mat A,const MatFactorInfo *info) 3473bf14a46SMatthew Knepley { 3483bf14a46SMatthew Knepley Mat_Pastix *lu =(Mat_Pastix*)(F)->spptr; 34941c8de11SBarry Smith Mat *tseq; 3503bf14a46SMatthew Knepley PetscErrorCode ierr = 0; 351b5e56a35SBarry Smith PetscInt icntl; 352b5e56a35SBarry Smith PetscInt M=A->rmap->N; 353ace3abfcSBarry Smith PetscBool valOnly,flg, isSym; 3543bf14a46SMatthew Knepley Mat F_diag; 3553bf14a46SMatthew Knepley IS is_iden; 3563bf14a46SMatthew Knepley Vec b; 3573bf14a46SMatthew Knepley IS isrow; 35851a30905SBarry Smith PetscBool isSeqAIJ,isSeqSBAIJ,isMPIAIJ; 3593bf14a46SMatthew Knepley 3603bf14a46SMatthew Knepley PetscFunctionBegin; 361251f4c67SDmitry Karpeev ierr = PetscObjectTypeCompare((PetscObject)A,MATSEQAIJ,&isSeqAIJ);CHKERRQ(ierr); 362251f4c67SDmitry Karpeev ierr = PetscObjectTypeCompare((PetscObject)A,MATMPIAIJ,&isMPIAIJ);CHKERRQ(ierr); 363251f4c67SDmitry Karpeev ierr = PetscObjectTypeCompare((PetscObject)A,MATSEQSBAIJ,&isSeqSBAIJ);CHKERRQ(ierr); 3643bf14a46SMatthew Knepley if (lu->matstruc == DIFFERENT_NONZERO_PATTERN) { 3653bf14a46SMatthew Knepley (F)->ops->solve = MatSolve_PaStiX; 3663bf14a46SMatthew Knepley 3673bf14a46SMatthew Knepley /* Initialize a PASTIX instance */ 368ce94432eSBarry Smith ierr = MPI_Comm_dup(PetscObjectComm((PetscObject)A),&(lu->pastix_comm));CHKERRQ(ierr); 3693bf14a46SMatthew Knepley ierr = MPI_Comm_rank(lu->pastix_comm, &lu->commRank);CHKERRQ(ierr); 3703bf14a46SMatthew Knepley ierr = MPI_Comm_size(lu->pastix_comm, &lu->commSize);CHKERRQ(ierr); 3713bf14a46SMatthew Knepley 3723bf14a46SMatthew Knepley /* Set pastix options */ 3733bf14a46SMatthew Knepley lu->iparm[IPARM_MODIFY_PARAMETER] = API_NO; 3743bf14a46SMatthew Knepley lu->iparm[IPARM_START_TASK] = API_TASK_INIT; 3753bf14a46SMatthew Knepley lu->iparm[IPARM_END_TASK] = API_TASK_INIT; 3762205254eSKarl Rupp 3773bf14a46SMatthew Knepley lu->rhsnbr = 1; 3783bf14a46SMatthew Knepley 3793bf14a46SMatthew Knepley /* Call to set default pastix options */ 380d41469e0Sxavier lacoste PASTIX_CALL(&(lu->pastix_data), 381d41469e0Sxavier lacoste lu->pastix_comm, 382d41469e0Sxavier lacoste lu->n, 383d41469e0Sxavier lacoste lu->colptr, 384d41469e0Sxavier lacoste lu->row, 3855ec454cfSSatish Balay (PastixScalar*)lu->val, 386d41469e0Sxavier lacoste lu->perm, 387d41469e0Sxavier lacoste lu->invp, 3885ec454cfSSatish Balay (PastixScalar*)lu->rhs, 389d41469e0Sxavier lacoste lu->rhsnbr, 390d41469e0Sxavier lacoste lu->iparm, 391d41469e0Sxavier lacoste lu->dparm); 3923bf14a46SMatthew Knepley 393ce94432eSBarry Smith ierr = PetscOptionsBegin(PetscObjectComm((PetscObject)A),((PetscObject)A)->prefix,"PaStiX Options","Mat");CHKERRQ(ierr); 3943bf14a46SMatthew Knepley 3953bf14a46SMatthew Knepley icntl = -1; 3962205254eSKarl Rupp 39741c8de11SBarry Smith lu->iparm[IPARM_VERBOSE] = API_VERBOSE_NOT; 3982205254eSKarl Rupp 39941c8de11SBarry Smith ierr = PetscOptionsInt("-mat_pastix_verbose","iparm[IPARM_VERBOSE] : level of printing (0 to 2)","None",lu->iparm[IPARM_VERBOSE],&icntl,&flg);CHKERRQ(ierr); 400d41469e0Sxavier lacoste if ((flg && icntl >= 0) || PetscLogPrintInfo) { 4013bf14a46SMatthew Knepley lu->iparm[IPARM_VERBOSE] = icntl; 4023bf14a46SMatthew Knepley } 4033bf14a46SMatthew Knepley icntl=-1; 404e4e47003SBarry Smith ierr = PetscOptionsInt("-mat_pastix_threadnbr","iparm[IPARM_THREAD_NBR] : Number of thread by MPI node","None",lu->iparm[IPARM_THREAD_NBR],&icntl,&flg);CHKERRQ(ierr); 4053bf14a46SMatthew Knepley if ((flg && icntl > 0)) { 4063bf14a46SMatthew Knepley lu->iparm[IPARM_THREAD_NBR] = icntl; 4073bf14a46SMatthew Knepley } 4083bf14a46SMatthew Knepley PetscOptionsEnd(); 4093bf14a46SMatthew Knepley valOnly = PETSC_FALSE; 41041c8de11SBarry Smith } else { 4115d6241c8SBarry Smith if (isSeqAIJ || isMPIAIJ) { 4125d6241c8SBarry Smith ierr = PetscFree(lu->colptr);CHKERRQ(ierr); 4135d6241c8SBarry Smith ierr = PetscFree(lu->row);CHKERRQ(ierr); 4145d6241c8SBarry Smith ierr = PetscFree(lu->val);CHKERRQ(ierr); 4155d6241c8SBarry Smith valOnly = PETSC_FALSE; 4165d6241c8SBarry Smith } else valOnly = PETSC_TRUE; 4173bf14a46SMatthew Knepley } 4183bf14a46SMatthew Knepley 4193bf14a46SMatthew Knepley lu->iparm[IPARM_MATRIX_VERIFICATION] = API_YES; 4203bf14a46SMatthew Knepley 4213bf14a46SMatthew Knepley /* convert mpi A to seq mat A */ 4223bf14a46SMatthew Knepley ierr = ISCreateStride(PETSC_COMM_SELF,M,0,1,&isrow);CHKERRQ(ierr); 4233bf14a46SMatthew Knepley ierr = MatGetSubMatrices(A,1,&isrow,&isrow,MAT_INITIAL_MATRIX,&tseq);CHKERRQ(ierr); 4246bf464f9SBarry Smith ierr = ISDestroy(&isrow);CHKERRQ(ierr); 4253bf14a46SMatthew Knepley 42641c8de11SBarry Smith ierr = MatConvertToCSC(*tseq,valOnly, &lu->n, &lu->colptr, &lu->row, &lu->val);CHKERRQ(ierr); 42741c8de11SBarry Smith ierr = MatIsSymmetric(*tseq,0.0,&isSym);CHKERRQ(ierr); 42841c8de11SBarry Smith ierr = MatDestroyMatrices(1,&tseq);CHKERRQ(ierr); 42941c8de11SBarry Smith 4305d6241c8SBarry Smith if (!lu->perm) { 431785e854fSJed Brown ierr = PetscMalloc1((lu->n),&(lu->perm));CHKERRQ(ierr); 432785e854fSJed Brown ierr = PetscMalloc1((lu->n),&(lu->invp));CHKERRQ(ierr); 4335d6241c8SBarry Smith } 4343bf14a46SMatthew Knepley 4353bf14a46SMatthew Knepley if (isSym) { 436745c78f7SBarry Smith /* On symmetric matrix, LLT */ 4373bf14a46SMatthew Knepley lu->iparm[IPARM_SYM] = API_SYM_YES; 43841c8de11SBarry Smith lu->iparm[IPARM_FACTORIZATION] = API_FACT_LDLT; 439f31ce8a6SBarry Smith } else { 440745c78f7SBarry Smith /* On unsymmetric matrix, LU */ 4413bf14a46SMatthew Knepley lu->iparm[IPARM_SYM] = API_SYM_NO; 4423bf14a46SMatthew Knepley lu->iparm[IPARM_FACTORIZATION] = API_FACT_LU; 4433bf14a46SMatthew Knepley } 4443bf14a46SMatthew Knepley 4453bf14a46SMatthew Knepley /*----------------*/ 4463bf14a46SMatthew Knepley if (lu->matstruc == DIFFERENT_NONZERO_PATTERN) { 4473bf14a46SMatthew Knepley if (!(isSeqAIJ || isSeqSBAIJ)) { 4483bf14a46SMatthew Knepley /* PaStiX only supports centralized rhs. Create scatter scat_rhs for repeated use in MatSolve() */ 4493bf14a46SMatthew Knepley ierr = VecCreateSeq(PETSC_COMM_SELF,A->cmap->N,&lu->b_seq);CHKERRQ(ierr); 4503bf14a46SMatthew Knepley ierr = ISCreateStride(PETSC_COMM_SELF,A->cmap->N,0,1,&is_iden);CHKERRQ(ierr); 451c0dedaeaSBarry Smith ierr = MatGetVecs(A,NULL,&b);CHKERRQ(ierr); 4523bf14a46SMatthew Knepley ierr = VecScatterCreate(b,is_iden,lu->b_seq,is_iden,&lu->scat_rhs);CHKERRQ(ierr); 4533bf14a46SMatthew Knepley ierr = VecScatterCreate(lu->b_seq,is_iden,b,is_iden,&lu->scat_sol);CHKERRQ(ierr); 4546bf464f9SBarry Smith ierr = ISDestroy(&is_iden);CHKERRQ(ierr); 4556bf464f9SBarry Smith ierr = VecDestroy(&b);CHKERRQ(ierr); 4563bf14a46SMatthew Knepley } 4573bf14a46SMatthew Knepley lu->iparm[IPARM_START_TASK] = API_TASK_ORDERING; 4583bf14a46SMatthew Knepley lu->iparm[IPARM_END_TASK] = API_TASK_NUMFACT; 4593bf14a46SMatthew Knepley 460d41469e0Sxavier lacoste PASTIX_CALL(&(lu->pastix_data), 461d41469e0Sxavier lacoste lu->pastix_comm, 462d41469e0Sxavier lacoste lu->n, 463d41469e0Sxavier lacoste lu->colptr, 464d41469e0Sxavier lacoste lu->row, 4655ec454cfSSatish Balay (PastixScalar*)lu->val, 466d41469e0Sxavier lacoste lu->perm, 467d41469e0Sxavier lacoste lu->invp, 4685ec454cfSSatish Balay (PastixScalar*)lu->rhs, 469d41469e0Sxavier lacoste lu->rhsnbr, 470d41469e0Sxavier lacoste lu->iparm, 471d41469e0Sxavier lacoste lu->dparm); 47265e19b50SBarry Smith if (lu->iparm[IPARM_ERROR_NUMBER] < 0) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"Error reported by PaStiX in analysis phase: iparm(IPARM_ERROR_NUMBER)=%d\n",lu->iparm[IPARM_ERROR_NUMBER]); 47341c8de11SBarry Smith } else { 4743bf14a46SMatthew Knepley lu->iparm[IPARM_START_TASK] = API_TASK_NUMFACT; 4753bf14a46SMatthew Knepley lu->iparm[IPARM_END_TASK] = API_TASK_NUMFACT; 476d41469e0Sxavier lacoste PASTIX_CALL(&(lu->pastix_data), 477d41469e0Sxavier lacoste lu->pastix_comm, 478d41469e0Sxavier lacoste lu->n, 479d41469e0Sxavier lacoste lu->colptr, 480d41469e0Sxavier lacoste lu->row, 4815ec454cfSSatish Balay (PastixScalar*)lu->val, 482d41469e0Sxavier lacoste lu->perm, 483d41469e0Sxavier lacoste lu->invp, 4845ec454cfSSatish Balay (PastixScalar*)lu->rhs, 485d41469e0Sxavier lacoste lu->rhsnbr, 486d41469e0Sxavier lacoste lu->iparm, 487d41469e0Sxavier lacoste lu->dparm); 4883bf14a46SMatthew Knepley 48965e19b50SBarry Smith if (lu->iparm[IPARM_ERROR_NUMBER] < 0) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"Error reported by PaStiX in analysis phase: iparm(IPARM_ERROR_NUMBER)=%d\n",lu->iparm[IPARM_ERROR_NUMBER]); 4903bf14a46SMatthew Knepley } 4913bf14a46SMatthew Knepley 4923bf14a46SMatthew Knepley if (lu->commSize > 1) { 493d5f3da31SBarry Smith if ((F)->factortype == MAT_FACTOR_LU) { 4943bf14a46SMatthew Knepley F_diag = ((Mat_MPIAIJ*)(F)->data)->A; 4953bf14a46SMatthew Knepley } else { 4963bf14a46SMatthew Knepley F_diag = ((Mat_MPISBAIJ*)(F)->data)->A; 4973bf14a46SMatthew Knepley } 4983bf14a46SMatthew Knepley F_diag->assembled = PETSC_TRUE; 4993bf14a46SMatthew Knepley } 5003bf14a46SMatthew Knepley (F)->assembled = PETSC_TRUE; 5013bf14a46SMatthew Knepley lu->matstruc = SAME_NONZERO_PATTERN; 5023bf14a46SMatthew Knepley lu->CleanUpPastix = PETSC_TRUE; 5033bf14a46SMatthew Knepley PetscFunctionReturn(0); 5043bf14a46SMatthew Knepley } 5053bf14a46SMatthew Knepley 5063bf14a46SMatthew Knepley /* Note the Petsc r and c permutations are ignored */ 5073bf14a46SMatthew Knepley #undef __FUNCT__ 5083bf14a46SMatthew Knepley #define __FUNCT__ "MatLUFactorSymbolic_AIJPASTIX" 5093bf14a46SMatthew Knepley PetscErrorCode MatLUFactorSymbolic_AIJPASTIX(Mat F,Mat A,IS r,IS c,const MatFactorInfo *info) 5103bf14a46SMatthew Knepley { 5113bf14a46SMatthew Knepley Mat_Pastix *lu = (Mat_Pastix*)F->spptr; 5123bf14a46SMatthew Knepley 5133bf14a46SMatthew Knepley PetscFunctionBegin; 5143bf14a46SMatthew Knepley lu->iparm[IPARM_FACTORIZATION] = API_FACT_LU; 5153bf14a46SMatthew Knepley lu->iparm[IPARM_SYM] = API_SYM_YES; 5163bf14a46SMatthew Knepley lu->matstruc = DIFFERENT_NONZERO_PATTERN; 5173bf14a46SMatthew Knepley F->ops->lufactornumeric = MatFactorNumeric_PaStiX; 5183bf14a46SMatthew Knepley PetscFunctionReturn(0); 5193bf14a46SMatthew Knepley } 5203bf14a46SMatthew Knepley 5213bf14a46SMatthew Knepley 5223bf14a46SMatthew Knepley /* Note the Petsc r permutation is ignored */ 5233bf14a46SMatthew Knepley #undef __FUNCT__ 5243bf14a46SMatthew Knepley #define __FUNCT__ "MatCholeskyFactorSymbolic_SBAIJPASTIX" 5253bf14a46SMatthew Knepley PetscErrorCode MatCholeskyFactorSymbolic_SBAIJPASTIX(Mat F,Mat A,IS r,const MatFactorInfo *info) 5263bf14a46SMatthew Knepley { 5273bf14a46SMatthew Knepley Mat_Pastix *lu = (Mat_Pastix*)(F)->spptr; 5283bf14a46SMatthew Knepley 5293bf14a46SMatthew Knepley PetscFunctionBegin; 5303bf14a46SMatthew Knepley lu->iparm[IPARM_FACTORIZATION] = API_FACT_LLT; 5313bf14a46SMatthew Knepley lu->iparm[IPARM_SYM] = API_SYM_NO; 5323bf14a46SMatthew Knepley lu->matstruc = DIFFERENT_NONZERO_PATTERN; 5333bf14a46SMatthew Knepley (F)->ops->choleskyfactornumeric = MatFactorNumeric_PaStiX; 5343bf14a46SMatthew Knepley PetscFunctionReturn(0); 5353bf14a46SMatthew Knepley } 5363bf14a46SMatthew Knepley 5373bf14a46SMatthew Knepley #undef __FUNCT__ 5383bf14a46SMatthew Knepley #define __FUNCT__ "MatView_PaStiX" 5393bf14a46SMatthew Knepley PetscErrorCode MatView_PaStiX(Mat A,PetscViewer viewer) 5403bf14a46SMatthew Knepley { 5413bf14a46SMatthew Knepley PetscErrorCode ierr; 542ace3abfcSBarry Smith PetscBool iascii; 5433bf14a46SMatthew Knepley PetscViewerFormat format; 5443bf14a46SMatthew Knepley 5453bf14a46SMatthew Knepley PetscFunctionBegin; 546251f4c67SDmitry Karpeev ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&iascii);CHKERRQ(ierr); 5473bf14a46SMatthew Knepley if (iascii) { 5483bf14a46SMatthew Knepley ierr = PetscViewerGetFormat(viewer,&format);CHKERRQ(ierr); 5493bf14a46SMatthew Knepley if (format == PETSC_VIEWER_ASCII_INFO) { 550b5e56a35SBarry Smith Mat_Pastix *lu=(Mat_Pastix*)A->spptr; 551b5e56a35SBarry Smith 552b5e56a35SBarry Smith ierr = PetscViewerASCIIPrintf(viewer,"PaStiX run parameters:\n");CHKERRQ(ierr); 553b5e56a35SBarry Smith ierr = PetscViewerASCIIPrintf(viewer," Matrix type : %s \n",((lu->iparm[IPARM_SYM] == API_SYM_YES) ? "Symmetric" : "Unsymmetric"));CHKERRQ(ierr); 554b5e56a35SBarry Smith ierr = PetscViewerASCIIPrintf(viewer," Level of printing (0,1,2): %d \n",lu->iparm[IPARM_VERBOSE]);CHKERRQ(ierr); 555b5e56a35SBarry Smith ierr = PetscViewerASCIIPrintf(viewer," Number of refinements iterations : %d \n",lu->iparm[IPARM_NBITER]);CHKERRQ(ierr); 556b5e56a35SBarry Smith ierr = PetscPrintf(PETSC_COMM_SELF," Error : %g \n",lu->dparm[DPARM_RELATIVE_ERROR]);CHKERRQ(ierr); 5573bf14a46SMatthew Knepley } 5583bf14a46SMatthew Knepley } 5593bf14a46SMatthew Knepley PetscFunctionReturn(0); 5603bf14a46SMatthew Knepley } 5613bf14a46SMatthew Knepley 5623bf14a46SMatthew Knepley 5633bf14a46SMatthew Knepley /*MC 5642692d6eeSBarry Smith MATSOLVERPASTIX - A solver package providing direct solvers (LU) for distributed 5653bf14a46SMatthew Knepley and sequential matrices via the external package PaStiX. 5663bf14a46SMatthew Knepley 567e2e64c6bSBarry Smith Use ./configure --download-pastix to have PETSc installed with PaStiX 5683bf14a46SMatthew Knepley 5693bf14a46SMatthew Knepley Options Database Keys: 570b5e56a35SBarry Smith + -mat_pastix_verbose <0,1,2> - print level 571b5e56a35SBarry Smith - -mat_pastix_threadnbr <integer> - Set the thread number by MPI task. 5723bf14a46SMatthew Knepley 5733bf14a46SMatthew Knepley Level: beginner 5743bf14a46SMatthew Knepley 57541c8de11SBarry Smith .seealso: PCFactorSetMatSolverPackage(), MatSolverPackage 57641c8de11SBarry Smith 5773bf14a46SMatthew Knepley M*/ 5783bf14a46SMatthew Knepley 5793bf14a46SMatthew Knepley 5803bf14a46SMatthew Knepley #undef __FUNCT__ 5813bf14a46SMatthew Knepley #define __FUNCT__ "MatGetInfo_PaStiX" 5823bf14a46SMatthew Knepley PetscErrorCode MatGetInfo_PaStiX(Mat A,MatInfoType flag,MatInfo *info) 5833bf14a46SMatthew Knepley { 5843bf14a46SMatthew Knepley Mat_Pastix *lu =(Mat_Pastix*)A->spptr; 5853bf14a46SMatthew Knepley 5863bf14a46SMatthew Knepley PetscFunctionBegin; 5873bf14a46SMatthew Knepley info->block_size = 1.0; 5883bf14a46SMatthew Knepley info->nz_allocated = lu->iparm[IPARM_NNZEROS]; 5893bf14a46SMatthew Knepley info->nz_used = lu->iparm[IPARM_NNZEROS]; 5903bf14a46SMatthew Knepley info->nz_unneeded = 0.0; 5913bf14a46SMatthew Knepley info->assemblies = 0.0; 5923bf14a46SMatthew Knepley info->mallocs = 0.0; 5933bf14a46SMatthew Knepley info->memory = 0.0; 5943bf14a46SMatthew Knepley info->fill_ratio_given = 0; 5953bf14a46SMatthew Knepley info->fill_ratio_needed = 0; 5963bf14a46SMatthew Knepley info->factor_mallocs = 0; 5973bf14a46SMatthew Knepley PetscFunctionReturn(0); 5983bf14a46SMatthew Knepley } 5993bf14a46SMatthew Knepley 6003bf14a46SMatthew Knepley #undef __FUNCT__ 6013bf14a46SMatthew Knepley #define __FUNCT__ "MatFactorGetSolverPackage_pastix" 6023bf14a46SMatthew Knepley PetscErrorCode MatFactorGetSolverPackage_pastix(Mat A,const MatSolverPackage *type) 6033bf14a46SMatthew Knepley { 6043bf14a46SMatthew Knepley PetscFunctionBegin; 6052692d6eeSBarry Smith *type = MATSOLVERPASTIX; 6063bf14a46SMatthew Knepley PetscFunctionReturn(0); 6073bf14a46SMatthew Knepley } 6083bf14a46SMatthew Knepley 6093bf14a46SMatthew Knepley /* 6103bf14a46SMatthew Knepley The seq and mpi versions of this function are the same 6113bf14a46SMatthew Knepley */ 6123bf14a46SMatthew Knepley #undef __FUNCT__ 6133bf14a46SMatthew Knepley #define __FUNCT__ "MatGetFactor_seqaij_pastix" 6148cc058d9SJed Brown PETSC_EXTERN PetscErrorCode MatGetFactor_seqaij_pastix(Mat A,MatFactorType ftype,Mat *F) 6153bf14a46SMatthew Knepley { 6163bf14a46SMatthew Knepley Mat B; 6173bf14a46SMatthew Knepley PetscErrorCode ierr; 6183bf14a46SMatthew Knepley Mat_Pastix *pastix; 6193bf14a46SMatthew Knepley 6203bf14a46SMatthew Knepley PetscFunctionBegin; 621e7e72b3dSBarry Smith if (ftype != MAT_FACTOR_LU) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP,"Cannot use PETSc AIJ matrices with PaStiX Cholesky, use SBAIJ matrix"); 6223bf14a46SMatthew Knepley /* Create the factorization matrix */ 623ce94432eSBarry Smith ierr = MatCreate(PetscObjectComm((PetscObject)A),&B);CHKERRQ(ierr); 6243bf14a46SMatthew Knepley ierr = MatSetSizes(B,A->rmap->n,A->cmap->n,A->rmap->N,A->cmap->N);CHKERRQ(ierr); 6253bf14a46SMatthew Knepley ierr = MatSetType(B,((PetscObject)A)->type_name);CHKERRQ(ierr); 6260298fd71SBarry Smith ierr = MatSeqAIJSetPreallocation(B,0,NULL);CHKERRQ(ierr); 6273bf14a46SMatthew Knepley 6283bf14a46SMatthew Knepley B->ops->lufactorsymbolic = MatLUFactorSymbolic_AIJPASTIX; 6293bf14a46SMatthew Knepley B->ops->view = MatView_PaStiX; 6303bf14a46SMatthew Knepley B->ops->getinfo = MatGetInfo_PaStiX; 6312205254eSKarl Rupp 632bdf89e91SBarry Smith ierr = PetscObjectComposeFunction((PetscObject)B,"MatFactorGetSolverPackage_C",MatFactorGetSolverPackage_pastix);CHKERRQ(ierr); 6332205254eSKarl Rupp 634d5f3da31SBarry Smith B->factortype = MAT_FACTOR_LU; 6353bf14a46SMatthew Knepley 636b00a9115SJed Brown ierr = PetscNewLog(B,&pastix);CHKERRQ(ierr); 6372205254eSKarl Rupp 6383bf14a46SMatthew Knepley pastix->CleanUpPastix = PETSC_FALSE; 6393bf14a46SMatthew Knepley pastix->isAIJ = PETSC_TRUE; 6400298fd71SBarry Smith pastix->scat_rhs = NULL; 6410298fd71SBarry Smith pastix->scat_sol = NULL; 642bf0cc555SLisandro Dalcin pastix->Destroy = B->ops->destroy; 6433bf14a46SMatthew Knepley B->ops->destroy = MatDestroy_Pastix; 6443bf14a46SMatthew Knepley B->spptr = (void*)pastix; 6453bf14a46SMatthew Knepley 6463bf14a46SMatthew Knepley *F = B; 6473bf14a46SMatthew Knepley PetscFunctionReturn(0); 6483bf14a46SMatthew Knepley } 6493bf14a46SMatthew Knepley 6503bf14a46SMatthew Knepley #undef __FUNCT__ 6513bf14a46SMatthew Knepley #define __FUNCT__ "MatGetFactor_mpiaij_pastix" 6528cc058d9SJed Brown PETSC_EXTERN PetscErrorCode MatGetFactor_mpiaij_pastix(Mat A,MatFactorType ftype,Mat *F) 6533bf14a46SMatthew Knepley { 6543bf14a46SMatthew Knepley Mat B; 6553bf14a46SMatthew Knepley PetscErrorCode ierr; 6563bf14a46SMatthew Knepley Mat_Pastix *pastix; 6573bf14a46SMatthew Knepley 6583bf14a46SMatthew Knepley PetscFunctionBegin; 659e32f2f54SBarry Smith if (ftype != MAT_FACTOR_LU) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP,"Cannot use PETSc AIJ matrices with PaStiX Cholesky, use SBAIJ matrix"); 6603bf14a46SMatthew Knepley /* Create the factorization matrix */ 661ce94432eSBarry Smith ierr = MatCreate(PetscObjectComm((PetscObject)A),&B);CHKERRQ(ierr); 6623bf14a46SMatthew Knepley ierr = MatSetSizes(B,A->rmap->n,A->cmap->n,A->rmap->N,A->cmap->N);CHKERRQ(ierr); 6633bf14a46SMatthew Knepley ierr = MatSetType(B,((PetscObject)A)->type_name);CHKERRQ(ierr); 6640298fd71SBarry Smith ierr = MatSeqAIJSetPreallocation(B,0,NULL);CHKERRQ(ierr); 6650298fd71SBarry Smith ierr = MatMPIAIJSetPreallocation(B,0,NULL,0,NULL);CHKERRQ(ierr); 6663bf14a46SMatthew Knepley 6673bf14a46SMatthew Knepley B->ops->lufactorsymbolic = MatLUFactorSymbolic_AIJPASTIX; 6683bf14a46SMatthew Knepley B->ops->view = MatView_PaStiX; 6692205254eSKarl Rupp 670bdf89e91SBarry Smith ierr = PetscObjectComposeFunction((PetscObject)B,"MatFactorGetSolverPackage_C",MatFactorGetSolverPackage_pastix);CHKERRQ(ierr); 6712205254eSKarl Rupp 672d5f3da31SBarry Smith B->factortype = MAT_FACTOR_LU; 6733bf14a46SMatthew Knepley 674b00a9115SJed Brown ierr = PetscNewLog(B,&pastix);CHKERRQ(ierr); 6752205254eSKarl Rupp 6763bf14a46SMatthew Knepley pastix->CleanUpPastix = PETSC_FALSE; 6773bf14a46SMatthew Knepley pastix->isAIJ = PETSC_TRUE; 6780298fd71SBarry Smith pastix->scat_rhs = NULL; 6790298fd71SBarry Smith pastix->scat_sol = NULL; 680bf0cc555SLisandro Dalcin pastix->Destroy = B->ops->destroy; 6813bf14a46SMatthew Knepley B->ops->destroy = MatDestroy_Pastix; 6823bf14a46SMatthew Knepley B->spptr = (void*)pastix; 6833bf14a46SMatthew Knepley 6843bf14a46SMatthew Knepley *F = B; 6853bf14a46SMatthew Knepley PetscFunctionReturn(0); 6863bf14a46SMatthew Knepley } 6873bf14a46SMatthew Knepley 6883bf14a46SMatthew Knepley #undef __FUNCT__ 6893bf14a46SMatthew Knepley #define __FUNCT__ "MatGetFactor_seqsbaij_pastix" 6908cc058d9SJed Brown PETSC_EXTERN PetscErrorCode MatGetFactor_seqsbaij_pastix(Mat A,MatFactorType ftype,Mat *F) 6913bf14a46SMatthew Knepley { 6923bf14a46SMatthew Knepley Mat B; 6933bf14a46SMatthew Knepley PetscErrorCode ierr; 6943bf14a46SMatthew Knepley Mat_Pastix *pastix; 6953bf14a46SMatthew Knepley 6963bf14a46SMatthew Knepley PetscFunctionBegin; 697e7e72b3dSBarry Smith if (ftype != MAT_FACTOR_CHOLESKY) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP,"Cannot use PETSc SBAIJ matrices with PaStiX LU, use AIJ matrix"); 6983bf14a46SMatthew Knepley /* Create the factorization matrix */ 699ce94432eSBarry Smith ierr = MatCreate(PetscObjectComm((PetscObject)A),&B);CHKERRQ(ierr); 7003bf14a46SMatthew Knepley ierr = MatSetSizes(B,A->rmap->n,A->cmap->n,A->rmap->N,A->cmap->N);CHKERRQ(ierr); 7013bf14a46SMatthew Knepley ierr = MatSetType(B,((PetscObject)A)->type_name);CHKERRQ(ierr); 7020298fd71SBarry Smith ierr = MatSeqSBAIJSetPreallocation(B,1,0,NULL);CHKERRQ(ierr); 7030298fd71SBarry Smith ierr = MatMPISBAIJSetPreallocation(B,1,0,NULL,0,NULL);CHKERRQ(ierr); 7043bf14a46SMatthew Knepley 7053bf14a46SMatthew Knepley B->ops->choleskyfactorsymbolic = MatCholeskyFactorSymbolic_SBAIJPASTIX; 7063bf14a46SMatthew Knepley B->ops->view = MatView_PaStiX; 7072205254eSKarl Rupp 708bdf89e91SBarry Smith ierr = PetscObjectComposeFunction((PetscObject)B,"MatFactorGetSolverPackage_C",MatFactorGetSolverPackage_pastix);CHKERRQ(ierr); 7092205254eSKarl Rupp 710d5f3da31SBarry Smith B->factortype = MAT_FACTOR_CHOLESKY; 7113bf14a46SMatthew Knepley 712b00a9115SJed Brown ierr = PetscNewLog(B,&pastix);CHKERRQ(ierr); 7132205254eSKarl Rupp 7143bf14a46SMatthew Knepley pastix->CleanUpPastix = PETSC_FALSE; 7153bf14a46SMatthew Knepley pastix->isAIJ = PETSC_TRUE; 7160298fd71SBarry Smith pastix->scat_rhs = NULL; 7170298fd71SBarry Smith pastix->scat_sol = NULL; 718bf0cc555SLisandro Dalcin pastix->Destroy = B->ops->destroy; 7193bf14a46SMatthew Knepley B->ops->destroy = MatDestroy_Pastix; 7203bf14a46SMatthew Knepley B->spptr = (void*)pastix; 7213bf14a46SMatthew Knepley 7223bf14a46SMatthew Knepley *F = B; 7233bf14a46SMatthew Knepley PetscFunctionReturn(0); 7243bf14a46SMatthew Knepley } 7253bf14a46SMatthew Knepley 7263bf14a46SMatthew Knepley #undef __FUNCT__ 7273bf14a46SMatthew Knepley #define __FUNCT__ "MatGetFactor_mpisbaij_pastix" 7288cc058d9SJed Brown PETSC_EXTERN PetscErrorCode MatGetFactor_mpisbaij_pastix(Mat A,MatFactorType ftype,Mat *F) 7293bf14a46SMatthew Knepley { 7303bf14a46SMatthew Knepley Mat B; 7313bf14a46SMatthew Knepley PetscErrorCode ierr; 7323bf14a46SMatthew Knepley Mat_Pastix *pastix; 7333bf14a46SMatthew Knepley 7343bf14a46SMatthew Knepley PetscFunctionBegin; 735e32f2f54SBarry Smith if (ftype != MAT_FACTOR_CHOLESKY) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP,"Cannot use PETSc SBAIJ matrices with PaStiX LU, use AIJ matrix"); 73641c8de11SBarry Smith 7373bf14a46SMatthew Knepley /* Create the factorization matrix */ 738ce94432eSBarry Smith ierr = MatCreate(PetscObjectComm((PetscObject)A),&B);CHKERRQ(ierr); 7393bf14a46SMatthew Knepley ierr = MatSetSizes(B,A->rmap->n,A->cmap->n,A->rmap->N,A->cmap->N);CHKERRQ(ierr); 7403bf14a46SMatthew Knepley ierr = MatSetType(B,((PetscObject)A)->type_name);CHKERRQ(ierr); 7410298fd71SBarry Smith ierr = MatSeqSBAIJSetPreallocation(B,1,0,NULL);CHKERRQ(ierr); 7420298fd71SBarry Smith ierr = MatMPISBAIJSetPreallocation(B,1,0,NULL,0,NULL);CHKERRQ(ierr); 7433bf14a46SMatthew Knepley 7443bf14a46SMatthew Knepley B->ops->choleskyfactorsymbolic = MatCholeskyFactorSymbolic_SBAIJPASTIX; 7453bf14a46SMatthew Knepley B->ops->view = MatView_PaStiX; 7462205254eSKarl Rupp 747bdf89e91SBarry Smith ierr = PetscObjectComposeFunction((PetscObject)B,"MatFactorGetSolverPackage_C",MatFactorGetSolverPackage_pastix);CHKERRQ(ierr); 7482205254eSKarl Rupp 749d5f3da31SBarry Smith B->factortype = MAT_FACTOR_CHOLESKY; 7503bf14a46SMatthew Knepley 751b00a9115SJed Brown ierr = PetscNewLog(B,&pastix);CHKERRQ(ierr); 7522205254eSKarl Rupp 7533bf14a46SMatthew Knepley pastix->CleanUpPastix = PETSC_FALSE; 7543bf14a46SMatthew Knepley pastix->isAIJ = PETSC_TRUE; 7550298fd71SBarry Smith pastix->scat_rhs = NULL; 7560298fd71SBarry Smith pastix->scat_sol = NULL; 757bf0cc555SLisandro Dalcin pastix->Destroy = B->ops->destroy; 7583bf14a46SMatthew Knepley B->ops->destroy = MatDestroy_Pastix; 7593bf14a46SMatthew Knepley B->spptr = (void*)pastix; 7603bf14a46SMatthew Knepley 7613bf14a46SMatthew Knepley *F = B; 7623bf14a46SMatthew Knepley PetscFunctionReturn(0); 7633bf14a46SMatthew Knepley } 764f7a08781SBarry Smith 765