14c1414c8SBarry Smith #define PETSCMAT_DLL 24c1414c8SBarry Smith 34c1414c8SBarry Smith /* 44c1414c8SBarry Smith This file provides high performance routines for the Inode format (compressed sparse row) 54c1414c8SBarry Smith by taking advantage of rows with identical nonzero structure (I-nodes). 64c1414c8SBarry Smith */ 74c1414c8SBarry Smith #include "src/mat/impls/aij/seq/aij.h" 84c1414c8SBarry Smith 94c1414c8SBarry Smith #undef __FUNCT__ 104c1414c8SBarry Smith #define __FUNCT__ "Mat_CreateColInode" 114c1414c8SBarry Smith static PetscErrorCode Mat_CreateColInode(Mat A,PetscInt* size,PetscInt ** ns) 124c1414c8SBarry Smith { 134c1414c8SBarry Smith Mat_SeqAIJ *a = (Mat_SeqAIJ*)A->data; 144c1414c8SBarry Smith PetscErrorCode ierr; 154c1414c8SBarry Smith PetscInt i,count,m,n,min_mn,*ns_row,*ns_col; 164c1414c8SBarry Smith 174c1414c8SBarry Smith PetscFunctionBegin; 184c1414c8SBarry Smith n = A->cmap.n; 194c1414c8SBarry Smith m = A->rmap.n; 204c1414c8SBarry Smith ns_row = a->inode.size; 214c1414c8SBarry Smith 224c1414c8SBarry Smith min_mn = (m < n) ? m : n; 234c1414c8SBarry Smith if (!ns) { 244c1414c8SBarry Smith for (count=0,i=0; count<min_mn; count+=ns_row[i],i++); 254c1414c8SBarry Smith for(; count+1 < n; count++,i++); 264c1414c8SBarry Smith if (count < n) { 274c1414c8SBarry Smith i++; 284c1414c8SBarry Smith } 294c1414c8SBarry Smith *size = i; 304c1414c8SBarry Smith PetscFunctionReturn(0); 314c1414c8SBarry Smith } 324c1414c8SBarry Smith ierr = PetscMalloc((n+1)*sizeof(PetscInt),&ns_col);CHKERRQ(ierr); 334c1414c8SBarry Smith 344c1414c8SBarry Smith /* Use the same row structure wherever feasible. */ 354c1414c8SBarry Smith for (count=0,i=0; count<min_mn; count+=ns_row[i],i++) { 364c1414c8SBarry Smith ns_col[i] = ns_row[i]; 374c1414c8SBarry Smith } 384c1414c8SBarry Smith 394c1414c8SBarry Smith /* if m < n; pad up the remainder with inode_limit */ 404c1414c8SBarry Smith for(; count+1 < n; count++,i++) { 414c1414c8SBarry Smith ns_col[i] = 1; 424c1414c8SBarry Smith } 434c1414c8SBarry Smith /* The last node is the odd ball. padd it up with the remaining rows; */ 444c1414c8SBarry Smith if (count < n) { 454c1414c8SBarry Smith ns_col[i] = n - count; 464c1414c8SBarry Smith i++; 474c1414c8SBarry Smith } else if (count > n) { 484c1414c8SBarry Smith /* Adjust for the over estimation */ 494c1414c8SBarry Smith ns_col[i-1] += n - count; 504c1414c8SBarry Smith } 514c1414c8SBarry Smith *size = i; 524c1414c8SBarry Smith *ns = ns_col; 534c1414c8SBarry Smith PetscFunctionReturn(0); 544c1414c8SBarry Smith } 554c1414c8SBarry Smith 564c1414c8SBarry Smith 574c1414c8SBarry Smith /* 584c1414c8SBarry Smith This builds symmetric version of nonzero structure, 594c1414c8SBarry Smith */ 604c1414c8SBarry Smith #undef __FUNCT__ 614c1414c8SBarry Smith #define __FUNCT__ "MatGetRowIJ_Inode_Symmetric" 624c1414c8SBarry Smith static PetscErrorCode MatGetRowIJ_Inode_Symmetric(Mat A,PetscInt *iia[],PetscInt *jja[],PetscInt ishift,PetscInt oshift) 634c1414c8SBarry Smith { 644c1414c8SBarry Smith Mat_SeqAIJ *a = (Mat_SeqAIJ*)A->data; 654c1414c8SBarry Smith PetscErrorCode ierr; 664c1414c8SBarry Smith PetscInt *work,*ia,*ja,*j,nz,nslim_row,nslim_col,m,row,col,*jmax,n; 674c1414c8SBarry Smith PetscInt *tns,*tvc,*ns_row = a->inode.size,*ns_col,nsz,i1,i2,*ai= a->i,*aj = a->j; 684c1414c8SBarry Smith 694c1414c8SBarry Smith PetscFunctionBegin; 704c1414c8SBarry Smith nslim_row = a->inode.node_count; 714c1414c8SBarry Smith m = A->rmap.n; 724c1414c8SBarry Smith n = A->cmap.n; 734c1414c8SBarry Smith if (m != n) SETERRQ(PETSC_ERR_SUP,"MatGetRowIJ_Inode_Symmetric: Matrix should be square"); 744c1414c8SBarry Smith 754c1414c8SBarry Smith /* Use the row_inode as column_inode */ 764c1414c8SBarry Smith nslim_col = nslim_row; 774c1414c8SBarry Smith ns_col = ns_row; 784c1414c8SBarry Smith 794c1414c8SBarry Smith /* allocate space for reformated inode structure */ 804c1414c8SBarry Smith ierr = PetscMalloc((nslim_col+1)*sizeof(PetscInt),&tns);CHKERRQ(ierr); 814c1414c8SBarry Smith ierr = PetscMalloc((n+1)*sizeof(PetscInt),&tvc);CHKERRQ(ierr); 824c1414c8SBarry Smith for (i1=0,tns[0]=0; i1<nslim_col; ++i1) tns[i1+1] = tns[i1]+ ns_row[i1]; 834c1414c8SBarry Smith 844c1414c8SBarry Smith for (i1=0,col=0; i1<nslim_col; ++i1){ 854c1414c8SBarry Smith nsz = ns_col[i1]; 864c1414c8SBarry Smith for (i2=0; i2<nsz; ++i2,++col) 874c1414c8SBarry Smith tvc[col] = i1; 884c1414c8SBarry Smith } 894c1414c8SBarry Smith /* allocate space for row pointers */ 904c1414c8SBarry Smith ierr = PetscMalloc((nslim_row+1)*sizeof(PetscInt),&ia);CHKERRQ(ierr); 914c1414c8SBarry Smith *iia = ia; 924c1414c8SBarry Smith ierr = PetscMemzero(ia,(nslim_row+1)*sizeof(PetscInt));CHKERRQ(ierr); 934c1414c8SBarry Smith ierr = PetscMalloc((nslim_row+1)*sizeof(PetscInt),&work);CHKERRQ(ierr); 944c1414c8SBarry Smith 954c1414c8SBarry Smith /* determine the number of columns in each row */ 964c1414c8SBarry Smith ia[0] = oshift; 974c1414c8SBarry Smith for (i1=0,row=0 ; i1<nslim_row; row+=ns_row[i1],i1++) { 984c1414c8SBarry Smith 994c1414c8SBarry Smith j = aj + ai[row] + ishift; 1004c1414c8SBarry Smith jmax = aj + ai[row+1] + ishift; 1014c1414c8SBarry Smith i2 = 0; 1024c1414c8SBarry Smith col = *j++ + ishift; 1034c1414c8SBarry Smith i2 = tvc[col]; 1044c1414c8SBarry Smith while (i2<i1 && j<jmax) { /* 1.[-xx-d-xx--] 2.[-xx-------],off-diagonal elemets */ 1054c1414c8SBarry Smith ia[i1+1]++; 1064c1414c8SBarry Smith ia[i2+1]++; 1074c1414c8SBarry Smith i2++; /* Start col of next node */ 1084c1414c8SBarry Smith while(((col=*j+ishift)<tns[i2]) && (j<jmax)) ++j; 1094c1414c8SBarry Smith i2 = tvc[col]; 1104c1414c8SBarry Smith } 1114c1414c8SBarry Smith if(i2 == i1) ia[i2+1]++; /* now the diagonal element */ 1124c1414c8SBarry Smith } 1134c1414c8SBarry Smith 1144c1414c8SBarry Smith /* shift ia[i] to point to next row */ 1154c1414c8SBarry Smith for (i1=1; i1<nslim_row+1; i1++) { 1164c1414c8SBarry Smith row = ia[i1-1]; 1174c1414c8SBarry Smith ia[i1] += row; 1184c1414c8SBarry Smith work[i1-1] = row - oshift; 1194c1414c8SBarry Smith } 1204c1414c8SBarry Smith 1214c1414c8SBarry Smith /* allocate space for column pointers */ 1224c1414c8SBarry Smith nz = ia[nslim_row] + (!ishift); 1234c1414c8SBarry Smith ierr = PetscMalloc(nz*sizeof(PetscInt),&ja);CHKERRQ(ierr); 1244c1414c8SBarry Smith *jja = ja; 1254c1414c8SBarry Smith 1264c1414c8SBarry Smith /* loop over lower triangular part putting into ja */ 1274c1414c8SBarry Smith for (i1=0,row=0; i1<nslim_row; row += ns_row[i1],i1++) { 1284c1414c8SBarry Smith j = aj + ai[row] + ishift; 1294c1414c8SBarry Smith jmax = aj + ai[row+1] + ishift; 1304c1414c8SBarry Smith i2 = 0; /* Col inode index */ 1314c1414c8SBarry Smith col = *j++ + ishift; 1324c1414c8SBarry Smith i2 = tvc[col]; 1334c1414c8SBarry Smith while (i2<i1 && j<jmax) { 1344c1414c8SBarry Smith ja[work[i2]++] = i1 + oshift; 1354c1414c8SBarry Smith ja[work[i1]++] = i2 + oshift; 1364c1414c8SBarry Smith ++i2; 1374c1414c8SBarry Smith while(((col=*j+ishift)< tns[i2])&&(j<jmax)) ++j; /* Skip rest col indices in this node */ 1384c1414c8SBarry Smith i2 = tvc[col]; 1394c1414c8SBarry Smith } 1404c1414c8SBarry Smith if (i2 == i1) ja[work[i1]++] = i2 + oshift; 1414c1414c8SBarry Smith 1424c1414c8SBarry Smith } 1434c1414c8SBarry Smith ierr = PetscFree(work);CHKERRQ(ierr); 1444c1414c8SBarry Smith ierr = PetscFree(tns);CHKERRQ(ierr); 1454c1414c8SBarry Smith ierr = PetscFree(tvc);CHKERRQ(ierr); 1464c1414c8SBarry Smith PetscFunctionReturn(0); 1474c1414c8SBarry Smith } 1484c1414c8SBarry Smith 1494c1414c8SBarry Smith /* 1504c1414c8SBarry Smith This builds nonsymmetric version of nonzero structure, 1514c1414c8SBarry Smith */ 1524c1414c8SBarry Smith #undef __FUNCT__ 1534c1414c8SBarry Smith #define __FUNCT__ "MatGetRowIJ_Inode_Nonsymmetric" 1544c1414c8SBarry Smith static PetscErrorCode MatGetRowIJ_Inode_Nonsymmetric(Mat A,PetscInt *iia[],PetscInt *jja[],PetscInt ishift,PetscInt oshift) 1554c1414c8SBarry Smith { 1564c1414c8SBarry Smith Mat_SeqAIJ *a = (Mat_SeqAIJ*)A->data; 1574c1414c8SBarry Smith PetscErrorCode ierr; 1584c1414c8SBarry Smith PetscInt *work,*ia,*ja,*j,nz,nslim_row,n,row,col,*ns_col,nslim_col; 1594c1414c8SBarry Smith PetscInt *tns,*tvc,*ns_row = a->inode.size,nsz,i1,i2,*ai= a->i,*aj = a->j; 1604c1414c8SBarry Smith 1614c1414c8SBarry Smith PetscFunctionBegin; 1624c1414c8SBarry Smith nslim_row = a->inode.node_count; 1634c1414c8SBarry Smith n = A->cmap.n; 1644c1414c8SBarry Smith 1654c1414c8SBarry Smith /* Create The column_inode for this matrix */ 1664c1414c8SBarry Smith ierr = Mat_CreateColInode(A,&nslim_col,&ns_col);CHKERRQ(ierr); 1674c1414c8SBarry Smith 1684c1414c8SBarry Smith /* allocate space for reformated column_inode structure */ 1694c1414c8SBarry Smith ierr = PetscMalloc((nslim_col +1)*sizeof(PetscInt),&tns);CHKERRQ(ierr); 1704c1414c8SBarry Smith ierr = PetscMalloc((n +1)*sizeof(PetscInt),&tvc);CHKERRQ(ierr); 1714c1414c8SBarry Smith for (i1=0,tns[0]=0; i1<nslim_col; ++i1) tns[i1+1] = tns[i1] + ns_col[i1]; 1724c1414c8SBarry Smith 1734c1414c8SBarry Smith for (i1=0,col=0; i1<nslim_col; ++i1){ 1744c1414c8SBarry Smith nsz = ns_col[i1]; 1754c1414c8SBarry Smith for (i2=0; i2<nsz; ++i2,++col) 1764c1414c8SBarry Smith tvc[col] = i1; 1774c1414c8SBarry Smith } 1784c1414c8SBarry Smith /* allocate space for row pointers */ 1794c1414c8SBarry Smith ierr = PetscMalloc((nslim_row+1)*sizeof(PetscInt),&ia);CHKERRQ(ierr); 1804c1414c8SBarry Smith *iia = ia; 1814c1414c8SBarry Smith ierr = PetscMemzero(ia,(nslim_row+1)*sizeof(PetscInt));CHKERRQ(ierr); 1824c1414c8SBarry Smith ierr = PetscMalloc((nslim_row+1)*sizeof(PetscInt),&work);CHKERRQ(ierr); 1834c1414c8SBarry Smith 1844c1414c8SBarry Smith /* determine the number of columns in each row */ 1854c1414c8SBarry Smith ia[0] = oshift; 1864c1414c8SBarry Smith for (i1=0,row=0; i1<nslim_row; row+=ns_row[i1],i1++) { 1874c1414c8SBarry Smith j = aj + ai[row] + ishift; 1884c1414c8SBarry Smith col = *j++ + ishift; 1894c1414c8SBarry Smith i2 = tvc[col]; 1904c1414c8SBarry Smith nz = ai[row+1] - ai[row]; 1914c1414c8SBarry Smith while (nz-- > 0) { /* off-diagonal elemets */ 1924c1414c8SBarry Smith ia[i1+1]++; 1934c1414c8SBarry Smith i2++; /* Start col of next node */ 1944c1414c8SBarry Smith while (((col = *j++ + ishift) < tns[i2]) && nz > 0) {nz--;} 1954c1414c8SBarry Smith if (nz > 0) i2 = tvc[col]; 1964c1414c8SBarry Smith } 1974c1414c8SBarry Smith } 1984c1414c8SBarry Smith 1994c1414c8SBarry Smith /* shift ia[i] to point to next row */ 2004c1414c8SBarry Smith for (i1=1; i1<nslim_row+1; i1++) { 2014c1414c8SBarry Smith row = ia[i1-1]; 2024c1414c8SBarry Smith ia[i1] += row; 2034c1414c8SBarry Smith work[i1-1] = row - oshift; 2044c1414c8SBarry Smith } 2054c1414c8SBarry Smith 2064c1414c8SBarry Smith /* allocate space for column pointers */ 2074c1414c8SBarry Smith nz = ia[nslim_row] + (!ishift); 2084c1414c8SBarry Smith ierr = PetscMalloc(nz*sizeof(PetscInt),&ja);CHKERRQ(ierr); 2094c1414c8SBarry Smith *jja = ja; 2104c1414c8SBarry Smith 2114c1414c8SBarry Smith /* loop over matrix putting into ja */ 2124c1414c8SBarry Smith for (i1=0,row=0; i1<nslim_row; row+=ns_row[i1],i1++) { 2134c1414c8SBarry Smith j = aj + ai[row] + ishift; 2144c1414c8SBarry Smith i2 = 0; /* Col inode index */ 2154c1414c8SBarry Smith col = *j++ + ishift; 2164c1414c8SBarry Smith i2 = tvc[col]; 2174c1414c8SBarry Smith nz = ai[row+1] - ai[row]; 2184c1414c8SBarry Smith while (nz-- > 0) { 2194c1414c8SBarry Smith ja[work[i1]++] = i2 + oshift; 2204c1414c8SBarry Smith ++i2; 2214c1414c8SBarry Smith while(((col = *j++ + ishift) < tns[i2]) && nz > 0) {nz--;} 2224c1414c8SBarry Smith if (nz > 0) i2 = tvc[col]; 2234c1414c8SBarry Smith } 2244c1414c8SBarry Smith } 2254c1414c8SBarry Smith ierr = PetscFree(ns_col);CHKERRQ(ierr); 2264c1414c8SBarry Smith ierr = PetscFree(work);CHKERRQ(ierr); 2274c1414c8SBarry Smith ierr = PetscFree(tns);CHKERRQ(ierr); 2284c1414c8SBarry Smith ierr = PetscFree(tvc);CHKERRQ(ierr); 2294c1414c8SBarry Smith PetscFunctionReturn(0); 2304c1414c8SBarry Smith } 2314c1414c8SBarry Smith 2324c1414c8SBarry Smith #undef __FUNCT__ 2334c1414c8SBarry Smith #define __FUNCT__ "MatGetRowIJ_Inode" 2348f7157efSSatish Balay static PetscErrorCode MatGetRowIJ_Inode(Mat A,PetscInt oshift,PetscTruth symmetric,PetscTruth blockcompressed,PetscInt *n,PetscInt *ia[],PetscInt *ja[],PetscTruth *done) 2354c1414c8SBarry Smith { 2364c1414c8SBarry Smith Mat_SeqAIJ *a = (Mat_SeqAIJ*)A->data; 2374c1414c8SBarry Smith PetscErrorCode ierr; 2384c1414c8SBarry Smith 2394c1414c8SBarry Smith PetscFunctionBegin; 2404c1414c8SBarry Smith *n = a->inode.node_count; 2414c1414c8SBarry Smith if (!ia) PetscFunctionReturn(0); 2428f7157efSSatish Balay if (!blockcompressed) { 2438f7157efSSatish Balay ierr = MatGetRowIJ_SeqAIJ(A,oshift,symmetric,blockcompressed,n,ia,ja,done);CHKERRQ(ierr);; 2448f7157efSSatish Balay } else if (symmetric) { 2454c1414c8SBarry Smith ierr = MatGetRowIJ_Inode_Symmetric(A,ia,ja,0,oshift);CHKERRQ(ierr); 2464c1414c8SBarry Smith } else { 2474c1414c8SBarry Smith ierr = MatGetRowIJ_Inode_Nonsymmetric(A,ia,ja,0,oshift);CHKERRQ(ierr); 2484c1414c8SBarry Smith } 2494c1414c8SBarry Smith PetscFunctionReturn(0); 2504c1414c8SBarry Smith } 2514c1414c8SBarry Smith 2524c1414c8SBarry Smith #undef __FUNCT__ 2534c1414c8SBarry Smith #define __FUNCT__ "MatRestoreRowIJ_Inode" 2548f7157efSSatish Balay static PetscErrorCode MatRestoreRowIJ_Inode(Mat A,PetscInt oshift,PetscTruth symmetric,PetscTruth blockcompressed,PetscInt *n,PetscInt *ia[],PetscInt *ja[],PetscTruth *done) 2554c1414c8SBarry Smith { 2564c1414c8SBarry Smith PetscErrorCode ierr; 2574c1414c8SBarry Smith 2584c1414c8SBarry Smith PetscFunctionBegin; 2594c1414c8SBarry Smith if (!ia) PetscFunctionReturn(0); 2608f7157efSSatish Balay 2618f7157efSSatish Balay if (!blockcompressed) { 2628f7157efSSatish Balay ierr = MatRestoreRowIJ_SeqAIJ(A,oshift,symmetric,blockcompressed,n,ia,ja,done);CHKERRQ(ierr);; 2638f7157efSSatish Balay } else { 2644c1414c8SBarry Smith ierr = PetscFree(*ia);CHKERRQ(ierr); 2654c1414c8SBarry Smith ierr = PetscFree(*ja);CHKERRQ(ierr); 2668f7157efSSatish Balay } 2678f7157efSSatish Balay 2684c1414c8SBarry Smith PetscFunctionReturn(0); 2694c1414c8SBarry Smith } 2704c1414c8SBarry Smith 2714c1414c8SBarry Smith /* ----------------------------------------------------------- */ 2724c1414c8SBarry Smith 2734c1414c8SBarry Smith #undef __FUNCT__ 2744c1414c8SBarry Smith #define __FUNCT__ "MatGetColumnIJ_Inode_Nonsymmetric" 2754c1414c8SBarry Smith static PetscErrorCode MatGetColumnIJ_Inode_Nonsymmetric(Mat A,PetscInt *iia[],PetscInt *jja[],PetscInt ishift,PetscInt oshift) 2764c1414c8SBarry Smith { 2774c1414c8SBarry Smith Mat_SeqAIJ *a = (Mat_SeqAIJ*)A->data; 2784c1414c8SBarry Smith PetscErrorCode ierr; 2794c1414c8SBarry Smith PetscInt *work,*ia,*ja,*j,nz,nslim_row, n,row,col,*ns_col,nslim_col; 2804c1414c8SBarry Smith PetscInt *tns,*tvc,*ns_row = a->inode.size,nsz,i1,i2,*ai= a->i,*aj = a->j; 2814c1414c8SBarry Smith 2824c1414c8SBarry Smith PetscFunctionBegin; 2834c1414c8SBarry Smith nslim_row = a->inode.node_count; 2844c1414c8SBarry Smith n = A->cmap.n; 2854c1414c8SBarry Smith 2864c1414c8SBarry Smith /* Create The column_inode for this matrix */ 2874c1414c8SBarry Smith ierr = Mat_CreateColInode(A,&nslim_col,&ns_col);CHKERRQ(ierr); 2884c1414c8SBarry Smith 2894c1414c8SBarry Smith /* allocate space for reformated column_inode structure */ 2904c1414c8SBarry Smith ierr = PetscMalloc((nslim_col + 1)*sizeof(PetscInt),&tns);CHKERRQ(ierr); 2914c1414c8SBarry Smith ierr = PetscMalloc((n + 1)*sizeof(PetscInt),&tvc);CHKERRQ(ierr); 2924c1414c8SBarry Smith for (i1=0,tns[0]=0; i1<nslim_col; ++i1) tns[i1+1] = tns[i1] + ns_col[i1]; 2934c1414c8SBarry Smith 2944c1414c8SBarry Smith for (i1=0,col=0; i1<nslim_col; ++i1){ 2954c1414c8SBarry Smith nsz = ns_col[i1]; 2964c1414c8SBarry Smith for (i2=0; i2<nsz; ++i2,++col) 2974c1414c8SBarry Smith tvc[col] = i1; 2984c1414c8SBarry Smith } 2994c1414c8SBarry Smith /* allocate space for column pointers */ 3004c1414c8SBarry Smith ierr = PetscMalloc((nslim_col+1)*sizeof(PetscInt),&ia);CHKERRQ(ierr); 3014c1414c8SBarry Smith *iia = ia; 3024c1414c8SBarry Smith ierr = PetscMemzero(ia,(nslim_col+1)*sizeof(PetscInt));CHKERRQ(ierr); 3034c1414c8SBarry Smith ierr = PetscMalloc((nslim_col+1)*sizeof(PetscInt),&work);CHKERRQ(ierr); 3044c1414c8SBarry Smith 3054c1414c8SBarry Smith /* determine the number of columns in each row */ 3064c1414c8SBarry Smith ia[0] = oshift; 3074c1414c8SBarry Smith for (i1=0,row=0; i1<nslim_row; row+=ns_row[i1],i1++) { 3084c1414c8SBarry Smith j = aj + ai[row] + ishift; 3094c1414c8SBarry Smith col = *j++ + ishift; 3104c1414c8SBarry Smith i2 = tvc[col]; 3114c1414c8SBarry Smith nz = ai[row+1] - ai[row]; 3124c1414c8SBarry Smith while (nz-- > 0) { /* off-diagonal elemets */ 3134c1414c8SBarry Smith /* ia[i1+1]++; */ 3144c1414c8SBarry Smith ia[i2+1]++; 3154c1414c8SBarry Smith i2++; 3164c1414c8SBarry Smith while (((col = *j++ + ishift) < tns[i2]) && nz > 0) {nz--;} 3174c1414c8SBarry Smith if (nz > 0) i2 = tvc[col]; 3184c1414c8SBarry Smith } 3194c1414c8SBarry Smith } 3204c1414c8SBarry Smith 3214c1414c8SBarry Smith /* shift ia[i] to point to next col */ 3224c1414c8SBarry Smith for (i1=1; i1<nslim_col+1; i1++) { 3234c1414c8SBarry Smith col = ia[i1-1]; 3244c1414c8SBarry Smith ia[i1] += col; 3254c1414c8SBarry Smith work[i1-1] = col - oshift; 3264c1414c8SBarry Smith } 3274c1414c8SBarry Smith 3284c1414c8SBarry Smith /* allocate space for column pointers */ 3294c1414c8SBarry Smith nz = ia[nslim_col] + (!ishift); 3304c1414c8SBarry Smith ierr = PetscMalloc(nz*sizeof(PetscInt),&ja);CHKERRQ(ierr); 3314c1414c8SBarry Smith *jja = ja; 3324c1414c8SBarry Smith 3334c1414c8SBarry Smith /* loop over matrix putting into ja */ 3344c1414c8SBarry Smith for (i1=0,row=0; i1<nslim_row; row+=ns_row[i1],i1++) { 3354c1414c8SBarry Smith j = aj + ai[row] + ishift; 3364c1414c8SBarry Smith i2 = 0; /* Col inode index */ 3374c1414c8SBarry Smith col = *j++ + ishift; 3384c1414c8SBarry Smith i2 = tvc[col]; 3394c1414c8SBarry Smith nz = ai[row+1] - ai[row]; 3404c1414c8SBarry Smith while (nz-- > 0) { 3414c1414c8SBarry Smith /* ja[work[i1]++] = i2 + oshift; */ 3424c1414c8SBarry Smith ja[work[i2]++] = i1 + oshift; 3434c1414c8SBarry Smith i2++; 3444c1414c8SBarry Smith while(((col = *j++ + ishift) < tns[i2]) && nz > 0) {nz--;} 3454c1414c8SBarry Smith if (nz > 0) i2 = tvc[col]; 3464c1414c8SBarry Smith } 3474c1414c8SBarry Smith } 3484c1414c8SBarry Smith ierr = PetscFree(ns_col);CHKERRQ(ierr); 3494c1414c8SBarry Smith ierr = PetscFree(work);CHKERRQ(ierr); 3504c1414c8SBarry Smith ierr = PetscFree(tns);CHKERRQ(ierr); 3514c1414c8SBarry Smith ierr = PetscFree(tvc);CHKERRQ(ierr); 3524c1414c8SBarry Smith PetscFunctionReturn(0); 3534c1414c8SBarry Smith } 3544c1414c8SBarry Smith 3554c1414c8SBarry Smith #undef __FUNCT__ 3564c1414c8SBarry Smith #define __FUNCT__ "MatGetColumnIJ_Inode" 3578f7157efSSatish Balay static PetscErrorCode MatGetColumnIJ_Inode(Mat A,PetscInt oshift,PetscTruth symmetric,PetscTruth blockcompressed,PetscInt *n,PetscInt *ia[],PetscInt *ja[],PetscTruth *done) 3584c1414c8SBarry Smith { 3594c1414c8SBarry Smith PetscErrorCode ierr; 3604c1414c8SBarry Smith 3614c1414c8SBarry Smith PetscFunctionBegin; 3624c1414c8SBarry Smith ierr = Mat_CreateColInode(A,n,PETSC_NULL);CHKERRQ(ierr); 3634c1414c8SBarry Smith if (!ia) PetscFunctionReturn(0); 3644c1414c8SBarry Smith 3658f7157efSSatish Balay if (!blockcompressed) { 3668f7157efSSatish Balay ierr = MatGetColumnIJ_SeqAIJ(A,oshift,symmetric,blockcompressed,n,ia,ja,done);CHKERRQ(ierr);; 3678f7157efSSatish Balay } else if (symmetric) { 3684c1414c8SBarry Smith /* Since the indices are symmetric it does'nt matter */ 3694c1414c8SBarry Smith ierr = MatGetRowIJ_Inode_Symmetric(A,ia,ja,0,oshift);CHKERRQ(ierr); 3704c1414c8SBarry Smith } else { 3714c1414c8SBarry Smith ierr = MatGetColumnIJ_Inode_Nonsymmetric(A,ia,ja,0,oshift);CHKERRQ(ierr); 3724c1414c8SBarry Smith } 3734c1414c8SBarry Smith PetscFunctionReturn(0); 3744c1414c8SBarry Smith } 3754c1414c8SBarry Smith 3764c1414c8SBarry Smith #undef __FUNCT__ 3774c1414c8SBarry Smith #define __FUNCT__ "MatRestoreColumnIJ_Inode" 3788f7157efSSatish Balay static PetscErrorCode MatRestoreColumnIJ_Inode(Mat A,PetscInt oshift,PetscTruth symmetric,PetscTruth blockcompressed,PetscInt *n,PetscInt *ia[],PetscInt *ja[],PetscTruth *done) 3794c1414c8SBarry Smith { 3804c1414c8SBarry Smith PetscErrorCode ierr; 3814c1414c8SBarry Smith 3824c1414c8SBarry Smith PetscFunctionBegin; 3834c1414c8SBarry Smith if (!ia) PetscFunctionReturn(0); 3848f7157efSSatish Balay if (!blockcompressed) { 3858f7157efSSatish Balay ierr = MatRestoreColumnIJ_SeqAIJ(A,oshift,symmetric,blockcompressed,n,ia,ja,done);CHKERRQ(ierr);; 3868f7157efSSatish Balay } else { 3874c1414c8SBarry Smith ierr = PetscFree(*ia);CHKERRQ(ierr); 3884c1414c8SBarry Smith ierr = PetscFree(*ja);CHKERRQ(ierr); 3898f7157efSSatish Balay } 3904c1414c8SBarry Smith PetscFunctionReturn(0); 3914c1414c8SBarry Smith } 3924c1414c8SBarry Smith 3934c1414c8SBarry Smith /* ----------------------------------------------------------- */ 3944c1414c8SBarry Smith 3954c1414c8SBarry Smith #undef __FUNCT__ 3964c1414c8SBarry Smith #define __FUNCT__ "MatMult_Inode" 3974c1414c8SBarry Smith static PetscErrorCode MatMult_Inode(Mat A,Vec xx,Vec yy) 3984c1414c8SBarry Smith { 3994c1414c8SBarry Smith Mat_SeqAIJ *a = (Mat_SeqAIJ*)A->data; 4004c1414c8SBarry Smith PetscScalar sum1,sum2,sum3,sum4,sum5,tmp0,tmp1; 4014c1414c8SBarry Smith PetscScalar *v1,*v2,*v3,*v4,*v5,*x,*y; 4024c1414c8SBarry Smith PetscErrorCode ierr; 403*98c9bda7SSatish Balay PetscInt *idx,i1,i2,n,i,row,node_max,*ns,*ii,nsz,sz,nonzerorow=0; 4044c1414c8SBarry Smith 4054c1414c8SBarry Smith #if defined(PETSC_HAVE_PRAGMA_DISJOINT) 4064c1414c8SBarry Smith #pragma disjoint(*x,*y,*v1,*v2,*v3,*v4,*v5) 4074c1414c8SBarry Smith #endif 4084c1414c8SBarry Smith 4094c1414c8SBarry Smith PetscFunctionBegin; 4104c1414c8SBarry Smith if (!a->inode.size) SETERRQ(PETSC_ERR_COR,"Missing Inode Structure"); 4114c1414c8SBarry Smith node_max = a->inode.node_count; 4124c1414c8SBarry Smith ns = a->inode.size; /* Node Size array */ 4134c1414c8SBarry Smith ierr = VecGetArray(xx,&x);CHKERRQ(ierr); 4144c1414c8SBarry Smith ierr = VecGetArray(yy,&y);CHKERRQ(ierr); 4154c1414c8SBarry Smith idx = a->j; 4164c1414c8SBarry Smith v1 = a->a; 4174c1414c8SBarry Smith ii = a->i; 4184c1414c8SBarry Smith 4194c1414c8SBarry Smith for (i = 0,row = 0; i< node_max; ++i){ 4204c1414c8SBarry Smith nsz = ns[i]; 4214c1414c8SBarry Smith n = ii[1] - ii[0]; 422*98c9bda7SSatish Balay nonzerorow += (n>0)*nsz; 4234c1414c8SBarry Smith ii += nsz; 4244c1414c8SBarry Smith sz = n; /* No of non zeros in this row */ 4254c1414c8SBarry Smith /* Switch on the size of Node */ 4264c1414c8SBarry Smith switch (nsz){ /* Each loop in 'case' is unrolled */ 4274c1414c8SBarry Smith case 1 : 4284c1414c8SBarry Smith sum1 = 0; 4294c1414c8SBarry Smith 4304c1414c8SBarry Smith for(n = 0; n< sz-1; n+=2) { 4314c1414c8SBarry Smith i1 = idx[0]; /* The instructions are ordered to */ 4324c1414c8SBarry Smith i2 = idx[1]; /* make the compiler's job easy */ 4334c1414c8SBarry Smith idx += 2; 4344c1414c8SBarry Smith tmp0 = x[i1]; 4354c1414c8SBarry Smith tmp1 = x[i2]; 4364c1414c8SBarry Smith sum1 += v1[0] * tmp0 + v1[1] * tmp1; v1 += 2; 4374c1414c8SBarry Smith } 4384c1414c8SBarry Smith 4394c1414c8SBarry Smith if (n == sz-1){ /* Take care of the last nonzero */ 4404c1414c8SBarry Smith tmp0 = x[*idx++]; 4414c1414c8SBarry Smith sum1 += *v1++ * tmp0; 4424c1414c8SBarry Smith } 4434c1414c8SBarry Smith y[row++]=sum1; 4444c1414c8SBarry Smith break; 4454c1414c8SBarry Smith case 2: 4464c1414c8SBarry Smith sum1 = 0; 4474c1414c8SBarry Smith sum2 = 0; 4484c1414c8SBarry Smith v2 = v1 + n; 4494c1414c8SBarry Smith 4504c1414c8SBarry Smith for (n = 0; n< sz-1; n+=2) { 4514c1414c8SBarry Smith i1 = idx[0]; 4524c1414c8SBarry Smith i2 = idx[1]; 4534c1414c8SBarry Smith idx += 2; 4544c1414c8SBarry Smith tmp0 = x[i1]; 4554c1414c8SBarry Smith tmp1 = x[i2]; 4564c1414c8SBarry Smith sum1 += v1[0] * tmp0 + v1[1] * tmp1; v1 += 2; 4574c1414c8SBarry Smith sum2 += v2[0] * tmp0 + v2[1] * tmp1; v2 += 2; 4584c1414c8SBarry Smith } 4594c1414c8SBarry Smith if (n == sz-1){ 4604c1414c8SBarry Smith tmp0 = x[*idx++]; 4614c1414c8SBarry Smith sum1 += *v1++ * tmp0; 4624c1414c8SBarry Smith sum2 += *v2++ * tmp0; 4634c1414c8SBarry Smith } 4644c1414c8SBarry Smith y[row++]=sum1; 4654c1414c8SBarry Smith y[row++]=sum2; 4664c1414c8SBarry Smith v1 =v2; /* Since the next block to be processed starts there*/ 4674c1414c8SBarry Smith idx +=sz; 4684c1414c8SBarry Smith break; 4694c1414c8SBarry Smith case 3: 4704c1414c8SBarry Smith sum1 = 0; 4714c1414c8SBarry Smith sum2 = 0; 4724c1414c8SBarry Smith sum3 = 0; 4734c1414c8SBarry Smith v2 = v1 + n; 4744c1414c8SBarry Smith v3 = v2 + n; 4754c1414c8SBarry Smith 4764c1414c8SBarry Smith for (n = 0; n< sz-1; n+=2) { 4774c1414c8SBarry Smith i1 = idx[0]; 4784c1414c8SBarry Smith i2 = idx[1]; 4794c1414c8SBarry Smith idx += 2; 4804c1414c8SBarry Smith tmp0 = x[i1]; 4814c1414c8SBarry Smith tmp1 = x[i2]; 4824c1414c8SBarry Smith sum1 += v1[0] * tmp0 + v1[1] * tmp1; v1 += 2; 4834c1414c8SBarry Smith sum2 += v2[0] * tmp0 + v2[1] * tmp1; v2 += 2; 4844c1414c8SBarry Smith sum3 += v3[0] * tmp0 + v3[1] * tmp1; v3 += 2; 4854c1414c8SBarry Smith } 4864c1414c8SBarry Smith if (n == sz-1){ 4874c1414c8SBarry Smith tmp0 = x[*idx++]; 4884c1414c8SBarry Smith sum1 += *v1++ * tmp0; 4894c1414c8SBarry Smith sum2 += *v2++ * tmp0; 4904c1414c8SBarry Smith sum3 += *v3++ * tmp0; 4914c1414c8SBarry Smith } 4924c1414c8SBarry Smith y[row++]=sum1; 4934c1414c8SBarry Smith y[row++]=sum2; 4944c1414c8SBarry Smith y[row++]=sum3; 4954c1414c8SBarry Smith v1 =v3; /* Since the next block to be processed starts there*/ 4964c1414c8SBarry Smith idx +=2*sz; 4974c1414c8SBarry Smith break; 4984c1414c8SBarry Smith case 4: 4994c1414c8SBarry Smith sum1 = 0; 5004c1414c8SBarry Smith sum2 = 0; 5014c1414c8SBarry Smith sum3 = 0; 5024c1414c8SBarry Smith sum4 = 0; 5034c1414c8SBarry Smith v2 = v1 + n; 5044c1414c8SBarry Smith v3 = v2 + n; 5054c1414c8SBarry Smith v4 = v3 + n; 5064c1414c8SBarry Smith 5074c1414c8SBarry Smith for (n = 0; n< sz-1; n+=2) { 5084c1414c8SBarry Smith i1 = idx[0]; 5094c1414c8SBarry Smith i2 = idx[1]; 5104c1414c8SBarry Smith idx += 2; 5114c1414c8SBarry Smith tmp0 = x[i1]; 5124c1414c8SBarry Smith tmp1 = x[i2]; 5134c1414c8SBarry Smith sum1 += v1[0] * tmp0 + v1[1] *tmp1; v1 += 2; 5144c1414c8SBarry Smith sum2 += v2[0] * tmp0 + v2[1] *tmp1; v2 += 2; 5154c1414c8SBarry Smith sum3 += v3[0] * tmp0 + v3[1] *tmp1; v3 += 2; 5164c1414c8SBarry Smith sum4 += v4[0] * tmp0 + v4[1] *tmp1; v4 += 2; 5174c1414c8SBarry Smith } 5184c1414c8SBarry Smith if (n == sz-1){ 5194c1414c8SBarry Smith tmp0 = x[*idx++]; 5204c1414c8SBarry Smith sum1 += *v1++ * tmp0; 5214c1414c8SBarry Smith sum2 += *v2++ * tmp0; 5224c1414c8SBarry Smith sum3 += *v3++ * tmp0; 5234c1414c8SBarry Smith sum4 += *v4++ * tmp0; 5244c1414c8SBarry Smith } 5254c1414c8SBarry Smith y[row++]=sum1; 5264c1414c8SBarry Smith y[row++]=sum2; 5274c1414c8SBarry Smith y[row++]=sum3; 5284c1414c8SBarry Smith y[row++]=sum4; 5294c1414c8SBarry Smith v1 =v4; /* Since the next block to be processed starts there*/ 5304c1414c8SBarry Smith idx +=3*sz; 5314c1414c8SBarry Smith break; 5324c1414c8SBarry Smith case 5: 5334c1414c8SBarry Smith sum1 = 0; 5344c1414c8SBarry Smith sum2 = 0; 5354c1414c8SBarry Smith sum3 = 0; 5364c1414c8SBarry Smith sum4 = 0; 5374c1414c8SBarry Smith sum5 = 0; 5384c1414c8SBarry Smith v2 = v1 + n; 5394c1414c8SBarry Smith v3 = v2 + n; 5404c1414c8SBarry Smith v4 = v3 + n; 5414c1414c8SBarry Smith v5 = v4 + n; 5424c1414c8SBarry Smith 5434c1414c8SBarry Smith for (n = 0; n<sz-1; n+=2) { 5444c1414c8SBarry Smith i1 = idx[0]; 5454c1414c8SBarry Smith i2 = idx[1]; 5464c1414c8SBarry Smith idx += 2; 5474c1414c8SBarry Smith tmp0 = x[i1]; 5484c1414c8SBarry Smith tmp1 = x[i2]; 5494c1414c8SBarry Smith sum1 += v1[0] * tmp0 + v1[1] *tmp1; v1 += 2; 5504c1414c8SBarry Smith sum2 += v2[0] * tmp0 + v2[1] *tmp1; v2 += 2; 5514c1414c8SBarry Smith sum3 += v3[0] * tmp0 + v3[1] *tmp1; v3 += 2; 5524c1414c8SBarry Smith sum4 += v4[0] * tmp0 + v4[1] *tmp1; v4 += 2; 5534c1414c8SBarry Smith sum5 += v5[0] * tmp0 + v5[1] *tmp1; v5 += 2; 5544c1414c8SBarry Smith } 5554c1414c8SBarry Smith if (n == sz-1){ 5564c1414c8SBarry Smith tmp0 = x[*idx++]; 5574c1414c8SBarry Smith sum1 += *v1++ * tmp0; 5584c1414c8SBarry Smith sum2 += *v2++ * tmp0; 5594c1414c8SBarry Smith sum3 += *v3++ * tmp0; 5604c1414c8SBarry Smith sum4 += *v4++ * tmp0; 5614c1414c8SBarry Smith sum5 += *v5++ * tmp0; 5624c1414c8SBarry Smith } 5634c1414c8SBarry Smith y[row++]=sum1; 5644c1414c8SBarry Smith y[row++]=sum2; 5654c1414c8SBarry Smith y[row++]=sum3; 5664c1414c8SBarry Smith y[row++]=sum4; 5674c1414c8SBarry Smith y[row++]=sum5; 5684c1414c8SBarry Smith v1 =v5; /* Since the next block to be processed starts there */ 5694c1414c8SBarry Smith idx +=4*sz; 5704c1414c8SBarry Smith break; 5714c1414c8SBarry Smith default : 5724c1414c8SBarry Smith SETERRQ(PETSC_ERR_COR,"Node size not yet supported"); 5734c1414c8SBarry Smith } 5744c1414c8SBarry Smith } 5754c1414c8SBarry Smith ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr); 5764c1414c8SBarry Smith ierr = VecRestoreArray(yy,&y);CHKERRQ(ierr); 577*98c9bda7SSatish Balay ierr = PetscLogFlops(2*a->nz - nonzerorow);CHKERRQ(ierr); 5784c1414c8SBarry Smith PetscFunctionReturn(0); 5794c1414c8SBarry Smith } 5804c1414c8SBarry Smith /* ----------------------------------------------------------- */ 5814c1414c8SBarry Smith /* Almost same code as the MatMult_Inode() */ 5824c1414c8SBarry Smith #undef __FUNCT__ 5834c1414c8SBarry Smith #define __FUNCT__ "MatMultAdd_Inode" 5844c1414c8SBarry Smith static PetscErrorCode MatMultAdd_Inode(Mat A,Vec xx,Vec zz,Vec yy) 5854c1414c8SBarry Smith { 5864c1414c8SBarry Smith Mat_SeqAIJ *a = (Mat_SeqAIJ*)A->data; 5874c1414c8SBarry Smith PetscScalar sum1,sum2,sum3,sum4,sum5,tmp0,tmp1; 5884c1414c8SBarry Smith PetscScalar *v1,*v2,*v3,*v4,*v5,*x,*y,*z,*zt; 5894c1414c8SBarry Smith PetscErrorCode ierr; 5904c1414c8SBarry Smith PetscInt *idx,i1,i2,n,i,row,node_max,*ns,*ii,nsz,sz; 5914c1414c8SBarry Smith 5924c1414c8SBarry Smith PetscFunctionBegin; 5934c1414c8SBarry Smith if (!a->inode.size) SETERRQ(PETSC_ERR_COR,"Missing Inode Structure"); 5944c1414c8SBarry Smith node_max = a->inode.node_count; 5954c1414c8SBarry Smith ns = a->inode.size; /* Node Size array */ 5964c1414c8SBarry Smith ierr = VecGetArray(xx,&x);CHKERRQ(ierr); 5974c1414c8SBarry Smith ierr = VecGetArray(yy,&y);CHKERRQ(ierr); 5984c1414c8SBarry Smith if (zz != yy) { 5994c1414c8SBarry Smith ierr = VecGetArray(zz,&z);CHKERRQ(ierr); 6004c1414c8SBarry Smith } else { 6014c1414c8SBarry Smith z = y; 6024c1414c8SBarry Smith } 6034c1414c8SBarry Smith zt = z; 6044c1414c8SBarry Smith 6054c1414c8SBarry Smith idx = a->j; 6064c1414c8SBarry Smith v1 = a->a; 6074c1414c8SBarry Smith ii = a->i; 6084c1414c8SBarry Smith 6094c1414c8SBarry Smith for (i = 0,row = 0; i< node_max; ++i){ 6104c1414c8SBarry Smith nsz = ns[i]; 6114c1414c8SBarry Smith n = ii[1] - ii[0]; 6124c1414c8SBarry Smith ii += nsz; 6134c1414c8SBarry Smith sz = n; /* No of non zeros in this row */ 6144c1414c8SBarry Smith /* Switch on the size of Node */ 6154c1414c8SBarry Smith switch (nsz){ /* Each loop in 'case' is unrolled */ 6164c1414c8SBarry Smith case 1 : 6174c1414c8SBarry Smith sum1 = *zt++; 6184c1414c8SBarry Smith 6194c1414c8SBarry Smith for(n = 0; n< sz-1; n+=2) { 6204c1414c8SBarry Smith i1 = idx[0]; /* The instructions are ordered to */ 6214c1414c8SBarry Smith i2 = idx[1]; /* make the compiler's job easy */ 6224c1414c8SBarry Smith idx += 2; 6234c1414c8SBarry Smith tmp0 = x[i1]; 6244c1414c8SBarry Smith tmp1 = x[i2]; 6254c1414c8SBarry Smith sum1 += v1[0] * tmp0 + v1[1] * tmp1; v1 += 2; 6264c1414c8SBarry Smith } 6274c1414c8SBarry Smith 6284c1414c8SBarry Smith if(n == sz-1){ /* Take care of the last nonzero */ 6294c1414c8SBarry Smith tmp0 = x[*idx++]; 6304c1414c8SBarry Smith sum1 += *v1++ * tmp0; 6314c1414c8SBarry Smith } 6324c1414c8SBarry Smith y[row++]=sum1; 6334c1414c8SBarry Smith break; 6344c1414c8SBarry Smith case 2: 6354c1414c8SBarry Smith sum1 = *zt++; 6364c1414c8SBarry Smith sum2 = *zt++; 6374c1414c8SBarry Smith v2 = v1 + n; 6384c1414c8SBarry Smith 6394c1414c8SBarry Smith for(n = 0; n< sz-1; n+=2) { 6404c1414c8SBarry Smith i1 = idx[0]; 6414c1414c8SBarry Smith i2 = idx[1]; 6424c1414c8SBarry Smith idx += 2; 6434c1414c8SBarry Smith tmp0 = x[i1]; 6444c1414c8SBarry Smith tmp1 = x[i2]; 6454c1414c8SBarry Smith sum1 += v1[0] * tmp0 + v1[1] * tmp1; v1 += 2; 6464c1414c8SBarry Smith sum2 += v2[0] * tmp0 + v2[1] * tmp1; v2 += 2; 6474c1414c8SBarry Smith } 6484c1414c8SBarry Smith if(n == sz-1){ 6494c1414c8SBarry Smith tmp0 = x[*idx++]; 6504c1414c8SBarry Smith sum1 += *v1++ * tmp0; 6514c1414c8SBarry Smith sum2 += *v2++ * tmp0; 6524c1414c8SBarry Smith } 6534c1414c8SBarry Smith y[row++]=sum1; 6544c1414c8SBarry Smith y[row++]=sum2; 6554c1414c8SBarry Smith v1 =v2; /* Since the next block to be processed starts there*/ 6564c1414c8SBarry Smith idx +=sz; 6574c1414c8SBarry Smith break; 6584c1414c8SBarry Smith case 3: 6594c1414c8SBarry Smith sum1 = *zt++; 6604c1414c8SBarry Smith sum2 = *zt++; 6614c1414c8SBarry Smith sum3 = *zt++; 6624c1414c8SBarry Smith v2 = v1 + n; 6634c1414c8SBarry Smith v3 = v2 + n; 6644c1414c8SBarry Smith 6654c1414c8SBarry Smith for (n = 0; n< sz-1; n+=2) { 6664c1414c8SBarry Smith i1 = idx[0]; 6674c1414c8SBarry Smith i2 = idx[1]; 6684c1414c8SBarry Smith idx += 2; 6694c1414c8SBarry Smith tmp0 = x[i1]; 6704c1414c8SBarry Smith tmp1 = x[i2]; 6714c1414c8SBarry Smith sum1 += v1[0] * tmp0 + v1[1] * tmp1; v1 += 2; 6724c1414c8SBarry Smith sum2 += v2[0] * tmp0 + v2[1] * tmp1; v2 += 2; 6734c1414c8SBarry Smith sum3 += v3[0] * tmp0 + v3[1] * tmp1; v3 += 2; 6744c1414c8SBarry Smith } 6754c1414c8SBarry Smith if (n == sz-1){ 6764c1414c8SBarry Smith tmp0 = x[*idx++]; 6774c1414c8SBarry Smith sum1 += *v1++ * tmp0; 6784c1414c8SBarry Smith sum2 += *v2++ * tmp0; 6794c1414c8SBarry Smith sum3 += *v3++ * tmp0; 6804c1414c8SBarry Smith } 6814c1414c8SBarry Smith y[row++]=sum1; 6824c1414c8SBarry Smith y[row++]=sum2; 6834c1414c8SBarry Smith y[row++]=sum3; 6844c1414c8SBarry Smith v1 =v3; /* Since the next block to be processed starts there*/ 6854c1414c8SBarry Smith idx +=2*sz; 6864c1414c8SBarry Smith break; 6874c1414c8SBarry Smith case 4: 6884c1414c8SBarry Smith sum1 = *zt++; 6894c1414c8SBarry Smith sum2 = *zt++; 6904c1414c8SBarry Smith sum3 = *zt++; 6914c1414c8SBarry Smith sum4 = *zt++; 6924c1414c8SBarry Smith v2 = v1 + n; 6934c1414c8SBarry Smith v3 = v2 + n; 6944c1414c8SBarry Smith v4 = v3 + n; 6954c1414c8SBarry Smith 6964c1414c8SBarry Smith for (n = 0; n< sz-1; n+=2) { 6974c1414c8SBarry Smith i1 = idx[0]; 6984c1414c8SBarry Smith i2 = idx[1]; 6994c1414c8SBarry Smith idx += 2; 7004c1414c8SBarry Smith tmp0 = x[i1]; 7014c1414c8SBarry Smith tmp1 = x[i2]; 7024c1414c8SBarry Smith sum1 += v1[0] * tmp0 + v1[1] *tmp1; v1 += 2; 7034c1414c8SBarry Smith sum2 += v2[0] * tmp0 + v2[1] *tmp1; v2 += 2; 7044c1414c8SBarry Smith sum3 += v3[0] * tmp0 + v3[1] *tmp1; v3 += 2; 7054c1414c8SBarry Smith sum4 += v4[0] * tmp0 + v4[1] *tmp1; v4 += 2; 7064c1414c8SBarry Smith } 7074c1414c8SBarry Smith if (n == sz-1){ 7084c1414c8SBarry Smith tmp0 = x[*idx++]; 7094c1414c8SBarry Smith sum1 += *v1++ * tmp0; 7104c1414c8SBarry Smith sum2 += *v2++ * tmp0; 7114c1414c8SBarry Smith sum3 += *v3++ * tmp0; 7124c1414c8SBarry Smith sum4 += *v4++ * tmp0; 7134c1414c8SBarry Smith } 7144c1414c8SBarry Smith y[row++]=sum1; 7154c1414c8SBarry Smith y[row++]=sum2; 7164c1414c8SBarry Smith y[row++]=sum3; 7174c1414c8SBarry Smith y[row++]=sum4; 7184c1414c8SBarry Smith v1 =v4; /* Since the next block to be processed starts there*/ 7194c1414c8SBarry Smith idx +=3*sz; 7204c1414c8SBarry Smith break; 7214c1414c8SBarry Smith case 5: 7224c1414c8SBarry Smith sum1 = *zt++; 7234c1414c8SBarry Smith sum2 = *zt++; 7244c1414c8SBarry Smith sum3 = *zt++; 7254c1414c8SBarry Smith sum4 = *zt++; 7264c1414c8SBarry Smith sum5 = *zt++; 7274c1414c8SBarry Smith v2 = v1 + n; 7284c1414c8SBarry Smith v3 = v2 + n; 7294c1414c8SBarry Smith v4 = v3 + n; 7304c1414c8SBarry Smith v5 = v4 + n; 7314c1414c8SBarry Smith 7324c1414c8SBarry Smith for (n = 0; n<sz-1; n+=2) { 7334c1414c8SBarry Smith i1 = idx[0]; 7344c1414c8SBarry Smith i2 = idx[1]; 7354c1414c8SBarry Smith idx += 2; 7364c1414c8SBarry Smith tmp0 = x[i1]; 7374c1414c8SBarry Smith tmp1 = x[i2]; 7384c1414c8SBarry Smith sum1 += v1[0] * tmp0 + v1[1] *tmp1; v1 += 2; 7394c1414c8SBarry Smith sum2 += v2[0] * tmp0 + v2[1] *tmp1; v2 += 2; 7404c1414c8SBarry Smith sum3 += v3[0] * tmp0 + v3[1] *tmp1; v3 += 2; 7414c1414c8SBarry Smith sum4 += v4[0] * tmp0 + v4[1] *tmp1; v4 += 2; 7424c1414c8SBarry Smith sum5 += v5[0] * tmp0 + v5[1] *tmp1; v5 += 2; 7434c1414c8SBarry Smith } 7444c1414c8SBarry Smith if(n == sz-1){ 7454c1414c8SBarry Smith tmp0 = x[*idx++]; 7464c1414c8SBarry Smith sum1 += *v1++ * tmp0; 7474c1414c8SBarry Smith sum2 += *v2++ * tmp0; 7484c1414c8SBarry Smith sum3 += *v3++ * tmp0; 7494c1414c8SBarry Smith sum4 += *v4++ * tmp0; 7504c1414c8SBarry Smith sum5 += *v5++ * tmp0; 7514c1414c8SBarry Smith } 7524c1414c8SBarry Smith y[row++]=sum1; 7534c1414c8SBarry Smith y[row++]=sum2; 7544c1414c8SBarry Smith y[row++]=sum3; 7554c1414c8SBarry Smith y[row++]=sum4; 7564c1414c8SBarry Smith y[row++]=sum5; 7574c1414c8SBarry Smith v1 =v5; /* Since the next block to be processed starts there */ 7584c1414c8SBarry Smith idx +=4*sz; 7594c1414c8SBarry Smith break; 7604c1414c8SBarry Smith default : 7614c1414c8SBarry Smith SETERRQ(PETSC_ERR_COR,"Node size not yet supported"); 7624c1414c8SBarry Smith } 7634c1414c8SBarry Smith } 7644c1414c8SBarry Smith ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr); 7654c1414c8SBarry Smith ierr = VecRestoreArray(yy,&y);CHKERRQ(ierr); 7664c1414c8SBarry Smith if (zz != yy) { 7674c1414c8SBarry Smith ierr = VecRestoreArray(zz,&z);CHKERRQ(ierr); 7684c1414c8SBarry Smith } 7694c1414c8SBarry Smith ierr = PetscLogFlops(2*a->nz);CHKERRQ(ierr); 7704c1414c8SBarry Smith PetscFunctionReturn(0); 7714c1414c8SBarry Smith } 7724c1414c8SBarry Smith 7734c1414c8SBarry Smith /* ----------------------------------------------------------- */ 7744c1414c8SBarry Smith #undef __FUNCT__ 7754c1414c8SBarry Smith #define __FUNCT__ "MatSolve_Inode" 7764c1414c8SBarry Smith PetscErrorCode MatSolve_Inode(Mat A,Vec bb,Vec xx) 7774c1414c8SBarry Smith { 7784c1414c8SBarry Smith Mat_SeqAIJ *a = (Mat_SeqAIJ*)A->data; 7794c1414c8SBarry Smith IS iscol = a->col,isrow = a->row; 7804c1414c8SBarry Smith PetscErrorCode ierr; 7814c1414c8SBarry Smith PetscInt *r,*c,i,j,n = A->rmap.n,*ai = a->i,nz,*a_j = a->j; 7824c1414c8SBarry Smith PetscInt node_max,*ns,row,nsz,aii,*vi,*ad,*aj,i0,i1,*rout,*cout; 7834c1414c8SBarry Smith PetscScalar *x,*b,*a_a = a->a,*tmp,*tmps,*aa,tmp0,tmp1; 7844c1414c8SBarry Smith PetscScalar sum1,sum2,sum3,sum4,sum5,*v1,*v2,*v3,*v4,*v5; 7854c1414c8SBarry Smith 7864c1414c8SBarry Smith PetscFunctionBegin; 7874c1414c8SBarry Smith if (A->factor!=FACTOR_LU) SETERRQ(PETSC_ERR_ARG_WRONGSTATE,"Not for unfactored matrix"); 7884c1414c8SBarry Smith if (!a->inode.size) SETERRQ(PETSC_ERR_COR,"Missing Inode Structure"); 7894c1414c8SBarry Smith node_max = a->inode.node_count; 7904c1414c8SBarry Smith ns = a->inode.size; /* Node Size array */ 7914c1414c8SBarry Smith 7924c1414c8SBarry Smith ierr = VecGetArray(bb,&b);CHKERRQ(ierr); 7934c1414c8SBarry Smith ierr = VecGetArray(xx,&x);CHKERRQ(ierr); 7944c1414c8SBarry Smith tmp = a->solve_work; 7954c1414c8SBarry Smith 7964c1414c8SBarry Smith ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout; 7974c1414c8SBarry Smith ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout + (n-1); 7984c1414c8SBarry Smith 7994c1414c8SBarry Smith /* forward solve the lower triangular */ 8004c1414c8SBarry Smith tmps = tmp ; 8014c1414c8SBarry Smith aa = a_a ; 8024c1414c8SBarry Smith aj = a_j ; 8034c1414c8SBarry Smith ad = a->diag; 8044c1414c8SBarry Smith 8054c1414c8SBarry Smith for (i = 0,row = 0; i< node_max; ++i){ 8064c1414c8SBarry Smith nsz = ns[i]; 8074c1414c8SBarry Smith aii = ai[row]; 8084c1414c8SBarry Smith v1 = aa + aii; 8094c1414c8SBarry Smith vi = aj + aii; 8104c1414c8SBarry Smith nz = ad[row]- aii; 8114c1414c8SBarry Smith 8124c1414c8SBarry Smith switch (nsz){ /* Each loop in 'case' is unrolled */ 8134c1414c8SBarry Smith case 1 : 8144c1414c8SBarry Smith sum1 = b[*r++]; 8154c1414c8SBarry Smith /* while (nz--) sum1 -= *v1++ *tmps[*vi++];*/ 8164c1414c8SBarry Smith for(j=0; j<nz-1; j+=2){ 8174c1414c8SBarry Smith i0 = vi[0]; 8184c1414c8SBarry Smith i1 = vi[1]; 8194c1414c8SBarry Smith vi +=2; 8204c1414c8SBarry Smith tmp0 = tmps[i0]; 8214c1414c8SBarry Smith tmp1 = tmps[i1]; 8224c1414c8SBarry Smith sum1 -= v1[0] * tmp0 + v1[1] * tmp1; v1 += 2; 8234c1414c8SBarry Smith } 8244c1414c8SBarry Smith if(j == nz-1){ 8254c1414c8SBarry Smith tmp0 = tmps[*vi++]; 8264c1414c8SBarry Smith sum1 -= *v1++ *tmp0; 8274c1414c8SBarry Smith } 8284c1414c8SBarry Smith tmp[row ++]=sum1; 8294c1414c8SBarry Smith break; 8304c1414c8SBarry Smith case 2: 8314c1414c8SBarry Smith sum1 = b[*r++]; 8324c1414c8SBarry Smith sum2 = b[*r++]; 8334c1414c8SBarry Smith v2 = aa + ai[row+1]; 8344c1414c8SBarry Smith 8354c1414c8SBarry Smith for(j=0; j<nz-1; j+=2){ 8364c1414c8SBarry Smith i0 = vi[0]; 8374c1414c8SBarry Smith i1 = vi[1]; 8384c1414c8SBarry Smith vi +=2; 8394c1414c8SBarry Smith tmp0 = tmps[i0]; 8404c1414c8SBarry Smith tmp1 = tmps[i1]; 8414c1414c8SBarry Smith sum1 -= v1[0] * tmp0 + v1[1] * tmp1; v1 += 2; 8424c1414c8SBarry Smith sum2 -= v2[0] * tmp0 + v2[1] * tmp1; v2 += 2; 8434c1414c8SBarry Smith } 8444c1414c8SBarry Smith if(j == nz-1){ 8454c1414c8SBarry Smith tmp0 = tmps[*vi++]; 8464c1414c8SBarry Smith sum1 -= *v1++ *tmp0; 8474c1414c8SBarry Smith sum2 -= *v2++ *tmp0; 8484c1414c8SBarry Smith } 8494c1414c8SBarry Smith sum2 -= *v2++ * sum1; 8504c1414c8SBarry Smith tmp[row ++]=sum1; 8514c1414c8SBarry Smith tmp[row ++]=sum2; 8524c1414c8SBarry Smith break; 8534c1414c8SBarry Smith case 3: 8544c1414c8SBarry Smith sum1 = b[*r++]; 8554c1414c8SBarry Smith sum2 = b[*r++]; 8564c1414c8SBarry Smith sum3 = b[*r++]; 8574c1414c8SBarry Smith v2 = aa + ai[row+1]; 8584c1414c8SBarry Smith v3 = aa + ai[row+2]; 8594c1414c8SBarry Smith 8604c1414c8SBarry Smith for (j=0; j<nz-1; j+=2){ 8614c1414c8SBarry Smith i0 = vi[0]; 8624c1414c8SBarry Smith i1 = vi[1]; 8634c1414c8SBarry Smith vi +=2; 8644c1414c8SBarry Smith tmp0 = tmps[i0]; 8654c1414c8SBarry Smith tmp1 = tmps[i1]; 8664c1414c8SBarry Smith sum1 -= v1[0] * tmp0 + v1[1] * tmp1; v1 += 2; 8674c1414c8SBarry Smith sum2 -= v2[0] * tmp0 + v2[1] * tmp1; v2 += 2; 8684c1414c8SBarry Smith sum3 -= v3[0] * tmp0 + v3[1] * tmp1; v3 += 2; 8694c1414c8SBarry Smith } 8704c1414c8SBarry Smith if (j == nz-1){ 8714c1414c8SBarry Smith tmp0 = tmps[*vi++]; 8724c1414c8SBarry Smith sum1 -= *v1++ *tmp0; 8734c1414c8SBarry Smith sum2 -= *v2++ *tmp0; 8744c1414c8SBarry Smith sum3 -= *v3++ *tmp0; 8754c1414c8SBarry Smith } 8764c1414c8SBarry Smith sum2 -= *v2++ * sum1; 8774c1414c8SBarry Smith sum3 -= *v3++ * sum1; 8784c1414c8SBarry Smith sum3 -= *v3++ * sum2; 8794c1414c8SBarry Smith tmp[row ++]=sum1; 8804c1414c8SBarry Smith tmp[row ++]=sum2; 8814c1414c8SBarry Smith tmp[row ++]=sum3; 8824c1414c8SBarry Smith break; 8834c1414c8SBarry Smith 8844c1414c8SBarry Smith case 4: 8854c1414c8SBarry Smith sum1 = b[*r++]; 8864c1414c8SBarry Smith sum2 = b[*r++]; 8874c1414c8SBarry Smith sum3 = b[*r++]; 8884c1414c8SBarry Smith sum4 = b[*r++]; 8894c1414c8SBarry Smith v2 = aa + ai[row+1]; 8904c1414c8SBarry Smith v3 = aa + ai[row+2]; 8914c1414c8SBarry Smith v4 = aa + ai[row+3]; 8924c1414c8SBarry Smith 8934c1414c8SBarry Smith for (j=0; j<nz-1; j+=2){ 8944c1414c8SBarry Smith i0 = vi[0]; 8954c1414c8SBarry Smith i1 = vi[1]; 8964c1414c8SBarry Smith vi +=2; 8974c1414c8SBarry Smith tmp0 = tmps[i0]; 8984c1414c8SBarry Smith tmp1 = tmps[i1]; 8994c1414c8SBarry Smith sum1 -= v1[0] * tmp0 + v1[1] * tmp1; v1 += 2; 9004c1414c8SBarry Smith sum2 -= v2[0] * tmp0 + v2[1] * tmp1; v2 += 2; 9014c1414c8SBarry Smith sum3 -= v3[0] * tmp0 + v3[1] * tmp1; v3 += 2; 9024c1414c8SBarry Smith sum4 -= v4[0] * tmp0 + v4[1] * tmp1; v4 += 2; 9034c1414c8SBarry Smith } 9044c1414c8SBarry Smith if (j == nz-1){ 9054c1414c8SBarry Smith tmp0 = tmps[*vi++]; 9064c1414c8SBarry Smith sum1 -= *v1++ *tmp0; 9074c1414c8SBarry Smith sum2 -= *v2++ *tmp0; 9084c1414c8SBarry Smith sum3 -= *v3++ *tmp0; 9094c1414c8SBarry Smith sum4 -= *v4++ *tmp0; 9104c1414c8SBarry Smith } 9114c1414c8SBarry Smith sum2 -= *v2++ * sum1; 9124c1414c8SBarry Smith sum3 -= *v3++ * sum1; 9134c1414c8SBarry Smith sum4 -= *v4++ * sum1; 9144c1414c8SBarry Smith sum3 -= *v3++ * sum2; 9154c1414c8SBarry Smith sum4 -= *v4++ * sum2; 9164c1414c8SBarry Smith sum4 -= *v4++ * sum3; 9174c1414c8SBarry Smith 9184c1414c8SBarry Smith tmp[row ++]=sum1; 9194c1414c8SBarry Smith tmp[row ++]=sum2; 9204c1414c8SBarry Smith tmp[row ++]=sum3; 9214c1414c8SBarry Smith tmp[row ++]=sum4; 9224c1414c8SBarry Smith break; 9234c1414c8SBarry Smith case 5: 9244c1414c8SBarry Smith sum1 = b[*r++]; 9254c1414c8SBarry Smith sum2 = b[*r++]; 9264c1414c8SBarry Smith sum3 = b[*r++]; 9274c1414c8SBarry Smith sum4 = b[*r++]; 9284c1414c8SBarry Smith sum5 = b[*r++]; 9294c1414c8SBarry Smith v2 = aa + ai[row+1]; 9304c1414c8SBarry Smith v3 = aa + ai[row+2]; 9314c1414c8SBarry Smith v4 = aa + ai[row+3]; 9324c1414c8SBarry Smith v5 = aa + ai[row+4]; 9334c1414c8SBarry Smith 9344c1414c8SBarry Smith for (j=0; j<nz-1; j+=2){ 9354c1414c8SBarry Smith i0 = vi[0]; 9364c1414c8SBarry Smith i1 = vi[1]; 9374c1414c8SBarry Smith vi +=2; 9384c1414c8SBarry Smith tmp0 = tmps[i0]; 9394c1414c8SBarry Smith tmp1 = tmps[i1]; 9404c1414c8SBarry Smith sum1 -= v1[0] * tmp0 + v1[1] * tmp1; v1 += 2; 9414c1414c8SBarry Smith sum2 -= v2[0] * tmp0 + v2[1] * tmp1; v2 += 2; 9424c1414c8SBarry Smith sum3 -= v3[0] * tmp0 + v3[1] * tmp1; v3 += 2; 9434c1414c8SBarry Smith sum4 -= v4[0] * tmp0 + v4[1] * tmp1; v4 += 2; 9444c1414c8SBarry Smith sum5 -= v5[0] * tmp0 + v5[1] * tmp1; v5 += 2; 9454c1414c8SBarry Smith } 9464c1414c8SBarry Smith if (j == nz-1){ 9474c1414c8SBarry Smith tmp0 = tmps[*vi++]; 9484c1414c8SBarry Smith sum1 -= *v1++ *tmp0; 9494c1414c8SBarry Smith sum2 -= *v2++ *tmp0; 9504c1414c8SBarry Smith sum3 -= *v3++ *tmp0; 9514c1414c8SBarry Smith sum4 -= *v4++ *tmp0; 9524c1414c8SBarry Smith sum5 -= *v5++ *tmp0; 9534c1414c8SBarry Smith } 9544c1414c8SBarry Smith 9554c1414c8SBarry Smith sum2 -= *v2++ * sum1; 9564c1414c8SBarry Smith sum3 -= *v3++ * sum1; 9574c1414c8SBarry Smith sum4 -= *v4++ * sum1; 9584c1414c8SBarry Smith sum5 -= *v5++ * sum1; 9594c1414c8SBarry Smith sum3 -= *v3++ * sum2; 9604c1414c8SBarry Smith sum4 -= *v4++ * sum2; 9614c1414c8SBarry Smith sum5 -= *v5++ * sum2; 9624c1414c8SBarry Smith sum4 -= *v4++ * sum3; 9634c1414c8SBarry Smith sum5 -= *v5++ * sum3; 9644c1414c8SBarry Smith sum5 -= *v5++ * sum4; 9654c1414c8SBarry Smith 9664c1414c8SBarry Smith tmp[row ++]=sum1; 9674c1414c8SBarry Smith tmp[row ++]=sum2; 9684c1414c8SBarry Smith tmp[row ++]=sum3; 9694c1414c8SBarry Smith tmp[row ++]=sum4; 9704c1414c8SBarry Smith tmp[row ++]=sum5; 9714c1414c8SBarry Smith break; 9724c1414c8SBarry Smith default: 9734c1414c8SBarry Smith SETERRQ(PETSC_ERR_COR,"Node size not yet supported \n"); 9744c1414c8SBarry Smith } 9754c1414c8SBarry Smith } 9764c1414c8SBarry Smith /* backward solve the upper triangular */ 9774c1414c8SBarry Smith for (i=node_max -1 ,row = n-1 ; i>=0; i--){ 9784c1414c8SBarry Smith nsz = ns[i]; 9794c1414c8SBarry Smith aii = ai[row+1] -1; 9804c1414c8SBarry Smith v1 = aa + aii; 9814c1414c8SBarry Smith vi = aj + aii; 9824c1414c8SBarry Smith nz = aii- ad[row]; 9834c1414c8SBarry Smith switch (nsz){ /* Each loop in 'case' is unrolled */ 9844c1414c8SBarry Smith case 1 : 9854c1414c8SBarry Smith sum1 = tmp[row]; 9864c1414c8SBarry Smith 9874c1414c8SBarry Smith for(j=nz ; j>1; j-=2){ 9884c1414c8SBarry Smith vi -=2; 9894c1414c8SBarry Smith i0 = vi[2]; 9904c1414c8SBarry Smith i1 = vi[1]; 9914c1414c8SBarry Smith tmp0 = tmps[i0]; 9924c1414c8SBarry Smith tmp1 = tmps[i1]; 9934c1414c8SBarry Smith v1 -= 2; 9944c1414c8SBarry Smith sum1 -= v1[2] * tmp0 + v1[1] * tmp1; 9954c1414c8SBarry Smith } 9964c1414c8SBarry Smith if (j==1){ 9974c1414c8SBarry Smith tmp0 = tmps[*vi--]; 9984c1414c8SBarry Smith sum1 -= *v1-- * tmp0; 9994c1414c8SBarry Smith } 10004c1414c8SBarry Smith x[*c--] = tmp[row] = sum1*a_a[ad[row]]; row--; 10014c1414c8SBarry Smith break; 10024c1414c8SBarry Smith case 2 : 10034c1414c8SBarry Smith sum1 = tmp[row]; 10044c1414c8SBarry Smith sum2 = tmp[row -1]; 10054c1414c8SBarry Smith v2 = aa + ai[row]-1; 10064c1414c8SBarry Smith for (j=nz ; j>1; j-=2){ 10074c1414c8SBarry Smith vi -=2; 10084c1414c8SBarry Smith i0 = vi[2]; 10094c1414c8SBarry Smith i1 = vi[1]; 10104c1414c8SBarry Smith tmp0 = tmps[i0]; 10114c1414c8SBarry Smith tmp1 = tmps[i1]; 10124c1414c8SBarry Smith v1 -= 2; 10134c1414c8SBarry Smith v2 -= 2; 10144c1414c8SBarry Smith sum1 -= v1[2] * tmp0 + v1[1] * tmp1; 10154c1414c8SBarry Smith sum2 -= v2[2] * tmp0 + v2[1] * tmp1; 10164c1414c8SBarry Smith } 10174c1414c8SBarry Smith if (j==1){ 10184c1414c8SBarry Smith tmp0 = tmps[*vi--]; 10194c1414c8SBarry Smith sum1 -= *v1-- * tmp0; 10204c1414c8SBarry Smith sum2 -= *v2-- * tmp0; 10214c1414c8SBarry Smith } 10224c1414c8SBarry Smith 10234c1414c8SBarry Smith tmp0 = x[*c--] = tmp[row] = sum1*a_a[ad[row]]; row--; 10244c1414c8SBarry Smith sum2 -= *v2-- * tmp0; 10254c1414c8SBarry Smith x[*c--] = tmp[row] = sum2*a_a[ad[row]]; row--; 10264c1414c8SBarry Smith break; 10274c1414c8SBarry Smith case 3 : 10284c1414c8SBarry Smith sum1 = tmp[row]; 10294c1414c8SBarry Smith sum2 = tmp[row -1]; 10304c1414c8SBarry Smith sum3 = tmp[row -2]; 10314c1414c8SBarry Smith v2 = aa + ai[row]-1; 10324c1414c8SBarry Smith v3 = aa + ai[row -1]-1; 10334c1414c8SBarry Smith for (j=nz ; j>1; j-=2){ 10344c1414c8SBarry Smith vi -=2; 10354c1414c8SBarry Smith i0 = vi[2]; 10364c1414c8SBarry Smith i1 = vi[1]; 10374c1414c8SBarry Smith tmp0 = tmps[i0]; 10384c1414c8SBarry Smith tmp1 = tmps[i1]; 10394c1414c8SBarry Smith v1 -= 2; 10404c1414c8SBarry Smith v2 -= 2; 10414c1414c8SBarry Smith v3 -= 2; 10424c1414c8SBarry Smith sum1 -= v1[2] * tmp0 + v1[1] * tmp1; 10434c1414c8SBarry Smith sum2 -= v2[2] * tmp0 + v2[1] * tmp1; 10444c1414c8SBarry Smith sum3 -= v3[2] * tmp0 + v3[1] * tmp1; 10454c1414c8SBarry Smith } 10464c1414c8SBarry Smith if (j==1){ 10474c1414c8SBarry Smith tmp0 = tmps[*vi--]; 10484c1414c8SBarry Smith sum1 -= *v1-- * tmp0; 10494c1414c8SBarry Smith sum2 -= *v2-- * tmp0; 10504c1414c8SBarry Smith sum3 -= *v3-- * tmp0; 10514c1414c8SBarry Smith } 10524c1414c8SBarry Smith tmp0 = x[*c--] = tmp[row] = sum1*a_a[ad[row]]; row--; 10534c1414c8SBarry Smith sum2 -= *v2-- * tmp0; 10544c1414c8SBarry Smith sum3 -= *v3-- * tmp0; 10554c1414c8SBarry Smith tmp0 = x[*c--] = tmp[row] = sum2*a_a[ad[row]]; row--; 10564c1414c8SBarry Smith sum3 -= *v3-- * tmp0; 10574c1414c8SBarry Smith x[*c--] = tmp[row] = sum3*a_a[ad[row]]; row--; 10584c1414c8SBarry Smith 10594c1414c8SBarry Smith break; 10604c1414c8SBarry Smith case 4 : 10614c1414c8SBarry Smith sum1 = tmp[row]; 10624c1414c8SBarry Smith sum2 = tmp[row -1]; 10634c1414c8SBarry Smith sum3 = tmp[row -2]; 10644c1414c8SBarry Smith sum4 = tmp[row -3]; 10654c1414c8SBarry Smith v2 = aa + ai[row]-1; 10664c1414c8SBarry Smith v3 = aa + ai[row -1]-1; 10674c1414c8SBarry Smith v4 = aa + ai[row -2]-1; 10684c1414c8SBarry Smith 10694c1414c8SBarry Smith for (j=nz ; j>1; j-=2){ 10704c1414c8SBarry Smith vi -=2; 10714c1414c8SBarry Smith i0 = vi[2]; 10724c1414c8SBarry Smith i1 = vi[1]; 10734c1414c8SBarry Smith tmp0 = tmps[i0]; 10744c1414c8SBarry Smith tmp1 = tmps[i1]; 10754c1414c8SBarry Smith v1 -= 2; 10764c1414c8SBarry Smith v2 -= 2; 10774c1414c8SBarry Smith v3 -= 2; 10784c1414c8SBarry Smith v4 -= 2; 10794c1414c8SBarry Smith sum1 -= v1[2] * tmp0 + v1[1] * tmp1; 10804c1414c8SBarry Smith sum2 -= v2[2] * tmp0 + v2[1] * tmp1; 10814c1414c8SBarry Smith sum3 -= v3[2] * tmp0 + v3[1] * tmp1; 10824c1414c8SBarry Smith sum4 -= v4[2] * tmp0 + v4[1] * tmp1; 10834c1414c8SBarry Smith } 10844c1414c8SBarry Smith if (j==1){ 10854c1414c8SBarry Smith tmp0 = tmps[*vi--]; 10864c1414c8SBarry Smith sum1 -= *v1-- * tmp0; 10874c1414c8SBarry Smith sum2 -= *v2-- * tmp0; 10884c1414c8SBarry Smith sum3 -= *v3-- * tmp0; 10894c1414c8SBarry Smith sum4 -= *v4-- * tmp0; 10904c1414c8SBarry Smith } 10914c1414c8SBarry Smith 10924c1414c8SBarry Smith tmp0 = x[*c--] = tmp[row] = sum1*a_a[ad[row]]; row--; 10934c1414c8SBarry Smith sum2 -= *v2-- * tmp0; 10944c1414c8SBarry Smith sum3 -= *v3-- * tmp0; 10954c1414c8SBarry Smith sum4 -= *v4-- * tmp0; 10964c1414c8SBarry Smith tmp0 = x[*c--] = tmp[row] = sum2*a_a[ad[row]]; row--; 10974c1414c8SBarry Smith sum3 -= *v3-- * tmp0; 10984c1414c8SBarry Smith sum4 -= *v4-- * tmp0; 10994c1414c8SBarry Smith tmp0 = x[*c--] = tmp[row] = sum3*a_a[ad[row]]; row--; 11004c1414c8SBarry Smith sum4 -= *v4-- * tmp0; 11014c1414c8SBarry Smith x[*c--] = tmp[row] = sum4*a_a[ad[row]]; row--; 11024c1414c8SBarry Smith break; 11034c1414c8SBarry Smith case 5 : 11044c1414c8SBarry Smith sum1 = tmp[row]; 11054c1414c8SBarry Smith sum2 = tmp[row -1]; 11064c1414c8SBarry Smith sum3 = tmp[row -2]; 11074c1414c8SBarry Smith sum4 = tmp[row -3]; 11084c1414c8SBarry Smith sum5 = tmp[row -4]; 11094c1414c8SBarry Smith v2 = aa + ai[row]-1; 11104c1414c8SBarry Smith v3 = aa + ai[row -1]-1; 11114c1414c8SBarry Smith v4 = aa + ai[row -2]-1; 11124c1414c8SBarry Smith v5 = aa + ai[row -3]-1; 11134c1414c8SBarry Smith for (j=nz ; j>1; j-=2){ 11144c1414c8SBarry Smith vi -= 2; 11154c1414c8SBarry Smith i0 = vi[2]; 11164c1414c8SBarry Smith i1 = vi[1]; 11174c1414c8SBarry Smith tmp0 = tmps[i0]; 11184c1414c8SBarry Smith tmp1 = tmps[i1]; 11194c1414c8SBarry Smith v1 -= 2; 11204c1414c8SBarry Smith v2 -= 2; 11214c1414c8SBarry Smith v3 -= 2; 11224c1414c8SBarry Smith v4 -= 2; 11234c1414c8SBarry Smith v5 -= 2; 11244c1414c8SBarry Smith sum1 -= v1[2] * tmp0 + v1[1] * tmp1; 11254c1414c8SBarry Smith sum2 -= v2[2] * tmp0 + v2[1] * tmp1; 11264c1414c8SBarry Smith sum3 -= v3[2] * tmp0 + v3[1] * tmp1; 11274c1414c8SBarry Smith sum4 -= v4[2] * tmp0 + v4[1] * tmp1; 11284c1414c8SBarry Smith sum5 -= v5[2] * tmp0 + v5[1] * tmp1; 11294c1414c8SBarry Smith } 11304c1414c8SBarry Smith if (j==1){ 11314c1414c8SBarry Smith tmp0 = tmps[*vi--]; 11324c1414c8SBarry Smith sum1 -= *v1-- * tmp0; 11334c1414c8SBarry Smith sum2 -= *v2-- * tmp0; 11344c1414c8SBarry Smith sum3 -= *v3-- * tmp0; 11354c1414c8SBarry Smith sum4 -= *v4-- * tmp0; 11364c1414c8SBarry Smith sum5 -= *v5-- * tmp0; 11374c1414c8SBarry Smith } 11384c1414c8SBarry Smith 11394c1414c8SBarry Smith tmp0 = x[*c--] = tmp[row] = sum1*a_a[ad[row]]; row--; 11404c1414c8SBarry Smith sum2 -= *v2-- * tmp0; 11414c1414c8SBarry Smith sum3 -= *v3-- * tmp0; 11424c1414c8SBarry Smith sum4 -= *v4-- * tmp0; 11434c1414c8SBarry Smith sum5 -= *v5-- * tmp0; 11444c1414c8SBarry Smith tmp0 = x[*c--] = tmp[row] = sum2*a_a[ad[row]]; row--; 11454c1414c8SBarry Smith sum3 -= *v3-- * tmp0; 11464c1414c8SBarry Smith sum4 -= *v4-- * tmp0; 11474c1414c8SBarry Smith sum5 -= *v5-- * tmp0; 11484c1414c8SBarry Smith tmp0 = x[*c--] = tmp[row] = sum3*a_a[ad[row]]; row--; 11494c1414c8SBarry Smith sum4 -= *v4-- * tmp0; 11504c1414c8SBarry Smith sum5 -= *v5-- * tmp0; 11514c1414c8SBarry Smith tmp0 = x[*c--] = tmp[row] = sum4*a_a[ad[row]]; row--; 11524c1414c8SBarry Smith sum5 -= *v5-- * tmp0; 11534c1414c8SBarry Smith x[*c--] = tmp[row] = sum5*a_a[ad[row]]; row--; 11544c1414c8SBarry Smith break; 11554c1414c8SBarry Smith default: 11564c1414c8SBarry Smith SETERRQ(PETSC_ERR_COR,"Node size not yet supported \n"); 11574c1414c8SBarry Smith } 11584c1414c8SBarry Smith } 11594c1414c8SBarry Smith ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr); 11604c1414c8SBarry Smith ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr); 11614c1414c8SBarry Smith ierr = VecRestoreArray(bb,&b);CHKERRQ(ierr); 11624c1414c8SBarry Smith ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr); 11634c1414c8SBarry Smith ierr = PetscLogFlops(2*a->nz - A->cmap.n);CHKERRQ(ierr); 11644c1414c8SBarry Smith PetscFunctionReturn(0); 11654c1414c8SBarry Smith } 11664c1414c8SBarry Smith 11674c1414c8SBarry Smith #undef __FUNCT__ 11684c1414c8SBarry Smith #define __FUNCT__ "MatLUFactorNumeric_Inode" 11694c1414c8SBarry Smith PetscErrorCode MatLUFactorNumeric_Inode(Mat A,MatFactorInfo *info,Mat *B) 11704c1414c8SBarry Smith { 11714c1414c8SBarry Smith Mat C = *B; 11724c1414c8SBarry Smith Mat_SeqAIJ *a = (Mat_SeqAIJ*)A->data,*b = (Mat_SeqAIJ*)C->data; 11734c1414c8SBarry Smith IS iscol = b->col,isrow = b->row,isicol = b->icol; 11744c1414c8SBarry Smith PetscErrorCode ierr; 11754c1414c8SBarry Smith PetscInt *r,*ic,*c,n = A->rmap.n,*bi = b->i; 11764c1414c8SBarry Smith PetscInt *bj = b->j,*nbj=b->j +1,*ajtmp,*bjtmp,nz,nz_tmp,row,prow; 11774c1414c8SBarry Smith PetscInt *ics,i,j,idx,*ai = a->i,*aj = a->j,*bd = b->diag,node_max,nodesz; 11784c1414c8SBarry Smith PetscInt *ns,*tmp_vec1,*tmp_vec2,*nsmap,*pj; 11794c1414c8SBarry Smith PetscScalar *rtmp1,*rtmp2,*rtmp3,*v1,*v2,*v3,*pc1,*pc2,*pc3,mul1,mul2,mul3; 11804c1414c8SBarry Smith PetscScalar tmp,*ba = b->a,*aa = a->a,*pv; 11814c1414c8SBarry Smith PetscReal rs=0.0; 11824c1414c8SBarry Smith LUShift_Ctx sctx; 11834c1414c8SBarry Smith PetscInt newshift; 11844c1414c8SBarry Smith 11854c1414c8SBarry Smith PetscFunctionBegin; 11864c1414c8SBarry Smith sctx.shift_top = 0; 11874c1414c8SBarry Smith sctx.nshift_max = 0; 11884c1414c8SBarry Smith sctx.shift_lo = 0; 11894c1414c8SBarry Smith sctx.shift_hi = 0; 11904c1414c8SBarry Smith 11914c1414c8SBarry Smith /* if both shift schemes are chosen by user, only use info->shiftpd */ 11924c1414c8SBarry Smith if (info->shiftpd && info->shiftnz) info->shiftnz = 0.0; 11934c1414c8SBarry Smith if (info->shiftpd) { /* set sctx.shift_top=max{rs} */ 11944c1414c8SBarry Smith sctx.shift_top = 0; 11954c1414c8SBarry Smith for (i=0; i<n; i++) { 11964c1414c8SBarry Smith /* calculate rs = sum(|aij|)-RealPart(aii), amt of shift needed for this row */ 11974c1414c8SBarry Smith rs = 0.0; 11984c1414c8SBarry Smith ajtmp = aj + ai[i]; 11994c1414c8SBarry Smith rtmp1 = aa + ai[i]; 12004c1414c8SBarry Smith nz = ai[i+1] - ai[i]; 12014c1414c8SBarry Smith for (j=0; j<nz; j++){ 12024c1414c8SBarry Smith if (*ajtmp != i){ 12034c1414c8SBarry Smith rs += PetscAbsScalar(*rtmp1++); 12044c1414c8SBarry Smith } else { 12054c1414c8SBarry Smith rs -= PetscRealPart(*rtmp1++); 12064c1414c8SBarry Smith } 12074c1414c8SBarry Smith ajtmp++; 12084c1414c8SBarry Smith } 12094c1414c8SBarry Smith if (rs>sctx.shift_top) sctx.shift_top = rs; 12104c1414c8SBarry Smith } 12114c1414c8SBarry Smith if (sctx.shift_top == 0.0) sctx.shift_top += 1.e-12; 12124c1414c8SBarry Smith sctx.shift_top *= 1.1; 12134c1414c8SBarry Smith sctx.nshift_max = 5; 12144c1414c8SBarry Smith sctx.shift_lo = 0.; 12154c1414c8SBarry Smith sctx.shift_hi = 1.; 12164c1414c8SBarry Smith } 12174c1414c8SBarry Smith sctx.shift_amount = 0; 12184c1414c8SBarry Smith sctx.nshift = 0; 12194c1414c8SBarry Smith 12204c1414c8SBarry Smith ierr = ISGetIndices(isrow,&r);CHKERRQ(ierr); 12214c1414c8SBarry Smith ierr = ISGetIndices(iscol,&c);CHKERRQ(ierr); 12224c1414c8SBarry Smith ierr = ISGetIndices(isicol,&ic);CHKERRQ(ierr); 12234c1414c8SBarry Smith ierr = PetscMalloc((3*n+1)*sizeof(PetscScalar),&rtmp1);CHKERRQ(ierr); 12244c1414c8SBarry Smith ierr = PetscMemzero(rtmp1,(3*n+1)*sizeof(PetscScalar));CHKERRQ(ierr); 12254c1414c8SBarry Smith ics = ic ; 12264c1414c8SBarry Smith rtmp2 = rtmp1 + n; 12274c1414c8SBarry Smith rtmp3 = rtmp2 + n; 12284c1414c8SBarry Smith 12294c1414c8SBarry Smith node_max = a->inode.node_count; 12304c1414c8SBarry Smith ns = a->inode.size ; 12314c1414c8SBarry Smith if (!ns){ 12324c1414c8SBarry Smith SETERRQ(PETSC_ERR_PLIB,"Matrix without inode information"); 12334c1414c8SBarry Smith } 12344c1414c8SBarry Smith 12354c1414c8SBarry Smith /* If max inode size > 3, split it into two inodes.*/ 12364c1414c8SBarry Smith /* also map the inode sizes according to the ordering */ 12374c1414c8SBarry Smith ierr = PetscMalloc((n+1)* sizeof(PetscInt),&tmp_vec1);CHKERRQ(ierr); 12384c1414c8SBarry Smith for (i=0,j=0; i<node_max; ++i,++j){ 12394c1414c8SBarry Smith if (ns[i]>3) { 12404c1414c8SBarry Smith tmp_vec1[j] = ns[i]/2; /* Assuming ns[i] < =5 */ 12414c1414c8SBarry Smith ++j; 12424c1414c8SBarry Smith tmp_vec1[j] = ns[i] - tmp_vec1[j-1]; 12434c1414c8SBarry Smith } else { 12444c1414c8SBarry Smith tmp_vec1[j] = ns[i]; 12454c1414c8SBarry Smith } 12464c1414c8SBarry Smith } 12474c1414c8SBarry Smith /* Use the correct node_max */ 12484c1414c8SBarry Smith node_max = j; 12494c1414c8SBarry Smith 12504c1414c8SBarry Smith /* Now reorder the inode info based on mat re-ordering info */ 12514c1414c8SBarry Smith /* First create a row -> inode_size_array_index map */ 12524c1414c8SBarry Smith ierr = PetscMalloc(n*sizeof(PetscInt)+1,&nsmap);CHKERRQ(ierr); 12534c1414c8SBarry Smith ierr = PetscMalloc(node_max*sizeof(PetscInt)+1,&tmp_vec2);CHKERRQ(ierr); 12544c1414c8SBarry Smith for (i=0,row=0; i<node_max; i++) { 12554c1414c8SBarry Smith nodesz = tmp_vec1[i]; 12564c1414c8SBarry Smith for (j=0; j<nodesz; j++,row++) { 12574c1414c8SBarry Smith nsmap[row] = i; 12584c1414c8SBarry Smith } 12594c1414c8SBarry Smith } 12604c1414c8SBarry Smith /* Using nsmap, create a reordered ns structure */ 12614c1414c8SBarry Smith for (i=0,j=0; i< node_max; i++) { 12624c1414c8SBarry Smith nodesz = tmp_vec1[nsmap[r[j]]]; /* here the reordered row_no is in r[] */ 12634c1414c8SBarry Smith tmp_vec2[i] = nodesz; 12644c1414c8SBarry Smith j += nodesz; 12654c1414c8SBarry Smith } 12664c1414c8SBarry Smith ierr = PetscFree(nsmap);CHKERRQ(ierr); 12674c1414c8SBarry Smith ierr = PetscFree(tmp_vec1);CHKERRQ(ierr); 12684c1414c8SBarry Smith /* Now use the correct ns */ 12694c1414c8SBarry Smith ns = tmp_vec2; 12704c1414c8SBarry Smith 12714c1414c8SBarry Smith do { 12724c1414c8SBarry Smith sctx.lushift = PETSC_FALSE; 12734c1414c8SBarry Smith /* Now loop over each block-row, and do the factorization */ 12744c1414c8SBarry Smith for (i=0,row=0; i<node_max; i++) { 12754c1414c8SBarry Smith nodesz = ns[i]; 12764c1414c8SBarry Smith nz = bi[row+1] - bi[row]; 12774c1414c8SBarry Smith bjtmp = bj + bi[row]; 12784c1414c8SBarry Smith 12794c1414c8SBarry Smith switch (nodesz){ 12804c1414c8SBarry Smith case 1: 12814c1414c8SBarry Smith for (j=0; j<nz; j++){ 12824c1414c8SBarry Smith idx = bjtmp[j]; 12834c1414c8SBarry Smith rtmp1[idx] = 0.0; 12844c1414c8SBarry Smith } 12854c1414c8SBarry Smith 12864c1414c8SBarry Smith /* load in initial (unfactored row) */ 12874c1414c8SBarry Smith idx = r[row]; 12884c1414c8SBarry Smith nz_tmp = ai[idx+1] - ai[idx]; 12894c1414c8SBarry Smith ajtmp = aj + ai[idx]; 12904c1414c8SBarry Smith v1 = aa + ai[idx]; 12914c1414c8SBarry Smith 12924c1414c8SBarry Smith for (j=0; j<nz_tmp; j++) { 12934c1414c8SBarry Smith idx = ics[ajtmp[j]]; 12944c1414c8SBarry Smith rtmp1[idx] = v1[j]; 12954c1414c8SBarry Smith } 12964c1414c8SBarry Smith rtmp1[ics[r[row]]] += sctx.shift_amount; 12974c1414c8SBarry Smith 12984c1414c8SBarry Smith prow = *bjtmp++ ; 12994c1414c8SBarry Smith while (prow < row) { 13004c1414c8SBarry Smith pc1 = rtmp1 + prow; 13014c1414c8SBarry Smith if (*pc1 != 0.0){ 13024c1414c8SBarry Smith pv = ba + bd[prow]; 13034c1414c8SBarry Smith pj = nbj + bd[prow]; 13044c1414c8SBarry Smith mul1 = *pc1 * *pv++; 13054c1414c8SBarry Smith *pc1 = mul1; 13064c1414c8SBarry Smith nz_tmp = bi[prow+1] - bd[prow] - 1; 13074c1414c8SBarry Smith ierr = PetscLogFlops(2*nz_tmp);CHKERRQ(ierr); 13084c1414c8SBarry Smith for (j=0; j<nz_tmp; j++) { 13094c1414c8SBarry Smith tmp = pv[j]; 13104c1414c8SBarry Smith idx = pj[j]; 13114c1414c8SBarry Smith rtmp1[idx] -= mul1 * tmp; 13124c1414c8SBarry Smith } 13134c1414c8SBarry Smith } 13144c1414c8SBarry Smith prow = *bjtmp++ ; 13154c1414c8SBarry Smith } 13164c1414c8SBarry Smith pj = bj + bi[row]; 13174c1414c8SBarry Smith pc1 = ba + bi[row]; 13184c1414c8SBarry Smith 13194c1414c8SBarry Smith sctx.pv = rtmp1[row]; 13204c1414c8SBarry Smith rtmp1[row] = 1.0/rtmp1[row]; /* invert diag */ 13214c1414c8SBarry Smith rs = 0.0; 13224c1414c8SBarry Smith for (j=0; j<nz; j++) { 13234c1414c8SBarry Smith idx = pj[j]; 13244c1414c8SBarry Smith pc1[j] = rtmp1[idx]; /* rtmp1 -> ba */ 13254c1414c8SBarry Smith if (idx != row) rs += PetscAbsScalar(pc1[j]); 13264c1414c8SBarry Smith } 13274c1414c8SBarry Smith sctx.rs = rs; 1328c6b1f410SHong Zhang ierr = MatLUCheckShift_inline(info,sctx,row,newshift);CHKERRQ(ierr); 13294c1414c8SBarry Smith if (newshift == 1) goto endofwhile; 13304c1414c8SBarry Smith break; 13314c1414c8SBarry Smith 13324c1414c8SBarry Smith case 2: 13334c1414c8SBarry Smith for (j=0; j<nz; j++) { 13344c1414c8SBarry Smith idx = bjtmp[j]; 13354c1414c8SBarry Smith rtmp1[idx] = 0.0; 13364c1414c8SBarry Smith rtmp2[idx] = 0.0; 13374c1414c8SBarry Smith } 13384c1414c8SBarry Smith 13394c1414c8SBarry Smith /* load in initial (unfactored row) */ 13404c1414c8SBarry Smith idx = r[row]; 13414c1414c8SBarry Smith nz_tmp = ai[idx+1] - ai[idx]; 13424c1414c8SBarry Smith ajtmp = aj + ai[idx]; 13434c1414c8SBarry Smith v1 = aa + ai[idx]; 13444c1414c8SBarry Smith v2 = aa + ai[idx+1]; 13454c1414c8SBarry Smith for (j=0; j<nz_tmp; j++) { 13464c1414c8SBarry Smith idx = ics[ajtmp[j]]; 13474c1414c8SBarry Smith rtmp1[idx] = v1[j]; 13484c1414c8SBarry Smith rtmp2[idx] = v2[j]; 13494c1414c8SBarry Smith } 13504c1414c8SBarry Smith rtmp1[ics[r[row]]] += sctx.shift_amount; 13514c1414c8SBarry Smith rtmp2[ics[r[row+1]]] += sctx.shift_amount; 13524c1414c8SBarry Smith 13534c1414c8SBarry Smith prow = *bjtmp++ ; 13544c1414c8SBarry Smith while (prow < row) { 13554c1414c8SBarry Smith pc1 = rtmp1 + prow; 13564c1414c8SBarry Smith pc2 = rtmp2 + prow; 13574c1414c8SBarry Smith if (*pc1 != 0.0 || *pc2 != 0.0){ 13584c1414c8SBarry Smith pv = ba + bd[prow]; 13594c1414c8SBarry Smith pj = nbj + bd[prow]; 13604c1414c8SBarry Smith mul1 = *pc1 * *pv; 13614c1414c8SBarry Smith mul2 = *pc2 * *pv; 13624c1414c8SBarry Smith ++pv; 13634c1414c8SBarry Smith *pc1 = mul1; 13644c1414c8SBarry Smith *pc2 = mul2; 13654c1414c8SBarry Smith 13664c1414c8SBarry Smith nz_tmp = bi[prow+1] - bd[prow] - 1; 13674c1414c8SBarry Smith for (j=0; j<nz_tmp; j++) { 13684c1414c8SBarry Smith tmp = pv[j]; 13694c1414c8SBarry Smith idx = pj[j]; 13704c1414c8SBarry Smith rtmp1[idx] -= mul1 * tmp; 13714c1414c8SBarry Smith rtmp2[idx] -= mul2 * tmp; 13724c1414c8SBarry Smith } 13734c1414c8SBarry Smith ierr = PetscLogFlops(4*nz_tmp);CHKERRQ(ierr); 13744c1414c8SBarry Smith } 13754c1414c8SBarry Smith prow = *bjtmp++ ; 13764c1414c8SBarry Smith } 13774c1414c8SBarry Smith 13784c1414c8SBarry Smith /* Now take care of diagonal 2x2 block. Note: prow = row here */ 13794c1414c8SBarry Smith pc1 = rtmp1 + prow; 13804c1414c8SBarry Smith pc2 = rtmp2 + prow; 13814c1414c8SBarry Smith 13824c1414c8SBarry Smith sctx.pv = *pc1; 13834c1414c8SBarry Smith pj = bj + bi[prow]; 13844c1414c8SBarry Smith rs = 0.0; 13854c1414c8SBarry Smith for (j=0; j<nz; j++){ 13864c1414c8SBarry Smith idx = pj[j]; 13874c1414c8SBarry Smith if (idx != prow) rs += PetscAbsScalar(rtmp1[idx]); 13884c1414c8SBarry Smith } 13894c1414c8SBarry Smith sctx.rs = rs; 1390c6b1f410SHong Zhang ierr = MatLUCheckShift_inline(info,sctx,row,newshift);CHKERRQ(ierr); 13914c1414c8SBarry Smith if (newshift == 1) goto endofwhile; 13924c1414c8SBarry Smith 13934c1414c8SBarry Smith if (*pc2 != 0.0){ 13944c1414c8SBarry Smith pj = nbj + bd[prow]; 13954c1414c8SBarry Smith mul2 = (*pc2)/(*pc1); /* since diag is not yet inverted.*/ 13964c1414c8SBarry Smith *pc2 = mul2; 13974c1414c8SBarry Smith nz_tmp = bi[prow+1] - bd[prow] - 1; 13984c1414c8SBarry Smith for (j=0; j<nz_tmp; j++) { 13994c1414c8SBarry Smith idx = pj[j] ; 14004c1414c8SBarry Smith tmp = rtmp1[idx]; 14014c1414c8SBarry Smith rtmp2[idx] -= mul2 * tmp; 14024c1414c8SBarry Smith } 14034c1414c8SBarry Smith ierr = PetscLogFlops(2*nz_tmp);CHKERRQ(ierr); 14044c1414c8SBarry Smith } 14054c1414c8SBarry Smith 14064c1414c8SBarry Smith pj = bj + bi[row]; 14074c1414c8SBarry Smith pc1 = ba + bi[row]; 14084c1414c8SBarry Smith pc2 = ba + bi[row+1]; 14094c1414c8SBarry Smith 14104c1414c8SBarry Smith sctx.pv = rtmp2[row+1]; 14114c1414c8SBarry Smith rs = 0.0; 14124c1414c8SBarry Smith rtmp1[row] = 1.0/rtmp1[row]; 14134c1414c8SBarry Smith rtmp2[row+1] = 1.0/rtmp2[row+1]; 14144c1414c8SBarry Smith /* copy row entries from dense representation to sparse */ 14154c1414c8SBarry Smith for (j=0; j<nz; j++) { 14164c1414c8SBarry Smith idx = pj[j]; 14174c1414c8SBarry Smith pc1[j] = rtmp1[idx]; 14184c1414c8SBarry Smith pc2[j] = rtmp2[idx]; 14194c1414c8SBarry Smith if (idx != row+1) rs += PetscAbsScalar(pc2[j]); 14204c1414c8SBarry Smith } 14214c1414c8SBarry Smith sctx.rs = rs; 1422c6b1f410SHong Zhang ierr = MatLUCheckShift_inline(info,sctx,row+1,newshift);CHKERRQ(ierr); 14234c1414c8SBarry Smith if (newshift == 1) goto endofwhile; 14244c1414c8SBarry Smith break; 14254c1414c8SBarry Smith 14264c1414c8SBarry Smith case 3: 14274c1414c8SBarry Smith for (j=0; j<nz; j++) { 14284c1414c8SBarry Smith idx = bjtmp[j]; 14294c1414c8SBarry Smith rtmp1[idx] = 0.0; 14304c1414c8SBarry Smith rtmp2[idx] = 0.0; 14314c1414c8SBarry Smith rtmp3[idx] = 0.0; 14324c1414c8SBarry Smith } 14334c1414c8SBarry Smith /* copy the nonzeros for the 3 rows from sparse representation to dense in rtmp*[] */ 14344c1414c8SBarry Smith idx = r[row]; 14354c1414c8SBarry Smith nz_tmp = ai[idx+1] - ai[idx]; 14364c1414c8SBarry Smith ajtmp = aj + ai[idx]; 14374c1414c8SBarry Smith v1 = aa + ai[idx]; 14384c1414c8SBarry Smith v2 = aa + ai[idx+1]; 14394c1414c8SBarry Smith v3 = aa + ai[idx+2]; 14404c1414c8SBarry Smith for (j=0; j<nz_tmp; j++) { 14414c1414c8SBarry Smith idx = ics[ajtmp[j]]; 14424c1414c8SBarry Smith rtmp1[idx] = v1[j]; 14434c1414c8SBarry Smith rtmp2[idx] = v2[j]; 14444c1414c8SBarry Smith rtmp3[idx] = v3[j]; 14454c1414c8SBarry Smith } 14464c1414c8SBarry Smith rtmp1[ics[r[row]]] += sctx.shift_amount; 14474c1414c8SBarry Smith rtmp2[ics[r[row+1]]] += sctx.shift_amount; 14484c1414c8SBarry Smith rtmp3[ics[r[row+2]]] += sctx.shift_amount; 14494c1414c8SBarry Smith 14504c1414c8SBarry Smith /* loop over all pivot row blocks above this row block */ 14514c1414c8SBarry Smith prow = *bjtmp++ ; 14524c1414c8SBarry Smith while (prow < row) { 14534c1414c8SBarry Smith pc1 = rtmp1 + prow; 14544c1414c8SBarry Smith pc2 = rtmp2 + prow; 14554c1414c8SBarry Smith pc3 = rtmp3 + prow; 14564c1414c8SBarry Smith if (*pc1 != 0.0 || *pc2 != 0.0 || *pc3 !=0.0){ 14574c1414c8SBarry Smith pv = ba + bd[prow]; 14584c1414c8SBarry Smith pj = nbj + bd[prow]; 14594c1414c8SBarry Smith mul1 = *pc1 * *pv; 14604c1414c8SBarry Smith mul2 = *pc2 * *pv; 14614c1414c8SBarry Smith mul3 = *pc3 * *pv; 14624c1414c8SBarry Smith ++pv; 14634c1414c8SBarry Smith *pc1 = mul1; 14644c1414c8SBarry Smith *pc2 = mul2; 14654c1414c8SBarry Smith *pc3 = mul3; 14664c1414c8SBarry Smith 14674c1414c8SBarry Smith nz_tmp = bi[prow+1] - bd[prow] - 1; 14684c1414c8SBarry Smith /* update this row based on pivot row */ 14694c1414c8SBarry Smith for (j=0; j<nz_tmp; j++) { 14704c1414c8SBarry Smith tmp = pv[j]; 14714c1414c8SBarry Smith idx = pj[j]; 14724c1414c8SBarry Smith rtmp1[idx] -= mul1 * tmp; 14734c1414c8SBarry Smith rtmp2[idx] -= mul2 * tmp; 14744c1414c8SBarry Smith rtmp3[idx] -= mul3 * tmp; 14754c1414c8SBarry Smith } 14764c1414c8SBarry Smith ierr = PetscLogFlops(6*nz_tmp);CHKERRQ(ierr); 14774c1414c8SBarry Smith } 14784c1414c8SBarry Smith prow = *bjtmp++ ; 14794c1414c8SBarry Smith } 14804c1414c8SBarry Smith 14814c1414c8SBarry Smith /* Now take care of diagonal 3x3 block in this set of rows */ 14824c1414c8SBarry Smith /* note: prow = row here */ 14834c1414c8SBarry Smith pc1 = rtmp1 + prow; 14844c1414c8SBarry Smith pc2 = rtmp2 + prow; 14854c1414c8SBarry Smith pc3 = rtmp3 + prow; 14864c1414c8SBarry Smith 14874c1414c8SBarry Smith sctx.pv = *pc1; 14884c1414c8SBarry Smith pj = bj + bi[prow]; 14894c1414c8SBarry Smith rs = 0.0; 14904c1414c8SBarry Smith for (j=0; j<nz; j++){ 14914c1414c8SBarry Smith idx = pj[j]; 14924c1414c8SBarry Smith if (idx != row) rs += PetscAbsScalar(rtmp1[idx]); 14934c1414c8SBarry Smith } 14944c1414c8SBarry Smith sctx.rs = rs; 1495c6b1f410SHong Zhang ierr = MatLUCheckShift_inline(info,sctx,row,newshift);CHKERRQ(ierr); 14964c1414c8SBarry Smith if (newshift == 1) goto endofwhile; 14974c1414c8SBarry Smith 14984c1414c8SBarry Smith if (*pc2 != 0.0 || *pc3 != 0.0){ 14994c1414c8SBarry Smith mul2 = (*pc2)/(*pc1); 15004c1414c8SBarry Smith mul3 = (*pc3)/(*pc1); 15014c1414c8SBarry Smith *pc2 = mul2; 15024c1414c8SBarry Smith *pc3 = mul3; 15034c1414c8SBarry Smith nz_tmp = bi[prow+1] - bd[prow] - 1; 15044c1414c8SBarry Smith pj = nbj + bd[prow]; 15054c1414c8SBarry Smith for (j=0; j<nz_tmp; j++) { 15064c1414c8SBarry Smith idx = pj[j] ; 15074c1414c8SBarry Smith tmp = rtmp1[idx]; 15084c1414c8SBarry Smith rtmp2[idx] -= mul2 * tmp; 15094c1414c8SBarry Smith rtmp3[idx] -= mul3 * tmp; 15104c1414c8SBarry Smith } 15114c1414c8SBarry Smith ierr = PetscLogFlops(4*nz_tmp);CHKERRQ(ierr); 15124c1414c8SBarry Smith } 15134c1414c8SBarry Smith ++prow; 15144c1414c8SBarry Smith 15154c1414c8SBarry Smith pc2 = rtmp2 + prow; 15164c1414c8SBarry Smith pc3 = rtmp3 + prow; 15174c1414c8SBarry Smith sctx.pv = *pc2; 15184c1414c8SBarry Smith pj = bj + bi[prow]; 15194c1414c8SBarry Smith rs = 0.0; 15204c1414c8SBarry Smith for (j=0; j<nz; j++){ 15214c1414c8SBarry Smith idx = pj[j]; 15224c1414c8SBarry Smith if (idx != prow) rs += PetscAbsScalar(rtmp2[idx]); 15234c1414c8SBarry Smith } 15244c1414c8SBarry Smith sctx.rs = rs; 1525c6b1f410SHong Zhang ierr = MatLUCheckShift_inline(info,sctx,row+1,newshift);CHKERRQ(ierr); 15264c1414c8SBarry Smith if (newshift == 1) goto endofwhile; 15274c1414c8SBarry Smith 15284c1414c8SBarry Smith if (*pc3 != 0.0){ 15294c1414c8SBarry Smith mul3 = (*pc3)/(*pc2); 15304c1414c8SBarry Smith *pc3 = mul3; 15314c1414c8SBarry Smith pj = nbj + bd[prow]; 15324c1414c8SBarry Smith nz_tmp = bi[prow+1] - bd[prow] - 1; 15334c1414c8SBarry Smith for (j=0; j<nz_tmp; j++) { 15344c1414c8SBarry Smith idx = pj[j] ; 15354c1414c8SBarry Smith tmp = rtmp2[idx]; 15364c1414c8SBarry Smith rtmp3[idx] -= mul3 * tmp; 15374c1414c8SBarry Smith } 15384c1414c8SBarry Smith ierr = PetscLogFlops(4*nz_tmp);CHKERRQ(ierr); 15394c1414c8SBarry Smith } 15404c1414c8SBarry Smith 15414c1414c8SBarry Smith pj = bj + bi[row]; 15424c1414c8SBarry Smith pc1 = ba + bi[row]; 15434c1414c8SBarry Smith pc2 = ba + bi[row+1]; 15444c1414c8SBarry Smith pc3 = ba + bi[row+2]; 15454c1414c8SBarry Smith 15464c1414c8SBarry Smith sctx.pv = rtmp3[row+2]; 15474c1414c8SBarry Smith rs = 0.0; 15484c1414c8SBarry Smith rtmp1[row] = 1.0/rtmp1[row]; 15494c1414c8SBarry Smith rtmp2[row+1] = 1.0/rtmp2[row+1]; 15504c1414c8SBarry Smith rtmp3[row+2] = 1.0/rtmp3[row+2]; 15514c1414c8SBarry Smith /* copy row entries from dense representation to sparse */ 15524c1414c8SBarry Smith for (j=0; j<nz; j++) { 15534c1414c8SBarry Smith idx = pj[j]; 15544c1414c8SBarry Smith pc1[j] = rtmp1[idx]; 15554c1414c8SBarry Smith pc2[j] = rtmp2[idx]; 15564c1414c8SBarry Smith pc3[j] = rtmp3[idx]; 15574c1414c8SBarry Smith if (idx != row+2) rs += PetscAbsScalar(pc3[j]); 15584c1414c8SBarry Smith } 15594c1414c8SBarry Smith 15604c1414c8SBarry Smith sctx.rs = rs; 1561c6b1f410SHong Zhang ierr = MatLUCheckShift_inline(info,sctx,row+2,newshift);CHKERRQ(ierr); 15624c1414c8SBarry Smith if (newshift == 1) goto endofwhile; 15634c1414c8SBarry Smith break; 15644c1414c8SBarry Smith 15654c1414c8SBarry Smith default: 15664c1414c8SBarry Smith SETERRQ(PETSC_ERR_COR,"Node size not yet supported \n"); 15674c1414c8SBarry Smith } 15684c1414c8SBarry Smith row += nodesz; /* Update the row */ 15694c1414c8SBarry Smith } 15704c1414c8SBarry Smith endofwhile:; 15714c1414c8SBarry Smith } while (sctx.lushift); 15724c1414c8SBarry Smith ierr = PetscFree(rtmp1);CHKERRQ(ierr); 15734c1414c8SBarry Smith ierr = PetscFree(tmp_vec2);CHKERRQ(ierr); 15744c1414c8SBarry Smith ierr = ISRestoreIndices(isicol,&ic);CHKERRQ(ierr); 15754c1414c8SBarry Smith ierr = ISRestoreIndices(isrow,&r);CHKERRQ(ierr); 15764c1414c8SBarry Smith ierr = ISRestoreIndices(iscol,&c);CHKERRQ(ierr); 15774c1414c8SBarry Smith C->factor = FACTOR_LU; 15784c1414c8SBarry Smith C->assembled = PETSC_TRUE; 15794c1414c8SBarry Smith if (sctx.nshift) { 15804c1414c8SBarry Smith if (info->shiftnz) { 15811e2582c4SBarry Smith ierr = PetscInfo2(A,"number of shift_nz tries %D, shift_amount %G\n",sctx.nshift,sctx.shift_amount);CHKERRQ(ierr); 15824c1414c8SBarry Smith } else if (info->shiftpd) { 15831e2582c4SBarry Smith ierr = PetscInfo4(A,"number of shift_pd tries %D, shift_amount %G, diagonal shifted up by %e fraction top_value %e\n",sctx.nshift,sctx.shift_amount,info->shift_fraction,sctx.shift_top);CHKERRQ(ierr); 15844c1414c8SBarry Smith } 15854c1414c8SBarry Smith } 15864c1414c8SBarry Smith ierr = PetscLogFlops(C->cmap.n);CHKERRQ(ierr); 15874c1414c8SBarry Smith PetscFunctionReturn(0); 15884c1414c8SBarry Smith } 15894c1414c8SBarry Smith 15904c1414c8SBarry Smith /* 15914c1414c8SBarry Smith Makes a longer coloring[] array and calls the usual code with that 15924c1414c8SBarry Smith */ 15934c1414c8SBarry Smith #undef __FUNCT__ 15944c1414c8SBarry Smith #define __FUNCT__ "MatColoringPatch_Inode" 15954c1414c8SBarry Smith PetscErrorCode MatColoringPatch_Inode(Mat mat,PetscInt ncolors,PetscInt nin,ISColoringValue coloring[],ISColoring *iscoloring) 15964c1414c8SBarry Smith { 15974c1414c8SBarry Smith Mat_SeqAIJ *a = (Mat_SeqAIJ*)mat->data; 15984c1414c8SBarry Smith PetscErrorCode ierr; 15994c1414c8SBarry Smith PetscInt n = mat->cmap.n,m = a->inode.node_count,j,*ns = a->inode.size,row; 16004c1414c8SBarry Smith PetscInt *colorused,i; 16014c1414c8SBarry Smith ISColoringValue *newcolor; 16024c1414c8SBarry Smith 16034c1414c8SBarry Smith PetscFunctionBegin; 16044c1414c8SBarry Smith ierr = PetscMalloc((n+1)*sizeof(PetscInt),&newcolor);CHKERRQ(ierr); 16054c1414c8SBarry Smith /* loop over inodes, marking a color for each column*/ 16064c1414c8SBarry Smith row = 0; 16074c1414c8SBarry Smith for (i=0; i<m; i++){ 16084c1414c8SBarry Smith for (j=0; j<ns[i]; j++) { 16094c1414c8SBarry Smith newcolor[row++] = coloring[i] + j*ncolors; 16104c1414c8SBarry Smith } 16114c1414c8SBarry Smith } 16124c1414c8SBarry Smith 16134c1414c8SBarry Smith /* eliminate unneeded colors */ 16144c1414c8SBarry Smith ierr = PetscMalloc(5*ncolors*sizeof(PetscInt),&colorused);CHKERRQ(ierr); 16154c1414c8SBarry Smith ierr = PetscMemzero(colorused,5*ncolors*sizeof(PetscInt));CHKERRQ(ierr); 16164c1414c8SBarry Smith for (i=0; i<n; i++) { 16174c1414c8SBarry Smith colorused[newcolor[i]] = 1; 16184c1414c8SBarry Smith } 16194c1414c8SBarry Smith 16204c1414c8SBarry Smith for (i=1; i<5*ncolors; i++) { 16214c1414c8SBarry Smith colorused[i] += colorused[i-1]; 16224c1414c8SBarry Smith } 16234c1414c8SBarry Smith ncolors = colorused[5*ncolors-1]; 16244c1414c8SBarry Smith for (i=0; i<n; i++) { 162557815681SSatish Balay newcolor[i] = colorused[newcolor[i]]-1; 16264c1414c8SBarry Smith } 16274c1414c8SBarry Smith ierr = PetscFree(colorused);CHKERRQ(ierr); 16284c1414c8SBarry Smith ierr = ISColoringCreate(mat->comm,ncolors,n,newcolor,iscoloring);CHKERRQ(ierr); 16294c1414c8SBarry Smith ierr = PetscFree(coloring);CHKERRQ(ierr); 16304c1414c8SBarry Smith PetscFunctionReturn(0); 16314c1414c8SBarry Smith } 16324c1414c8SBarry Smith 16332af78befSBarry Smith #include "src/inline/ilu.h" 16342af78befSBarry Smith 16352af78befSBarry Smith #undef __FUNCT__ 16362af78befSBarry Smith #define __FUNCT__ "MatRelax_Inode" 16372af78befSBarry Smith PetscErrorCode MatRelax_Inode(Mat A,Vec bb,PetscReal omega,MatSORType flag,PetscReal fshift,PetscInt its,PetscInt lits,Vec xx) 16382af78befSBarry Smith { 16392af78befSBarry Smith Mat_SeqAIJ *a = (Mat_SeqAIJ*)A->data; 1640f0d39aaaSBarry Smith PetscScalar *x,*xs,*ibdiag,*bdiag,sum1,sum2,sum3,sum4,sum5,tmp0,tmp1,tmp2,tmp3,*v1,*v2,*v3,*v4,*v5; 1641f0d39aaaSBarry Smith PetscScalar *v = a->a,*b,*xb,tmp4,tmp5,x1,x2,x3,x4,x5; 164264c62002SMatthew Knepley PetscReal zeropivot = 1.0e-15; 16432af78befSBarry Smith PetscErrorCode ierr; 1644f0d39aaaSBarry Smith PetscInt n,m = a->inode.node_count,*sizes = a->inode.size,cnt = 0,i,j,row,i1,i2; 1645f0d39aaaSBarry Smith PetscInt *idx,*diag = a->diag,*ii = a->i,sz,k; 16462af78befSBarry Smith 16472af78befSBarry Smith PetscFunctionBegin; 164871f1c65dSBarry Smith if (omega != 1.0) SETERRQ(PETSC_ERR_SUP,"No support for omega != 1.0; use -mat_no_inode"); 164971f1c65dSBarry Smith if (fshift != 0.0) SETERRQ(PETSC_ERR_SUP,"No support for fshift != 0.0; use -mat_no_inode"); 165071f1c65dSBarry Smith if (flag & SOR_EISENSTAT) SETERRQ(PETSC_ERR_SUP,"No support for Eisenstat trick; use -mat_no_inode"); 16512af78befSBarry Smith 165271f1c65dSBarry Smith if (!a->inode.ibdiagvalid) { 16532af78befSBarry Smith if (!a->inode.ibdiag) { 16542af78befSBarry Smith /* calculate space needed for diagonal blocks */ 16552af78befSBarry Smith for (i=0; i<m; i++) { 16562af78befSBarry Smith cnt += sizes[i]*sizes[i]; 16572af78befSBarry Smith } 1658f0d39aaaSBarry Smith a->inode.bdiagsize = cnt; 16592af78befSBarry Smith ierr = PetscMalloc2(cnt,PetscScalar,&a->inode.ibdiag,cnt,PetscScalar,&a->inode.bdiag);CHKERRQ(ierr); 166071f1c65dSBarry Smith } 166171f1c65dSBarry Smith 166271f1c65dSBarry Smith /* copy over the diagonal blocks and invert them */ 16632af78befSBarry Smith ibdiag = a->inode.ibdiag; 16642af78befSBarry Smith bdiag = a->inode.bdiag; 16652af78befSBarry Smith cnt = 0; 16662af78befSBarry Smith for (i=0, row = 0; i<m; i++) { 16672af78befSBarry Smith for (j=0; j<sizes[i]; j++) { 1668f0d39aaaSBarry Smith for (k=0; k<sizes[i]; k++) { 1669f0d39aaaSBarry Smith bdiag[cnt+k*sizes[i]+j] = v[diag[row+j] - j + k]; 1670f0d39aaaSBarry Smith } 16712af78befSBarry Smith } 16722af78befSBarry Smith ierr = PetscMemcpy(ibdiag+cnt,bdiag+cnt,sizes[i]*sizes[i]*sizeof(PetscScalar));CHKERRQ(ierr); 16732af78befSBarry Smith 16742af78befSBarry Smith switch(sizes[i]) { 16752af78befSBarry Smith case 1: 16762af78befSBarry Smith /* Create matrix data structure */ 167764c62002SMatthew Knepley if (PetscAbsScalar(ibdiag[cnt]) < zeropivot) SETERRQ1(PETSC_ERR_MAT_LU_ZRPVT,"Zero pivot on row %D",row); 167864c62002SMatthew Knepley ibdiag[cnt] = 1.0/ibdiag[cnt]; 16792af78befSBarry Smith break; 16802af78befSBarry Smith case 2: 16812af78befSBarry Smith ierr = Kernel_A_gets_inverse_A_2(ibdiag+cnt);CHKERRQ(ierr); 16822af78befSBarry Smith break; 16832af78befSBarry Smith case 3: 16842af78befSBarry Smith ierr = Kernel_A_gets_inverse_A_3(ibdiag+cnt);CHKERRQ(ierr); 16852af78befSBarry Smith break; 16862af78befSBarry Smith case 4: 16872af78befSBarry Smith ierr = Kernel_A_gets_inverse_A_4(ibdiag+cnt);CHKERRQ(ierr); 16882af78befSBarry Smith break; 16892af78befSBarry Smith case 5: 16902af78befSBarry Smith ierr = Kernel_A_gets_inverse_A_5(ibdiag+cnt);CHKERRQ(ierr); 16912af78befSBarry Smith break; 16922af78befSBarry Smith default: 16932af78befSBarry Smith SETERRQ1(PETSC_ERR_SUP,"Inode size %D not supported",sizes[i]); 16942af78befSBarry Smith } 16952af78befSBarry Smith cnt += sizes[i]*sizes[i]; 16962af78befSBarry Smith row += sizes[i]; 16972af78befSBarry Smith } 169871f1c65dSBarry Smith a->inode.ibdiagvalid = PETSC_TRUE; 16992af78befSBarry Smith } 17002af78befSBarry Smith ibdiag = a->inode.ibdiag; 17012af78befSBarry Smith bdiag = a->inode.bdiag; 17022af78befSBarry Smith 17032af78befSBarry Smith ierr = VecGetArray(xx,&x);CHKERRQ(ierr); 17042af78befSBarry Smith if (xx != bb) { 17052af78befSBarry Smith ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 17062af78befSBarry Smith } else { 17072af78befSBarry Smith b = x; 17082af78befSBarry Smith } 17092af78befSBarry Smith 17102af78befSBarry Smith /* We count flops by assuming the upper triangular and lower triangular parts have the same number of nonzeros */ 17112af78befSBarry Smith xs = x; 17122af78befSBarry Smith if (flag & SOR_ZERO_INITIAL_GUESS) { 17132af78befSBarry Smith if (flag & SOR_FORWARD_SWEEP || flag & SOR_LOCAL_FORWARD_SWEEP){ 17142af78befSBarry Smith 17158862d2efSBarry Smith for (i=0, row=0; i<m; i++) { 17168862d2efSBarry Smith sz = diag[row] - ii[row]; 17178862d2efSBarry Smith v1 = a->a + ii[row]; 17188862d2efSBarry Smith idx = a->j + ii[row]; 17198862d2efSBarry Smith 17208862d2efSBarry Smith /* see comments for MatMult_Inode() for how this is coded */ 17218862d2efSBarry Smith switch (sizes[i]){ 17228862d2efSBarry Smith case 1: 17238862d2efSBarry Smith 17248862d2efSBarry Smith sum1 = b[row]; 17258862d2efSBarry Smith for(n = 0; n<sz-1; n+=2) { 17268862d2efSBarry Smith i1 = idx[0]; 17278862d2efSBarry Smith i2 = idx[1]; 17288862d2efSBarry Smith idx += 2; 17298862d2efSBarry Smith tmp0 = x[i1]; 17308862d2efSBarry Smith tmp1 = x[i2]; 17318862d2efSBarry Smith sum1 -= v1[0] * tmp0 + v1[1] * tmp1; v1 += 2; 17328862d2efSBarry Smith } 17338862d2efSBarry Smith 17348862d2efSBarry Smith if (n == sz-1){ 1735f0d39aaaSBarry Smith tmp0 = x[*idx]; 1736f0d39aaaSBarry Smith sum1 -= *v1 * tmp0; 17378862d2efSBarry Smith } 17388862d2efSBarry Smith x[row++] = sum1*(*ibdiag++); 17398862d2efSBarry Smith break; 1740f0d39aaaSBarry Smith case 2: 1741f0d39aaaSBarry Smith v2 = a->a + ii[row+1]; 1742f0d39aaaSBarry Smith sum1 = b[row]; 1743f0d39aaaSBarry Smith sum2 = b[row+1]; 1744f0d39aaaSBarry Smith for(n = 0; n<sz-1; n+=2) { 1745f0d39aaaSBarry Smith i1 = idx[0]; 1746f0d39aaaSBarry Smith i2 = idx[1]; 1747f0d39aaaSBarry Smith idx += 2; 1748f0d39aaaSBarry Smith tmp0 = x[i1]; 1749f0d39aaaSBarry Smith tmp1 = x[i2]; 1750f0d39aaaSBarry Smith sum1 -= v1[0] * tmp0 + v1[1] * tmp1; v1 += 2; 1751f0d39aaaSBarry Smith sum2 -= v2[0] * tmp0 + v2[1] * tmp1; v2 += 2; 1752f0d39aaaSBarry Smith } 1753f0d39aaaSBarry Smith 1754f0d39aaaSBarry Smith if (n == sz-1){ 1755f0d39aaaSBarry Smith tmp0 = x[*idx]; 1756f0d39aaaSBarry Smith sum1 -= v1[0] * tmp0; 1757f0d39aaaSBarry Smith sum2 -= v2[0] * tmp0; 1758f0d39aaaSBarry Smith } 1759f0d39aaaSBarry Smith x[row++] = sum1*ibdiag[0] + sum2*ibdiag[2]; 1760f0d39aaaSBarry Smith x[row++] = sum1*ibdiag[1] + sum2*ibdiag[3]; 1761f0d39aaaSBarry Smith ibdiag += 4; 1762f0d39aaaSBarry Smith break; 1763f0d39aaaSBarry Smith case 3: 1764f0d39aaaSBarry Smith v2 = a->a + ii[row+1]; 1765f0d39aaaSBarry Smith v3 = a->a + ii[row+2]; 1766f0d39aaaSBarry Smith sum1 = b[row]; 1767f0d39aaaSBarry Smith sum2 = b[row+1]; 1768f0d39aaaSBarry Smith sum3 = b[row+2]; 1769f0d39aaaSBarry Smith for(n = 0; n<sz-1; n+=2) { 1770f0d39aaaSBarry Smith i1 = idx[0]; 1771f0d39aaaSBarry Smith i2 = idx[1]; 1772f0d39aaaSBarry Smith idx += 2; 1773f0d39aaaSBarry Smith tmp0 = x[i1]; 1774f0d39aaaSBarry Smith tmp1 = x[i2]; 1775f0d39aaaSBarry Smith sum1 -= v1[0] * tmp0 + v1[1] * tmp1; v1 += 2; 1776f0d39aaaSBarry Smith sum2 -= v2[0] * tmp0 + v2[1] * tmp1; v2 += 2; 1777f0d39aaaSBarry Smith sum3 -= v3[0] * tmp0 + v3[1] * tmp1; v3 += 2; 1778f0d39aaaSBarry Smith } 1779f0d39aaaSBarry Smith 1780f0d39aaaSBarry Smith if (n == sz-1){ 1781f0d39aaaSBarry Smith tmp0 = x[*idx]; 1782f0d39aaaSBarry Smith sum1 -= v1[0] * tmp0; 1783f0d39aaaSBarry Smith sum2 -= v2[0] * tmp0; 1784f0d39aaaSBarry Smith sum3 -= v3[0] * tmp0; 1785f0d39aaaSBarry Smith } 1786f0d39aaaSBarry Smith x[row++] = sum1*ibdiag[0] + sum2*ibdiag[3] + sum3*ibdiag[6]; 1787f0d39aaaSBarry Smith x[row++] = sum1*ibdiag[1] + sum2*ibdiag[4] + sum3*ibdiag[7]; 1788f0d39aaaSBarry Smith x[row++] = sum1*ibdiag[2] + sum2*ibdiag[5] + sum3*ibdiag[8]; 1789f0d39aaaSBarry Smith ibdiag += 9; 1790f0d39aaaSBarry Smith break; 1791f0d39aaaSBarry Smith case 4: 1792f0d39aaaSBarry Smith v2 = a->a + ii[row+1]; 1793f0d39aaaSBarry Smith v3 = a->a + ii[row+2]; 1794f0d39aaaSBarry Smith v4 = a->a + ii[row+3]; 1795f0d39aaaSBarry Smith sum1 = b[row]; 1796f0d39aaaSBarry Smith sum2 = b[row+1]; 1797f0d39aaaSBarry Smith sum3 = b[row+2]; 1798f0d39aaaSBarry Smith sum4 = b[row+3]; 1799f0d39aaaSBarry Smith for(n = 0; n<sz-1; n+=2) { 1800f0d39aaaSBarry Smith i1 = idx[0]; 1801f0d39aaaSBarry Smith i2 = idx[1]; 1802f0d39aaaSBarry Smith idx += 2; 1803f0d39aaaSBarry Smith tmp0 = x[i1]; 1804f0d39aaaSBarry Smith tmp1 = x[i2]; 1805f0d39aaaSBarry Smith sum1 -= v1[0] * tmp0 + v1[1] * tmp1; v1 += 2; 1806f0d39aaaSBarry Smith sum2 -= v2[0] * tmp0 + v2[1] * tmp1; v2 += 2; 1807f0d39aaaSBarry Smith sum3 -= v3[0] * tmp0 + v3[1] * tmp1; v3 += 2; 1808f0d39aaaSBarry Smith sum4 -= v4[0] * tmp0 + v4[1] * tmp1; v4 += 2; 1809f0d39aaaSBarry Smith } 1810f0d39aaaSBarry Smith 1811f0d39aaaSBarry Smith if (n == sz-1){ 1812f0d39aaaSBarry Smith tmp0 = x[*idx]; 1813f0d39aaaSBarry Smith sum1 -= v1[0] * tmp0; 1814f0d39aaaSBarry Smith sum2 -= v2[0] * tmp0; 1815f0d39aaaSBarry Smith sum3 -= v3[0] * tmp0; 1816f0d39aaaSBarry Smith sum4 -= v4[0] * tmp0; 1817f0d39aaaSBarry Smith } 1818f0d39aaaSBarry Smith x[row++] = sum1*ibdiag[0] + sum2*ibdiag[4] + sum3*ibdiag[8] + sum4*ibdiag[12]; 1819f0d39aaaSBarry Smith x[row++] = sum1*ibdiag[1] + sum2*ibdiag[5] + sum3*ibdiag[9] + sum4*ibdiag[13]; 1820f0d39aaaSBarry Smith x[row++] = sum1*ibdiag[2] + sum2*ibdiag[6] + sum3*ibdiag[10] + sum4*ibdiag[14]; 1821f0d39aaaSBarry Smith x[row++] = sum1*ibdiag[3] + sum2*ibdiag[7] + sum3*ibdiag[11] + sum4*ibdiag[15]; 1822f0d39aaaSBarry Smith ibdiag += 16; 1823f0d39aaaSBarry Smith break; 1824f0d39aaaSBarry Smith case 5: 1825f0d39aaaSBarry Smith v2 = a->a + ii[row+1]; 1826f0d39aaaSBarry Smith v3 = a->a + ii[row+2]; 1827f0d39aaaSBarry Smith v4 = a->a + ii[row+3]; 1828f0d39aaaSBarry Smith v5 = a->a + ii[row+4]; 1829f0d39aaaSBarry Smith sum1 = b[row]; 1830f0d39aaaSBarry Smith sum2 = b[row+1]; 1831f0d39aaaSBarry Smith sum3 = b[row+2]; 1832f0d39aaaSBarry Smith sum4 = b[row+3]; 1833f0d39aaaSBarry Smith sum5 = b[row+4]; 1834f0d39aaaSBarry Smith for(n = 0; n<sz-1; n+=2) { 1835f0d39aaaSBarry Smith i1 = idx[0]; 1836f0d39aaaSBarry Smith i2 = idx[1]; 1837f0d39aaaSBarry Smith idx += 2; 1838f0d39aaaSBarry Smith tmp0 = x[i1]; 1839f0d39aaaSBarry Smith tmp1 = x[i2]; 1840f0d39aaaSBarry Smith sum1 -= v1[0] * tmp0 + v1[1] * tmp1; v1 += 2; 1841f0d39aaaSBarry Smith sum2 -= v2[0] * tmp0 + v2[1] * tmp1; v2 += 2; 1842f0d39aaaSBarry Smith sum3 -= v3[0] * tmp0 + v3[1] * tmp1; v3 += 2; 1843f0d39aaaSBarry Smith sum4 -= v4[0] * tmp0 + v4[1] * tmp1; v4 += 2; 1844f0d39aaaSBarry Smith sum5 -= v5[0] * tmp0 + v5[1] * tmp1; v5 += 2; 1845f0d39aaaSBarry Smith } 1846f0d39aaaSBarry Smith 1847f0d39aaaSBarry Smith if (n == sz-1){ 1848f0d39aaaSBarry Smith tmp0 = x[*idx]; 1849f0d39aaaSBarry Smith sum1 -= v1[0] * tmp0; 1850f0d39aaaSBarry Smith sum2 -= v2[0] * tmp0; 1851f0d39aaaSBarry Smith sum3 -= v3[0] * tmp0; 1852f0d39aaaSBarry Smith sum4 -= v4[0] * tmp0; 1853f0d39aaaSBarry Smith sum5 -= v5[0] * tmp0; 1854f0d39aaaSBarry Smith } 1855f0d39aaaSBarry Smith x[row++] = sum1*ibdiag[0] + sum2*ibdiag[5] + sum3*ibdiag[10] + sum4*ibdiag[15] + sum5*ibdiag[20]; 1856f0d39aaaSBarry Smith x[row++] = sum1*ibdiag[1] + sum2*ibdiag[6] + sum3*ibdiag[11] + sum4*ibdiag[16] + sum5*ibdiag[21]; 1857f0d39aaaSBarry Smith x[row++] = sum1*ibdiag[2] + sum2*ibdiag[7] + sum3*ibdiag[12] + sum4*ibdiag[17] + sum5*ibdiag[22]; 1858f0d39aaaSBarry Smith x[row++] = sum1*ibdiag[3] + sum2*ibdiag[8] + sum3*ibdiag[13] + sum4*ibdiag[18] + sum5*ibdiag[23]; 1859f0d39aaaSBarry Smith x[row++] = sum1*ibdiag[4] + sum2*ibdiag[9] + sum3*ibdiag[14] + sum4*ibdiag[19] + sum5*ibdiag[24]; 1860f0d39aaaSBarry Smith ibdiag += 25; 1861f0d39aaaSBarry Smith break; 18628862d2efSBarry Smith default: 18638862d2efSBarry Smith SETERRQ1(PETSC_ERR_SUP,"Inode size %D not supported",sizes[i]); 18648862d2efSBarry Smith } 18652af78befSBarry Smith } 18662af78befSBarry Smith 18672af78befSBarry Smith xb = x; 18682af78befSBarry Smith ierr = PetscLogFlops(a->nz);CHKERRQ(ierr); 18692af78befSBarry Smith } else xb = b; 18702af78befSBarry Smith if ((flag & SOR_FORWARD_SWEEP || flag & SOR_LOCAL_FORWARD_SWEEP) && 18712af78befSBarry Smith (flag & SOR_BACKWARD_SWEEP || flag & SOR_LOCAL_BACKWARD_SWEEP)) { 18728862d2efSBarry Smith cnt = 0; 18738862d2efSBarry Smith for (i=0, row=0; i<m; i++) { 18742af78befSBarry Smith 18758862d2efSBarry Smith switch (sizes[i]){ 18768862d2efSBarry Smith case 1: 18778862d2efSBarry Smith x[row++] *= bdiag[cnt++]; 18788862d2efSBarry Smith break; 1879f0d39aaaSBarry Smith case 2: 1880f0d39aaaSBarry Smith x1 = x[row]; x2 = x[row+1]; 1881f0d39aaaSBarry Smith tmp1 = x1*bdiag[cnt] + x2*bdiag[cnt+2]; 1882f0d39aaaSBarry Smith tmp2 = x1*bdiag[cnt+1] + x2*bdiag[cnt+3]; 1883f0d39aaaSBarry Smith x[row++] = tmp1; 1884f0d39aaaSBarry Smith x[row++] = tmp2; 1885f0d39aaaSBarry Smith cnt += 4; 1886f0d39aaaSBarry Smith break; 1887f0d39aaaSBarry Smith case 3: 1888f0d39aaaSBarry Smith x1 = x[row]; x2 = x[row+1]; x3 = x[row+2]; 1889f0d39aaaSBarry Smith tmp1 = x1*bdiag[cnt] + x2*bdiag[cnt+3] + x3*bdiag[cnt+6]; 1890f0d39aaaSBarry Smith tmp2 = x1*bdiag[cnt+1] + x2*bdiag[cnt+4] + x3*bdiag[cnt+7]; 1891f0d39aaaSBarry Smith tmp3 = x1*bdiag[cnt+2] + x2*bdiag[cnt+5] + x3*bdiag[cnt+8]; 1892f0d39aaaSBarry Smith x[row++] = tmp1; 1893f0d39aaaSBarry Smith x[row++] = tmp2; 1894f0d39aaaSBarry Smith x[row++] = tmp3; 1895f0d39aaaSBarry Smith cnt += 9; 1896f0d39aaaSBarry Smith break; 1897f0d39aaaSBarry Smith case 4: 1898f0d39aaaSBarry Smith x1 = x[row]; x2 = x[row+1]; x3 = x[row+2]; x4 = x[row+3]; 1899f0d39aaaSBarry Smith tmp1 = x1*bdiag[cnt] + x2*bdiag[cnt+4] + x3*bdiag[cnt+8] + x4*bdiag[cnt+12]; 1900f0d39aaaSBarry Smith tmp2 = x1*bdiag[cnt+1] + x2*bdiag[cnt+5] + x3*bdiag[cnt+9] + x4*bdiag[cnt+13]; 1901f0d39aaaSBarry Smith tmp3 = x1*bdiag[cnt+2] + x2*bdiag[cnt+6] + x3*bdiag[cnt+10] + x4*bdiag[cnt+14]; 1902f0d39aaaSBarry Smith tmp4 = x1*bdiag[cnt+3] + x2*bdiag[cnt+7] + x3*bdiag[cnt+11] + x4*bdiag[cnt+15]; 1903f0d39aaaSBarry Smith x[row++] = tmp1; 1904f0d39aaaSBarry Smith x[row++] = tmp2; 1905f0d39aaaSBarry Smith x[row++] = tmp3; 1906f0d39aaaSBarry Smith x[row++] = tmp4; 1907f0d39aaaSBarry Smith cnt += 16; 1908f0d39aaaSBarry Smith break; 1909f0d39aaaSBarry Smith case 5: 1910f0d39aaaSBarry Smith x1 = x[row]; x2 = x[row+1]; x3 = x[row+2]; x4 = x[row+3]; x5 = x[row+4]; 1911f0d39aaaSBarry Smith tmp1 = x1*bdiag[cnt] + x2*bdiag[cnt+5] + x3*bdiag[cnt+10] + x4*bdiag[cnt+15] + x5*bdiag[cnt+20]; 1912f0d39aaaSBarry Smith tmp2 = x1*bdiag[cnt+1] + x2*bdiag[cnt+6] + x3*bdiag[cnt+11] + x4*bdiag[cnt+16] + x5*bdiag[cnt+21]; 1913f0d39aaaSBarry Smith tmp3 = x1*bdiag[cnt+2] + x2*bdiag[cnt+7] + x3*bdiag[cnt+12] + x4*bdiag[cnt+17] + x5*bdiag[cnt+22]; 1914f0d39aaaSBarry Smith tmp4 = x1*bdiag[cnt+3] + x2*bdiag[cnt+8] + x3*bdiag[cnt+13] + x4*bdiag[cnt+18] + x5*bdiag[cnt+23]; 1915f0d39aaaSBarry Smith tmp5 = x1*bdiag[cnt+4] + x2*bdiag[cnt+9] + x3*bdiag[cnt+14] + x4*bdiag[cnt+19] + x5*bdiag[cnt+24]; 1916f0d39aaaSBarry Smith x[row++] = tmp1; 1917f0d39aaaSBarry Smith x[row++] = tmp2; 1918f0d39aaaSBarry Smith x[row++] = tmp3; 1919f0d39aaaSBarry Smith x[row++] = tmp4; 1920f0d39aaaSBarry Smith x[row++] = tmp5; 1921f0d39aaaSBarry Smith cnt += 25; 1922f0d39aaaSBarry Smith break; 19238862d2efSBarry Smith default: 19248862d2efSBarry Smith SETERRQ1(PETSC_ERR_SUP,"Inode size %D not supported",sizes[i]); 19258862d2efSBarry Smith } 19262af78befSBarry Smith } 19272af78befSBarry Smith ierr = PetscLogFlops(m);CHKERRQ(ierr); 19282af78befSBarry Smith } 19292af78befSBarry Smith if (flag & SOR_BACKWARD_SWEEP || flag & SOR_LOCAL_BACKWARD_SWEEP){ 19302af78befSBarry Smith 1931f0d39aaaSBarry Smith ibdiag = a->inode.ibdiag+a->inode.bdiagsize; 1932f0d39aaaSBarry Smith for (i=m-1, row=A->rmap.n-1; i>=0; i--) { 1933f0d39aaaSBarry Smith ibdiag -= sizes[i]*sizes[i]; 19348862d2efSBarry Smith sz = ii[row+1] - diag[row] - 1; 19358862d2efSBarry Smith v1 = a->a + diag[row] + 1; 19368862d2efSBarry Smith idx = a->j + diag[row] + 1; 19372af78befSBarry Smith 19388862d2efSBarry Smith /* see comments for MatMult_Inode() for how this is coded */ 19398862d2efSBarry Smith switch (sizes[i]){ 19408862d2efSBarry Smith case 1: 19418862d2efSBarry Smith 19428862d2efSBarry Smith sum1 = xb[row]; 19438862d2efSBarry Smith for(n = 0; n<sz-1; n+=2) { 19448862d2efSBarry Smith i1 = idx[0]; 19458862d2efSBarry Smith i2 = idx[1]; 19468862d2efSBarry Smith idx += 2; 19478862d2efSBarry Smith tmp0 = x[i1]; 19488862d2efSBarry Smith tmp1 = x[i2]; 19498862d2efSBarry Smith sum1 -= v1[0] * tmp0 + v1[1] * tmp1; v1 += 2; 19508862d2efSBarry Smith } 19518862d2efSBarry Smith 19528862d2efSBarry Smith if (n == sz-1){ 1953f0d39aaaSBarry Smith tmp0 = x[*idx]; 1954f0d39aaaSBarry Smith sum1 -= *v1*tmp0; 19558862d2efSBarry Smith } 1956f0d39aaaSBarry Smith x[row--] = sum1*(*ibdiag); 1957f0d39aaaSBarry Smith break; 1958f0d39aaaSBarry Smith 1959f0d39aaaSBarry Smith case 2: 1960f0d39aaaSBarry Smith 1961f0d39aaaSBarry Smith sum1 = xb[row]; 1962f0d39aaaSBarry Smith sum2 = xb[row-1]; 1963f0d39aaaSBarry Smith /* note that sum1 is associated with the second of the two rows */ 1964f0d39aaaSBarry Smith v2 = a->a + diag[row-1] + 2; 1965f0d39aaaSBarry Smith for(n = 0; n<sz-1; n+=2) { 1966f0d39aaaSBarry Smith i1 = idx[0]; 1967f0d39aaaSBarry Smith i2 = idx[1]; 1968f0d39aaaSBarry Smith idx += 2; 1969f0d39aaaSBarry Smith tmp0 = x[i1]; 1970f0d39aaaSBarry Smith tmp1 = x[i2]; 1971f0d39aaaSBarry Smith sum1 -= v1[0] * tmp0 + v1[1] * tmp1; v1 += 2; 1972f0d39aaaSBarry Smith sum2 -= v2[0] * tmp0 + v2[1] * tmp1; v2 += 2; 1973f0d39aaaSBarry Smith } 1974f0d39aaaSBarry Smith 1975f0d39aaaSBarry Smith if (n == sz-1){ 1976f0d39aaaSBarry Smith tmp0 = x[*idx]; 1977f0d39aaaSBarry Smith sum1 -= *v1*tmp0; 1978f0d39aaaSBarry Smith sum2 -= *v2*tmp0; 1979f0d39aaaSBarry Smith } 1980f0d39aaaSBarry Smith x[row--] = sum2*ibdiag[1] + sum1*ibdiag[3]; 1981f0d39aaaSBarry Smith x[row--] = sum2*ibdiag[0] + sum1*ibdiag[2]; 1982f0d39aaaSBarry Smith break; 1983f0d39aaaSBarry Smith case 3: 1984f0d39aaaSBarry Smith 1985f0d39aaaSBarry Smith sum1 = xb[row]; 1986f0d39aaaSBarry Smith sum2 = xb[row-1]; 1987f0d39aaaSBarry Smith sum3 = xb[row-2]; 1988f0d39aaaSBarry Smith v2 = a->a + diag[row-1] + 2; 1989f0d39aaaSBarry Smith v3 = a->a + diag[row-2] + 3; 1990f0d39aaaSBarry Smith for(n = 0; n<sz-1; n+=2) { 1991f0d39aaaSBarry Smith i1 = idx[0]; 1992f0d39aaaSBarry Smith i2 = idx[1]; 1993f0d39aaaSBarry Smith idx += 2; 1994f0d39aaaSBarry Smith tmp0 = x[i1]; 1995f0d39aaaSBarry Smith tmp1 = x[i2]; 1996f0d39aaaSBarry Smith sum1 -= v1[0] * tmp0 + v1[1] * tmp1; v1 += 2; 1997f0d39aaaSBarry Smith sum2 -= v2[0] * tmp0 + v2[1] * tmp1; v2 += 2; 1998f0d39aaaSBarry Smith sum3 -= v3[0] * tmp0 + v3[1] * tmp1; v3 += 2; 1999f0d39aaaSBarry Smith } 2000f0d39aaaSBarry Smith 2001f0d39aaaSBarry Smith if (n == sz-1){ 2002f0d39aaaSBarry Smith tmp0 = x[*idx]; 2003f0d39aaaSBarry Smith sum1 -= *v1*tmp0; 2004f0d39aaaSBarry Smith sum2 -= *v2*tmp0; 2005f0d39aaaSBarry Smith sum3 -= *v3*tmp0; 2006f0d39aaaSBarry Smith } 2007f0d39aaaSBarry Smith x[row--] = sum3*ibdiag[2] + sum2*ibdiag[5] + sum1*ibdiag[8]; 2008f0d39aaaSBarry Smith x[row--] = sum3*ibdiag[1] + sum2*ibdiag[4] + sum1*ibdiag[7]; 2009f0d39aaaSBarry Smith x[row--] = sum3*ibdiag[0] + sum2*ibdiag[3] + sum1*ibdiag[6]; 2010f0d39aaaSBarry Smith break; 2011f0d39aaaSBarry Smith case 4: 2012f0d39aaaSBarry Smith 2013f0d39aaaSBarry Smith sum1 = xb[row]; 2014f0d39aaaSBarry Smith sum2 = xb[row-1]; 2015f0d39aaaSBarry Smith sum3 = xb[row-2]; 2016f0d39aaaSBarry Smith sum4 = xb[row-3]; 2017f0d39aaaSBarry Smith v2 = a->a + diag[row-1] + 2; 2018f0d39aaaSBarry Smith v3 = a->a + diag[row-2] + 3; 2019f0d39aaaSBarry Smith v4 = a->a + diag[row-3] + 4; 2020f0d39aaaSBarry Smith for(n = 0; n<sz-1; n+=2) { 2021f0d39aaaSBarry Smith i1 = idx[0]; 2022f0d39aaaSBarry Smith i2 = idx[1]; 2023f0d39aaaSBarry Smith idx += 2; 2024f0d39aaaSBarry Smith tmp0 = x[i1]; 2025f0d39aaaSBarry Smith tmp1 = x[i2]; 2026f0d39aaaSBarry Smith sum1 -= v1[0] * tmp0 + v1[1] * tmp1; v1 += 2; 2027f0d39aaaSBarry Smith sum2 -= v2[0] * tmp0 + v2[1] * tmp1; v2 += 2; 2028f0d39aaaSBarry Smith sum3 -= v3[0] * tmp0 + v3[1] * tmp1; v3 += 2; 2029f0d39aaaSBarry Smith sum4 -= v4[0] * tmp0 + v4[1] * tmp1; v4 += 2; 2030f0d39aaaSBarry Smith } 2031f0d39aaaSBarry Smith 2032f0d39aaaSBarry Smith if (n == sz-1){ 2033f0d39aaaSBarry Smith tmp0 = x[*idx]; 2034f0d39aaaSBarry Smith sum1 -= *v1*tmp0; 2035f0d39aaaSBarry Smith sum2 -= *v2*tmp0; 2036f0d39aaaSBarry Smith sum3 -= *v3*tmp0; 2037f0d39aaaSBarry Smith sum4 -= *v4*tmp0; 2038f0d39aaaSBarry Smith } 2039f0d39aaaSBarry Smith x[row--] = sum4*ibdiag[3] + sum3*ibdiag[7] + sum2*ibdiag[11] + sum1*ibdiag[15]; 2040f0d39aaaSBarry Smith x[row--] = sum4*ibdiag[2] + sum3*ibdiag[6] + sum2*ibdiag[10] + sum1*ibdiag[14]; 2041f0d39aaaSBarry Smith x[row--] = sum4*ibdiag[1] + sum3*ibdiag[5] + sum2*ibdiag[9] + sum1*ibdiag[13]; 2042f0d39aaaSBarry Smith x[row--] = sum4*ibdiag[0] + sum3*ibdiag[4] + sum2*ibdiag[8] + sum1*ibdiag[12]; 2043f0d39aaaSBarry Smith break; 2044f0d39aaaSBarry Smith case 5: 2045f0d39aaaSBarry Smith 2046f0d39aaaSBarry Smith sum1 = xb[row]; 2047f0d39aaaSBarry Smith sum2 = xb[row-1]; 2048f0d39aaaSBarry Smith sum3 = xb[row-2]; 2049f0d39aaaSBarry Smith sum4 = xb[row-3]; 2050f0d39aaaSBarry Smith sum5 = xb[row-4]; 2051f0d39aaaSBarry Smith v2 = a->a + diag[row-1] + 2; 2052f0d39aaaSBarry Smith v3 = a->a + diag[row-2] + 3; 2053f0d39aaaSBarry Smith v4 = a->a + diag[row-3] + 4; 2054f0d39aaaSBarry Smith v5 = a->a + diag[row-4] + 5; 2055f0d39aaaSBarry Smith for(n = 0; n<sz-1; n+=2) { 2056f0d39aaaSBarry Smith i1 = idx[0]; 2057f0d39aaaSBarry Smith i2 = idx[1]; 2058f0d39aaaSBarry Smith idx += 2; 2059f0d39aaaSBarry Smith tmp0 = x[i1]; 2060f0d39aaaSBarry Smith tmp1 = x[i2]; 2061f0d39aaaSBarry Smith sum1 -= v1[0] * tmp0 + v1[1] * tmp1; v1 += 2; 2062f0d39aaaSBarry Smith sum2 -= v2[0] * tmp0 + v2[1] * tmp1; v2 += 2; 2063f0d39aaaSBarry Smith sum3 -= v3[0] * tmp0 + v3[1] * tmp1; v3 += 2; 2064f0d39aaaSBarry Smith sum4 -= v4[0] * tmp0 + v4[1] * tmp1; v4 += 2; 2065f0d39aaaSBarry Smith sum5 -= v5[0] * tmp0 + v5[1] * tmp1; v5 += 2; 2066f0d39aaaSBarry Smith } 2067f0d39aaaSBarry Smith 2068f0d39aaaSBarry Smith if (n == sz-1){ 2069f0d39aaaSBarry Smith tmp0 = x[*idx]; 2070f0d39aaaSBarry Smith sum1 -= *v1*tmp0; 2071f0d39aaaSBarry Smith sum2 -= *v2*tmp0; 2072f0d39aaaSBarry Smith sum3 -= *v3*tmp0; 2073f0d39aaaSBarry Smith sum4 -= *v4*tmp0; 2074f0d39aaaSBarry Smith sum5 -= *v5*tmp0; 2075f0d39aaaSBarry Smith } 2076f0d39aaaSBarry Smith x[row--] = sum5*ibdiag[4] + sum4*ibdiag[9] + sum3*ibdiag[14] + sum2*ibdiag[19] + sum1*ibdiag[24]; 2077f0d39aaaSBarry Smith x[row--] = sum5*ibdiag[3] + sum4*ibdiag[8] + sum3*ibdiag[13] + sum2*ibdiag[18] + sum1*ibdiag[23]; 2078f0d39aaaSBarry Smith x[row--] = sum5*ibdiag[2] + sum4*ibdiag[7] + sum3*ibdiag[12] + sum2*ibdiag[17] + sum1*ibdiag[22]; 2079f0d39aaaSBarry Smith x[row--] = sum5*ibdiag[1] + sum4*ibdiag[6] + sum3*ibdiag[11] + sum2*ibdiag[16] + sum1*ibdiag[21]; 2080f0d39aaaSBarry Smith x[row--] = sum5*ibdiag[0] + sum4*ibdiag[5] + sum3*ibdiag[10] + sum2*ibdiag[15] + sum1*ibdiag[20]; 20818862d2efSBarry Smith break; 20828862d2efSBarry Smith default: 20838862d2efSBarry Smith SETERRQ1(PETSC_ERR_SUP,"Inode size %D not supported",sizes[i]); 20848862d2efSBarry Smith } 20852af78befSBarry Smith } 20862af78befSBarry Smith 20872af78befSBarry Smith ierr = PetscLogFlops(a->nz);CHKERRQ(ierr); 20882af78befSBarry Smith } 20892af78befSBarry Smith its--; 20902af78befSBarry Smith } 20918862d2efSBarry Smith if (its) SETERRQ(PETSC_ERR_SUP,"Currently no support for multiply SOR sweeps using inode version of AIJ matrix format;\n run with the option -mat_no_inode"); 20922af78befSBarry Smith ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr); 20932af78befSBarry Smith if (bb != xx) {ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);} 20942af78befSBarry Smith PetscFunctionReturn(0); 20952af78befSBarry Smith } 20962af78befSBarry Smith 20972af78befSBarry Smith 20984c1414c8SBarry Smith /* 20994c1414c8SBarry Smith samestructure indicates that the matrix has not changed its nonzero structure so we 21004c1414c8SBarry Smith do not need to recompute the inodes 21014c1414c8SBarry Smith */ 21024c1414c8SBarry Smith #undef __FUNCT__ 21034c1414c8SBarry Smith #define __FUNCT__ "Mat_CheckInode" 21044c1414c8SBarry Smith PetscErrorCode Mat_CheckInode(Mat A,PetscTruth samestructure) 21054c1414c8SBarry Smith { 21064c1414c8SBarry Smith Mat_SeqAIJ *a = (Mat_SeqAIJ*)A->data; 21074c1414c8SBarry Smith PetscErrorCode ierr; 21084c1414c8SBarry Smith PetscInt i,j,m,nzx,nzy,*idx,*idy,*ns,*ii,node_count,blk_size; 2109d74fe821SBarry Smith PetscTruth flag; 21104c1414c8SBarry Smith 21114c1414c8SBarry Smith PetscFunctionBegin; 2112d74fe821SBarry Smith if (!a->inode.use) PetscFunctionReturn(0); 21134c1414c8SBarry Smith if (a->inode.checked && samestructure) PetscFunctionReturn(0); 21144c1414c8SBarry Smith 21154c1414c8SBarry Smith 21164c1414c8SBarry Smith m = A->rmap.n; 21174c1414c8SBarry Smith if (a->inode.size) {ns = a->inode.size;} 21184c1414c8SBarry Smith else {ierr = PetscMalloc((m+1)*sizeof(PetscInt),&ns);CHKERRQ(ierr);} 21194c1414c8SBarry Smith 21204c1414c8SBarry Smith i = 0; 21214c1414c8SBarry Smith node_count = 0; 21224c1414c8SBarry Smith idx = a->j; 21234c1414c8SBarry Smith ii = a->i; 21244c1414c8SBarry Smith while (i < m){ /* For each row */ 21254c1414c8SBarry Smith nzx = ii[i+1] - ii[i]; /* Number of nonzeros */ 21264c1414c8SBarry Smith /* Limits the number of elements in a node to 'a->inode.limit' */ 21274c1414c8SBarry Smith for (j=i+1,idy=idx,blk_size=1; j<m && blk_size <a->inode.limit; ++j,++blk_size) { 21284c1414c8SBarry Smith nzy = ii[j+1] - ii[j]; /* Same number of nonzeros */ 21294c1414c8SBarry Smith if (nzy != nzx) break; 21304c1414c8SBarry Smith idy += nzx; /* Same nonzero pattern */ 21314c1414c8SBarry Smith ierr = PetscMemcmp(idx,idy,nzx*sizeof(PetscInt),&flag);CHKERRQ(ierr); 21324c1414c8SBarry Smith if (!flag) break; 21334c1414c8SBarry Smith } 21344c1414c8SBarry Smith ns[node_count++] = blk_size; 21354c1414c8SBarry Smith idx += blk_size*nzx; 21364c1414c8SBarry Smith i = j; 21374c1414c8SBarry Smith } 21384c1414c8SBarry Smith /* If not enough inodes found,, do not use inode version of the routines */ 2139f0d39aaaSBarry Smith if (!a->inode.size && m && node_count > .9*m) { 21404c1414c8SBarry Smith ierr = PetscFree(ns);CHKERRQ(ierr); 21414c1414c8SBarry Smith a->inode.node_count = 0; 21424c1414c8SBarry Smith a->inode.size = PETSC_NULL; 21434c1414c8SBarry Smith a->inode.use = PETSC_FALSE; 21444c1414c8SBarry Smith ierr = PetscInfo2(A,"Found %D nodes out of %D rows. Not using Inode routines\n",node_count,m);CHKERRQ(ierr); 21454c1414c8SBarry Smith } else { 21464c1414c8SBarry Smith A->ops->mult = MatMult_Inode; 21472af78befSBarry Smith A->ops->relax = MatRelax_Inode; 21484c1414c8SBarry Smith A->ops->multadd = MatMultAdd_Inode; 21494c1414c8SBarry Smith A->ops->solve = MatSolve_Inode; 21504c1414c8SBarry Smith A->ops->lufactornumeric = MatLUFactorNumeric_Inode; 21514c1414c8SBarry Smith A->ops->getrowij = MatGetRowIJ_Inode; 21524c1414c8SBarry Smith A->ops->restorerowij = MatRestoreRowIJ_Inode; 21534c1414c8SBarry Smith A->ops->getcolumnij = MatGetColumnIJ_Inode; 21544c1414c8SBarry Smith A->ops->restorecolumnij = MatRestoreColumnIJ_Inode; 21554c1414c8SBarry Smith A->ops->coloringpatch = MatColoringPatch_Inode; 21564c1414c8SBarry Smith a->inode.node_count = node_count; 21574c1414c8SBarry Smith a->inode.size = ns; 21584c1414c8SBarry Smith ierr = PetscInfo3(A,"Found %D nodes of %D. Limit used: %D. Using Inode routines\n",node_count,m,a->inode.limit);CHKERRQ(ierr); 21594c1414c8SBarry Smith } 21604c1414c8SBarry Smith PetscFunctionReturn(0); 21614c1414c8SBarry Smith } 21624c1414c8SBarry Smith 21634c1414c8SBarry Smith /* 21644c1414c8SBarry Smith This is really ugly. if inodes are used this replaces the 21654c1414c8SBarry Smith permutations with ones that correspond to rows/cols of the matrix 21664c1414c8SBarry Smith rather then inode blocks 21674c1414c8SBarry Smith */ 21684c1414c8SBarry Smith #undef __FUNCT__ 21694c1414c8SBarry Smith #define __FUNCT__ "MatInodeAdjustForInodes" 21704c1414c8SBarry Smith PetscErrorCode PETSCMAT_DLLEXPORT MatInodeAdjustForInodes(Mat A,IS *rperm,IS *cperm) 21714c1414c8SBarry Smith { 21724c1414c8SBarry Smith PetscErrorCode ierr,(*f)(Mat,IS*,IS*); 21734c1414c8SBarry Smith 21744c1414c8SBarry Smith PetscFunctionBegin; 21754c1414c8SBarry Smith ierr = PetscObjectQueryFunction((PetscObject)A,"MatInodeAdjustForInodes_C",(void (**)(void))&f);CHKERRQ(ierr); 21764c1414c8SBarry Smith if (f) { 21774c1414c8SBarry Smith ierr = (*f)(A,rperm,cperm);CHKERRQ(ierr); 21784c1414c8SBarry Smith } 21794c1414c8SBarry Smith PetscFunctionReturn(0); 21804c1414c8SBarry Smith } 21814c1414c8SBarry Smith 21824c1414c8SBarry Smith EXTERN_C_BEGIN 21834c1414c8SBarry Smith #undef __FUNCT__ 21844c1414c8SBarry Smith #define __FUNCT__ "MatAdjustForInodes_Inode" 21854c1414c8SBarry Smith PetscErrorCode PETSCMAT_DLLEXPORT MatInodeAdjustForInodes_Inode(Mat A,IS *rperm,IS *cperm) 21864c1414c8SBarry Smith { 21874c1414c8SBarry Smith Mat_SeqAIJ *a=(Mat_SeqAIJ*)A->data; 21884c1414c8SBarry Smith PetscErrorCode ierr; 21894c1414c8SBarry Smith PetscInt m = A->rmap.n,n = A->cmap.n,i,j,*ridx,*cidx,nslim_row = a->inode.node_count; 21904c1414c8SBarry Smith PetscInt row,col,*permr,*permc,*ns_row = a->inode.size,*tns,start_val,end_val,indx; 21914c1414c8SBarry Smith PetscInt nslim_col,*ns_col; 21924c1414c8SBarry Smith IS ris = *rperm,cis = *cperm; 21934c1414c8SBarry Smith 21944c1414c8SBarry Smith PetscFunctionBegin; 21954c1414c8SBarry Smith if (!a->inode.size) PetscFunctionReturn(0); /* no inodes so return */ 21964c1414c8SBarry Smith if (a->inode.node_count == m) PetscFunctionReturn(0); /* all inodes are of size 1 */ 21974c1414c8SBarry Smith 21984c1414c8SBarry Smith ierr = Mat_CreateColInode(A,&nslim_col,&ns_col);CHKERRQ(ierr); 21994c1414c8SBarry Smith ierr = PetscMalloc((((nslim_row>nslim_col)?nslim_row:nslim_col)+1)*sizeof(PetscInt),&tns);CHKERRQ(ierr); 22004c1414c8SBarry Smith ierr = PetscMalloc((m+n+1)*sizeof(PetscInt),&permr);CHKERRQ(ierr); 22014c1414c8SBarry Smith permc = permr + m; 22024c1414c8SBarry Smith 22034c1414c8SBarry Smith ierr = ISGetIndices(ris,&ridx);CHKERRQ(ierr); 22044c1414c8SBarry Smith ierr = ISGetIndices(cis,&cidx);CHKERRQ(ierr); 22054c1414c8SBarry Smith 22064c1414c8SBarry Smith /* Form the inode structure for the rows of permuted matric using inv perm*/ 22074c1414c8SBarry Smith for (i=0,tns[0]=0; i<nslim_row; ++i) tns[i+1] = tns[i] + ns_row[i]; 22084c1414c8SBarry Smith 22094c1414c8SBarry Smith /* Construct the permutations for rows*/ 22104c1414c8SBarry Smith for (i=0,row = 0; i<nslim_row; ++i){ 22114c1414c8SBarry Smith indx = ridx[i]; 22124c1414c8SBarry Smith start_val = tns[indx]; 22134c1414c8SBarry Smith end_val = tns[indx + 1]; 22144c1414c8SBarry Smith for (j=start_val; j<end_val; ++j,++row) permr[row]= j; 22154c1414c8SBarry Smith } 22164c1414c8SBarry Smith 22174c1414c8SBarry Smith /* Form the inode structure for the columns of permuted matrix using inv perm*/ 22184c1414c8SBarry Smith for (i=0,tns[0]=0; i<nslim_col; ++i) tns[i+1] = tns[i] + ns_col[i]; 22194c1414c8SBarry Smith 22204c1414c8SBarry Smith /* Construct permutations for columns */ 22214c1414c8SBarry Smith for (i=0,col=0; i<nslim_col; ++i){ 22224c1414c8SBarry Smith indx = cidx[i]; 22234c1414c8SBarry Smith start_val = tns[indx]; 22244c1414c8SBarry Smith end_val = tns[indx + 1]; 22254c1414c8SBarry Smith for (j = start_val; j<end_val; ++j,++col) permc[col]= j; 22264c1414c8SBarry Smith } 22274c1414c8SBarry Smith 22284c1414c8SBarry Smith ierr = ISCreateGeneral(PETSC_COMM_SELF,n,permr,rperm);CHKERRQ(ierr); 22294c1414c8SBarry Smith ISSetPermutation(*rperm); 22304c1414c8SBarry Smith ierr = ISCreateGeneral(PETSC_COMM_SELF,n,permc,cperm);CHKERRQ(ierr); 22314c1414c8SBarry Smith ISSetPermutation(*cperm); 22324c1414c8SBarry Smith 22334c1414c8SBarry Smith ierr = ISRestoreIndices(ris,&ridx);CHKERRQ(ierr); 22344c1414c8SBarry Smith ierr = ISRestoreIndices(cis,&cidx);CHKERRQ(ierr); 22354c1414c8SBarry Smith 22364c1414c8SBarry Smith ierr = PetscFree(ns_col);CHKERRQ(ierr); 22374c1414c8SBarry Smith ierr = PetscFree(permr);CHKERRQ(ierr); 22384c1414c8SBarry Smith ierr = ISDestroy(cis);CHKERRQ(ierr); 22394c1414c8SBarry Smith ierr = ISDestroy(ris);CHKERRQ(ierr); 22404c1414c8SBarry Smith ierr = PetscFree(tns);CHKERRQ(ierr); 22414c1414c8SBarry Smith PetscFunctionReturn(0); 22424c1414c8SBarry Smith } 22434c1414c8SBarry Smith EXTERN_C_END 22444c1414c8SBarry Smith 22454c1414c8SBarry Smith #undef __FUNCT__ 22464c1414c8SBarry Smith #define __FUNCT__ "MatInodeGetInodeSizes" 22474c1414c8SBarry Smith /*@C 22484c1414c8SBarry Smith MatInodeGetInodeSizes - Returns the inode information of the Inode matrix. 22494c1414c8SBarry Smith 22504c1414c8SBarry Smith Collective on Mat 22514c1414c8SBarry Smith 22524c1414c8SBarry Smith Input Parameter: 22534c1414c8SBarry Smith . A - the Inode matrix or matrix derived from the Inode class -- e.g., SeqAIJ 22544c1414c8SBarry Smith 22554c1414c8SBarry Smith Output Parameter: 22564c1414c8SBarry Smith + node_count - no of inodes present in the matrix. 22574c1414c8SBarry Smith . sizes - an array of size node_count,with sizes of each inode. 22584c1414c8SBarry Smith - limit - the max size used to generate the inodes. 22594c1414c8SBarry Smith 22604c1414c8SBarry Smith Level: advanced 22614c1414c8SBarry Smith 22624c1414c8SBarry Smith Notes: This routine returns some internal storage information 22634c1414c8SBarry Smith of the matrix, it is intended to be used by advanced users. 22644c1414c8SBarry Smith It should be called after the matrix is assembled. 22654c1414c8SBarry Smith The contents of the sizes[] array should not be changed. 22664c1414c8SBarry Smith PETSC_NULL may be passed for information not requested. 22674c1414c8SBarry Smith 22684c1414c8SBarry Smith .keywords: matrix, seqaij, get, inode 22694c1414c8SBarry Smith 22704c1414c8SBarry Smith .seealso: MatGetInfo() 22714c1414c8SBarry Smith @*/ 22724c1414c8SBarry Smith PetscErrorCode PETSCMAT_DLLEXPORT MatInodeGetInodeSizes(Mat A,PetscInt *node_count,PetscInt *sizes[],PetscInt *limit) 22734c1414c8SBarry Smith { 22744c1414c8SBarry Smith PetscErrorCode ierr,(*f)(Mat,PetscInt*,PetscInt*[],PetscInt*); 22754c1414c8SBarry Smith 22764c1414c8SBarry Smith PetscFunctionBegin; 22774c1414c8SBarry Smith if (!A->assembled) SETERRQ(PETSC_ERR_ARG_WRONGSTATE,"Not for unassembled matrix"); 22784c1414c8SBarry Smith ierr = PetscObjectQueryFunction((PetscObject)A,"MatInodeGetInodeSizes_C",(void (**)(void))&f);CHKERRQ(ierr); 22794c1414c8SBarry Smith if (f) { 22804c1414c8SBarry Smith ierr = (*f)(A,node_count,sizes,limit);CHKERRQ(ierr); 22814c1414c8SBarry Smith } 22824c1414c8SBarry Smith PetscFunctionReturn(0); 22834c1414c8SBarry Smith } 22844c1414c8SBarry Smith 22854c1414c8SBarry Smith EXTERN_C_BEGIN 22864c1414c8SBarry Smith #undef __FUNCT__ 22874c1414c8SBarry Smith #define __FUNCT__ "MatInodeGetInodeSizes_Inode" 22884c1414c8SBarry Smith PetscErrorCode PETSCMAT_DLLEXPORT MatInodeGetInodeSizes_Inode(Mat A,PetscInt *node_count,PetscInt *sizes[],PetscInt *limit) 22894c1414c8SBarry Smith { 22904c1414c8SBarry Smith Mat_SeqAIJ *a = (Mat_SeqAIJ*)A->data; 22914c1414c8SBarry Smith 22924c1414c8SBarry Smith PetscFunctionBegin; 22934c1414c8SBarry Smith if (node_count) *node_count = a->inode.node_count; 22944c1414c8SBarry Smith if (sizes) *sizes = a->inode.size; 22954c1414c8SBarry Smith if (limit) *limit = a->inode.limit; 22964c1414c8SBarry Smith PetscFunctionReturn(0); 22974c1414c8SBarry Smith } 22984c1414c8SBarry Smith EXTERN_C_END 2299