13bf14a46SMatthew Knepley #define PETSCMAT_DLL 23bf14a46SMatthew Knepley 33bf14a46SMatthew Knepley /* 43bf14a46SMatthew Knepley Provides an interface to the PaStiX sparse solver 53bf14a46SMatthew Knepley */ 63bf14a46SMatthew Knepley #include "../src/mat/impls/aij/seq/aij.h" 73bf14a46SMatthew Knepley #include "../src/mat/impls/aij/mpi/mpiaij.h" 83bf14a46SMatthew Knepley #include "../src/mat/impls/sbaij/seq/sbaij.h" 93bf14a46SMatthew Knepley #include "../src/mat/impls/sbaij/mpi/mpisbaij.h" 103bf14a46SMatthew Knepley 1143801a69SSatish Balay #if defined(PETSC_HAVE_STDLIB_H) 1243801a69SSatish Balay #include <stdlib.h> 1343801a69SSatish Balay #endif 1443801a69SSatish Balay #if defined(PETSC_HAVE_STRING_H) 1543801a69SSatish Balay #include <string.h> 1643801a69SSatish Balay #endif 1743801a69SSatish Balay 183bf14a46SMatthew Knepley EXTERN_C_BEGIN 193bf14a46SMatthew Knepley #include "pastix.h" 203bf14a46SMatthew Knepley EXTERN_C_END 213bf14a46SMatthew Knepley 223bf14a46SMatthew Knepley typedef struct Mat_Pastix_ { 233bf14a46SMatthew Knepley pastix_data_t *pastix_data; /* Pastix data storage structure */ 243bf14a46SMatthew Knepley MatStructure matstruc; 253bf14a46SMatthew Knepley PetscInt n; /* Number of columns in the matrix */ 263bf14a46SMatthew Knepley PetscInt *colptr; /* Index of first element of each column in row and val */ 273bf14a46SMatthew Knepley PetscInt *row; /* Row of each element of the matrix */ 283bf14a46SMatthew Knepley PetscScalar *val; /* Value of each element of the matrix */ 293bf14a46SMatthew Knepley PetscInt *perm; /* Permutation tabular */ 303bf14a46SMatthew Knepley PetscInt *invp; /* Reverse permutation tabular */ 313bf14a46SMatthew Knepley PetscScalar *rhs; /* Rhight-hand-side member */ 323bf14a46SMatthew Knepley PetscInt rhsnbr; /* Rhight-hand-side number (must be 1) */ 333bf14a46SMatthew Knepley PetscInt iparm[64]; /* Integer parameters */ 343bf14a46SMatthew Knepley double dparm[64]; /* Floating point parameters */ 353bf14a46SMatthew Knepley MPI_Comm pastix_comm; /* PaStiX MPI communicator */ 363bf14a46SMatthew Knepley PetscMPIInt commRank; /* MPI rank */ 373bf14a46SMatthew Knepley PetscMPIInt commSize; /* MPI communicator size */ 38ace3abfcSBarry Smith PetscBool CleanUpPastix; /* Boolean indicating if we call PaStiX clean step */ 393bf14a46SMatthew Knepley VecScatter scat_rhs; 403bf14a46SMatthew Knepley VecScatter scat_sol; 41f31ce8a6SBarry Smith Vec b_seq; 42ace3abfcSBarry Smith PetscBool isAIJ; 433bf14a46SMatthew Knepley PetscErrorCode (*MatDestroy)(Mat); 443bf14a46SMatthew Knepley } Mat_Pastix; 453bf14a46SMatthew Knepley 46*09573ac7SBarry Smith extern PetscErrorCode MatDuplicate_Pastix(Mat,MatDuplicateOption,Mat*); 473bf14a46SMatthew Knepley 48eb1f6c34SBarry Smith #undef __FUNCT__ 49eb1f6c34SBarry Smith #define __FUNCT__ "MatConvertToCSC" 503bf14a46SMatthew Knepley /* 513bf14a46SMatthew Knepley convert Petsc seqaij matrix to CSC: colptr[n], row[nz], val[nz] 523bf14a46SMatthew Knepley 533bf14a46SMatthew Knepley input: 543bf14a46SMatthew Knepley A - matrix in seqaij or mpisbaij (bs=1) format 553bf14a46SMatthew Knepley valOnly - FALSE: spaces are allocated and values are set for the CSC 563bf14a46SMatthew Knepley TRUE: Only fill values 573bf14a46SMatthew Knepley output: 583bf14a46SMatthew Knepley n - Size of the matrix 593bf14a46SMatthew Knepley colptr - Index of first element of each column in row and val 603bf14a46SMatthew Knepley row - Row of each element of the matrix 613bf14a46SMatthew Knepley values - Value of each element of the matrix 623bf14a46SMatthew Knepley */ 63ace3abfcSBarry Smith PetscErrorCode MatConvertToCSC(Mat A,PetscBool valOnly,PetscInt *n,PetscInt **colptr,PetscInt **row,PetscScalar **values) 6441c8de11SBarry Smith { 653bf14a46SMatthew Knepley Mat_SeqAIJ *aa = (Mat_SeqAIJ*)A->data; 663bf14a46SMatthew Knepley PetscInt *rowptr = aa->i; 673bf14a46SMatthew Knepley PetscInt *col = aa->j; 683bf14a46SMatthew Knepley PetscScalar *rvalues = aa->a; 693bf14a46SMatthew Knepley PetscInt m = A->rmap->N; 70745c78f7SBarry Smith PetscInt nnz; 713bf14a46SMatthew Knepley PetscInt i,j, k; 723bf14a46SMatthew Knepley PetscInt base = 1; 733bf14a46SMatthew Knepley PetscInt idx; 743bf14a46SMatthew Knepley PetscErrorCode ierr; 753bf14a46SMatthew Knepley PetscInt colidx; 763bf14a46SMatthew Knepley PetscInt *colcount; 77ace3abfcSBarry Smith PetscBool isSBAIJ; 78ace3abfcSBarry Smith PetscBool isSeqSBAIJ; 79ace3abfcSBarry Smith PetscBool isMpiSBAIJ; 80ace3abfcSBarry Smith PetscBool isSym; 813bf14a46SMatthew Knepley 823bf14a46SMatthew Knepley PetscFunctionBegin; 8341c8de11SBarry Smith ierr = MatIsSymmetric(A,0.0,&isSym);CHKERRQ(ierr); 8441c8de11SBarry Smith ierr = PetscTypeCompare((PetscObject)A,MATSBAIJ,&isSBAIJ);CHKERRQ(ierr); 8541c8de11SBarry Smith ierr = PetscTypeCompare((PetscObject)A,MATSEQSBAIJ,&isSeqSBAIJ);CHKERRQ(ierr); 8641c8de11SBarry Smith ierr = PetscTypeCompare((PetscObject)A,MATMPISBAIJ,&isMpiSBAIJ);CHKERRQ(ierr); 873bf14a46SMatthew Knepley 88745c78f7SBarry Smith *n = A->cmap->N; 89745c78f7SBarry Smith 90745c78f7SBarry Smith /* PaStiX only needs triangular matrix if matrix is symmetric 91745c78f7SBarry Smith */ 9241c8de11SBarry Smith if (isSym && !(isSBAIJ || isSeqSBAIJ || isMpiSBAIJ)) { 93745c78f7SBarry Smith nnz = (aa->nz - *n)/2 + *n; 94745c78f7SBarry Smith } 9541c8de11SBarry Smith else { 96745c78f7SBarry Smith nnz = aa->nz; 973bf14a46SMatthew Knepley } 983bf14a46SMatthew Knepley 993bf14a46SMatthew Knepley if (!valOnly){ 1003bf14a46SMatthew Knepley ierr = PetscMalloc(((*n)+1) *sizeof(PetscInt) ,colptr );CHKERRQ(ierr); 1013bf14a46SMatthew Knepley ierr = PetscMalloc( nnz *sizeof(PetscInt) ,row);CHKERRQ(ierr); 1023bf14a46SMatthew Knepley ierr = PetscMalloc( nnz *sizeof(PetscScalar),values);CHKERRQ(ierr); 1033bf14a46SMatthew Knepley 10441c8de11SBarry Smith if (isSBAIJ || isSeqSBAIJ || isMpiSBAIJ) { 10541c8de11SBarry Smith ierr = PetscMemcpy (*colptr, rowptr, ((*n)+1)*sizeof(PetscInt));CHKERRQ(ierr); 10641c8de11SBarry Smith for (i = 0; i < *n+1; i++) 10741c8de11SBarry Smith (*colptr)[i] += base; 10841c8de11SBarry Smith ierr = PetscMemcpy (*row, col, (nnz)*sizeof(PetscInt));CHKERRQ(ierr); 10941c8de11SBarry Smith for (i = 0; i < nnz; i++) 11041c8de11SBarry Smith (*row)[i] += base; 11141c8de11SBarry Smith ierr = PetscMemcpy (*values, rvalues, (nnz)*sizeof(PetscScalar));CHKERRQ(ierr); 11241c8de11SBarry Smith } else { 11341c8de11SBarry Smith ierr = PetscMalloc((*n)*sizeof(PetscInt) ,&colcount);CHKERRQ(ierr); 11441c8de11SBarry Smith 115f31ce8a6SBarry Smith for (i = 0; i < m; i++) colcount[i] = 0; 1163bf14a46SMatthew Knepley /* Fill-in colptr */ 117f31ce8a6SBarry Smith for (i = 0; i < m; i++) { 118f31ce8a6SBarry Smith for (j = rowptr[i]; j < rowptr[i+1]; j++) { 119f31ce8a6SBarry Smith if (!isSym || col[j] <= i) colcount[col[j]]++; 120f31ce8a6SBarry Smith } 121f31ce8a6SBarry Smith } 122745c78f7SBarry Smith 1233bf14a46SMatthew Knepley (*colptr)[0] = base; 1243bf14a46SMatthew Knepley for (j = 0; j < *n; j++) { 1253bf14a46SMatthew Knepley (*colptr)[j+1] = (*colptr)[j] + colcount[j]; 126745c78f7SBarry Smith /* in next loop we fill starting from (*colptr)[colidx] - base */ 1273bf14a46SMatthew Knepley colcount[j] = -base; 1283bf14a46SMatthew Knepley } 1293bf14a46SMatthew Knepley 1303bf14a46SMatthew Knepley /* Fill-in rows and values */ 1313bf14a46SMatthew Knepley for (i = 0; i < m; i++) { 1323bf14a46SMatthew Knepley for (j = rowptr[i]; j < rowptr[i+1]; j++) { 13341c8de11SBarry Smith if (!isSym || col[j] <= i) { 1343bf14a46SMatthew Knepley colidx = col[j]; 1353bf14a46SMatthew Knepley idx = (*colptr)[colidx] + colcount[colidx]; 1363bf14a46SMatthew Knepley (*row)[idx] = i + base; 1373bf14a46SMatthew Knepley (*values)[idx] = rvalues[j]; 1383bf14a46SMatthew Knepley colcount[colidx]++; 1393bf14a46SMatthew Knepley } 1403bf14a46SMatthew Knepley } 1413bf14a46SMatthew Knepley } 14241c8de11SBarry Smith ierr = PetscFree(colcount);CHKERRQ(ierr); 143745c78f7SBarry Smith } 14441c8de11SBarry Smith } else { 145745c78f7SBarry Smith /* Fill-in only values */ 1463bf14a46SMatthew Knepley for (i = 0; i < m; i++) { 1473bf14a46SMatthew Knepley for (j = rowptr[i]; j < rowptr[i+1]; j++) { 1483bf14a46SMatthew Knepley colidx = col[j]; 14941c8de11SBarry Smith if ((isSBAIJ || isSeqSBAIJ || isMpiSBAIJ) ||!isSym || col[j] <= i) 150745c78f7SBarry Smith { 151745c78f7SBarry Smith /* look for the value to fill */ 152f31ce8a6SBarry Smith for (k = (*colptr)[colidx] - base; k < (*colptr)[colidx + 1] - base; k++) { 153eb1f6c34SBarry Smith if (((*row)[k]-base) == i) { 1543bf14a46SMatthew Knepley (*values)[k] = rvalues[j]; 1553bf14a46SMatthew Knepley break; 1563bf14a46SMatthew Knepley } 1573bf14a46SMatthew Knepley } 158f31ce8a6SBarry Smith /* data structure of sparse matrix has changed */ 159e32f2f54SBarry Smith if (k == (*colptr)[colidx + 1] - base) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_PLIB,"overflow on k %D",k); 1603bf14a46SMatthew Knepley } 1613bf14a46SMatthew Knepley } 1623bf14a46SMatthew Knepley } 163745c78f7SBarry Smith } 16443801a69SSatish Balay { 16570fe17b1SSatish Balay PetscScalar *tmpvalues; 16670fe17b1SSatish Balay PetscInt *tmprows,*tmpcolptr; 16770fe17b1SSatish Balay ierr = PetscMalloc3(nnz,PetscScalar,&tmpvalues,nnz,PetscInt,&tmprows,(*n+1),PetscInt,&tmpcolptr);CHKERRQ(ierr); 16870fe17b1SSatish Balay ierr = PetscMemcpy(tmpcolptr,*colptr,(*n+1)*sizeof(PetscInt));CHKERRQ(ierr); 16970fe17b1SSatish Balay ierr = PetscMemcpy(tmprows,*row,nnz*sizeof(PetscInt));CHKERRQ(ierr); 17070fe17b1SSatish Balay ierr = PetscMemcpy(tmpvalues,*values,nnz*sizeof(PetscScalar));CHKERRQ(ierr); 17143801a69SSatish Balay ierr = PetscFree(*row);CHKERRQ(ierr); 17243801a69SSatish Balay ierr = PetscFree(*values);CHKERRQ(ierr); 17343801a69SSatish Balay 174f31ce8a6SBarry Smith pastix_checkMatrix(MPI_COMM_WORLD,API_VERBOSE_NO,((isSym != 0) ? API_SYM_YES : API_SYM_NO),API_YES,*n,&tmpcolptr,&tmprows,&tmpvalues,NULL,1); 17543801a69SSatish Balay 17670fe17b1SSatish Balay ierr = PetscMemcpy(*colptr,tmpcolptr,(*n+1)*sizeof(PetscInt));CHKERRQ(ierr); 17743801a69SSatish Balay ierr = PetscMalloc(((*colptr)[*n]-1)*sizeof(PetscInt),row);CHKERRQ(ierr); 17870fe17b1SSatish Balay ierr = PetscMemcpy(*row,tmprows,((*colptr)[*n]-1)*sizeof(PetscInt));CHKERRQ(ierr); 17943801a69SSatish Balay ierr = PetscMalloc(((*colptr)[*n]-1)*sizeof(PetscScalar),values);CHKERRQ(ierr); 18070fe17b1SSatish Balay ierr = PetscMemcpy(*values,tmpvalues,((*colptr)[*n]-1)*sizeof(PetscScalar));CHKERRQ(ierr); 18170fe17b1SSatish Balay ierr = PetscFree3(tmpvalues,tmprows,tmpcolptr);CHKERRQ(ierr); 18243801a69SSatish Balay } 1833bf14a46SMatthew Knepley PetscFunctionReturn(0); 1843bf14a46SMatthew Knepley } 1853bf14a46SMatthew Knepley 1863bf14a46SMatthew Knepley 1873bf14a46SMatthew Knepley 1883bf14a46SMatthew Knepley #undef __FUNCT__ 1893bf14a46SMatthew Knepley #define __FUNCT__ "MatDestroy_Pastix" 1903bf14a46SMatthew Knepley /* 1913bf14a46SMatthew Knepley Call clean step of PaStiX if lu->CleanUpPastix == true. 1923bf14a46SMatthew Knepley Free the CSC matrix. 1933bf14a46SMatthew Knepley */ 1943bf14a46SMatthew Knepley PetscErrorCode MatDestroy_Pastix(Mat A) 1953bf14a46SMatthew Knepley { 1963bf14a46SMatthew Knepley Mat_Pastix *lu=(Mat_Pastix*)A->spptr; 1973bf14a46SMatthew Knepley PetscErrorCode ierr; 1983bf14a46SMatthew Knepley PetscMPIInt size=lu->commSize; 199745c78f7SBarry Smith 2003bf14a46SMatthew Knepley PetscFunctionBegin; 2013bf14a46SMatthew Knepley if (lu->CleanUpPastix) { 2023bf14a46SMatthew Knepley /* Terminate instance, deallocate memories */ 2033bf14a46SMatthew Knepley if (size > 1){ 2043bf14a46SMatthew Knepley ierr = VecScatterDestroy(lu->scat_rhs);CHKERRQ(ierr); 2053bf14a46SMatthew Knepley ierr = VecDestroy(lu->b_seq);CHKERRQ(ierr); 206f31ce8a6SBarry Smith ierr = VecScatterDestroy(lu->scat_sol);CHKERRQ(ierr); 2073bf14a46SMatthew Knepley } 2083bf14a46SMatthew Knepley 2093bf14a46SMatthew Knepley lu->iparm[IPARM_START_TASK]=API_TASK_CLEAN; 2103bf14a46SMatthew Knepley lu->iparm[IPARM_END_TASK]=API_TASK_CLEAN; 2113bf14a46SMatthew Knepley 2123bf14a46SMatthew Knepley pastix((pastix_data_t **)&(lu->pastix_data), 2133bf14a46SMatthew Knepley lu->pastix_comm, 2143bf14a46SMatthew Knepley (pastix_int_t) lu->n, 2153bf14a46SMatthew Knepley (pastix_int_t*) lu->colptr, 2163bf14a46SMatthew Knepley (pastix_int_t*) lu->row, 2173bf14a46SMatthew Knepley (pastix_float_t*) lu->val, 2183bf14a46SMatthew Knepley (pastix_int_t*) lu->perm, 2193bf14a46SMatthew Knepley (pastix_int_t*) lu->invp, 2203bf14a46SMatthew Knepley (pastix_float_t*) lu->rhs, 2213bf14a46SMatthew Knepley (pastix_int_t) lu->rhsnbr, 2223bf14a46SMatthew Knepley (pastix_int_t*) lu->iparm, 2233bf14a46SMatthew Knepley lu->dparm); 2243bf14a46SMatthew Knepley 2253bf14a46SMatthew Knepley ierr = PetscFree(lu->colptr);CHKERRQ(ierr); 2263bf14a46SMatthew Knepley ierr = PetscFree(lu->row); CHKERRQ(ierr); 2273bf14a46SMatthew Knepley ierr = PetscFree(lu->val); CHKERRQ(ierr); 2283bf14a46SMatthew Knepley ierr = PetscFree(lu->perm); CHKERRQ(ierr); 2293bf14a46SMatthew Knepley ierr = PetscFree(lu->invp); CHKERRQ(ierr); 2303bf14a46SMatthew Knepley ierr = MPI_Comm_free(&(lu->pastix_comm));CHKERRQ(ierr); 2313bf14a46SMatthew Knepley } 2323bf14a46SMatthew Knepley ierr = (lu->MatDestroy)(A);CHKERRQ(ierr); 2333bf14a46SMatthew Knepley PetscFunctionReturn(0); 2343bf14a46SMatthew Knepley } 2353bf14a46SMatthew Knepley 2363bf14a46SMatthew Knepley #undef __FUNCT__ 2373bf14a46SMatthew Knepley #define __FUNCT__ "MatSolve_PaStiX" 2383bf14a46SMatthew Knepley /* 2393bf14a46SMatthew Knepley Gather right-hand-side. 2403bf14a46SMatthew Knepley Call for Solve step. 2413bf14a46SMatthew Knepley Scatter solution. 2423bf14a46SMatthew Knepley */ 2433bf14a46SMatthew Knepley PetscErrorCode MatSolve_PaStiX(Mat A,Vec b,Vec x) 2443bf14a46SMatthew Knepley { 2453bf14a46SMatthew Knepley Mat_Pastix *lu=(Mat_Pastix*)A->spptr; 2463bf14a46SMatthew Knepley PetscScalar *array; 2473bf14a46SMatthew Knepley Vec x_seq; 2483bf14a46SMatthew Knepley PetscErrorCode ierr; 2493bf14a46SMatthew Knepley 2503bf14a46SMatthew Knepley PetscFunctionBegin; 2513bf14a46SMatthew Knepley lu->rhsnbr = 1; 2523bf14a46SMatthew Knepley x_seq = lu->b_seq; 2533bf14a46SMatthew Knepley if (lu->commSize > 1){ 2543bf14a46SMatthew Knepley /* PaStiX only supports centralized rhs. Scatter b into a seqential rhs vector */ 2553bf14a46SMatthew Knepley ierr = VecScatterBegin(lu->scat_rhs,b,x_seq,INSERT_VALUES,SCATTER_FORWARD);CHKERRQ(ierr); 2563bf14a46SMatthew Knepley ierr = VecScatterEnd(lu->scat_rhs,b,x_seq,INSERT_VALUES,SCATTER_FORWARD);CHKERRQ(ierr); 257b5e56a35SBarry Smith ierr = VecGetArray(x_seq,&array);CHKERRQ(ierr); 25841c8de11SBarry Smith } else { /* size == 1 */ 2593bf14a46SMatthew Knepley ierr = VecCopy(b,x);CHKERRQ(ierr); 2603bf14a46SMatthew Knepley ierr = VecGetArray(x,&array);CHKERRQ(ierr); 2613bf14a46SMatthew Knepley } 2623bf14a46SMatthew Knepley lu->rhs = array; 2633bf14a46SMatthew Knepley if (lu->commSize == 1){ 2643bf14a46SMatthew Knepley ierr = VecRestoreArray(x,&array);CHKERRQ(ierr); 2653bf14a46SMatthew Knepley } else { 2663bf14a46SMatthew Knepley ierr = VecRestoreArray(x_seq,&array);CHKERRQ(ierr); 2673bf14a46SMatthew Knepley } 2683bf14a46SMatthew Knepley 2693bf14a46SMatthew Knepley /* solve phase */ 2703bf14a46SMatthew Knepley /*-------------*/ 2713bf14a46SMatthew Knepley lu->iparm[IPARM_START_TASK] = API_TASK_SOLVE; 2723bf14a46SMatthew Knepley lu->iparm[IPARM_END_TASK] = API_TASK_REFINE; 273745c78f7SBarry Smith lu->iparm[IPARM_RHS_MAKING] = API_RHS_B; 2743bf14a46SMatthew Knepley 2753bf14a46SMatthew Knepley pastix((pastix_data_t **)&(lu->pastix_data), 2763bf14a46SMatthew Knepley (MPI_Comm) lu->pastix_comm, 2773bf14a46SMatthew Knepley (pastix_int_t) lu->n, 2783bf14a46SMatthew Knepley (pastix_int_t*) lu->colptr, 2793bf14a46SMatthew Knepley (pastix_int_t*) lu->row, 2803bf14a46SMatthew Knepley (pastix_float_t*) lu->val, 2813bf14a46SMatthew Knepley (pastix_int_t*) lu->perm, 2823bf14a46SMatthew Knepley (pastix_int_t*) lu->invp, 2833bf14a46SMatthew Knepley (pastix_float_t*) lu->rhs, 2843bf14a46SMatthew Knepley (pastix_int_t) lu->rhsnbr, 2853bf14a46SMatthew Knepley (pastix_int_t*) lu->iparm, 2863bf14a46SMatthew Knepley (double*) lu->dparm); 2873bf14a46SMatthew Knepley 28865e19b50SBarry 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] ); 2893bf14a46SMatthew Knepley 2903bf14a46SMatthew Knepley if (lu->commSize == 1){ 2913bf14a46SMatthew Knepley ierr = VecRestoreArray(x,&(lu->rhs));CHKERRQ(ierr); 2923bf14a46SMatthew Knepley } else { 2933bf14a46SMatthew Knepley ierr = VecRestoreArray(x_seq,&(lu->rhs));CHKERRQ(ierr); 2943bf14a46SMatthew Knepley } 2953bf14a46SMatthew Knepley 2963bf14a46SMatthew Knepley if (lu->commSize > 1) { /* convert PaStiX centralized solution to petsc mpi x */ 2973bf14a46SMatthew Knepley ierr = VecScatterBegin(lu->scat_sol,x_seq,x,INSERT_VALUES,SCATTER_FORWARD);CHKERRQ(ierr); 2983bf14a46SMatthew Knepley ierr = VecScatterEnd(lu->scat_sol,x_seq,x,INSERT_VALUES,SCATTER_FORWARD);CHKERRQ(ierr); 2993bf14a46SMatthew Knepley } 3003bf14a46SMatthew Knepley PetscFunctionReturn(0); 3013bf14a46SMatthew Knepley } 3023bf14a46SMatthew Knepley 3033bf14a46SMatthew Knepley /* 3043bf14a46SMatthew Knepley Numeric factorisation using PaStiX solver. 3053bf14a46SMatthew Knepley 3063bf14a46SMatthew Knepley */ 3073bf14a46SMatthew Knepley #undef __FUNCT__ 30853c77d0aSJed Brown #define __FUNCT__ "MatFactorNumeric_PaStiX" 3093bf14a46SMatthew Knepley PetscErrorCode MatFactorNumeric_PaStiX(Mat F,Mat A,const MatFactorInfo *info) 3103bf14a46SMatthew Knepley { 3113bf14a46SMatthew Knepley Mat_Pastix *lu =(Mat_Pastix*)(F)->spptr; 31241c8de11SBarry Smith Mat *tseq; 3133bf14a46SMatthew Knepley PetscErrorCode ierr = 0; 314b5e56a35SBarry Smith PetscInt icntl; 315b5e56a35SBarry Smith PetscInt M=A->rmap->N; 316ace3abfcSBarry Smith PetscBool valOnly,flg, isSym; 3173bf14a46SMatthew Knepley Mat F_diag; 3183bf14a46SMatthew Knepley IS is_iden; 3193bf14a46SMatthew Knepley Vec b; 3203bf14a46SMatthew Knepley IS isrow; 321ace3abfcSBarry Smith PetscBool isSeqAIJ,isSeqSBAIJ; 3223bf14a46SMatthew Knepley 3233bf14a46SMatthew Knepley PetscFunctionBegin; 32441c8de11SBarry Smith 3253bf14a46SMatthew Knepley ierr = PetscTypeCompare((PetscObject)A,MATSEQAIJ,&isSeqAIJ);CHKERRQ(ierr); 3263bf14a46SMatthew Knepley ierr = PetscTypeCompare((PetscObject)A,MATSEQSBAIJ,&isSeqSBAIJ);CHKERRQ(ierr); 3273bf14a46SMatthew Knepley if (lu->matstruc == DIFFERENT_NONZERO_PATTERN){ 3283bf14a46SMatthew Knepley (F)->ops->solve = MatSolve_PaStiX; 3293bf14a46SMatthew Knepley 3303bf14a46SMatthew Knepley /* Initialize a PASTIX instance */ 3313bf14a46SMatthew Knepley ierr = MPI_Comm_dup(((PetscObject)A)->comm,&(lu->pastix_comm));CHKERRQ(ierr); 3323bf14a46SMatthew Knepley ierr = MPI_Comm_rank(lu->pastix_comm, &lu->commRank); CHKERRQ(ierr); 3333bf14a46SMatthew Knepley ierr = MPI_Comm_size(lu->pastix_comm, &lu->commSize); CHKERRQ(ierr); 3343bf14a46SMatthew Knepley 3353bf14a46SMatthew Knepley /* Set pastix options */ 3363bf14a46SMatthew Knepley lu->iparm[IPARM_MODIFY_PARAMETER] = API_NO; 3373bf14a46SMatthew Knepley lu->iparm[IPARM_START_TASK] = API_TASK_INIT; 3383bf14a46SMatthew Knepley lu->iparm[IPARM_END_TASK] = API_TASK_INIT; 3393bf14a46SMatthew Knepley lu->rhsnbr = 1; 3403bf14a46SMatthew Knepley 3413bf14a46SMatthew Knepley /* Call to set default pastix options */ 3423bf14a46SMatthew Knepley pastix((pastix_data_t **)&(lu->pastix_data), 3433bf14a46SMatthew Knepley (MPI_Comm) lu->pastix_comm, 3443bf14a46SMatthew Knepley (pastix_int_t) lu->n, 3453bf14a46SMatthew Knepley (pastix_int_t*) lu->colptr, 3463bf14a46SMatthew Knepley (pastix_int_t*) lu->row, 3473bf14a46SMatthew Knepley (pastix_float_t*) lu->val, 3483bf14a46SMatthew Knepley (pastix_int_t*) lu->perm, 3493bf14a46SMatthew Knepley (pastix_int_t*) lu->invp, 3503bf14a46SMatthew Knepley (pastix_float_t*) lu->rhs, 3513bf14a46SMatthew Knepley (pastix_int_t) lu->rhsnbr, 3523bf14a46SMatthew Knepley (pastix_int_t*) lu->iparm, 3533bf14a46SMatthew Knepley (double*) lu->dparm); 3543bf14a46SMatthew Knepley 3553bf14a46SMatthew Knepley ierr = PetscOptionsBegin(((PetscObject)A)->comm,((PetscObject)A)->prefix,"PaStiX Options","Mat");CHKERRQ(ierr); 3563bf14a46SMatthew Knepley 3573bf14a46SMatthew Knepley icntl=-1; 35841c8de11SBarry Smith lu->iparm[IPARM_VERBOSE] = API_VERBOSE_NOT; 35941c8de11SBarry Smith ierr = PetscOptionsInt("-mat_pastix_verbose","iparm[IPARM_VERBOSE] : level of printing (0 to 2)","None",lu->iparm[IPARM_VERBOSE],&icntl,&flg);CHKERRQ(ierr); 3603bf14a46SMatthew Knepley if ((flg && icntl > 0) || PetscLogPrintInfo) { 3613bf14a46SMatthew Knepley lu->iparm[IPARM_VERBOSE] = icntl; 3623bf14a46SMatthew Knepley } 3633bf14a46SMatthew Knepley icntl=-1; 36441c8de11SBarry Smith ierr = PetscOptionsInt("-mat_pastix_threadnbr","iparm[IPARM_THREAD_NBR] : Number of thread by MPI node","None",lu->iparm[IPARM_THREAD_NBR],&icntl,PETSC_NULL);CHKERRQ(ierr); 3653bf14a46SMatthew Knepley if ((flg && icntl > 0)) { 3663bf14a46SMatthew Knepley lu->iparm[IPARM_THREAD_NBR] = icntl; 3673bf14a46SMatthew Knepley } 3683bf14a46SMatthew Knepley PetscOptionsEnd(); 3693bf14a46SMatthew Knepley valOnly = PETSC_FALSE; 37041c8de11SBarry Smith } else { 3713bf14a46SMatthew Knepley valOnly = PETSC_TRUE; 3723bf14a46SMatthew Knepley } 3733bf14a46SMatthew Knepley 3743bf14a46SMatthew Knepley lu->iparm[IPARM_MATRIX_VERIFICATION] = API_YES; 3753bf14a46SMatthew Knepley 3763bf14a46SMatthew Knepley /* convert mpi A to seq mat A */ 3773bf14a46SMatthew Knepley ierr = ISCreateStride(PETSC_COMM_SELF,M,0,1,&isrow);CHKERRQ(ierr); 3783bf14a46SMatthew Knepley ierr = MatGetSubMatrices(A,1,&isrow,&isrow,MAT_INITIAL_MATRIX,&tseq);CHKERRQ(ierr); 3793bf14a46SMatthew Knepley ierr = ISDestroy(isrow);CHKERRQ(ierr); 3803bf14a46SMatthew Knepley 38141c8de11SBarry Smith ierr = MatConvertToCSC(*tseq,valOnly, &lu->n, &lu->colptr, &lu->row, &lu->val);CHKERRQ(ierr); 38241c8de11SBarry Smith ierr = MatIsSymmetric(*tseq,0.0,&isSym);CHKERRQ(ierr); 38341c8de11SBarry Smith ierr = MatDestroyMatrices(1,&tseq);CHKERRQ(ierr); 38441c8de11SBarry Smith 3853bf14a46SMatthew Knepley ierr = PetscMalloc((lu->n)*sizeof(PetscInt) ,&(lu->perm));CHKERRQ(ierr); 3863bf14a46SMatthew Knepley ierr = PetscMalloc((lu->n)*sizeof(PetscInt) ,&(lu->invp));CHKERRQ(ierr); 3873bf14a46SMatthew Knepley 3883bf14a46SMatthew Knepley if (isSym) { 389745c78f7SBarry Smith /* On symmetric matrix, LLT */ 3903bf14a46SMatthew Knepley lu->iparm[IPARM_SYM] = API_SYM_YES; 39141c8de11SBarry Smith lu->iparm[IPARM_FACTORIZATION] = API_FACT_LDLT; 392f31ce8a6SBarry Smith } else { 393745c78f7SBarry Smith /* On unsymmetric matrix, LU */ 3943bf14a46SMatthew Knepley lu->iparm[IPARM_SYM] = API_SYM_NO; 3953bf14a46SMatthew Knepley lu->iparm[IPARM_FACTORIZATION] = API_FACT_LU; 3963bf14a46SMatthew Knepley } 3973bf14a46SMatthew Knepley 3983bf14a46SMatthew Knepley /*----------------*/ 3993bf14a46SMatthew Knepley if (lu->matstruc == DIFFERENT_NONZERO_PATTERN){ 4003bf14a46SMatthew Knepley if (!(isSeqAIJ || isSeqSBAIJ)) { 4013bf14a46SMatthew Knepley /* PaStiX only supports centralized rhs. Create scatter scat_rhs for repeated use in MatSolve() */ 4023bf14a46SMatthew Knepley ierr = VecCreateSeq(PETSC_COMM_SELF,A->cmap->N,&lu->b_seq);CHKERRQ(ierr); 4033bf14a46SMatthew Knepley ierr = ISCreateStride(PETSC_COMM_SELF,A->cmap->N,0,1,&is_iden);CHKERRQ(ierr); 4043bf14a46SMatthew Knepley ierr = VecCreate(((PetscObject)A)->comm,&b);CHKERRQ(ierr); 4053bf14a46SMatthew Knepley ierr = VecSetSizes(b,A->rmap->n,PETSC_DECIDE);CHKERRQ(ierr); 4063bf14a46SMatthew Knepley ierr = VecSetFromOptions(b);CHKERRQ(ierr); 4073bf14a46SMatthew Knepley 4083bf14a46SMatthew Knepley ierr = VecScatterCreate(b,is_iden,lu->b_seq,is_iden,&lu->scat_rhs);CHKERRQ(ierr); 4093bf14a46SMatthew Knepley ierr = VecScatterCreate(lu->b_seq,is_iden,b,is_iden,&lu->scat_sol);CHKERRQ(ierr); 4103bf14a46SMatthew Knepley ierr = ISDestroy(is_iden);CHKERRQ(ierr); 4113bf14a46SMatthew Knepley ierr = VecDestroy(b);CHKERRQ(ierr); 4123bf14a46SMatthew Knepley } 4133bf14a46SMatthew Knepley lu->iparm[IPARM_START_TASK] = API_TASK_ORDERING; 4143bf14a46SMatthew Knepley lu->iparm[IPARM_END_TASK] = API_TASK_NUMFACT; 4153bf14a46SMatthew Knepley 4163bf14a46SMatthew Knepley pastix((pastix_data_t **)&(lu->pastix_data), 4173bf14a46SMatthew Knepley (MPI_Comm) lu->pastix_comm, 4183bf14a46SMatthew Knepley (pastix_int_t) lu->n, 4193bf14a46SMatthew Knepley (pastix_int_t*) lu->colptr, 4203bf14a46SMatthew Knepley (pastix_int_t*) lu->row, 4213bf14a46SMatthew Knepley (pastix_float_t*) lu->val, 4223bf14a46SMatthew Knepley (pastix_int_t*) lu->perm, 4233bf14a46SMatthew Knepley (pastix_int_t*) lu->invp, 4243bf14a46SMatthew Knepley (pastix_float_t*) lu->rhs, 4253bf14a46SMatthew Knepley (pastix_int_t) lu->rhsnbr, 4263bf14a46SMatthew Knepley (pastix_int_t*) lu->iparm, 4273bf14a46SMatthew Knepley (double*) lu->dparm); 42865e19b50SBarry 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]); 42941c8de11SBarry Smith } else { 4303bf14a46SMatthew Knepley lu->iparm[IPARM_START_TASK] = API_TASK_NUMFACT; 4313bf14a46SMatthew Knepley lu->iparm[IPARM_END_TASK] = API_TASK_NUMFACT; 4323bf14a46SMatthew Knepley pastix((pastix_data_t **)&(lu->pastix_data), 4333bf14a46SMatthew Knepley (MPI_Comm) lu->pastix_comm, 4343bf14a46SMatthew Knepley (pastix_int_t) lu->n, 4353bf14a46SMatthew Knepley (pastix_int_t*) lu->colptr, 4363bf14a46SMatthew Knepley (pastix_int_t*) lu->row, 4373bf14a46SMatthew Knepley (pastix_float_t*) lu->val, 4383bf14a46SMatthew Knepley (pastix_int_t*) lu->perm, 4393bf14a46SMatthew Knepley (pastix_int_t*) lu->invp, 4403bf14a46SMatthew Knepley (pastix_float_t*) lu->rhs, 4413bf14a46SMatthew Knepley (pastix_int_t) lu->rhsnbr, 4423bf14a46SMatthew Knepley (pastix_int_t*) lu->iparm, 4433bf14a46SMatthew Knepley (double*) lu->dparm); 4443bf14a46SMatthew Knepley 44565e19b50SBarry 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]); 4463bf14a46SMatthew Knepley } 4473bf14a46SMatthew Knepley 4483bf14a46SMatthew Knepley if (lu->commSize > 1){ 449d5f3da31SBarry Smith if ((F)->factortype == MAT_FACTOR_LU){ 4503bf14a46SMatthew Knepley F_diag = ((Mat_MPIAIJ *)(F)->data)->A; 4513bf14a46SMatthew Knepley } else { 4523bf14a46SMatthew Knepley F_diag = ((Mat_MPISBAIJ *)(F)->data)->A; 4533bf14a46SMatthew Knepley } 4543bf14a46SMatthew Knepley F_diag->assembled = PETSC_TRUE; 4553bf14a46SMatthew Knepley } 4563bf14a46SMatthew Knepley (F)->assembled = PETSC_TRUE; 4573bf14a46SMatthew Knepley lu->matstruc = SAME_NONZERO_PATTERN; 4583bf14a46SMatthew Knepley lu->CleanUpPastix = PETSC_TRUE; 4593bf14a46SMatthew Knepley PetscFunctionReturn(0); 4603bf14a46SMatthew Knepley } 4613bf14a46SMatthew Knepley 4623bf14a46SMatthew Knepley /* Note the Petsc r and c permutations are ignored */ 4633bf14a46SMatthew Knepley #undef __FUNCT__ 4643bf14a46SMatthew Knepley #define __FUNCT__ "MatLUFactorSymbolic_AIJPASTIX" 4653bf14a46SMatthew Knepley PetscErrorCode MatLUFactorSymbolic_AIJPASTIX(Mat F,Mat A,IS r,IS c,const MatFactorInfo *info) 4663bf14a46SMatthew Knepley { 4673bf14a46SMatthew Knepley Mat_Pastix *lu = (Mat_Pastix*)F->spptr; 4683bf14a46SMatthew Knepley 4693bf14a46SMatthew Knepley PetscFunctionBegin; 4703bf14a46SMatthew Knepley lu->iparm[IPARM_FACTORIZATION] = API_FACT_LU; 4713bf14a46SMatthew Knepley lu->iparm[IPARM_SYM] = API_SYM_YES; 4723bf14a46SMatthew Knepley lu->matstruc = DIFFERENT_NONZERO_PATTERN; 4733bf14a46SMatthew Knepley F->ops->lufactornumeric = MatFactorNumeric_PaStiX; 4743bf14a46SMatthew Knepley PetscFunctionReturn(0); 4753bf14a46SMatthew Knepley } 4763bf14a46SMatthew Knepley 4773bf14a46SMatthew Knepley 4783bf14a46SMatthew Knepley /* Note the Petsc r permutation is ignored */ 4793bf14a46SMatthew Knepley #undef __FUNCT__ 4803bf14a46SMatthew Knepley #define __FUNCT__ "MatCholeskyFactorSymbolic_SBAIJPASTIX" 4813bf14a46SMatthew Knepley PetscErrorCode MatCholeskyFactorSymbolic_SBAIJPASTIX(Mat F,Mat A,IS r,const MatFactorInfo *info) 4823bf14a46SMatthew Knepley { 4833bf14a46SMatthew Knepley Mat_Pastix *lu = (Mat_Pastix*)(F)->spptr; 4843bf14a46SMatthew Knepley 4853bf14a46SMatthew Knepley PetscFunctionBegin; 4863bf14a46SMatthew Knepley lu->iparm[IPARM_FACTORIZATION] = API_FACT_LLT; 4873bf14a46SMatthew Knepley lu->iparm[IPARM_SYM] = API_SYM_NO; 4883bf14a46SMatthew Knepley lu->matstruc = DIFFERENT_NONZERO_PATTERN; 4893bf14a46SMatthew Knepley (F)->ops->choleskyfactornumeric = MatFactorNumeric_PaStiX; 4903bf14a46SMatthew Knepley PetscFunctionReturn(0); 4913bf14a46SMatthew Knepley } 4923bf14a46SMatthew Knepley 4933bf14a46SMatthew Knepley #undef __FUNCT__ 4943bf14a46SMatthew Knepley #define __FUNCT__ "MatView_PaStiX" 4953bf14a46SMatthew Knepley PetscErrorCode MatView_PaStiX(Mat A,PetscViewer viewer) 4963bf14a46SMatthew Knepley { 4973bf14a46SMatthew Knepley PetscErrorCode ierr; 498ace3abfcSBarry Smith PetscBool iascii; 4993bf14a46SMatthew Knepley PetscViewerFormat format; 5003bf14a46SMatthew Knepley 5013bf14a46SMatthew Knepley PetscFunctionBegin; 5022692d6eeSBarry Smith ierr = PetscTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&iascii);CHKERRQ(ierr); 5033bf14a46SMatthew Knepley if (iascii) { 5043bf14a46SMatthew Knepley ierr = PetscViewerGetFormat(viewer,&format);CHKERRQ(ierr); 5053bf14a46SMatthew Knepley if (format == PETSC_VIEWER_ASCII_INFO){ 506b5e56a35SBarry Smith Mat_Pastix *lu=(Mat_Pastix*)A->spptr; 507b5e56a35SBarry Smith 508b5e56a35SBarry Smith ierr = PetscViewerASCIIPrintf(viewer,"PaStiX run parameters:\n");CHKERRQ(ierr); 509b5e56a35SBarry Smith ierr = PetscViewerASCIIPrintf(viewer," Matrix type : %s \n",((lu->iparm[IPARM_SYM] == API_SYM_YES)?"Symmetric":"Unsymmetric"));CHKERRQ(ierr); 510b5e56a35SBarry Smith ierr = PetscViewerASCIIPrintf(viewer," Level of printing (0,1,2): %d \n",lu->iparm[IPARM_VERBOSE]);CHKERRQ(ierr); 511b5e56a35SBarry Smith ierr = PetscViewerASCIIPrintf(viewer," Number of refinements iterations : %d \n",lu->iparm[IPARM_NBITER]);CHKERRQ(ierr); 512b5e56a35SBarry Smith ierr = PetscPrintf(PETSC_COMM_SELF," Error : %g \n",lu->dparm[DPARM_RELATIVE_ERROR]);CHKERRQ(ierr); 5133bf14a46SMatthew Knepley } 5143bf14a46SMatthew Knepley } 5153bf14a46SMatthew Knepley PetscFunctionReturn(0); 5163bf14a46SMatthew Knepley } 5173bf14a46SMatthew Knepley 5183bf14a46SMatthew Knepley 5193bf14a46SMatthew Knepley /*MC 5202692d6eeSBarry Smith MATSOLVERPASTIX - A solver package providing direct solvers (LU) for distributed 5213bf14a46SMatthew Knepley and sequential matrices via the external package PaStiX. 5223bf14a46SMatthew Knepley 523e2e64c6bSBarry Smith Use ./configure --download-pastix to have PETSc installed with PaStiX 5243bf14a46SMatthew Knepley 5253bf14a46SMatthew Knepley Options Database Keys: 526b5e56a35SBarry Smith + -mat_pastix_verbose <0,1,2> - print level 527b5e56a35SBarry Smith - -mat_pastix_threadnbr <integer> - Set the thread number by MPI task. 5283bf14a46SMatthew Knepley 5293bf14a46SMatthew Knepley Level: beginner 5303bf14a46SMatthew Knepley 53141c8de11SBarry Smith .seealso: PCFactorSetMatSolverPackage(), MatSolverPackage 53241c8de11SBarry Smith 5333bf14a46SMatthew Knepley M*/ 5343bf14a46SMatthew Knepley 5353bf14a46SMatthew Knepley 5363bf14a46SMatthew Knepley #undef __FUNCT__ 5373bf14a46SMatthew Knepley #define __FUNCT__ "MatGetInfo_PaStiX" 5383bf14a46SMatthew Knepley PetscErrorCode MatGetInfo_PaStiX(Mat A,MatInfoType flag,MatInfo *info) 5393bf14a46SMatthew Knepley { 5403bf14a46SMatthew Knepley Mat_Pastix *lu =(Mat_Pastix*)A->spptr; 5413bf14a46SMatthew Knepley 5423bf14a46SMatthew Knepley PetscFunctionBegin; 5433bf14a46SMatthew Knepley info->block_size = 1.0; 5443bf14a46SMatthew Knepley info->nz_allocated = lu->iparm[IPARM_NNZEROS]; 5453bf14a46SMatthew Knepley info->nz_used = lu->iparm[IPARM_NNZEROS]; 5463bf14a46SMatthew Knepley info->nz_unneeded = 0.0; 5473bf14a46SMatthew Knepley info->assemblies = 0.0; 5483bf14a46SMatthew Knepley info->mallocs = 0.0; 5493bf14a46SMatthew Knepley info->memory = 0.0; 5503bf14a46SMatthew Knepley info->fill_ratio_given = 0; 5513bf14a46SMatthew Knepley info->fill_ratio_needed = 0; 5523bf14a46SMatthew Knepley info->factor_mallocs = 0; 5533bf14a46SMatthew Knepley PetscFunctionReturn(0); 5543bf14a46SMatthew Knepley } 5553bf14a46SMatthew Knepley 5563bf14a46SMatthew Knepley EXTERN_C_BEGIN 5573bf14a46SMatthew Knepley #undef __FUNCT__ 5583bf14a46SMatthew Knepley #define __FUNCT__ "MatFactorGetSolverPackage_pastix" 5593bf14a46SMatthew Knepley PetscErrorCode MatFactorGetSolverPackage_pastix(Mat A,const MatSolverPackage *type) 5603bf14a46SMatthew Knepley { 5613bf14a46SMatthew Knepley PetscFunctionBegin; 5622692d6eeSBarry Smith *type = MATSOLVERPASTIX; 5633bf14a46SMatthew Knepley PetscFunctionReturn(0); 5643bf14a46SMatthew Knepley } 5653bf14a46SMatthew Knepley EXTERN_C_END 5663bf14a46SMatthew Knepley 5673bf14a46SMatthew Knepley EXTERN_C_BEGIN 5683bf14a46SMatthew Knepley /* 5693bf14a46SMatthew Knepley The seq and mpi versions of this function are the same 5703bf14a46SMatthew Knepley */ 5713bf14a46SMatthew Knepley #undef __FUNCT__ 5723bf14a46SMatthew Knepley #define __FUNCT__ "MatGetFactor_seqaij_pastix" 5733bf14a46SMatthew Knepley PetscErrorCode MatGetFactor_seqaij_pastix(Mat A,MatFactorType ftype,Mat *F) 5743bf14a46SMatthew Knepley { 5753bf14a46SMatthew Knepley Mat B; 5763bf14a46SMatthew Knepley PetscErrorCode ierr; 5773bf14a46SMatthew Knepley Mat_Pastix *pastix; 5783bf14a46SMatthew Knepley 5793bf14a46SMatthew Knepley PetscFunctionBegin; 580e7e72b3dSBarry Smith if (ftype != MAT_FACTOR_LU) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP,"Cannot use PETSc AIJ matrices with PaStiX Cholesky, use SBAIJ matrix"); 5813bf14a46SMatthew Knepley /* Create the factorization matrix */ 5823bf14a46SMatthew Knepley ierr = MatCreate(((PetscObject)A)->comm,&B);CHKERRQ(ierr); 5833bf14a46SMatthew Knepley ierr = MatSetSizes(B,A->rmap->n,A->cmap->n,A->rmap->N,A->cmap->N);CHKERRQ(ierr); 5843bf14a46SMatthew Knepley ierr = MatSetType(B,((PetscObject)A)->type_name);CHKERRQ(ierr); 5853bf14a46SMatthew Knepley ierr = MatSeqAIJSetPreallocation(B,0,PETSC_NULL);CHKERRQ(ierr); 5863bf14a46SMatthew Knepley 5873bf14a46SMatthew Knepley B->ops->lufactorsymbolic = MatLUFactorSymbolic_AIJPASTIX; 5883bf14a46SMatthew Knepley B->ops->view = MatView_PaStiX; 5893bf14a46SMatthew Knepley B->ops->getinfo = MatGetInfo_PaStiX; 59031e762f5SBarry Smith ierr = PetscObjectComposeFunctionDynamic((PetscObject)B,"MatFactorGetSolverPackage_C","MatFactorGetSolverPackage_pastix", MatFactorGetSolverPackage_pastix);CHKERRQ(ierr); 591d5f3da31SBarry Smith B->factortype = MAT_FACTOR_LU; 5923bf14a46SMatthew Knepley 5933bf14a46SMatthew Knepley ierr = PetscNewLog(B,Mat_Pastix,&pastix);CHKERRQ(ierr); 5943bf14a46SMatthew Knepley pastix->CleanUpPastix = PETSC_FALSE; 5953bf14a46SMatthew Knepley pastix->isAIJ = PETSC_TRUE; 5963bf14a46SMatthew Knepley pastix->scat_rhs = PETSC_NULL; 5973bf14a46SMatthew Knepley pastix->scat_sol = PETSC_NULL; 5983bf14a46SMatthew Knepley pastix->MatDestroy = B->ops->destroy; 5993bf14a46SMatthew Knepley B->ops->destroy = MatDestroy_Pastix; 6003bf14a46SMatthew Knepley B->spptr = (void*)pastix; 6013bf14a46SMatthew Knepley 6023bf14a46SMatthew Knepley *F = B; 6033bf14a46SMatthew Knepley PetscFunctionReturn(0); 6043bf14a46SMatthew Knepley } 6053bf14a46SMatthew Knepley EXTERN_C_END 6063bf14a46SMatthew Knepley 607b5e56a35SBarry Smith 6083bf14a46SMatthew Knepley EXTERN_C_BEGIN 6093bf14a46SMatthew Knepley #undef __FUNCT__ 6103bf14a46SMatthew Knepley #define __FUNCT__ "MatGetFactor_mpiaij_pastix" 6113bf14a46SMatthew Knepley PetscErrorCode MatGetFactor_mpiaij_pastix(Mat A,MatFactorType ftype,Mat *F) 6123bf14a46SMatthew Knepley { 6133bf14a46SMatthew Knepley Mat B; 6143bf14a46SMatthew Knepley PetscErrorCode ierr; 6153bf14a46SMatthew Knepley Mat_Pastix *pastix; 6163bf14a46SMatthew Knepley 6173bf14a46SMatthew Knepley PetscFunctionBegin; 618e32f2f54SBarry Smith if (ftype != MAT_FACTOR_LU) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP,"Cannot use PETSc AIJ matrices with PaStiX Cholesky, use SBAIJ matrix"); 6193bf14a46SMatthew Knepley /* Create the factorization matrix */ 6203bf14a46SMatthew Knepley ierr = MatCreate(((PetscObject)A)->comm,&B);CHKERRQ(ierr); 6213bf14a46SMatthew Knepley ierr = MatSetSizes(B,A->rmap->n,A->cmap->n,A->rmap->N,A->cmap->N);CHKERRQ(ierr); 6223bf14a46SMatthew Knepley ierr = MatSetType(B,((PetscObject)A)->type_name);CHKERRQ(ierr); 6233bf14a46SMatthew Knepley ierr = MatSeqAIJSetPreallocation(B,0,PETSC_NULL);CHKERRQ(ierr); 6243bf14a46SMatthew Knepley ierr = MatMPIAIJSetPreallocation(B,0,PETSC_NULL,0,PETSC_NULL);CHKERRQ(ierr); 6253bf14a46SMatthew Knepley 6263bf14a46SMatthew Knepley B->ops->lufactorsymbolic = MatLUFactorSymbolic_AIJPASTIX; 6273bf14a46SMatthew Knepley B->ops->view = MatView_PaStiX; 62831e762f5SBarry Smith ierr = PetscObjectComposeFunctionDynamic((PetscObject)B,"MatFactorGetSolverPackage_C","MatFactorGetSolverPackage_pastix",MatFactorGetSolverPackage_pastix);CHKERRQ(ierr); 629d5f3da31SBarry Smith B->factortype = MAT_FACTOR_LU; 6303bf14a46SMatthew Knepley 6313bf14a46SMatthew Knepley ierr = PetscNewLog(B,Mat_Pastix,&pastix);CHKERRQ(ierr); 6323bf14a46SMatthew Knepley pastix->CleanUpPastix = PETSC_FALSE; 6333bf14a46SMatthew Knepley pastix->isAIJ = PETSC_TRUE; 6343bf14a46SMatthew Knepley pastix->scat_rhs = PETSC_NULL; 6353bf14a46SMatthew Knepley pastix->scat_sol = PETSC_NULL; 6363bf14a46SMatthew Knepley pastix->MatDestroy = B->ops->destroy; 6373bf14a46SMatthew Knepley B->ops->destroy = MatDestroy_Pastix; 6383bf14a46SMatthew Knepley B->spptr = (void*)pastix; 6393bf14a46SMatthew Knepley 6403bf14a46SMatthew Knepley *F = B; 6413bf14a46SMatthew Knepley PetscFunctionReturn(0); 6423bf14a46SMatthew Knepley } 6433bf14a46SMatthew Knepley EXTERN_C_END 6443bf14a46SMatthew Knepley 6453bf14a46SMatthew Knepley EXTERN_C_BEGIN 6463bf14a46SMatthew Knepley #undef __FUNCT__ 6473bf14a46SMatthew Knepley #define __FUNCT__ "MatGetFactor_seqsbaij_pastix" 6483bf14a46SMatthew Knepley PetscErrorCode MatGetFactor_seqsbaij_pastix(Mat A,MatFactorType ftype,Mat *F) 6493bf14a46SMatthew Knepley { 6503bf14a46SMatthew Knepley Mat B; 6513bf14a46SMatthew Knepley PetscErrorCode ierr; 6523bf14a46SMatthew Knepley Mat_Pastix *pastix; 6533bf14a46SMatthew Knepley 6543bf14a46SMatthew Knepley PetscFunctionBegin; 655e7e72b3dSBarry Smith if (ftype != MAT_FACTOR_CHOLESKY) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP,"Cannot use PETSc SBAIJ matrices with PaStiX LU, use AIJ matrix"); 6563bf14a46SMatthew Knepley /* Create the factorization matrix */ 6573bf14a46SMatthew Knepley ierr = MatCreate(((PetscObject)A)->comm,&B);CHKERRQ(ierr); 6583bf14a46SMatthew Knepley ierr = MatSetSizes(B,A->rmap->n,A->cmap->n,A->rmap->N,A->cmap->N);CHKERRQ(ierr); 6593bf14a46SMatthew Knepley ierr = MatSetType(B,((PetscObject)A)->type_name);CHKERRQ(ierr); 6603bf14a46SMatthew Knepley ierr = MatSeqSBAIJSetPreallocation(B,1,0,PETSC_NULL);CHKERRQ(ierr); 6613bf14a46SMatthew Knepley ierr = MatMPISBAIJSetPreallocation(B,1,0,PETSC_NULL,0,PETSC_NULL);CHKERRQ(ierr); 6623bf14a46SMatthew Knepley 6633bf14a46SMatthew Knepley B->ops->choleskyfactorsymbolic = MatCholeskyFactorSymbolic_SBAIJPASTIX; 6643bf14a46SMatthew Knepley B->ops->view = MatView_PaStiX; 66531e762f5SBarry Smith ierr = PetscObjectComposeFunctionDynamic((PetscObject)B,"MatFactorGetSolverPackage_C","MatFactorGetSolverPackage_pastix",MatFactorGetSolverPackage_pastix);CHKERRQ(ierr); 666d5f3da31SBarry Smith B->factortype = MAT_FACTOR_CHOLESKY; 6673bf14a46SMatthew Knepley 6683bf14a46SMatthew Knepley ierr = PetscNewLog(B,Mat_Pastix,&pastix);CHKERRQ(ierr); 6693bf14a46SMatthew Knepley pastix->CleanUpPastix = PETSC_FALSE; 6703bf14a46SMatthew Knepley pastix->isAIJ = PETSC_TRUE; 6713bf14a46SMatthew Knepley pastix->scat_rhs = PETSC_NULL; 6723bf14a46SMatthew Knepley pastix->scat_sol = PETSC_NULL; 6733bf14a46SMatthew Knepley pastix->MatDestroy = B->ops->destroy; 6743bf14a46SMatthew Knepley B->ops->destroy = MatDestroy_Pastix; 6753bf14a46SMatthew Knepley B->spptr = (void*)pastix; 6763bf14a46SMatthew Knepley 6773bf14a46SMatthew Knepley *F = B; 6783bf14a46SMatthew Knepley PetscFunctionReturn(0); 6793bf14a46SMatthew Knepley } 6803bf14a46SMatthew Knepley EXTERN_C_END 6813bf14a46SMatthew Knepley 6823bf14a46SMatthew Knepley EXTERN_C_BEGIN 6833bf14a46SMatthew Knepley #undef __FUNCT__ 6843bf14a46SMatthew Knepley #define __FUNCT__ "MatGetFactor_mpisbaij_pastix" 6853bf14a46SMatthew Knepley PetscErrorCode MatGetFactor_mpisbaij_pastix(Mat A,MatFactorType ftype,Mat *F) 6863bf14a46SMatthew Knepley { 6873bf14a46SMatthew Knepley Mat B; 6883bf14a46SMatthew Knepley PetscErrorCode ierr; 6893bf14a46SMatthew Knepley Mat_Pastix *pastix; 6903bf14a46SMatthew Knepley 6913bf14a46SMatthew Knepley PetscFunctionBegin; 692e32f2f54SBarry Smith if (ftype != MAT_FACTOR_CHOLESKY) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP,"Cannot use PETSc SBAIJ matrices with PaStiX LU, use AIJ matrix"); 69341c8de11SBarry Smith 6943bf14a46SMatthew Knepley /* Create the factorization matrix */ 6953bf14a46SMatthew Knepley ierr = MatCreate(((PetscObject)A)->comm,&B);CHKERRQ(ierr); 6963bf14a46SMatthew Knepley ierr = MatSetSizes(B,A->rmap->n,A->cmap->n,A->rmap->N,A->cmap->N);CHKERRQ(ierr); 6973bf14a46SMatthew Knepley ierr = MatSetType(B,((PetscObject)A)->type_name);CHKERRQ(ierr); 6983bf14a46SMatthew Knepley ierr = MatSeqSBAIJSetPreallocation(B,1,0,PETSC_NULL);CHKERRQ(ierr); 6993bf14a46SMatthew Knepley ierr = MatMPISBAIJSetPreallocation(B,1,0,PETSC_NULL,0,PETSC_NULL);CHKERRQ(ierr); 7003bf14a46SMatthew Knepley 7013bf14a46SMatthew Knepley B->ops->choleskyfactorsymbolic = MatCholeskyFactorSymbolic_SBAIJPASTIX; 7023bf14a46SMatthew Knepley B->ops->view = MatView_PaStiX; 70331e762f5SBarry Smith ierr = PetscObjectComposeFunctionDynamic((PetscObject)B,"MatFactorGetSolverPackage_C","MatFactorGetSolverPackage_pastix",MatFactorGetSolverPackage_pastix);CHKERRQ(ierr); 704d5f3da31SBarry Smith B->factortype = MAT_FACTOR_CHOLESKY; 7053bf14a46SMatthew Knepley 7063bf14a46SMatthew Knepley ierr = PetscNewLog(B,Mat_Pastix,&pastix);CHKERRQ(ierr); 7073bf14a46SMatthew Knepley pastix->CleanUpPastix = PETSC_FALSE; 7083bf14a46SMatthew Knepley pastix->isAIJ = PETSC_TRUE; 7093bf14a46SMatthew Knepley pastix->scat_rhs = PETSC_NULL; 7103bf14a46SMatthew Knepley pastix->scat_sol = PETSC_NULL; 7113bf14a46SMatthew Knepley pastix->MatDestroy = B->ops->destroy; 7123bf14a46SMatthew Knepley B->ops->destroy = MatDestroy_Pastix; 7133bf14a46SMatthew Knepley B->spptr = (void*)pastix; 7143bf14a46SMatthew Knepley 7153bf14a46SMatthew Knepley *F = B; 7163bf14a46SMatthew Knepley PetscFunctionReturn(0); 7173bf14a46SMatthew Knepley } 7183bf14a46SMatthew Knepley EXTERN_C_END 719