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 9dbbbd53dSSatish Balay #if defined(PETSC_USE_COMPLEX) 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 #else 225ec454cfSSatish Balay #define PASTIX_CALL z_pastix 235ec454cfSSatish Balay #define PASTIX_CHECKMATRIX z_pastix_checkMatrix 245ec454cfSSatish Balay #endif 25d41469e0Sxavier lacoste 26d41469e0Sxavier lacoste #else /* PETSC_USE_COMPLEX */ 27d41469e0Sxavier lacoste 28519f805aSKarl Rupp #if defined(PETSC_USE_REAL_SINGLE) 295ec454cfSSatish Balay #define PASTIX_CALL s_pastix 305ec454cfSSatish Balay #define PASTIX_CHECKMATRIX s_pastix_checkMatrix 315ec454cfSSatish Balay #else 325ec454cfSSatish Balay #define PASTIX_CALL d_pastix 335ec454cfSSatish Balay #define PASTIX_CHECKMATRIX d_pastix_checkMatrix 345ec454cfSSatish Balay #endif 35d41469e0Sxavier lacoste 36d41469e0Sxavier lacoste #endif /* PETSC_USE_COMPLEX */ 37d41469e0Sxavier lacoste 38dbbbd53dSSatish Balay typedef PetscScalar PastixScalar; 39dbbbd53dSSatish Balay 403bf14a46SMatthew Knepley typedef struct Mat_Pastix_ { 413bf14a46SMatthew Knepley pastix_data_t *pastix_data; /* Pastix data storage structure */ 423bf14a46SMatthew Knepley MatStructure matstruc; 433bf14a46SMatthew Knepley PetscInt n; /* Number of columns in the matrix */ 443bf14a46SMatthew Knepley PetscInt *colptr; /* Index of first element of each column in row and val */ 453bf14a46SMatthew Knepley PetscInt *row; /* Row of each element of the matrix */ 463bf14a46SMatthew Knepley PetscScalar *val; /* Value of each element of the matrix */ 473bf14a46SMatthew Knepley PetscInt *perm; /* Permutation tabular */ 483bf14a46SMatthew Knepley PetscInt *invp; /* Reverse permutation tabular */ 493bf14a46SMatthew Knepley PetscScalar *rhs; /* Rhight-hand-side member */ 503bf14a46SMatthew Knepley PetscInt rhsnbr; /* Rhight-hand-side number (must be 1) */ 513bf14a46SMatthew Knepley PetscInt iparm[64]; /* Integer parameters */ 523bf14a46SMatthew Knepley double dparm[64]; /* Floating point parameters */ 533bf14a46SMatthew Knepley MPI_Comm pastix_comm; /* PaStiX MPI communicator */ 543bf14a46SMatthew Knepley PetscMPIInt commRank; /* MPI rank */ 553bf14a46SMatthew Knepley PetscMPIInt commSize; /* MPI communicator size */ 56ace3abfcSBarry Smith PetscBool CleanUpPastix; /* Boolean indicating if we call PaStiX clean step */ 573bf14a46SMatthew Knepley VecScatter scat_rhs; 583bf14a46SMatthew Knepley VecScatter scat_sol; 59f31ce8a6SBarry Smith Vec b_seq; 60ace3abfcSBarry Smith PetscBool isAIJ; 61bf0cc555SLisandro Dalcin PetscErrorCode (*Destroy)(Mat); 623bf14a46SMatthew Knepley } Mat_Pastix; 633bf14a46SMatthew Knepley 6409573ac7SBarry Smith extern PetscErrorCode MatDuplicate_Pastix(Mat,MatDuplicateOption,Mat*); 653bf14a46SMatthew Knepley 66eb1f6c34SBarry Smith #undef __FUNCT__ 67eb1f6c34SBarry Smith #define __FUNCT__ "MatConvertToCSC" 683bf14a46SMatthew Knepley /* 693bf14a46SMatthew Knepley convert Petsc seqaij matrix to CSC: colptr[n], row[nz], val[nz] 703bf14a46SMatthew Knepley 713bf14a46SMatthew Knepley input: 723bf14a46SMatthew Knepley A - matrix in seqaij or mpisbaij (bs=1) format 733bf14a46SMatthew Knepley valOnly - FALSE: spaces are allocated and values are set for the CSC 743bf14a46SMatthew Knepley TRUE: Only fill values 753bf14a46SMatthew Knepley output: 763bf14a46SMatthew Knepley n - Size of the matrix 773bf14a46SMatthew Knepley colptr - Index of first element of each column in row and val 783bf14a46SMatthew Knepley row - Row of each element of the matrix 793bf14a46SMatthew Knepley values - Value of each element of the matrix 803bf14a46SMatthew Knepley */ 81ace3abfcSBarry Smith PetscErrorCode MatConvertToCSC(Mat A,PetscBool valOnly,PetscInt *n,PetscInt **colptr,PetscInt **row,PetscScalar **values) 8241c8de11SBarry Smith { 833bf14a46SMatthew Knepley Mat_SeqAIJ *aa = (Mat_SeqAIJ*)A->data; 843bf14a46SMatthew Knepley PetscInt *rowptr = aa->i; 853bf14a46SMatthew Knepley PetscInt *col = aa->j; 863bf14a46SMatthew Knepley PetscScalar *rvalues = aa->a; 873bf14a46SMatthew Knepley PetscInt m = A->rmap->N; 88745c78f7SBarry Smith PetscInt nnz; 893bf14a46SMatthew Knepley PetscInt i,j, k; 903bf14a46SMatthew Knepley PetscInt base = 1; 913bf14a46SMatthew Knepley PetscInt idx; 923bf14a46SMatthew Knepley PetscErrorCode ierr; 933bf14a46SMatthew Knepley PetscInt colidx; 943bf14a46SMatthew Knepley PetscInt *colcount; 95ace3abfcSBarry Smith PetscBool isSBAIJ; 96ace3abfcSBarry Smith PetscBool isSeqSBAIJ; 97ace3abfcSBarry Smith PetscBool isMpiSBAIJ; 98ace3abfcSBarry Smith PetscBool isSym; 99d41469e0Sxavier lacoste PetscBool flg; 100d41469e0Sxavier lacoste PetscInt icntl; 101d41469e0Sxavier lacoste PetscInt verb; 102d41469e0Sxavier lacoste PetscInt check; 1033bf14a46SMatthew Knepley 1043bf14a46SMatthew Knepley PetscFunctionBegin; 10541c8de11SBarry Smith ierr = MatIsSymmetric(A,0.0,&isSym);CHKERRQ(ierr); 106251f4c67SDmitry Karpeev ierr = PetscObjectTypeCompare((PetscObject)A,MATSBAIJ,&isSBAIJ);CHKERRQ(ierr); 107251f4c67SDmitry Karpeev ierr = PetscObjectTypeCompare((PetscObject)A,MATSEQSBAIJ,&isSeqSBAIJ);CHKERRQ(ierr); 108251f4c67SDmitry Karpeev ierr = PetscObjectTypeCompare((PetscObject)A,MATMPISBAIJ,&isMpiSBAIJ);CHKERRQ(ierr); 1093bf14a46SMatthew Knepley 110745c78f7SBarry Smith *n = A->cmap->N; 111745c78f7SBarry Smith 112745c78f7SBarry Smith /* PaStiX only needs triangular matrix if matrix is symmetric 113745c78f7SBarry Smith */ 1142205254eSKarl Rupp if (isSym && !(isSBAIJ || isSeqSBAIJ || isMpiSBAIJ)) nnz = (aa->nz - *n)/2 + *n; 1152205254eSKarl Rupp else nnz = aa->nz; 1163bf14a46SMatthew Knepley 1173bf14a46SMatthew Knepley if (!valOnly) { 118854ce69bSBarry Smith ierr = PetscMalloc1((*n)+1,colptr);CHKERRQ(ierr); 119854ce69bSBarry Smith ierr = PetscMalloc1(nnz,row);CHKERRQ(ierr); 120785e854fSJed Brown ierr = PetscMalloc1(nnz,values);CHKERRQ(ierr); 1213bf14a46SMatthew Knepley 12241c8de11SBarry Smith if (isSBAIJ || isSeqSBAIJ || isMpiSBAIJ) { 12341c8de11SBarry Smith ierr = PetscMemcpy (*colptr, rowptr, ((*n)+1)*sizeof(PetscInt));CHKERRQ(ierr); 1242205254eSKarl Rupp for (i = 0; i < *n+1; i++) (*colptr)[i] += base; 12541c8de11SBarry Smith ierr = PetscMemcpy (*row, col, (nnz)*sizeof(PetscInt));CHKERRQ(ierr); 1262205254eSKarl Rupp for (i = 0; i < nnz; i++) (*row)[i] += base; 12741c8de11SBarry Smith ierr = PetscMemcpy (*values, rvalues, (nnz)*sizeof(PetscScalar));CHKERRQ(ierr); 12841c8de11SBarry Smith } else { 129854ce69bSBarry Smith ierr = PetscMalloc1(*n,&colcount);CHKERRQ(ierr); 13041c8de11SBarry Smith 131f31ce8a6SBarry Smith for (i = 0; i < m; i++) colcount[i] = 0; 1323bf14a46SMatthew Knepley /* Fill-in colptr */ 133f31ce8a6SBarry Smith for (i = 0; i < m; i++) { 134f31ce8a6SBarry Smith for (j = rowptr[i]; j < rowptr[i+1]; j++) { 135f31ce8a6SBarry Smith if (!isSym || col[j] <= i) colcount[col[j]]++; 136f31ce8a6SBarry Smith } 137f31ce8a6SBarry Smith } 138745c78f7SBarry Smith 1393bf14a46SMatthew Knepley (*colptr)[0] = base; 1403bf14a46SMatthew Knepley for (j = 0; j < *n; j++) { 1413bf14a46SMatthew Knepley (*colptr)[j+1] = (*colptr)[j] + colcount[j]; 142745c78f7SBarry Smith /* in next loop we fill starting from (*colptr)[colidx] - base */ 1433bf14a46SMatthew Knepley colcount[j] = -base; 1443bf14a46SMatthew Knepley } 1453bf14a46SMatthew Knepley 1463bf14a46SMatthew Knepley /* Fill-in rows and values */ 1473bf14a46SMatthew Knepley for (i = 0; i < m; i++) { 1483bf14a46SMatthew Knepley for (j = rowptr[i]; j < rowptr[i+1]; j++) { 14941c8de11SBarry Smith if (!isSym || col[j] <= i) { 1503bf14a46SMatthew Knepley colidx = col[j]; 1513bf14a46SMatthew Knepley idx = (*colptr)[colidx] + colcount[colidx]; 1523bf14a46SMatthew Knepley (*row)[idx] = i + base; 1533bf14a46SMatthew Knepley (*values)[idx] = rvalues[j]; 1543bf14a46SMatthew Knepley colcount[colidx]++; 1553bf14a46SMatthew Knepley } 1563bf14a46SMatthew Knepley } 1573bf14a46SMatthew Knepley } 15841c8de11SBarry Smith ierr = PetscFree(colcount);CHKERRQ(ierr); 159745c78f7SBarry Smith } 16041c8de11SBarry Smith } else { 161745c78f7SBarry Smith /* Fill-in only values */ 1623bf14a46SMatthew Knepley for (i = 0; i < m; i++) { 1633bf14a46SMatthew Knepley for (j = rowptr[i]; j < rowptr[i+1]; j++) { 1643bf14a46SMatthew Knepley colidx = col[j]; 1652205254eSKarl Rupp if ((isSBAIJ || isSeqSBAIJ || isMpiSBAIJ) ||!isSym || col[j] <= i) { 166745c78f7SBarry Smith /* look for the value to fill */ 167f31ce8a6SBarry Smith for (k = (*colptr)[colidx] - base; k < (*colptr)[colidx + 1] - base; k++) { 168eb1f6c34SBarry Smith if (((*row)[k]-base) == i) { 1693bf14a46SMatthew Knepley (*values)[k] = rvalues[j]; 1703bf14a46SMatthew Knepley break; 1713bf14a46SMatthew Knepley } 1723bf14a46SMatthew Knepley } 173f31ce8a6SBarry Smith /* data structure of sparse matrix has changed */ 174e32f2f54SBarry Smith if (k == (*colptr)[colidx + 1] - base) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_PLIB,"overflow on k %D",k); 1753bf14a46SMatthew Knepley } 1763bf14a46SMatthew Knepley } 1773bf14a46SMatthew Knepley } 178745c78f7SBarry Smith } 179d41469e0Sxavier lacoste 180d41469e0Sxavier lacoste icntl =-1; 181d41469e0Sxavier lacoste check = 0; 182c5929fdfSBarry Smith ierr = PetscOptionsGetInt(NULL,((PetscObject) A)->prefix, "-mat_pastix_check", &icntl, &flg);CHKERRQ(ierr); 1832205254eSKarl Rupp if ((flg && icntl >= 0) || PetscLogPrintInfo) check = icntl; 1842205254eSKarl Rupp 185d41469e0Sxavier lacoste if (check == 1) { 18670fe17b1SSatish Balay PetscScalar *tmpvalues; 18770fe17b1SSatish Balay PetscInt *tmprows,*tmpcolptr; 1880f11a792SBarry Smith tmpvalues = (PetscScalar*)malloc(nnz*sizeof(PetscScalar)); if (!tmpvalues) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_MEM,"Unable to allocate memory"); 1890f11a792SBarry Smith tmprows = (PetscInt*) malloc(nnz*sizeof(PetscInt)); if (!tmprows) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_MEM,"Unable to allocate memory"); 1900f11a792SBarry Smith tmpcolptr = (PetscInt*) malloc((*n+1)*sizeof(PetscInt)); if (!tmpcolptr) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_MEM,"Unable to allocate memory"); 19143801a69SSatish Balay 19270fe17b1SSatish Balay ierr = PetscMemcpy(tmpcolptr,*colptr,(*n+1)*sizeof(PetscInt));CHKERRQ(ierr); 19370fe17b1SSatish Balay ierr = PetscMemcpy(tmprows,*row,nnz*sizeof(PetscInt));CHKERRQ(ierr); 19470fe17b1SSatish Balay ierr = PetscMemcpy(tmpvalues,*values,nnz*sizeof(PetscScalar));CHKERRQ(ierr); 19543801a69SSatish Balay ierr = PetscFree(*row);CHKERRQ(ierr); 19643801a69SSatish Balay ierr = PetscFree(*values);CHKERRQ(ierr); 19743801a69SSatish Balay 198d41469e0Sxavier lacoste icntl=-1; 199d41469e0Sxavier lacoste verb = API_VERBOSE_NOT; 200952ee8f4SMatthew G. Knepley /* "iparm[IPARM_VERBOSE] : level of printing (0 to 2)" */ 201c5929fdfSBarry Smith ierr = PetscOptionsGetInt(NULL,((PetscObject) A)->prefix, "-mat_pastix_verbose", &icntl, &flg);CHKERRQ(ierr); 202952ee8f4SMatthew G. Knepley if ((flg && icntl >= 0) || PetscLogPrintInfo) verb = icntl; 2035ec454cfSSatish Balay PASTIX_CHECKMATRIX(MPI_COMM_WORLD,verb,((isSym != 0) ? API_SYM_YES : API_SYM_NO),API_YES,*n,&tmpcolptr,&tmprows,(PastixScalar**)&tmpvalues,NULL,1); 20443801a69SSatish Balay 20570fe17b1SSatish Balay ierr = PetscMemcpy(*colptr,tmpcolptr,(*n+1)*sizeof(PetscInt));CHKERRQ(ierr); 206785e854fSJed Brown ierr = PetscMalloc1(((*colptr)[*n]-1),row);CHKERRQ(ierr); 20770fe17b1SSatish Balay ierr = PetscMemcpy(*row,tmprows,((*colptr)[*n]-1)*sizeof(PetscInt));CHKERRQ(ierr); 208785e854fSJed Brown ierr = PetscMalloc1(((*colptr)[*n]-1),values);CHKERRQ(ierr); 20970fe17b1SSatish Balay ierr = PetscMemcpy(*values,tmpvalues,((*colptr)[*n]-1)*sizeof(PetscScalar));CHKERRQ(ierr); 210be76a908SBarry Smith free(tmpvalues); 211be76a908SBarry Smith free(tmprows); 212be76a908SBarry Smith free(tmpcolptr); 213be76a908SBarry Smith 21443801a69SSatish Balay } 2153bf14a46SMatthew Knepley PetscFunctionReturn(0); 2163bf14a46SMatthew Knepley } 2173bf14a46SMatthew Knepley 2180c729824SHong Zhang #undef __FUNCT__ 2190c729824SHong Zhang #define __FUNCT__ "MatGetDiagonal_Pastix" 2200c729824SHong Zhang PetscErrorCode MatGetDiagonal_Pastix(Mat A,Vec v) 2210c729824SHong Zhang { 2220c729824SHong Zhang PetscFunctionBegin; 2230c729824SHong Zhang SETERRQ(PetscObjectComm((PetscObject)A),PETSC_ERR_SUP,"Mat type: Pastix factor"); 2240c729824SHong Zhang PetscFunctionReturn(0); 2250c729824SHong Zhang } 2263bf14a46SMatthew Knepley 2273bf14a46SMatthew Knepley #undef __FUNCT__ 2283bf14a46SMatthew Knepley #define __FUNCT__ "MatDestroy_Pastix" 2293bf14a46SMatthew Knepley /* 2303bf14a46SMatthew Knepley Call clean step of PaStiX if lu->CleanUpPastix == true. 2313bf14a46SMatthew Knepley Free the CSC matrix. 2323bf14a46SMatthew Knepley */ 2333bf14a46SMatthew Knepley PetscErrorCode MatDestroy_Pastix(Mat A) 2343bf14a46SMatthew Knepley { 2353bf14a46SMatthew Knepley Mat_Pastix *lu=(Mat_Pastix*)A->spptr; 2363bf14a46SMatthew Knepley PetscErrorCode ierr; 2373bf14a46SMatthew Knepley PetscMPIInt size=lu->commSize; 238745c78f7SBarry Smith 2393bf14a46SMatthew Knepley PetscFunctionBegin; 240bf0cc555SLisandro Dalcin if (lu && lu->CleanUpPastix) { 2413bf14a46SMatthew Knepley /* Terminate instance, deallocate memories */ 2423bf14a46SMatthew Knepley if (size > 1) { 2436bf464f9SBarry Smith ierr = VecScatterDestroy(&lu->scat_rhs);CHKERRQ(ierr); 2446bf464f9SBarry Smith ierr = VecDestroy(&lu->b_seq);CHKERRQ(ierr); 2456bf464f9SBarry Smith ierr = VecScatterDestroy(&lu->scat_sol);CHKERRQ(ierr); 2463bf14a46SMatthew Knepley } 2473bf14a46SMatthew Knepley 2483bf14a46SMatthew Knepley lu->iparm[IPARM_START_TASK]=API_TASK_CLEAN; 2493bf14a46SMatthew Knepley lu->iparm[IPARM_END_TASK] =API_TASK_CLEAN; 2503bf14a46SMatthew Knepley 251d41469e0Sxavier lacoste PASTIX_CALL(&(lu->pastix_data), 2523bf14a46SMatthew Knepley lu->pastix_comm, 253d41469e0Sxavier lacoste lu->n, 254d41469e0Sxavier lacoste lu->colptr, 255d41469e0Sxavier lacoste lu->row, 2565ec454cfSSatish Balay (PastixScalar*)lu->val, 257d41469e0Sxavier lacoste lu->perm, 258d41469e0Sxavier lacoste lu->invp, 2595ec454cfSSatish Balay (PastixScalar*)lu->rhs, 260d41469e0Sxavier lacoste lu->rhsnbr, 261d41469e0Sxavier lacoste lu->iparm, 2623bf14a46SMatthew Knepley lu->dparm); 2633bf14a46SMatthew Knepley 2643bf14a46SMatthew Knepley ierr = PetscFree(lu->colptr);CHKERRQ(ierr); 2653bf14a46SMatthew Knepley ierr = PetscFree(lu->row);CHKERRQ(ierr); 2663bf14a46SMatthew Knepley ierr = PetscFree(lu->val);CHKERRQ(ierr); 2673bf14a46SMatthew Knepley ierr = PetscFree(lu->perm);CHKERRQ(ierr); 2683bf14a46SMatthew Knepley ierr = PetscFree(lu->invp);CHKERRQ(ierr); 2693bf14a46SMatthew Knepley ierr = MPI_Comm_free(&(lu->pastix_comm));CHKERRQ(ierr); 2703bf14a46SMatthew Knepley } 271bf0cc555SLisandro Dalcin if (lu && lu->Destroy) { 272bf0cc555SLisandro Dalcin ierr = (lu->Destroy)(A);CHKERRQ(ierr); 273bf0cc555SLisandro Dalcin } 274bf0cc555SLisandro Dalcin ierr = PetscFree(A->spptr);CHKERRQ(ierr); 2753bf14a46SMatthew Knepley PetscFunctionReturn(0); 2763bf14a46SMatthew Knepley } 2773bf14a46SMatthew Knepley 2783bf14a46SMatthew Knepley #undef __FUNCT__ 2793bf14a46SMatthew Knepley #define __FUNCT__ "MatSolve_PaStiX" 2803bf14a46SMatthew Knepley /* 2813bf14a46SMatthew Knepley Gather right-hand-side. 2823bf14a46SMatthew Knepley Call for Solve step. 2833bf14a46SMatthew Knepley Scatter solution. 2843bf14a46SMatthew Knepley */ 2853bf14a46SMatthew Knepley PetscErrorCode MatSolve_PaStiX(Mat A,Vec b,Vec x) 2863bf14a46SMatthew Knepley { 2873bf14a46SMatthew Knepley Mat_Pastix *lu=(Mat_Pastix*)A->spptr; 2883bf14a46SMatthew Knepley PetscScalar *array; 2893bf14a46SMatthew Knepley Vec x_seq; 2903bf14a46SMatthew Knepley PetscErrorCode ierr; 2913bf14a46SMatthew Knepley 2923bf14a46SMatthew Knepley PetscFunctionBegin; 2933bf14a46SMatthew Knepley lu->rhsnbr = 1; 2943bf14a46SMatthew Knepley x_seq = lu->b_seq; 2953bf14a46SMatthew Knepley if (lu->commSize > 1) { 2963bf14a46SMatthew Knepley /* PaStiX only supports centralized rhs. Scatter b into a seqential rhs vector */ 2973bf14a46SMatthew Knepley ierr = VecScatterBegin(lu->scat_rhs,b,x_seq,INSERT_VALUES,SCATTER_FORWARD);CHKERRQ(ierr); 2983bf14a46SMatthew Knepley ierr = VecScatterEnd(lu->scat_rhs,b,x_seq,INSERT_VALUES,SCATTER_FORWARD);CHKERRQ(ierr); 299b5e56a35SBarry Smith ierr = VecGetArray(x_seq,&array);CHKERRQ(ierr); 30041c8de11SBarry Smith } else { /* size == 1 */ 3013bf14a46SMatthew Knepley ierr = VecCopy(b,x);CHKERRQ(ierr); 3023bf14a46SMatthew Knepley ierr = VecGetArray(x,&array);CHKERRQ(ierr); 3033bf14a46SMatthew Knepley } 3043bf14a46SMatthew Knepley lu->rhs = array; 3053bf14a46SMatthew Knepley if (lu->commSize == 1) { 3063bf14a46SMatthew Knepley ierr = VecRestoreArray(x,&array);CHKERRQ(ierr); 3073bf14a46SMatthew Knepley } else { 3083bf14a46SMatthew Knepley ierr = VecRestoreArray(x_seq,&array);CHKERRQ(ierr); 3093bf14a46SMatthew Knepley } 3103bf14a46SMatthew Knepley 3113bf14a46SMatthew Knepley /* solve phase */ 3123bf14a46SMatthew Knepley /*-------------*/ 3133bf14a46SMatthew Knepley lu->iparm[IPARM_START_TASK] = API_TASK_SOLVE; 3143bf14a46SMatthew Knepley lu->iparm[IPARM_END_TASK] = API_TASK_REFINE; 315745c78f7SBarry Smith lu->iparm[IPARM_RHS_MAKING] = API_RHS_B; 3163bf14a46SMatthew Knepley 317d41469e0Sxavier lacoste PASTIX_CALL(&(lu->pastix_data), 318d41469e0Sxavier lacoste lu->pastix_comm, 319d41469e0Sxavier lacoste lu->n, 320d41469e0Sxavier lacoste lu->colptr, 321d41469e0Sxavier lacoste lu->row, 3225ec454cfSSatish Balay (PastixScalar*)lu->val, 323d41469e0Sxavier lacoste lu->perm, 324d41469e0Sxavier lacoste lu->invp, 3255ec454cfSSatish Balay (PastixScalar*)lu->rhs, 326d41469e0Sxavier lacoste lu->rhsnbr, 327d41469e0Sxavier lacoste lu->iparm, 328d41469e0Sxavier lacoste lu->dparm); 3293bf14a46SMatthew Knepley 33065e19b50SBarry 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]); 3313bf14a46SMatthew Knepley 3323bf14a46SMatthew Knepley if (lu->commSize == 1) { 3333bf14a46SMatthew Knepley ierr = VecRestoreArray(x,&(lu->rhs));CHKERRQ(ierr); 3343bf14a46SMatthew Knepley } else { 3353bf14a46SMatthew Knepley ierr = VecRestoreArray(x_seq,&(lu->rhs));CHKERRQ(ierr); 3363bf14a46SMatthew Knepley } 3373bf14a46SMatthew Knepley 3383bf14a46SMatthew Knepley if (lu->commSize > 1) { /* convert PaStiX centralized solution to petsc mpi x */ 3393bf14a46SMatthew Knepley ierr = VecScatterBegin(lu->scat_sol,x_seq,x,INSERT_VALUES,SCATTER_FORWARD);CHKERRQ(ierr); 3403bf14a46SMatthew Knepley ierr = VecScatterEnd(lu->scat_sol,x_seq,x,INSERT_VALUES,SCATTER_FORWARD);CHKERRQ(ierr); 3413bf14a46SMatthew Knepley } 3423bf14a46SMatthew Knepley PetscFunctionReturn(0); 3433bf14a46SMatthew Knepley } 3443bf14a46SMatthew Knepley 3453bf14a46SMatthew Knepley /* 3463bf14a46SMatthew Knepley Numeric factorisation using PaStiX solver. 3473bf14a46SMatthew Knepley 3483bf14a46SMatthew Knepley */ 3493bf14a46SMatthew Knepley #undef __FUNCT__ 35053c77d0aSJed Brown #define __FUNCT__ "MatFactorNumeric_PaStiX" 3513bf14a46SMatthew Knepley PetscErrorCode MatFactorNumeric_PaStiX(Mat F,Mat A,const MatFactorInfo *info) 3523bf14a46SMatthew Knepley { 3533bf14a46SMatthew Knepley Mat_Pastix *lu =(Mat_Pastix*)(F)->spptr; 35441c8de11SBarry Smith Mat *tseq; 3553bf14a46SMatthew Knepley PetscErrorCode ierr = 0; 356b5e56a35SBarry Smith PetscInt icntl; 357b5e56a35SBarry Smith PetscInt M=A->rmap->N; 358ace3abfcSBarry Smith PetscBool valOnly,flg, isSym; 3593bf14a46SMatthew Knepley Mat F_diag; 3603bf14a46SMatthew Knepley IS is_iden; 3613bf14a46SMatthew Knepley Vec b; 3623bf14a46SMatthew Knepley IS isrow; 36351a30905SBarry Smith PetscBool isSeqAIJ,isSeqSBAIJ,isMPIAIJ; 3643bf14a46SMatthew Knepley 3653bf14a46SMatthew Knepley PetscFunctionBegin; 366251f4c67SDmitry Karpeev ierr = PetscObjectTypeCompare((PetscObject)A,MATSEQAIJ,&isSeqAIJ);CHKERRQ(ierr); 367251f4c67SDmitry Karpeev ierr = PetscObjectTypeCompare((PetscObject)A,MATMPIAIJ,&isMPIAIJ);CHKERRQ(ierr); 368251f4c67SDmitry Karpeev ierr = PetscObjectTypeCompare((PetscObject)A,MATSEQSBAIJ,&isSeqSBAIJ);CHKERRQ(ierr); 3693bf14a46SMatthew Knepley if (lu->matstruc == DIFFERENT_NONZERO_PATTERN) { 3703bf14a46SMatthew Knepley (F)->ops->solve = MatSolve_PaStiX; 3713bf14a46SMatthew Knepley 3723bf14a46SMatthew Knepley /* Initialize a PASTIX instance */ 373ce94432eSBarry Smith ierr = MPI_Comm_dup(PetscObjectComm((PetscObject)A),&(lu->pastix_comm));CHKERRQ(ierr); 3743bf14a46SMatthew Knepley ierr = MPI_Comm_rank(lu->pastix_comm, &lu->commRank);CHKERRQ(ierr); 3753bf14a46SMatthew Knepley ierr = MPI_Comm_size(lu->pastix_comm, &lu->commSize);CHKERRQ(ierr); 3763bf14a46SMatthew Knepley 3773bf14a46SMatthew Knepley /* Set pastix options */ 3783bf14a46SMatthew Knepley lu->iparm[IPARM_MODIFY_PARAMETER] = API_NO; 3793bf14a46SMatthew Knepley lu->iparm[IPARM_START_TASK] = API_TASK_INIT; 3803bf14a46SMatthew Knepley lu->iparm[IPARM_END_TASK] = API_TASK_INIT; 3812205254eSKarl Rupp 3823bf14a46SMatthew Knepley lu->rhsnbr = 1; 3833bf14a46SMatthew Knepley 3843bf14a46SMatthew Knepley /* Call to set default pastix options */ 385d41469e0Sxavier lacoste PASTIX_CALL(&(lu->pastix_data), 386d41469e0Sxavier lacoste lu->pastix_comm, 387d41469e0Sxavier lacoste lu->n, 388d41469e0Sxavier lacoste lu->colptr, 389d41469e0Sxavier lacoste lu->row, 3905ec454cfSSatish Balay (PastixScalar*)lu->val, 391d41469e0Sxavier lacoste lu->perm, 392d41469e0Sxavier lacoste lu->invp, 3935ec454cfSSatish Balay (PastixScalar*)lu->rhs, 394d41469e0Sxavier lacoste lu->rhsnbr, 395d41469e0Sxavier lacoste lu->iparm, 396d41469e0Sxavier lacoste lu->dparm); 3973bf14a46SMatthew Knepley 398ce94432eSBarry Smith ierr = PetscOptionsBegin(PetscObjectComm((PetscObject)A),((PetscObject)A)->prefix,"PaStiX Options","Mat");CHKERRQ(ierr); 3993bf14a46SMatthew Knepley 4003bf14a46SMatthew Knepley icntl = -1; 4012205254eSKarl Rupp 40241c8de11SBarry Smith lu->iparm[IPARM_VERBOSE] = API_VERBOSE_NOT; 4032205254eSKarl Rupp 40441c8de11SBarry Smith ierr = PetscOptionsInt("-mat_pastix_verbose","iparm[IPARM_VERBOSE] : level of printing (0 to 2)","None",lu->iparm[IPARM_VERBOSE],&icntl,&flg);CHKERRQ(ierr); 405d41469e0Sxavier lacoste if ((flg && icntl >= 0) || PetscLogPrintInfo) { 4063bf14a46SMatthew Knepley lu->iparm[IPARM_VERBOSE] = icntl; 4073bf14a46SMatthew Knepley } 4083bf14a46SMatthew Knepley icntl=-1; 409e4e47003SBarry 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); 4103bf14a46SMatthew Knepley if ((flg && icntl > 0)) { 4113bf14a46SMatthew Knepley lu->iparm[IPARM_THREAD_NBR] = icntl; 4123bf14a46SMatthew Knepley } 4133bf14a46SMatthew Knepley PetscOptionsEnd(); 4143bf14a46SMatthew Knepley valOnly = PETSC_FALSE; 41541c8de11SBarry Smith } else { 4165d6241c8SBarry Smith if (isSeqAIJ || isMPIAIJ) { 4175d6241c8SBarry Smith ierr = PetscFree(lu->colptr);CHKERRQ(ierr); 4185d6241c8SBarry Smith ierr = PetscFree(lu->row);CHKERRQ(ierr); 4195d6241c8SBarry Smith ierr = PetscFree(lu->val);CHKERRQ(ierr); 4205d6241c8SBarry Smith valOnly = PETSC_FALSE; 4215d6241c8SBarry Smith } else valOnly = PETSC_TRUE; 4223bf14a46SMatthew Knepley } 4233bf14a46SMatthew Knepley 4243bf14a46SMatthew Knepley lu->iparm[IPARM_MATRIX_VERIFICATION] = API_YES; 4253bf14a46SMatthew Knepley 4263bf14a46SMatthew Knepley /* convert mpi A to seq mat A */ 4273bf14a46SMatthew Knepley ierr = ISCreateStride(PETSC_COMM_SELF,M,0,1,&isrow);CHKERRQ(ierr); 4283bf14a46SMatthew Knepley ierr = MatGetSubMatrices(A,1,&isrow,&isrow,MAT_INITIAL_MATRIX,&tseq);CHKERRQ(ierr); 4296bf464f9SBarry Smith ierr = ISDestroy(&isrow);CHKERRQ(ierr); 4303bf14a46SMatthew Knepley 43141c8de11SBarry Smith ierr = MatConvertToCSC(*tseq,valOnly, &lu->n, &lu->colptr, &lu->row, &lu->val);CHKERRQ(ierr); 43241c8de11SBarry Smith ierr = MatIsSymmetric(*tseq,0.0,&isSym);CHKERRQ(ierr); 43341c8de11SBarry Smith ierr = MatDestroyMatrices(1,&tseq);CHKERRQ(ierr); 43441c8de11SBarry Smith 4355d6241c8SBarry Smith if (!lu->perm) { 436854ce69bSBarry Smith ierr = PetscMalloc1(lu->n,&(lu->perm));CHKERRQ(ierr); 437854ce69bSBarry Smith ierr = PetscMalloc1(lu->n,&(lu->invp));CHKERRQ(ierr); 4385d6241c8SBarry Smith } 4393bf14a46SMatthew Knepley 4403bf14a46SMatthew Knepley if (isSym) { 441745c78f7SBarry Smith /* On symmetric matrix, LLT */ 4423bf14a46SMatthew Knepley lu->iparm[IPARM_SYM] = API_SYM_YES; 44341c8de11SBarry Smith lu->iparm[IPARM_FACTORIZATION] = API_FACT_LDLT; 444f31ce8a6SBarry Smith } else { 445745c78f7SBarry Smith /* On unsymmetric matrix, LU */ 4463bf14a46SMatthew Knepley lu->iparm[IPARM_SYM] = API_SYM_NO; 4473bf14a46SMatthew Knepley lu->iparm[IPARM_FACTORIZATION] = API_FACT_LU; 4483bf14a46SMatthew Knepley } 4493bf14a46SMatthew Knepley 4503bf14a46SMatthew Knepley /*----------------*/ 4513bf14a46SMatthew Knepley if (lu->matstruc == DIFFERENT_NONZERO_PATTERN) { 4523bf14a46SMatthew Knepley if (!(isSeqAIJ || isSeqSBAIJ)) { 4533bf14a46SMatthew Knepley /* PaStiX only supports centralized rhs. Create scatter scat_rhs for repeated use in MatSolve() */ 4543bf14a46SMatthew Knepley ierr = VecCreateSeq(PETSC_COMM_SELF,A->cmap->N,&lu->b_seq);CHKERRQ(ierr); 4553bf14a46SMatthew Knepley ierr = ISCreateStride(PETSC_COMM_SELF,A->cmap->N,0,1,&is_iden);CHKERRQ(ierr); 4562a7a6963SBarry Smith ierr = MatCreateVecs(A,NULL,&b);CHKERRQ(ierr); 4573bf14a46SMatthew Knepley ierr = VecScatterCreate(b,is_iden,lu->b_seq,is_iden,&lu->scat_rhs);CHKERRQ(ierr); 4583bf14a46SMatthew Knepley ierr = VecScatterCreate(lu->b_seq,is_iden,b,is_iden,&lu->scat_sol);CHKERRQ(ierr); 4596bf464f9SBarry Smith ierr = ISDestroy(&is_iden);CHKERRQ(ierr); 4606bf464f9SBarry Smith ierr = VecDestroy(&b);CHKERRQ(ierr); 4613bf14a46SMatthew Knepley } 4623bf14a46SMatthew Knepley lu->iparm[IPARM_START_TASK] = API_TASK_ORDERING; 4633bf14a46SMatthew Knepley lu->iparm[IPARM_END_TASK] = API_TASK_NUMFACT; 4643bf14a46SMatthew Knepley 465d41469e0Sxavier lacoste PASTIX_CALL(&(lu->pastix_data), 466d41469e0Sxavier lacoste lu->pastix_comm, 467d41469e0Sxavier lacoste lu->n, 468d41469e0Sxavier lacoste lu->colptr, 469d41469e0Sxavier lacoste lu->row, 4705ec454cfSSatish Balay (PastixScalar*)lu->val, 471d41469e0Sxavier lacoste lu->perm, 472d41469e0Sxavier lacoste lu->invp, 4735ec454cfSSatish Balay (PastixScalar*)lu->rhs, 474d41469e0Sxavier lacoste lu->rhsnbr, 475d41469e0Sxavier lacoste lu->iparm, 476d41469e0Sxavier lacoste lu->dparm); 47765e19b50SBarry 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]); 47841c8de11SBarry Smith } else { 4793bf14a46SMatthew Knepley lu->iparm[IPARM_START_TASK] = API_TASK_NUMFACT; 4803bf14a46SMatthew Knepley lu->iparm[IPARM_END_TASK] = API_TASK_NUMFACT; 481d41469e0Sxavier lacoste PASTIX_CALL(&(lu->pastix_data), 482d41469e0Sxavier lacoste lu->pastix_comm, 483d41469e0Sxavier lacoste lu->n, 484d41469e0Sxavier lacoste lu->colptr, 485d41469e0Sxavier lacoste lu->row, 4865ec454cfSSatish Balay (PastixScalar*)lu->val, 487d41469e0Sxavier lacoste lu->perm, 488d41469e0Sxavier lacoste lu->invp, 4895ec454cfSSatish Balay (PastixScalar*)lu->rhs, 490d41469e0Sxavier lacoste lu->rhsnbr, 491d41469e0Sxavier lacoste lu->iparm, 492d41469e0Sxavier lacoste lu->dparm); 4933bf14a46SMatthew Knepley 49465e19b50SBarry 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]); 4953bf14a46SMatthew Knepley } 4963bf14a46SMatthew Knepley 4973bf14a46SMatthew Knepley if (lu->commSize > 1) { 498d5f3da31SBarry Smith if ((F)->factortype == MAT_FACTOR_LU) { 4993bf14a46SMatthew Knepley F_diag = ((Mat_MPIAIJ*)(F)->data)->A; 5003bf14a46SMatthew Knepley } else { 5013bf14a46SMatthew Knepley F_diag = ((Mat_MPISBAIJ*)(F)->data)->A; 5023bf14a46SMatthew Knepley } 5033bf14a46SMatthew Knepley F_diag->assembled = PETSC_TRUE; 5043bf14a46SMatthew Knepley } 5053bf14a46SMatthew Knepley (F)->assembled = PETSC_TRUE; 5063bf14a46SMatthew Knepley lu->matstruc = SAME_NONZERO_PATTERN; 5073bf14a46SMatthew Knepley lu->CleanUpPastix = PETSC_TRUE; 5083bf14a46SMatthew Knepley PetscFunctionReturn(0); 5093bf14a46SMatthew Knepley } 5103bf14a46SMatthew Knepley 5113bf14a46SMatthew Knepley /* Note the Petsc r and c permutations are ignored */ 5123bf14a46SMatthew Knepley #undef __FUNCT__ 5133bf14a46SMatthew Knepley #define __FUNCT__ "MatLUFactorSymbolic_AIJPASTIX" 5143bf14a46SMatthew Knepley PetscErrorCode MatLUFactorSymbolic_AIJPASTIX(Mat F,Mat A,IS r,IS c,const MatFactorInfo *info) 5153bf14a46SMatthew Knepley { 5163bf14a46SMatthew Knepley Mat_Pastix *lu = (Mat_Pastix*)F->spptr; 5173bf14a46SMatthew Knepley 5183bf14a46SMatthew Knepley PetscFunctionBegin; 5193bf14a46SMatthew Knepley lu->iparm[IPARM_FACTORIZATION] = API_FACT_LU; 5203bf14a46SMatthew Knepley lu->iparm[IPARM_SYM] = API_SYM_YES; 5213bf14a46SMatthew Knepley lu->matstruc = DIFFERENT_NONZERO_PATTERN; 5223bf14a46SMatthew Knepley F->ops->lufactornumeric = MatFactorNumeric_PaStiX; 5233bf14a46SMatthew Knepley PetscFunctionReturn(0); 5243bf14a46SMatthew Knepley } 5253bf14a46SMatthew Knepley 5263bf14a46SMatthew Knepley 5273bf14a46SMatthew Knepley /* Note the Petsc r permutation is ignored */ 5283bf14a46SMatthew Knepley #undef __FUNCT__ 5293bf14a46SMatthew Knepley #define __FUNCT__ "MatCholeskyFactorSymbolic_SBAIJPASTIX" 5303bf14a46SMatthew Knepley PetscErrorCode MatCholeskyFactorSymbolic_SBAIJPASTIX(Mat F,Mat A,IS r,const MatFactorInfo *info) 5313bf14a46SMatthew Knepley { 5323bf14a46SMatthew Knepley Mat_Pastix *lu = (Mat_Pastix*)(F)->spptr; 5333bf14a46SMatthew Knepley 5343bf14a46SMatthew Knepley PetscFunctionBegin; 5353bf14a46SMatthew Knepley lu->iparm[IPARM_FACTORIZATION] = API_FACT_LLT; 5363bf14a46SMatthew Knepley lu->iparm[IPARM_SYM] = API_SYM_NO; 5373bf14a46SMatthew Knepley lu->matstruc = DIFFERENT_NONZERO_PATTERN; 5383bf14a46SMatthew Knepley (F)->ops->choleskyfactornumeric = MatFactorNumeric_PaStiX; 5393bf14a46SMatthew Knepley PetscFunctionReturn(0); 5403bf14a46SMatthew Knepley } 5413bf14a46SMatthew Knepley 5423bf14a46SMatthew Knepley #undef __FUNCT__ 5433bf14a46SMatthew Knepley #define __FUNCT__ "MatView_PaStiX" 5443bf14a46SMatthew Knepley PetscErrorCode MatView_PaStiX(Mat A,PetscViewer viewer) 5453bf14a46SMatthew Knepley { 5463bf14a46SMatthew Knepley PetscErrorCode ierr; 547ace3abfcSBarry Smith PetscBool iascii; 5483bf14a46SMatthew Knepley PetscViewerFormat format; 5493bf14a46SMatthew Knepley 5503bf14a46SMatthew Knepley PetscFunctionBegin; 551251f4c67SDmitry Karpeev ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&iascii);CHKERRQ(ierr); 5523bf14a46SMatthew Knepley if (iascii) { 5533bf14a46SMatthew Knepley ierr = PetscViewerGetFormat(viewer,&format);CHKERRQ(ierr); 5543bf14a46SMatthew Knepley if (format == PETSC_VIEWER_ASCII_INFO) { 555b5e56a35SBarry Smith Mat_Pastix *lu=(Mat_Pastix*)A->spptr; 556b5e56a35SBarry Smith 557b5e56a35SBarry Smith ierr = PetscViewerASCIIPrintf(viewer,"PaStiX run parameters:\n");CHKERRQ(ierr); 558b5e56a35SBarry Smith ierr = PetscViewerASCIIPrintf(viewer," Matrix type : %s \n",((lu->iparm[IPARM_SYM] == API_SYM_YES) ? "Symmetric" : "Unsymmetric"));CHKERRQ(ierr); 559b5e56a35SBarry Smith ierr = PetscViewerASCIIPrintf(viewer," Level of printing (0,1,2): %d \n",lu->iparm[IPARM_VERBOSE]);CHKERRQ(ierr); 560b5e56a35SBarry Smith ierr = PetscViewerASCIIPrintf(viewer," Number of refinements iterations : %d \n",lu->iparm[IPARM_NBITER]);CHKERRQ(ierr); 561b5e56a35SBarry Smith ierr = PetscPrintf(PETSC_COMM_SELF," Error : %g \n",lu->dparm[DPARM_RELATIVE_ERROR]);CHKERRQ(ierr); 5623bf14a46SMatthew Knepley } 5633bf14a46SMatthew Knepley } 5643bf14a46SMatthew Knepley PetscFunctionReturn(0); 5653bf14a46SMatthew Knepley } 5663bf14a46SMatthew Knepley 5673bf14a46SMatthew Knepley 5683bf14a46SMatthew Knepley /*MC 5692692d6eeSBarry Smith MATSOLVERPASTIX - A solver package providing direct solvers (LU) for distributed 5703bf14a46SMatthew Knepley and sequential matrices via the external package PaStiX. 5713bf14a46SMatthew Knepley 572c2b89b5dSBarry Smith Use ./configure --download-pastix --download-parmetis --download-metis --download-ptscotch to have PETSc installed with PasTiX 573c2b89b5dSBarry Smith 574c2b89b5dSBarry Smith Use -pc_type lu -pc_factor_mat_solver_package pastix to us this direct solver 5753bf14a46SMatthew Knepley 5763bf14a46SMatthew Knepley Options Database Keys: 577b5e56a35SBarry Smith + -mat_pastix_verbose <0,1,2> - print level 578b5e56a35SBarry Smith - -mat_pastix_threadnbr <integer> - Set the thread number by MPI task. 5793bf14a46SMatthew Knepley 5803bf14a46SMatthew Knepley Level: beginner 5813bf14a46SMatthew Knepley 58241c8de11SBarry Smith .seealso: PCFactorSetMatSolverPackage(), MatSolverPackage 58341c8de11SBarry Smith 5843bf14a46SMatthew Knepley M*/ 5853bf14a46SMatthew Knepley 5863bf14a46SMatthew Knepley 5873bf14a46SMatthew Knepley #undef __FUNCT__ 5883bf14a46SMatthew Knepley #define __FUNCT__ "MatGetInfo_PaStiX" 5893bf14a46SMatthew Knepley PetscErrorCode MatGetInfo_PaStiX(Mat A,MatInfoType flag,MatInfo *info) 5903bf14a46SMatthew Knepley { 5913bf14a46SMatthew Knepley Mat_Pastix *lu =(Mat_Pastix*)A->spptr; 5923bf14a46SMatthew Knepley 5933bf14a46SMatthew Knepley PetscFunctionBegin; 5943bf14a46SMatthew Knepley info->block_size = 1.0; 5953bf14a46SMatthew Knepley info->nz_allocated = lu->iparm[IPARM_NNZEROS]; 5963bf14a46SMatthew Knepley info->nz_used = lu->iparm[IPARM_NNZEROS]; 5973bf14a46SMatthew Knepley info->nz_unneeded = 0.0; 5983bf14a46SMatthew Knepley info->assemblies = 0.0; 5993bf14a46SMatthew Knepley info->mallocs = 0.0; 6003bf14a46SMatthew Knepley info->memory = 0.0; 6013bf14a46SMatthew Knepley info->fill_ratio_given = 0; 6023bf14a46SMatthew Knepley info->fill_ratio_needed = 0; 6033bf14a46SMatthew Knepley info->factor_mallocs = 0; 6043bf14a46SMatthew Knepley PetscFunctionReturn(0); 6053bf14a46SMatthew Knepley } 6063bf14a46SMatthew Knepley 6073bf14a46SMatthew Knepley #undef __FUNCT__ 6083bf14a46SMatthew Knepley #define __FUNCT__ "MatFactorGetSolverPackage_pastix" 609*cc2e6a90SBarry Smith static PetscErrorCode MatFactorGetSolverPackage_pastix(Mat A,const MatSolverPackage *type) 6103bf14a46SMatthew Knepley { 6113bf14a46SMatthew Knepley PetscFunctionBegin; 6122692d6eeSBarry Smith *type = MATSOLVERPASTIX; 6133bf14a46SMatthew Knepley PetscFunctionReturn(0); 6143bf14a46SMatthew Knepley } 6153bf14a46SMatthew Knepley 6163bf14a46SMatthew Knepley /* 6173bf14a46SMatthew Knepley The seq and mpi versions of this function are the same 6183bf14a46SMatthew Knepley */ 6193bf14a46SMatthew Knepley #undef __FUNCT__ 6203bf14a46SMatthew Knepley #define __FUNCT__ "MatGetFactor_seqaij_pastix" 621*cc2e6a90SBarry Smith static PetscErrorCode MatGetFactor_seqaij_pastix(Mat A,MatFactorType ftype,Mat *F) 6223bf14a46SMatthew Knepley { 6233bf14a46SMatthew Knepley Mat B; 6243bf14a46SMatthew Knepley PetscErrorCode ierr; 6253bf14a46SMatthew Knepley Mat_Pastix *pastix; 6263bf14a46SMatthew Knepley 6273bf14a46SMatthew Knepley PetscFunctionBegin; 628e7e72b3dSBarry Smith if (ftype != MAT_FACTOR_LU) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP,"Cannot use PETSc AIJ matrices with PaStiX Cholesky, use SBAIJ matrix"); 6293bf14a46SMatthew Knepley /* Create the factorization matrix */ 630ce94432eSBarry Smith ierr = MatCreate(PetscObjectComm((PetscObject)A),&B);CHKERRQ(ierr); 6313bf14a46SMatthew Knepley ierr = MatSetSizes(B,A->rmap->n,A->cmap->n,A->rmap->N,A->cmap->N);CHKERRQ(ierr); 6323bf14a46SMatthew Knepley ierr = MatSetType(B,((PetscObject)A)->type_name);CHKERRQ(ierr); 6330298fd71SBarry Smith ierr = MatSeqAIJSetPreallocation(B,0,NULL);CHKERRQ(ierr); 6343bf14a46SMatthew Knepley 6353bf14a46SMatthew Knepley B->ops->lufactorsymbolic = MatLUFactorSymbolic_AIJPASTIX; 6363bf14a46SMatthew Knepley B->ops->view = MatView_PaStiX; 6373bf14a46SMatthew Knepley B->ops->getinfo = MatGetInfo_PaStiX; 6386bdbcefdSHong Zhang B->ops->getdiagonal = MatGetDiagonal_Pastix; 6392205254eSKarl Rupp 640bdf89e91SBarry Smith ierr = PetscObjectComposeFunction((PetscObject)B,"MatFactorGetSolverPackage_C",MatFactorGetSolverPackage_pastix);CHKERRQ(ierr); 6412205254eSKarl Rupp 642d5f3da31SBarry Smith B->factortype = MAT_FACTOR_LU; 6433bf14a46SMatthew Knepley 644b00a9115SJed Brown ierr = PetscNewLog(B,&pastix);CHKERRQ(ierr); 6452205254eSKarl Rupp 6463bf14a46SMatthew Knepley pastix->CleanUpPastix = PETSC_FALSE; 6473bf14a46SMatthew Knepley pastix->isAIJ = PETSC_TRUE; 6480298fd71SBarry Smith pastix->scat_rhs = NULL; 6490298fd71SBarry Smith pastix->scat_sol = NULL; 650bf0cc555SLisandro Dalcin pastix->Destroy = B->ops->destroy; 6513bf14a46SMatthew Knepley B->ops->destroy = MatDestroy_Pastix; 6523bf14a46SMatthew Knepley B->spptr = (void*)pastix; 6533bf14a46SMatthew Knepley 6543bf14a46SMatthew Knepley *F = B; 6553bf14a46SMatthew Knepley PetscFunctionReturn(0); 6563bf14a46SMatthew Knepley } 6573bf14a46SMatthew Knepley 6583bf14a46SMatthew Knepley #undef __FUNCT__ 6593bf14a46SMatthew Knepley #define __FUNCT__ "MatGetFactor_mpiaij_pastix" 660*cc2e6a90SBarry Smith static PetscErrorCode MatGetFactor_mpiaij_pastix(Mat A,MatFactorType ftype,Mat *F) 6613bf14a46SMatthew Knepley { 6623bf14a46SMatthew Knepley Mat B; 6633bf14a46SMatthew Knepley PetscErrorCode ierr; 6643bf14a46SMatthew Knepley Mat_Pastix *pastix; 6653bf14a46SMatthew Knepley 6663bf14a46SMatthew Knepley PetscFunctionBegin; 667e32f2f54SBarry Smith if (ftype != MAT_FACTOR_LU) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP,"Cannot use PETSc AIJ matrices with PaStiX Cholesky, use SBAIJ matrix"); 6683bf14a46SMatthew Knepley /* Create the factorization matrix */ 669ce94432eSBarry Smith ierr = MatCreate(PetscObjectComm((PetscObject)A),&B);CHKERRQ(ierr); 6703bf14a46SMatthew Knepley ierr = MatSetSizes(B,A->rmap->n,A->cmap->n,A->rmap->N,A->cmap->N);CHKERRQ(ierr); 6713bf14a46SMatthew Knepley ierr = MatSetType(B,((PetscObject)A)->type_name);CHKERRQ(ierr); 6720298fd71SBarry Smith ierr = MatSeqAIJSetPreallocation(B,0,NULL);CHKERRQ(ierr); 6730298fd71SBarry Smith ierr = MatMPIAIJSetPreallocation(B,0,NULL,0,NULL);CHKERRQ(ierr); 6743bf14a46SMatthew Knepley 6753bf14a46SMatthew Knepley B->ops->lufactorsymbolic = MatLUFactorSymbolic_AIJPASTIX; 6763bf14a46SMatthew Knepley B->ops->view = MatView_PaStiX; 6776bdbcefdSHong Zhang B->ops->getdiagonal = MatGetDiagonal_Pastix; 6782205254eSKarl Rupp 679bdf89e91SBarry Smith ierr = PetscObjectComposeFunction((PetscObject)B,"MatFactorGetSolverPackage_C",MatFactorGetSolverPackage_pastix);CHKERRQ(ierr); 6802205254eSKarl Rupp 681d5f3da31SBarry Smith B->factortype = MAT_FACTOR_LU; 6823bf14a46SMatthew Knepley 683b00a9115SJed Brown ierr = PetscNewLog(B,&pastix);CHKERRQ(ierr); 6842205254eSKarl Rupp 6853bf14a46SMatthew Knepley pastix->CleanUpPastix = PETSC_FALSE; 6863bf14a46SMatthew Knepley pastix->isAIJ = PETSC_TRUE; 6870298fd71SBarry Smith pastix->scat_rhs = NULL; 6880298fd71SBarry Smith pastix->scat_sol = NULL; 689bf0cc555SLisandro Dalcin pastix->Destroy = B->ops->destroy; 6903bf14a46SMatthew Knepley B->ops->destroy = MatDestroy_Pastix; 6913bf14a46SMatthew Knepley B->spptr = (void*)pastix; 6923bf14a46SMatthew Knepley 6933bf14a46SMatthew Knepley *F = B; 6943bf14a46SMatthew Knepley PetscFunctionReturn(0); 6953bf14a46SMatthew Knepley } 6963bf14a46SMatthew Knepley 6973bf14a46SMatthew Knepley #undef __FUNCT__ 6983bf14a46SMatthew Knepley #define __FUNCT__ "MatGetFactor_seqsbaij_pastix" 699*cc2e6a90SBarry Smith static PetscErrorCode MatGetFactor_seqsbaij_pastix(Mat A,MatFactorType ftype,Mat *F) 7003bf14a46SMatthew Knepley { 7013bf14a46SMatthew Knepley Mat B; 7023bf14a46SMatthew Knepley PetscErrorCode ierr; 7033bf14a46SMatthew Knepley Mat_Pastix *pastix; 7043bf14a46SMatthew Knepley 7053bf14a46SMatthew Knepley PetscFunctionBegin; 706e7e72b3dSBarry Smith if (ftype != MAT_FACTOR_CHOLESKY) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP,"Cannot use PETSc SBAIJ matrices with PaStiX LU, use AIJ matrix"); 7073bf14a46SMatthew Knepley /* Create the factorization matrix */ 708ce94432eSBarry Smith ierr = MatCreate(PetscObjectComm((PetscObject)A),&B);CHKERRQ(ierr); 7093bf14a46SMatthew Knepley ierr = MatSetSizes(B,A->rmap->n,A->cmap->n,A->rmap->N,A->cmap->N);CHKERRQ(ierr); 7103bf14a46SMatthew Knepley ierr = MatSetType(B,((PetscObject)A)->type_name);CHKERRQ(ierr); 7110298fd71SBarry Smith ierr = MatSeqSBAIJSetPreallocation(B,1,0,NULL);CHKERRQ(ierr); 7120298fd71SBarry Smith ierr = MatMPISBAIJSetPreallocation(B,1,0,NULL,0,NULL);CHKERRQ(ierr); 7133bf14a46SMatthew Knepley 7143bf14a46SMatthew Knepley B->ops->choleskyfactorsymbolic = MatCholeskyFactorSymbolic_SBAIJPASTIX; 7153bf14a46SMatthew Knepley B->ops->view = MatView_PaStiX; 7166bdbcefdSHong Zhang B->ops->getdiagonal = MatGetDiagonal_Pastix; 7172205254eSKarl Rupp 718bdf89e91SBarry Smith ierr = PetscObjectComposeFunction((PetscObject)B,"MatFactorGetSolverPackage_C",MatFactorGetSolverPackage_pastix);CHKERRQ(ierr); 7192205254eSKarl Rupp 720d5f3da31SBarry Smith B->factortype = MAT_FACTOR_CHOLESKY; 7213bf14a46SMatthew Knepley 722b00a9115SJed Brown ierr = PetscNewLog(B,&pastix);CHKERRQ(ierr); 7232205254eSKarl Rupp 7243bf14a46SMatthew Knepley pastix->CleanUpPastix = PETSC_FALSE; 7253bf14a46SMatthew Knepley pastix->isAIJ = PETSC_TRUE; 7260298fd71SBarry Smith pastix->scat_rhs = NULL; 7270298fd71SBarry Smith pastix->scat_sol = NULL; 728bf0cc555SLisandro Dalcin pastix->Destroy = B->ops->destroy; 7293bf14a46SMatthew Knepley B->ops->destroy = MatDestroy_Pastix; 7303bf14a46SMatthew Knepley B->spptr = (void*)pastix; 7313bf14a46SMatthew Knepley 7323bf14a46SMatthew Knepley *F = B; 7333bf14a46SMatthew Knepley PetscFunctionReturn(0); 7343bf14a46SMatthew Knepley } 7353bf14a46SMatthew Knepley 7363bf14a46SMatthew Knepley #undef __FUNCT__ 7373bf14a46SMatthew Knepley #define __FUNCT__ "MatGetFactor_mpisbaij_pastix" 738*cc2e6a90SBarry Smith static PetscErrorCode MatGetFactor_mpisbaij_pastix(Mat A,MatFactorType ftype,Mat *F) 7393bf14a46SMatthew Knepley { 7403bf14a46SMatthew Knepley Mat B; 7413bf14a46SMatthew Knepley PetscErrorCode ierr; 7423bf14a46SMatthew Knepley Mat_Pastix *pastix; 7433bf14a46SMatthew Knepley 7443bf14a46SMatthew Knepley PetscFunctionBegin; 745e32f2f54SBarry Smith if (ftype != MAT_FACTOR_CHOLESKY) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP,"Cannot use PETSc SBAIJ matrices with PaStiX LU, use AIJ matrix"); 74641c8de11SBarry Smith 7473bf14a46SMatthew Knepley /* Create the factorization matrix */ 748ce94432eSBarry Smith ierr = MatCreate(PetscObjectComm((PetscObject)A),&B);CHKERRQ(ierr); 7493bf14a46SMatthew Knepley ierr = MatSetSizes(B,A->rmap->n,A->cmap->n,A->rmap->N,A->cmap->N);CHKERRQ(ierr); 7503bf14a46SMatthew Knepley ierr = MatSetType(B,((PetscObject)A)->type_name);CHKERRQ(ierr); 7510298fd71SBarry Smith ierr = MatSeqSBAIJSetPreallocation(B,1,0,NULL);CHKERRQ(ierr); 7520298fd71SBarry Smith ierr = MatMPISBAIJSetPreallocation(B,1,0,NULL,0,NULL);CHKERRQ(ierr); 7533bf14a46SMatthew Knepley 7543bf14a46SMatthew Knepley B->ops->choleskyfactorsymbolic = MatCholeskyFactorSymbolic_SBAIJPASTIX; 7553bf14a46SMatthew Knepley B->ops->view = MatView_PaStiX; 7566bdbcefdSHong Zhang B->ops->getdiagonal = MatGetDiagonal_Pastix; 7572205254eSKarl Rupp 758bdf89e91SBarry Smith ierr = PetscObjectComposeFunction((PetscObject)B,"MatFactorGetSolverPackage_C",MatFactorGetSolverPackage_pastix);CHKERRQ(ierr); 7592205254eSKarl Rupp 760d5f3da31SBarry Smith B->factortype = MAT_FACTOR_CHOLESKY; 7613bf14a46SMatthew Knepley 762b00a9115SJed Brown ierr = PetscNewLog(B,&pastix);CHKERRQ(ierr); 7632205254eSKarl Rupp 7643bf14a46SMatthew Knepley pastix->CleanUpPastix = PETSC_FALSE; 7653bf14a46SMatthew Knepley pastix->isAIJ = PETSC_TRUE; 7660298fd71SBarry Smith pastix->scat_rhs = NULL; 7670298fd71SBarry Smith pastix->scat_sol = NULL; 768bf0cc555SLisandro Dalcin pastix->Destroy = B->ops->destroy; 7693bf14a46SMatthew Knepley B->ops->destroy = MatDestroy_Pastix; 7703bf14a46SMatthew Knepley B->spptr = (void*)pastix; 7713bf14a46SMatthew Knepley 7723bf14a46SMatthew Knepley *F = B; 7733bf14a46SMatthew Knepley PetscFunctionReturn(0); 7743bf14a46SMatthew Knepley } 775f7a08781SBarry Smith 77642c9c57cSBarry Smith #undef __FUNCT__ 77742c9c57cSBarry Smith #define __FUNCT__ "MatSolverPackageRegister_Pastix" 77829b38603SBarry Smith PETSC_EXTERN PetscErrorCode MatSolverPackageRegister_Pastix(void) 77942c9c57cSBarry Smith { 78042c9c57cSBarry Smith PetscErrorCode ierr; 78142c9c57cSBarry Smith 78242c9c57cSBarry Smith PetscFunctionBegin; 78342c9c57cSBarry Smith ierr = MatSolverPackageRegister(MATSOLVERPASTIX,MATMPIAIJ, MAT_FACTOR_LU,MatGetFactor_mpiaij_pastix);CHKERRQ(ierr); 78442c9c57cSBarry Smith ierr = MatSolverPackageRegister(MATSOLVERPASTIX,MATSEQAIJ, MAT_FACTOR_LU,MatGetFactor_seqaij_pastix);CHKERRQ(ierr); 78542c9c57cSBarry Smith ierr = MatSolverPackageRegister(MATSOLVERPASTIX,MATMPISBAIJ, MAT_FACTOR_CHOLESKY,MatGetFactor_mpisbaij_pastix);CHKERRQ(ierr); 78642c9c57cSBarry Smith ierr = MatSolverPackageRegister(MATSOLVERPASTIX,MATSEQSBAIJ, MAT_FACTOR_CHOLESKY,MatGetFactor_seqsbaij_pastix);CHKERRQ(ierr); 78742c9c57cSBarry Smith PetscFunctionReturn(0); 78842c9c57cSBarry Smith } 789