149b5e25fSSatish Balay /* Using Modified Sparse Row (MSR) storage. 249b5e25fSSatish Balay See page 85, "Iterative Methods ..." by Saad. */ 349b5e25fSSatish Balay 4*4445ddedSHong Zhang /*$Id: sbaijfact.c,v 1.25 2000/10/20 19:21:01 hzhang Exp bsmith $*/ 549b5e25fSSatish Balay /* 6658e7b3eSHong Zhang Symbolic (-UT)*D*(-U) factorization for SBAIJ format. Modified from SSF of YSMP. 749b5e25fSSatish Balay */ 849b5e25fSSatish Balay #include "sbaij.h" 949b5e25fSSatish Balay #include "src/mat/impls/baij/seq/baij.h" 1049b5e25fSSatish Balay #include "src/vec/vecimpl.h" 1149b5e25fSSatish Balay #include "src/inline/ilu.h" 1249a6740bSHong Zhang #include "include/petscis.h" 1349b5e25fSSatish Balay 1449b5e25fSSatish Balay #undef __FUNC__ 156f9a564bSHong Zhang #define __FUNC__ "MatCholeskyFactorSymbolic_SeqSBAIJ" 1677f73120SHong Zhang int MatCholeskyFactorSymbolic_SeqSBAIJ(Mat A,IS perm,PetscReal f,Mat *B) 1749b5e25fSSatish Balay { 1849b5e25fSSatish Balay Mat_SeqSBAIJ *a = (Mat_SeqSBAIJ*)A->data,*b; 19cb718733SHong Zhang int *rip,ierr,i,mbs = a->mbs,*ai,*aj; 20066653e3SSatish Balay int *jutmp,bs = a->bs,bs2=a->bs2; 21066653e3SSatish Balay int m,nzi,realloc = 0; 22066653e3SSatish Balay int *jl,*q,jumin,jmin,jmax,juptr,nzk,qm,*iu,*ju,k,j,vj,umax,maxadd; 23cb718733SHong Zhang /* PetscTruth ident; */ 2449b5e25fSSatish Balay 2549b5e25fSSatish Balay PetscFunctionBegin; 2677f73120SHong Zhang PetscValidHeaderSpecific(perm,IS_COOKIE); 2729bbc08cSBarry Smith if (A->M != A->N) SETERRQ(PETSC_ERR_ARG_WRONG,"matrix must be square"); 282d007305SHong Zhang 29cb718733SHong Zhang /* check whether perm is the identity mapping */ 30cb718733SHong Zhang /* 31cb718733SHong Zhang ierr = ISView(perm, VIEWER_STDOUT_SELF);CHKERRA(ierr); 32cb718733SHong Zhang ierr = ISIdentity(perm,&ident);CHKERRQ(ierr); 33cb718733SHong Zhang printf("ident = %d\n", ident); 34cb718733SHong Zhang */ 35cb718733SHong Zhang ierr = ISGetIndices(perm,&rip);CHKERRQ(ierr); 36cb718733SHong Zhang for (i=0; i<mbs; i++){ 37cb718733SHong Zhang if (rip[i] != i){ 38cb718733SHong Zhang a->permute = PETSC_TRUE; 39cb718733SHong Zhang /* printf("non-trivial perm\n"); */ 40cb718733SHong Zhang break; 4149a6740bSHong Zhang } 42cb718733SHong Zhang } 432d007305SHong Zhang 44cb718733SHong Zhang if (!a->permute){ /* without permutation */ 452d007305SHong Zhang ai = a->i; aj = a->j; 462d007305SHong Zhang } else { /* non-trivial permutation */ 472d007305SHong Zhang ierr = MatReorderingSeqSBAIJ(A, perm);CHKERRA(ierr); 482d007305SHong Zhang ai = a->inew; aj = a->jnew; 492d007305SHong Zhang } 502d007305SHong Zhang 5149b5e25fSSatish Balay /* initialization */ 5249b5e25fSSatish Balay /* Don't know how many column pointers are needed so estimate. 5349b5e25fSSatish Balay Use Modified Sparse Row storage for u and ju, see Sasd pp.85 */ 549f9cb213SHong Zhang iu = (int*)PetscMalloc((mbs+1)*sizeof(int));CHKPTRQ(iu); 5549b5e25fSSatish Balay umax = (int)(f*ai[mbs] + 1); umax += mbs + 1; 569f9cb213SHong Zhang ju = (int*)PetscMalloc(umax*sizeof(int));CHKPTRQ(ju); 5749b5e25fSSatish Balay iu[0] = mbs+1; 5849b5e25fSSatish Balay juptr = mbs; 5949b5e25fSSatish Balay jl = (int*)PetscMalloc(mbs*sizeof(int));CHKPTRQ(jl); 6049b5e25fSSatish Balay q = (int*)PetscMalloc(mbs*sizeof(int));CHKPTRQ(q); 6149b5e25fSSatish Balay for (i=0; i<mbs; i++){ 6249b5e25fSSatish Balay jl[i] = mbs; q[i] = 0; 6349b5e25fSSatish Balay } 6449b5e25fSSatish Balay 6549b5e25fSSatish Balay /* for each row k */ 6649b5e25fSSatish Balay for (k=0; k<mbs; k++){ 6749b5e25fSSatish Balay nzk = 0; /* num. of nz blocks in k-th block row with diagonal block excluded */ 6849b5e25fSSatish Balay q[k] = mbs; 6949b5e25fSSatish Balay /* initialize nonzero structure of k-th row to row rip[k] of A */ 7049b5e25fSSatish Balay jmin = ai[rip[k]]; 7149b5e25fSSatish Balay jmax = ai[rip[k]+1]; 7249b5e25fSSatish Balay for (j=jmin; j<jmax; j++){ 73cb718733SHong Zhang vj = rip[aj[j]]; /* col. value */ 7449b5e25fSSatish Balay if(vj > k){ 7549b5e25fSSatish Balay qm = k; 7649b5e25fSSatish Balay do { 7749b5e25fSSatish Balay m = qm; qm = q[m]; 7849b5e25fSSatish Balay } while(qm < vj); 7949b5e25fSSatish Balay if (qm == vj) { 8049b5e25fSSatish Balay printf(" error: duplicate entry in A\n"); break; 8149b5e25fSSatish Balay } 8249b5e25fSSatish Balay nzk++; 8349b5e25fSSatish Balay q[m] = vj; 8449b5e25fSSatish Balay q[vj] = qm; 8549b5e25fSSatish Balay } /* if(vj > k) */ 8649b5e25fSSatish Balay } /* for (j=jmin; j<jmax; j++) */ 8749b5e25fSSatish Balay 8849b5e25fSSatish Balay /* modify nonzero structure of k-th row by computing fill-in 8949b5e25fSSatish Balay for each row i to be merged in */ 9049b5e25fSSatish Balay i = k; 9149b5e25fSSatish Balay i = jl[i]; /* next pivot row (== mbs for symbolic factorization) */ 9249b5e25fSSatish Balay /* printf(" next pivot row i=%d\n",i); */ 9349b5e25fSSatish Balay while (i < mbs){ 9449b5e25fSSatish Balay /* merge row i into k-th row */ 9549b5e25fSSatish Balay nzi = iu[i+1] - (iu[i]+1); 9649b5e25fSSatish Balay jmin = iu[i] + 1; jmax = iu[i] + nzi; 9749b5e25fSSatish Balay qm = k; 9849b5e25fSSatish Balay for (j=jmin; j<jmax+1; j++){ 9949b5e25fSSatish Balay vj = ju[j]; 10049b5e25fSSatish Balay do { 10149b5e25fSSatish Balay m = qm; qm = q[m]; 10249b5e25fSSatish Balay } while (qm < vj); 10349b5e25fSSatish Balay if (qm != vj){ 10449b5e25fSSatish Balay nzk++; q[m] = vj; q[vj] = qm; qm = vj; 10549b5e25fSSatish Balay } 10649b5e25fSSatish Balay } 10749b5e25fSSatish Balay i = jl[i]; /* next pivot row */ 10849b5e25fSSatish Balay } 10949b5e25fSSatish Balay 11049b5e25fSSatish Balay /* add k to row list for first nonzero element in k-th row */ 11149b5e25fSSatish Balay if (nzk > 0){ 11249b5e25fSSatish Balay i = q[k]; /* col value of first nonzero element in U(k, k+1:mbs-1) */ 11349b5e25fSSatish Balay jl[k] = jl[i]; jl[i] = k; 11449b5e25fSSatish Balay } 11549b5e25fSSatish Balay iu[k+1] = iu[k] + nzk; /* printf(" iu[%d]=%d, umax=%d\n", k+1, iu[k+1],umax);*/ 11649b5e25fSSatish Balay 11749b5e25fSSatish Balay /* allocate more space to ju if needed */ 11849b5e25fSSatish Balay if (iu[k+1] > umax) { printf("allocate more space, iu[%d]=%d > umax=%d\n",k+1, iu[k+1],umax); 11949b5e25fSSatish Balay /* estimate how much additional space we will need */ 12049b5e25fSSatish Balay /* use the strategy suggested by David Hysom <hysom@perch-t.icase.edu> */ 12149b5e25fSSatish Balay /* just double the memory each time */ 12249b5e25fSSatish Balay maxadd = umax; 12349b5e25fSSatish Balay if (maxadd < nzk) maxadd = (mbs-k)*(nzk+1)/2; 12449b5e25fSSatish Balay umax += maxadd; 12549b5e25fSSatish Balay 1269f9cb213SHong Zhang /* allocate a longer ju */ 12749b5e25fSSatish Balay jutmp = (int*)PetscMalloc(umax*sizeof(int));CHKPTRQ(jutmp); 12849b5e25fSSatish Balay ierr = PetscMemcpy(jutmp,ju,iu[k]*sizeof(int));CHKERRQ(ierr); 12949b5e25fSSatish Balay ierr = PetscFree(ju);CHKERRQ(ierr); 1309f9cb213SHong Zhang ju = jutmp; 13149b5e25fSSatish Balay realloc++; /* count how many times we realloc */ 13249b5e25fSSatish Balay } 13349b5e25fSSatish Balay 13449b5e25fSSatish Balay /* save nonzero structure of k-th row in ju */ 13549b5e25fSSatish Balay i=k; 13649b5e25fSSatish Balay jumin = juptr + 1; juptr += nzk; 13749b5e25fSSatish Balay for (j=jumin; j<juptr+1; j++){ 13849b5e25fSSatish Balay i=q[i]; 13949b5e25fSSatish Balay ju[j]=i; 14049b5e25fSSatish Balay } 14177f73120SHong Zhang } 14249b5e25fSSatish Balay 14349b5e25fSSatish Balay if (ai[mbs] != 0) { 14449b5e25fSSatish Balay PetscReal af = ((PetscReal)iu[mbs])/((PetscReal)ai[mbs]); 1456f9a564bSHong Zhang PLogInfo(A,"MatCholeskyFactorSymbolic_SeqSBAIJ:Reallocs %d Fill ratio:given %g needed %g\n",realloc,f,af); 1466f9a564bSHong Zhang PLogInfo(A,"MatCholeskyFactorSymbolic_SeqSBAIJ:Run with -pc_lu_fill %g or use \n",af); 1476f9a564bSHong Zhang PLogInfo(A,"MatCholeskyFactorSymbolic_SeqSBAIJ:PCLUSetFill(pc,%g);\n",af); 1486f9a564bSHong Zhang PLogInfo(A,"MatCholeskyFactorSymbolic_SeqSBAIJ:for best performance.\n"); 14949b5e25fSSatish Balay } else { 1506f9a564bSHong Zhang PLogInfo(A,"MatCholeskyFactorSymbolic_SeqSBAIJ:Empty matrix.\n"); 15149b5e25fSSatish Balay } 15249b5e25fSSatish Balay 15377f73120SHong Zhang ierr = ISRestoreIndices(perm,&rip);CHKERRQ(ierr); 15449b5e25fSSatish Balay ierr = PetscFree(q);CHKERRQ(ierr); 15549b5e25fSSatish Balay ierr = PetscFree(jl);CHKERRQ(ierr); 15649b5e25fSSatish Balay 15749b5e25fSSatish Balay /* put together the new matrix */ 15849b5e25fSSatish Balay ierr = MatCreateSeqSBAIJ(A->comm,bs,bs*mbs,bs*mbs,0,PETSC_NULL,B);CHKERRQ(ierr); 1593d840bdaSHong Zhang /* PLogObjectParent(*B,iperm); */ 16049b5e25fSSatish Balay b = (Mat_SeqSBAIJ*)(*B)->data; 16149b5e25fSSatish Balay ierr = PetscFree(b->imax);CHKERRQ(ierr); 16249b5e25fSSatish Balay b->singlemalloc = PETSC_FALSE; 16349b5e25fSSatish Balay /* the next line frees the default space generated by the Create() */ 16449b5e25fSSatish Balay ierr = PetscFree(b->a);CHKERRQ(ierr); 16549b5e25fSSatish Balay ierr = PetscFree(b->ilen);CHKERRQ(ierr); 16649b5e25fSSatish Balay b->a = (MatScalar*)PetscMalloc((iu[mbs]+1)*sizeof(MatScalar)*bs2);CHKPTRQ(b->a); 16749b5e25fSSatish Balay b->j = ju; 16849b5e25fSSatish Balay b->i = iu; 16949b5e25fSSatish Balay b->diag = 0; 17049b5e25fSSatish Balay b->ilen = 0; 17149b5e25fSSatish Balay b->imax = 0; 17277f73120SHong Zhang b->row = perm; 17377f73120SHong Zhang ierr = PetscObjectReference((PetscObject)perm);CHKERRQ(ierr); 174cb718733SHong Zhang b->icol = perm; 175cb718733SHong Zhang ierr = PetscObjectReference((PetscObject)perm);CHKERRQ(ierr); 17649b5e25fSSatish Balay b->solve_work = (Scalar*)PetscMalloc((bs*mbs+bs)*sizeof(Scalar));CHKPTRQ(b->solve_work); 17749b5e25fSSatish Balay /* In b structure: Free imax, ilen, old a, old j. 17849b5e25fSSatish Balay Allocate idnew, solve_work, new a, new j */ 17949b5e25fSSatish Balay PLogObjectMemory(*B,(iu[mbs]-mbs)*(sizeof(int)+sizeof(MatScalar))); 18049b5e25fSSatish Balay b->s_maxnz = b->s_nz = iu[mbs]; 18149b5e25fSSatish Balay 18249b5e25fSSatish Balay (*B)->factor = FACTOR_LU; 18349b5e25fSSatish Balay (*B)->info.factor_mallocs = realloc; 18449b5e25fSSatish Balay (*B)->info.fill_ratio_given = f; 18549b5e25fSSatish Balay if (ai[mbs] != 0) { 18649b5e25fSSatish Balay (*B)->info.fill_ratio_needed = ((PetscReal)iu[mbs])/((PetscReal)ai[mbs]); 18749b5e25fSSatish Balay } else { 18849b5e25fSSatish Balay (*B)->info.fill_ratio_needed = 0.0; 18949b5e25fSSatish Balay } 19049b5e25fSSatish Balay PetscFunctionReturn(0); 19149b5e25fSSatish Balay } 19249b5e25fSSatish Balay 19349b5e25fSSatish Balay #undef __FUNC__ 1946f9a564bSHong Zhang #define __FUNC__ "MatCholeskyFactorNumeric_SeqSBAIJ_N" 1956f9a564bSHong Zhang int MatCholeskyFactorNumeric_SeqSBAIJ_N(Mat A,Mat *B) 19649b5e25fSSatish Balay { 19749b5e25fSSatish Balay Mat C = *B; 19849b5e25fSSatish Balay Mat_SeqBAIJ *a = (Mat_SeqBAIJ*)A->data,*b = (Mat_SeqBAIJ *)C->data; 19949b5e25fSSatish Balay IS isrow = b->row,isicol = b->icol; 20049b5e25fSSatish Balay int *r,*ic,ierr,i,j,n = a->mbs,*bi = b->i,*bj = b->j; 20149b5e25fSSatish Balay int *ajtmpold,*ajtmp,nz,row,bslog,*ai=a->i,*aj=a->j,k,flg; 20249b5e25fSSatish Balay int *diag_offset=b->diag,diag,bs=a->bs,bs2 = a->bs2,*v_pivots,*pj; 20349b5e25fSSatish Balay MatScalar *ba = b->a,*aa = a->a,*pv,*v,*rtmp,*multiplier,*v_work,*pc,*w; 20449b5e25fSSatish Balay 20549b5e25fSSatish Balay PetscFunctionBegin; 20649b5e25fSSatish Balay ierr = ISGetIndices(isrow,&r);CHKERRQ(ierr); 20749b5e25fSSatish Balay ierr = ISGetIndices(isicol,&ic);CHKERRQ(ierr); 20849b5e25fSSatish Balay rtmp = (MatScalar*)PetscMalloc(bs2*(n+1)*sizeof(MatScalar));CHKPTRQ(rtmp); 20949b5e25fSSatish Balay ierr = PetscMemzero(rtmp,bs2*(n+1)*sizeof(MatScalar));CHKERRQ(ierr); 21049b5e25fSSatish Balay /* generate work space needed by dense LU factorization */ 21149b5e25fSSatish Balay v_work = (MatScalar*)PetscMalloc(bs*sizeof(int) + (bs+bs2)*sizeof(MatScalar));CHKPTRQ(v_work); 21249b5e25fSSatish Balay multiplier = v_work + bs; 21349b5e25fSSatish Balay v_pivots = (int*)(multiplier + bs2); 21449b5e25fSSatish Balay 21549b5e25fSSatish Balay /* flops in while loop */ 21649b5e25fSSatish Balay bslog = 2*bs*bs2; 21749b5e25fSSatish Balay 21849b5e25fSSatish Balay for (i=0; i<n; i++) { 21949b5e25fSSatish Balay nz = bi[i+1] - bi[i]; 22049b5e25fSSatish Balay ajtmp = bj + bi[i]; 22149b5e25fSSatish Balay for (j=0; j<nz; j++) { 22249b5e25fSSatish Balay ierr = PetscMemzero(rtmp+bs2*ajtmp[j],bs2*sizeof(MatScalar));CHKERRQ(ierr); 22349b5e25fSSatish Balay } 22449b5e25fSSatish Balay /* load in initial (unfactored row) */ 22549b5e25fSSatish Balay nz = ai[r[i]+1] - ai[r[i]]; 22649b5e25fSSatish Balay ajtmpold = aj + ai[r[i]]; 22749b5e25fSSatish Balay v = aa + bs2*ai[r[i]]; 22849b5e25fSSatish Balay for (j=0; j<nz; j++) { 22949b5e25fSSatish Balay ierr = PetscMemcpy(rtmp+bs2*ic[ajtmpold[j]],v+bs2*j,bs2*sizeof(MatScalar));CHKERRQ(ierr); 23049b5e25fSSatish Balay } 23149b5e25fSSatish Balay row = *ajtmp++; 23249b5e25fSSatish Balay while (row < i) { 23349b5e25fSSatish Balay pc = rtmp + bs2*row; 23449b5e25fSSatish Balay /* if (*pc) { */ 23549b5e25fSSatish Balay for (flg=0,k=0; k<bs2; k++) { if (pc[k]!=0.0) { flg =1; break; }} 23649b5e25fSSatish Balay if (flg) { 23749b5e25fSSatish Balay pv = ba + bs2*diag_offset[row]; 23849b5e25fSSatish Balay pj = bj + diag_offset[row] + 1; 23949b5e25fSSatish Balay Kernel_A_gets_A_times_B(bs,pc,pv,multiplier); 24049b5e25fSSatish Balay nz = bi[row+1] - diag_offset[row] - 1; 24149b5e25fSSatish Balay pv += bs2; 24249b5e25fSSatish Balay for (j=0; j<nz; j++) { 24349b5e25fSSatish Balay Kernel_A_gets_A_minus_B_times_C(bs,rtmp+bs2*pj[j],pc,pv+bs2*j); 24449b5e25fSSatish Balay } 24549b5e25fSSatish Balay PLogFlops(bslog*(nz+1)-bs); 24649b5e25fSSatish Balay } 24749b5e25fSSatish Balay row = *ajtmp++; 24849b5e25fSSatish Balay } 24949b5e25fSSatish Balay /* finished row so stick it into b->a */ 25049b5e25fSSatish Balay pv = ba + bs2*bi[i]; 25149b5e25fSSatish Balay pj = bj + bi[i]; 25249b5e25fSSatish Balay nz = bi[i+1] - bi[i]; 25349b5e25fSSatish Balay for (j=0; j<nz; j++) { 25449b5e25fSSatish Balay ierr = PetscMemcpy(pv+bs2*j,rtmp+bs2*pj[j],bs2*sizeof(MatScalar));CHKERRQ(ierr); 25549b5e25fSSatish Balay } 25649b5e25fSSatish Balay diag = diag_offset[i] - bi[i]; 25749b5e25fSSatish Balay /* invert diagonal block */ 25849b5e25fSSatish Balay w = pv + bs2*diag; 25949b5e25fSSatish Balay Kernel_A_gets_inverse_A(bs,w,v_pivots,v_work); 26049b5e25fSSatish Balay } 26149b5e25fSSatish Balay 26249b5e25fSSatish Balay ierr = PetscFree(rtmp);CHKERRQ(ierr); 26349b5e25fSSatish Balay ierr = PetscFree(v_work);CHKERRQ(ierr); 26449b5e25fSSatish Balay ierr = ISRestoreIndices(isicol,&ic);CHKERRQ(ierr); 26549b5e25fSSatish Balay ierr = ISRestoreIndices(isrow,&r);CHKERRQ(ierr); 26649b5e25fSSatish Balay C->factor = FACTOR_LU; 26749b5e25fSSatish Balay C->assembled = PETSC_TRUE; 26849b5e25fSSatish Balay PLogFlops(1.3333*bs*bs2*b->mbs); /* from inverting diagonal blocks */ 26949b5e25fSSatish Balay PetscFunctionReturn(0); 27049b5e25fSSatish Balay } 271d4edadd4SHong Zhang 27249b5e25fSSatish Balay /* 27349b5e25fSSatish Balay Version for when blocks are 7 by 7 27449b5e25fSSatish Balay */ 27549b5e25fSSatish Balay #undef __FUNC__ 2766f9a564bSHong Zhang #define __FUNC__ "MatCholeskyFactorNumeric_SeqSBAIJ_7" 2776f9a564bSHong Zhang int MatCholeskyFactorNumeric_SeqSBAIJ_7(Mat A,Mat *B) 27849b5e25fSSatish Balay { 27949b5e25fSSatish Balay Mat C = *B; 28049b5e25fSSatish Balay Mat_SeqBAIJ *a = (Mat_SeqBAIJ*)A->data,*b = (Mat_SeqBAIJ *)C->data; 28149b5e25fSSatish Balay IS isrow = b->row,isicol = b->icol; 28249b5e25fSSatish Balay int *r,*ic,ierr,i,j,n = a->mbs,*bi = b->i,*bj = b->j; 28349b5e25fSSatish Balay int *ajtmpold,*ajtmp,nz,row; 28449b5e25fSSatish Balay int *diag_offset = b->diag,idx,*ai=a->i,*aj=a->j,*pj; 28549b5e25fSSatish Balay MatScalar *pv,*v,*rtmp,*pc,*w,*x; 28649b5e25fSSatish Balay MatScalar p1,p2,p3,p4,m1,m2,m3,m4,m5,m6,m7,m8,m9,x1,x2,x3,x4; 28749b5e25fSSatish Balay MatScalar p5,p6,p7,p8,p9,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,x16; 28849b5e25fSSatish Balay MatScalar x17,x18,x19,x20,x21,x22,x23,x24,x25,p10,p11,p12,p13,p14; 28949b5e25fSSatish Balay MatScalar p15,p16,p17,p18,p19,p20,p21,p22,p23,p24,p25,m10,m11,m12; 29049b5e25fSSatish Balay MatScalar m13,m14,m15,m16,m17,m18,m19,m20,m21,m22,m23,m24,m25; 29149b5e25fSSatish Balay MatScalar p26,p27,p28,p29,p30,p31,p32,p33,p34,p35,p36; 29249b5e25fSSatish Balay MatScalar p37,p38,p39,p40,p41,p42,p43,p44,p45,p46,p47,p48,p49; 29349b5e25fSSatish Balay MatScalar x26,x27,x28,x29,x30,x31,x32,x33,x34,x35,x36; 29449b5e25fSSatish Balay MatScalar x37,x38,x39,x40,x41,x42,x43,x44,x45,x46,x47,x48,x49; 29549b5e25fSSatish Balay MatScalar m26,m27,m28,m29,m30,m31,m32,m33,m34,m35,m36; 29649b5e25fSSatish Balay MatScalar m37,m38,m39,m40,m41,m42,m43,m44,m45,m46,m47,m48,m49; 29749b5e25fSSatish Balay MatScalar *ba = b->a,*aa = a->a; 29849b5e25fSSatish Balay 29949b5e25fSSatish Balay PetscFunctionBegin; 30049b5e25fSSatish Balay ierr = ISGetIndices(isrow,&r);CHKERRQ(ierr); 30149b5e25fSSatish Balay ierr = ISGetIndices(isicol,&ic);CHKERRQ(ierr); 30249b5e25fSSatish Balay rtmp = (MatScalar*)PetscMalloc(49*(n+1)*sizeof(MatScalar));CHKPTRQ(rtmp); 30349b5e25fSSatish Balay 30449b5e25fSSatish Balay for (i=0; i<n; i++) { 30549b5e25fSSatish Balay nz = bi[i+1] - bi[i]; 30649b5e25fSSatish Balay ajtmp = bj + bi[i]; 30749b5e25fSSatish Balay for (j=0; j<nz; j++) { 30849b5e25fSSatish Balay x = rtmp+49*ajtmp[j]; 30949b5e25fSSatish Balay x[0] = x[1] = x[2] = x[3] = x[4] = x[5] = x[6] = x[7] = x[8] = x[9] = 0.0; 31049b5e25fSSatish Balay x[10] = x[11] = x[12] = x[13] = x[14] = x[15] = x[16] = x[17] = 0.0; 31149b5e25fSSatish Balay x[18] = x[19] = x[20] = x[21] = x[22] = x[23] = x[24] = x[25] = 0.0 ; 31249b5e25fSSatish Balay x[26] = x[27] = x[28] = x[29] = x[30] = x[31] = x[32] = x[33] = 0.0 ; 31349b5e25fSSatish Balay x[34] = x[35] = x[36] = x[37] = x[38] = x[39] = x[40] = x[41] = 0.0 ; 31449b5e25fSSatish Balay x[42] = x[43] = x[44] = x[45] = x[46] = x[47] = x[48] = 0.0 ; 31549b5e25fSSatish Balay } 31649b5e25fSSatish Balay /* load in initial (unfactored row) */ 31749b5e25fSSatish Balay idx = r[i]; 31849b5e25fSSatish Balay nz = ai[idx+1] - ai[idx]; 31949b5e25fSSatish Balay ajtmpold = aj + ai[idx]; 32049b5e25fSSatish Balay v = aa + 49*ai[idx]; 32149b5e25fSSatish Balay for (j=0; j<nz; j++) { 32249b5e25fSSatish Balay x = rtmp+49*ic[ajtmpold[j]]; 32349b5e25fSSatish Balay x[0] = v[0]; x[1] = v[1]; x[2] = v[2]; x[3] = v[3]; 32449b5e25fSSatish Balay x[4] = v[4]; x[5] = v[5]; x[6] = v[6]; x[7] = v[7]; 32549b5e25fSSatish Balay x[8] = v[8]; x[9] = v[9]; x[10] = v[10]; x[11] = v[11]; 32649b5e25fSSatish Balay x[12] = v[12]; x[13] = v[13]; x[14] = v[14]; x[15] = v[15]; 32749b5e25fSSatish Balay x[16] = v[16]; x[17] = v[17]; x[18] = v[18]; x[19] = v[19]; 32849b5e25fSSatish Balay x[20] = v[20]; x[21] = v[21]; x[22] = v[22]; x[23] = v[23]; 32949b5e25fSSatish Balay x[24] = v[24]; x[25] = v[25]; x[26] = v[26]; x[27] = v[27]; 33049b5e25fSSatish Balay x[28] = v[28]; x[29] = v[29]; x[30] = v[30]; x[31] = v[31]; 33149b5e25fSSatish Balay x[32] = v[32]; x[33] = v[33]; x[34] = v[34]; x[35] = v[35]; 33249b5e25fSSatish Balay x[36] = v[36]; x[37] = v[37]; x[38] = v[38]; x[39] = v[39]; 33349b5e25fSSatish Balay x[40] = v[40]; x[41] = v[41]; x[42] = v[42]; x[43] = v[43]; 33449b5e25fSSatish Balay x[44] = v[44]; x[45] = v[45]; x[46] = v[46]; x[47] = v[47]; 33549b5e25fSSatish Balay x[48] = v[48]; 33649b5e25fSSatish Balay v += 49; 33749b5e25fSSatish Balay } 33849b5e25fSSatish Balay row = *ajtmp++; 33949b5e25fSSatish Balay while (row < i) { 34049b5e25fSSatish Balay pc = rtmp + 49*row; 34149b5e25fSSatish Balay p1 = pc[0]; p2 = pc[1]; p3 = pc[2]; p4 = pc[3]; 34249b5e25fSSatish Balay p5 = pc[4]; p6 = pc[5]; p7 = pc[6]; p8 = pc[7]; 34349b5e25fSSatish Balay p9 = pc[8]; p10 = pc[9]; p11 = pc[10]; p12 = pc[11]; 34449b5e25fSSatish Balay p13 = pc[12]; p14 = pc[13]; p15 = pc[14]; p16 = pc[15]; 34549b5e25fSSatish Balay p17 = pc[16]; p18 = pc[17]; p19 = pc[18]; p20 = pc[19]; 34649b5e25fSSatish Balay p21 = pc[20]; p22 = pc[21]; p23 = pc[22]; p24 = pc[23]; 34749b5e25fSSatish Balay p25 = pc[24]; p26 = pc[25]; p27 = pc[26]; p28 = pc[27]; 34849b5e25fSSatish Balay p29 = pc[28]; p30 = pc[29]; p31 = pc[30]; p32 = pc[31]; 34949b5e25fSSatish Balay p33 = pc[32]; p34 = pc[33]; p35 = pc[34]; p36 = pc[35]; 35049b5e25fSSatish Balay p37 = pc[36]; p38 = pc[37]; p39 = pc[38]; p40 = pc[39]; 35149b5e25fSSatish Balay p41 = pc[40]; p42 = pc[41]; p43 = pc[42]; p44 = pc[43]; 35249b5e25fSSatish Balay p45 = pc[44]; p46 = pc[45]; p47 = pc[46]; p48 = pc[47]; 35349b5e25fSSatish Balay p49 = pc[48]; 35449b5e25fSSatish Balay if (p1 != 0.0 || p2 != 0.0 || p3 != 0.0 || p4 != 0.0 || 35549b5e25fSSatish Balay p5 != 0.0 || p6 != 0.0 || p7 != 0.0 || p8 != 0.0 || 35649b5e25fSSatish Balay p9 != 0.0 || p10 != 0.0 || p11 != 0.0 || p12 != 0.0 || 35749b5e25fSSatish Balay p13 != 0.0 || p14 != 0.0 || p15 != 0.0 || p16 != 0.0 || 35849b5e25fSSatish Balay p17 != 0.0 || p18 != 0.0 || p19 != 0.0 || p20 != 0.0 || 35949b5e25fSSatish Balay p21 != 0.0 || p22 != 0.0 || p23 != 0.0 || p24 != 0.0 || 36049b5e25fSSatish Balay p25 != 0.0 || p26 != 0.0 || p27 != 0.0 || p28 != 0.0 || 36149b5e25fSSatish Balay p29 != 0.0 || p30 != 0.0 || p31 != 0.0 || p32 != 0.0 || 36249b5e25fSSatish Balay p33 != 0.0 || p34 != 0.0 || p35 != 0.0 || p36 != 0.0 || 36349b5e25fSSatish Balay p37 != 0.0 || p38 != 0.0 || p39 != 0.0 || p40 != 0.0 || 36449b5e25fSSatish Balay p41 != 0.0 || p42 != 0.0 || p43 != 0.0 || p44 != 0.0 || 36549b5e25fSSatish Balay p45 != 0.0 || p46 != 0.0 || p47 != 0.0 || p48 != 0.0 || 36649b5e25fSSatish Balay p49 != 0.0) { 36749b5e25fSSatish Balay pv = ba + 49*diag_offset[row]; 36849b5e25fSSatish Balay pj = bj + diag_offset[row] + 1; 36949b5e25fSSatish Balay x1 = pv[0]; x2 = pv[1]; x3 = pv[2]; x4 = pv[3]; 37049b5e25fSSatish Balay x5 = pv[4]; x6 = pv[5]; x7 = pv[6]; x8 = pv[7]; 37149b5e25fSSatish Balay x9 = pv[8]; x10 = pv[9]; x11 = pv[10]; x12 = pv[11]; 37249b5e25fSSatish Balay x13 = pv[12]; x14 = pv[13]; x15 = pv[14]; x16 = pv[15]; 37349b5e25fSSatish Balay x17 = pv[16]; x18 = pv[17]; x19 = pv[18]; x20 = pv[19]; 37449b5e25fSSatish Balay x21 = pv[20]; x22 = pv[21]; x23 = pv[22]; x24 = pv[23]; 37549b5e25fSSatish Balay x25 = pv[24]; x26 = pv[25]; x27 = pv[26]; x28 = pv[27]; 37649b5e25fSSatish Balay x29 = pv[28]; x30 = pv[29]; x31 = pv[30]; x32 = pv[31]; 37749b5e25fSSatish Balay x33 = pv[32]; x34 = pv[33]; x35 = pv[34]; x36 = pv[35]; 37849b5e25fSSatish Balay x37 = pv[36]; x38 = pv[37]; x39 = pv[38]; x40 = pv[39]; 37949b5e25fSSatish Balay x41 = pv[40]; x42 = pv[41]; x43 = pv[42]; x44 = pv[43]; 38049b5e25fSSatish Balay x45 = pv[44]; x46 = pv[45]; x47 = pv[46]; x48 = pv[47]; 38149b5e25fSSatish Balay x49 = pv[48]; 38249b5e25fSSatish Balay pc[0] = m1 = p1*x1 + p8*x2 + p15*x3 + p22*x4 + p29*x5 + p36*x6 + p43*x7; 38349b5e25fSSatish Balay pc[1] = m2 = p2*x1 + p9*x2 + p16*x3 + p23*x4 + p30*x5 + p37*x6 + p44*x7; 38449b5e25fSSatish Balay pc[2] = m3 = p3*x1 + p10*x2 + p17*x3 + p24*x4 + p31*x5 + p38*x6 + p45*x7; 38549b5e25fSSatish Balay pc[3] = m4 = p4*x1 + p11*x2 + p18*x3 + p25*x4 + p32*x5 + p39*x6 + p46*x7; 38649b5e25fSSatish Balay pc[4] = m5 = p5*x1 + p12*x2 + p19*x3 + p26*x4 + p33*x5 + p40*x6 + p47*x7; 38749b5e25fSSatish Balay pc[5] = m6 = p6*x1 + p13*x2 + p20*x3 + p27*x4 + p34*x5 + p41*x6 + p48*x7; 38849b5e25fSSatish Balay pc[6] = m7 = p7*x1 + p14*x2 + p21*x3 + p28*x4 + p35*x5 + p42*x6 + p49*x7; 38949b5e25fSSatish Balay 39049b5e25fSSatish Balay pc[7] = m8 = p1*x8 + p8*x9 + p15*x10 + p22*x11 + p29*x12 + p36*x13 + p43*x14; 39149b5e25fSSatish Balay pc[8] = m9 = p2*x8 + p9*x9 + p16*x10 + p23*x11 + p30*x12 + p37*x13 + p44*x14; 39249b5e25fSSatish Balay pc[9] = m10 = p3*x8 + p10*x9 + p17*x10 + p24*x11 + p31*x12 + p38*x13 + p45*x14; 39349b5e25fSSatish Balay pc[10] = m11 = p4*x8 + p11*x9 + p18*x10 + p25*x11 + p32*x12 + p39*x13 + p46*x14; 39449b5e25fSSatish Balay pc[11] = m12 = p5*x8 + p12*x9 + p19*x10 + p26*x11 + p33*x12 + p40*x13 + p47*x14; 39549b5e25fSSatish Balay pc[12] = m13 = p6*x8 + p13*x9 + p20*x10 + p27*x11 + p34*x12 + p41*x13 + p48*x14; 39649b5e25fSSatish Balay pc[13] = m14 = p7*x8 + p14*x9 + p21*x10 + p28*x11 + p35*x12 + p42*x13 + p49*x14; 39749b5e25fSSatish Balay 39849b5e25fSSatish Balay pc[14] = m15 = p1*x15 + p8*x16 + p15*x17 + p22*x18 + p29*x19 + p36*x20 + p43*x21; 39949b5e25fSSatish Balay pc[15] = m16 = p2*x15 + p9*x16 + p16*x17 + p23*x18 + p30*x19 + p37*x20 + p44*x21; 40049b5e25fSSatish Balay pc[16] = m17 = p3*x15 + p10*x16 + p17*x17 + p24*x18 + p31*x19 + p38*x20 + p45*x21; 40149b5e25fSSatish Balay pc[17] = m18 = p4*x15 + p11*x16 + p18*x17 + p25*x18 + p32*x19 + p39*x20 + p46*x21; 40249b5e25fSSatish Balay pc[18] = m19 = p5*x15 + p12*x16 + p19*x17 + p26*x18 + p33*x19 + p40*x20 + p47*x21; 40349b5e25fSSatish Balay pc[19] = m20 = p6*x15 + p13*x16 + p20*x17 + p27*x18 + p34*x19 + p41*x20 + p48*x21; 40449b5e25fSSatish Balay pc[20] = m21 = p7*x15 + p14*x16 + p21*x17 + p28*x18 + p35*x19 + p42*x20 + p49*x21; 40549b5e25fSSatish Balay 40649b5e25fSSatish Balay pc[21] = m22 = p1*x22 + p8*x23 + p15*x24 + p22*x25 + p29*x26 + p36*x27 + p43*x28; 40749b5e25fSSatish Balay pc[22] = m23 = p2*x22 + p9*x23 + p16*x24 + p23*x25 + p30*x26 + p37*x27 + p44*x28; 40849b5e25fSSatish Balay pc[23] = m24 = p3*x22 + p10*x23 + p17*x24 + p24*x25 + p31*x26 + p38*x27 + p45*x28; 40949b5e25fSSatish Balay pc[24] = m25 = p4*x22 + p11*x23 + p18*x24 + p25*x25 + p32*x26 + p39*x27 + p46*x28; 41049b5e25fSSatish Balay pc[25] = m26 = p5*x22 + p12*x23 + p19*x24 + p26*x25 + p33*x26 + p40*x27 + p47*x28; 41149b5e25fSSatish Balay pc[26] = m27 = p6*x22 + p13*x23 + p20*x24 + p27*x25 + p34*x26 + p41*x27 + p48*x28; 41249b5e25fSSatish Balay pc[27] = m28 = p7*x22 + p14*x23 + p21*x24 + p28*x25 + p35*x26 + p42*x27 + p49*x28; 41349b5e25fSSatish Balay 41449b5e25fSSatish Balay pc[28] = m29 = p1*x29 + p8*x30 + p15*x31 + p22*x32 + p29*x33 + p36*x34 + p43*x35; 41549b5e25fSSatish Balay pc[29] = m30 = p2*x29 + p9*x30 + p16*x31 + p23*x32 + p30*x33 + p37*x34 + p44*x35; 41649b5e25fSSatish Balay pc[30] = m31 = p3*x29 + p10*x30 + p17*x31 + p24*x32 + p31*x33 + p38*x34 + p45*x35; 41749b5e25fSSatish Balay pc[31] = m32 = p4*x29 + p11*x30 + p18*x31 + p25*x32 + p32*x33 + p39*x34 + p46*x35; 41849b5e25fSSatish Balay pc[32] = m33 = p5*x29 + p12*x30 + p19*x31 + p26*x32 + p33*x33 + p40*x34 + p47*x35; 41949b5e25fSSatish Balay pc[33] = m34 = p6*x29 + p13*x30 + p20*x31 + p27*x32 + p34*x33 + p41*x34 + p48*x35; 42049b5e25fSSatish Balay pc[34] = m35 = p7*x29 + p14*x30 + p21*x31 + p28*x32 + p35*x33 + p42*x34 + p49*x35; 42149b5e25fSSatish Balay 42249b5e25fSSatish Balay pc[35] = m36 = p1*x36 + p8*x37 + p15*x38 + p22*x39 + p29*x40 + p36*x41 + p43*x42; 42349b5e25fSSatish Balay pc[36] = m37 = p2*x36 + p9*x37 + p16*x38 + p23*x39 + p30*x40 + p37*x41 + p44*x42; 42449b5e25fSSatish Balay pc[37] = m38 = p3*x36 + p10*x37 + p17*x38 + p24*x39 + p31*x40 + p38*x41 + p45*x42; 42549b5e25fSSatish Balay pc[38] = m39 = p4*x36 + p11*x37 + p18*x38 + p25*x39 + p32*x40 + p39*x41 + p46*x42; 42649b5e25fSSatish Balay pc[39] = m40 = p5*x36 + p12*x37 + p19*x38 + p26*x39 + p33*x40 + p40*x41 + p47*x42; 42749b5e25fSSatish Balay pc[40] = m41 = p6*x36 + p13*x37 + p20*x38 + p27*x39 + p34*x40 + p41*x41 + p48*x42; 42849b5e25fSSatish Balay pc[41] = m42 = p7*x36 + p14*x37 + p21*x38 + p28*x39 + p35*x40 + p42*x41 + p49*x42; 42949b5e25fSSatish Balay 43049b5e25fSSatish Balay pc[42] = m43 = p1*x43 + p8*x44 + p15*x45 + p22*x46 + p29*x47 + p36*x48 + p43*x49; 43149b5e25fSSatish Balay pc[43] = m44 = p2*x43 + p9*x44 + p16*x45 + p23*x46 + p30*x47 + p37*x48 + p44*x49; 43249b5e25fSSatish Balay pc[44] = m45 = p3*x43 + p10*x44 + p17*x45 + p24*x46 + p31*x47 + p38*x48 + p45*x49; 43349b5e25fSSatish Balay pc[45] = m46 = p4*x43 + p11*x44 + p18*x45 + p25*x46 + p32*x47 + p39*x48 + p46*x49; 43449b5e25fSSatish Balay pc[46] = m47 = p5*x43 + p12*x44 + p19*x45 + p26*x46 + p33*x47 + p40*x48 + p47*x49; 43549b5e25fSSatish Balay pc[47] = m48 = p6*x43 + p13*x44 + p20*x45 + p27*x46 + p34*x47 + p41*x48 + p48*x49; 43649b5e25fSSatish Balay pc[48] = m49 = p7*x43 + p14*x44 + p21*x45 + p28*x46 + p35*x47 + p42*x48 + p49*x49; 43749b5e25fSSatish Balay 43849b5e25fSSatish Balay nz = bi[row+1] - diag_offset[row] - 1; 43949b5e25fSSatish Balay pv += 49; 44049b5e25fSSatish Balay for (j=0; j<nz; j++) { 44149b5e25fSSatish Balay x1 = pv[0]; x2 = pv[1]; x3 = pv[2]; x4 = pv[3]; 44249b5e25fSSatish Balay x5 = pv[4]; x6 = pv[5]; x7 = pv[6]; x8 = pv[7]; 44349b5e25fSSatish Balay x9 = pv[8]; x10 = pv[9]; x11 = pv[10]; x12 = pv[11]; 44449b5e25fSSatish Balay x13 = pv[12]; x14 = pv[13]; x15 = pv[14]; x16 = pv[15]; 44549b5e25fSSatish Balay x17 = pv[16]; x18 = pv[17]; x19 = pv[18]; x20 = pv[19]; 44649b5e25fSSatish Balay x21 = pv[20]; x22 = pv[21]; x23 = pv[22]; x24 = pv[23]; 44749b5e25fSSatish Balay x25 = pv[24]; x26 = pv[25]; x27 = pv[26]; x28 = pv[27]; 44849b5e25fSSatish Balay x29 = pv[28]; x30 = pv[29]; x31 = pv[30]; x32 = pv[31]; 44949b5e25fSSatish Balay x33 = pv[32]; x34 = pv[33]; x35 = pv[34]; x36 = pv[35]; 45049b5e25fSSatish Balay x37 = pv[36]; x38 = pv[37]; x39 = pv[38]; x40 = pv[39]; 45149b5e25fSSatish Balay x41 = pv[40]; x42 = pv[41]; x43 = pv[42]; x44 = pv[43]; 45249b5e25fSSatish Balay x45 = pv[44]; x46 = pv[45]; x47 = pv[46]; x48 = pv[47]; 45349b5e25fSSatish Balay x49 = pv[48]; 45449b5e25fSSatish Balay x = rtmp + 49*pj[j]; 45549b5e25fSSatish Balay x[0] -= m1*x1 + m8*x2 + m15*x3 + m22*x4 + m29*x5 + m36*x6 + m43*x7; 45649b5e25fSSatish Balay x[1] -= m2*x1 + m9*x2 + m16*x3 + m23*x4 + m30*x5 + m37*x6 + m44*x7; 45749b5e25fSSatish Balay x[2] -= m3*x1 + m10*x2 + m17*x3 + m24*x4 + m31*x5 + m38*x6 + m45*x7; 45849b5e25fSSatish Balay x[3] -= m4*x1 + m11*x2 + m18*x3 + m25*x4 + m32*x5 + m39*x6 + m46*x7; 45949b5e25fSSatish Balay x[4] -= m5*x1 + m12*x2 + m19*x3 + m26*x4 + m33*x5 + m40*x6 + m47*x7; 46049b5e25fSSatish Balay x[5] -= m6*x1 + m13*x2 + m20*x3 + m27*x4 + m34*x5 + m41*x6 + m48*x7; 46149b5e25fSSatish Balay x[6] -= m7*x1 + m14*x2 + m21*x3 + m28*x4 + m35*x5 + m42*x6 + m49*x7; 46249b5e25fSSatish Balay 46349b5e25fSSatish Balay x[7] -= m1*x8 + m8*x9 + m15*x10 + m22*x11 + m29*x12 + m36*x13 + m43*x14; 46449b5e25fSSatish Balay x[8] -= m2*x8 + m9*x9 + m16*x10 + m23*x11 + m30*x12 + m37*x13 + m44*x14; 46549b5e25fSSatish Balay x[9] -= m3*x8 + m10*x9 + m17*x10 + m24*x11 + m31*x12 + m38*x13 + m45*x14; 46649b5e25fSSatish Balay x[10] -= m4*x8 + m11*x9 + m18*x10 + m25*x11 + m32*x12 + m39*x13 + m46*x14; 46749b5e25fSSatish Balay x[11] -= m5*x8 + m12*x9 + m19*x10 + m26*x11 + m33*x12 + m40*x13 + m47*x14; 46849b5e25fSSatish Balay x[12] -= m6*x8 + m13*x9 + m20*x10 + m27*x11 + m34*x12 + m41*x13 + m48*x14; 46949b5e25fSSatish Balay x[13] -= m7*x8 + m14*x9 + m21*x10 + m28*x11 + m35*x12 + m42*x13 + m49*x14; 47049b5e25fSSatish Balay 47149b5e25fSSatish Balay x[14] -= m1*x15 + m8*x16 + m15*x17 + m22*x18 + m29*x19 + m36*x20 + m43*x21; 47249b5e25fSSatish Balay x[15] -= m2*x15 + m9*x16 + m16*x17 + m23*x18 + m30*x19 + m37*x20 + m44*x21; 47349b5e25fSSatish Balay x[16] -= m3*x15 + m10*x16 + m17*x17 + m24*x18 + m31*x19 + m38*x20 + m45*x21; 47449b5e25fSSatish Balay x[17] -= m4*x15 + m11*x16 + m18*x17 + m25*x18 + m32*x19 + m39*x20 + m46*x21; 47549b5e25fSSatish Balay x[18] -= m5*x15 + m12*x16 + m19*x17 + m26*x18 + m33*x19 + m40*x20 + m47*x21; 47649b5e25fSSatish Balay x[19] -= m6*x15 + m13*x16 + m20*x17 + m27*x18 + m34*x19 + m41*x20 + m48*x21; 47749b5e25fSSatish Balay x[20] -= m7*x15 + m14*x16 + m21*x17 + m28*x18 + m35*x19 + m42*x20 + m49*x21; 47849b5e25fSSatish Balay 47949b5e25fSSatish Balay x[21] -= m1*x22 + m8*x23 + m15*x24 + m22*x25 + m29*x26 + m36*x27 + m43*x28; 48049b5e25fSSatish Balay x[22] -= m2*x22 + m9*x23 + m16*x24 + m23*x25 + m30*x26 + m37*x27 + m44*x28; 48149b5e25fSSatish Balay x[23] -= m3*x22 + m10*x23 + m17*x24 + m24*x25 + m31*x26 + m38*x27 + m45*x28; 48249b5e25fSSatish Balay x[24] -= m4*x22 + m11*x23 + m18*x24 + m25*x25 + m32*x26 + m39*x27 + m46*x28; 48349b5e25fSSatish Balay x[25] -= m5*x22 + m12*x23 + m19*x24 + m26*x25 + m33*x26 + m40*x27 + m47*x28; 48449b5e25fSSatish Balay x[26] -= m6*x22 + m13*x23 + m20*x24 + m27*x25 + m34*x26 + m41*x27 + m48*x28; 48549b5e25fSSatish Balay x[27] -= m7*x22 + m14*x23 + m21*x24 + m28*x25 + m35*x26 + m42*x27 + m49*x28; 48649b5e25fSSatish Balay 48749b5e25fSSatish Balay x[28] -= m1*x29 + m8*x30 + m15*x31 + m22*x32 + m29*x33 + m36*x34 + m43*x35; 48849b5e25fSSatish Balay x[29] -= m2*x29 + m9*x30 + m16*x31 + m23*x32 + m30*x33 + m37*x34 + m44*x35; 48949b5e25fSSatish Balay x[30] -= m3*x29 + m10*x30 + m17*x31 + m24*x32 + m31*x33 + m38*x34 + m45*x35; 49049b5e25fSSatish Balay x[31] -= m4*x29 + m11*x30 + m18*x31 + m25*x32 + m32*x33 + m39*x34 + m46*x35; 49149b5e25fSSatish Balay x[32] -= m5*x29 + m12*x30 + m19*x31 + m26*x32 + m33*x33 + m40*x34 + m47*x35; 49249b5e25fSSatish Balay x[33] -= m6*x29 + m13*x30 + m20*x31 + m27*x32 + m34*x33 + m41*x34 + m48*x35; 49349b5e25fSSatish Balay x[34] -= m7*x29 + m14*x30 + m21*x31 + m28*x32 + m35*x33 + m42*x34 + m49*x35; 49449b5e25fSSatish Balay 49549b5e25fSSatish Balay x[35] -= m1*x36 + m8*x37 + m15*x38 + m22*x39 + m29*x40 + m36*x41 + m43*x42; 49649b5e25fSSatish Balay x[36] -= m2*x36 + m9*x37 + m16*x38 + m23*x39 + m30*x40 + m37*x41 + m44*x42; 49749b5e25fSSatish Balay x[37] -= m3*x36 + m10*x37 + m17*x38 + m24*x39 + m31*x40 + m38*x41 + m45*x42; 49849b5e25fSSatish Balay x[38] -= m4*x36 + m11*x37 + m18*x38 + m25*x39 + m32*x40 + m39*x41 + m46*x42; 49949b5e25fSSatish Balay x[39] -= m5*x36 + m12*x37 + m19*x38 + m26*x39 + m33*x40 + m40*x41 + m47*x42; 50049b5e25fSSatish Balay x[40] -= m6*x36 + m13*x37 + m20*x38 + m27*x39 + m34*x40 + m41*x41 + m48*x42; 50149b5e25fSSatish Balay x[41] -= m7*x36 + m14*x37 + m21*x38 + m28*x39 + m35*x40 + m42*x41 + m49*x42; 50249b5e25fSSatish Balay 50349b5e25fSSatish Balay x[42] -= m1*x43 + m8*x44 + m15*x45 + m22*x46 + m29*x47 + m36*x48 + m43*x49; 50449b5e25fSSatish Balay x[43] -= m2*x43 + m9*x44 + m16*x45 + m23*x46 + m30*x47 + m37*x48 + m44*x49; 50549b5e25fSSatish Balay x[44] -= m3*x43 + m10*x44 + m17*x45 + m24*x46 + m31*x47 + m38*x48 + m45*x49; 50649b5e25fSSatish Balay x[45] -= m4*x43 + m11*x44 + m18*x45 + m25*x46 + m32*x47 + m39*x48 + m46*x49; 50749b5e25fSSatish Balay x[46] -= m5*x43 + m12*x44 + m19*x45 + m26*x46 + m33*x47 + m40*x48 + m47*x49; 50849b5e25fSSatish Balay x[47] -= m6*x43 + m13*x44 + m20*x45 + m27*x46 + m34*x47 + m41*x48 + m48*x49; 50949b5e25fSSatish Balay x[48] -= m7*x43 + m14*x44 + m21*x45 + m28*x46 + m35*x47 + m42*x48 + m49*x49; 51049b5e25fSSatish Balay pv += 49; 51149b5e25fSSatish Balay } 51249b5e25fSSatish Balay PLogFlops(686*nz+637); 51349b5e25fSSatish Balay } 51449b5e25fSSatish Balay row = *ajtmp++; 51549b5e25fSSatish Balay } 51649b5e25fSSatish Balay /* finished row so stick it into b->a */ 51749b5e25fSSatish Balay pv = ba + 49*bi[i]; 51849b5e25fSSatish Balay pj = bj + bi[i]; 51949b5e25fSSatish Balay nz = bi[i+1] - bi[i]; 52049b5e25fSSatish Balay for (j=0; j<nz; j++) { 52149b5e25fSSatish Balay x = rtmp+49*pj[j]; 52249b5e25fSSatish Balay pv[0] = x[0]; pv[1] = x[1]; pv[2] = x[2]; pv[3] = x[3]; 52349b5e25fSSatish Balay pv[4] = x[4]; pv[5] = x[5]; pv[6] = x[6]; pv[7] = x[7]; 52449b5e25fSSatish Balay pv[8] = x[8]; pv[9] = x[9]; pv[10] = x[10]; pv[11] = x[11]; 52549b5e25fSSatish Balay pv[12] = x[12]; pv[13] = x[13]; pv[14] = x[14]; pv[15] = x[15]; 52649b5e25fSSatish Balay pv[16] = x[16]; pv[17] = x[17]; pv[18] = x[18]; pv[19] = x[19]; 52749b5e25fSSatish Balay pv[20] = x[20]; pv[21] = x[21]; pv[22] = x[22]; pv[23] = x[23]; 52849b5e25fSSatish Balay pv[24] = x[24]; pv[25] = x[25]; pv[26] = x[26]; pv[27] = x[27]; 52949b5e25fSSatish Balay pv[28] = x[28]; pv[29] = x[29]; pv[30] = x[30]; pv[31] = x[31]; 53049b5e25fSSatish Balay pv[32] = x[32]; pv[33] = x[33]; pv[34] = x[34]; pv[35] = x[35]; 53149b5e25fSSatish Balay pv[36] = x[36]; pv[37] = x[37]; pv[38] = x[38]; pv[39] = x[39]; 53249b5e25fSSatish Balay pv[40] = x[40]; pv[41] = x[41]; pv[42] = x[42]; pv[43] = x[43]; 53349b5e25fSSatish Balay pv[44] = x[44]; pv[45] = x[45]; pv[46] = x[46]; pv[47] = x[47]; 53449b5e25fSSatish Balay pv[48] = x[48]; 53549b5e25fSSatish Balay pv += 49; 53649b5e25fSSatish Balay } 53749b5e25fSSatish Balay /* invert diagonal block */ 53849b5e25fSSatish Balay w = ba + 49*diag_offset[i]; 53949b5e25fSSatish Balay ierr = Kernel_A_gets_inverse_A_7(w);CHKERRQ(ierr); 54049b5e25fSSatish Balay } 54149b5e25fSSatish Balay 54249b5e25fSSatish Balay ierr = PetscFree(rtmp);CHKERRQ(ierr); 54349b5e25fSSatish Balay ierr = ISRestoreIndices(isicol,&ic);CHKERRQ(ierr); 54449b5e25fSSatish Balay ierr = ISRestoreIndices(isrow,&r);CHKERRQ(ierr); 54549b5e25fSSatish Balay C->factor = FACTOR_LU; 54649b5e25fSSatish Balay C->assembled = PETSC_TRUE; 54749b5e25fSSatish Balay PLogFlops(1.3333*343*b->mbs); /* from inverting diagonal blocks */ 54849b5e25fSSatish Balay PetscFunctionReturn(0); 54949b5e25fSSatish Balay } 55049b5e25fSSatish Balay 55149b5e25fSSatish Balay /* 55249b5e25fSSatish Balay Version for when blocks are 7 by 7 Using natural ordering 55349b5e25fSSatish Balay */ 55449b5e25fSSatish Balay #undef __FUNC__ 5556f9a564bSHong Zhang #define __FUNC__ "MatCholeskyFactorNumeric_SeqSBAIJ_7_NaturalOrdering" 5566f9a564bSHong Zhang int MatCholeskyFactorNumeric_SeqSBAIJ_7_NaturalOrdering(Mat A,Mat *B) 55749b5e25fSSatish Balay { 55849b5e25fSSatish Balay Mat C = *B; 55949b5e25fSSatish Balay Mat_SeqBAIJ *a = (Mat_SeqBAIJ*)A->data,*b = (Mat_SeqBAIJ *)C->data; 56049b5e25fSSatish Balay int ierr,i,j,n = a->mbs,*bi = b->i,*bj = b->j; 56149b5e25fSSatish Balay int *ajtmpold,*ajtmp,nz,row; 56249b5e25fSSatish Balay int *diag_offset = b->diag,*ai=a->i,*aj=a->j,*pj; 56349b5e25fSSatish Balay MatScalar *pv,*v,*rtmp,*pc,*w,*x; 56449b5e25fSSatish Balay MatScalar x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15; 56549b5e25fSSatish Balay MatScalar x16,x17,x18,x19,x20,x21,x22,x23,x24,x25; 56649b5e25fSSatish Balay MatScalar p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15; 56749b5e25fSSatish Balay MatScalar p16,p17,p18,p19,p20,p21,p22,p23,p24,p25; 56849b5e25fSSatish Balay MatScalar m1,m2,m3,m4,m5,m6,m7,m8,m9,m10,m11,m12,m13,m14,m15; 56949b5e25fSSatish Balay MatScalar m16,m17,m18,m19,m20,m21,m22,m23,m24,m25; 57049b5e25fSSatish Balay MatScalar p26,p27,p28,p29,p30,p31,p32,p33,p34,p35,p36; 57149b5e25fSSatish Balay MatScalar p37,p38,p39,p40,p41,p42,p43,p44,p45,p46,p47,p48,p49; 57249b5e25fSSatish Balay MatScalar x26,x27,x28,x29,x30,x31,x32,x33,x34,x35,x36; 57349b5e25fSSatish Balay MatScalar x37,x38,x39,x40,x41,x42,x43,x44,x45,x46,x47,x48,x49; 57449b5e25fSSatish Balay MatScalar m26,m27,m28,m29,m30,m31,m32,m33,m34,m35,m36; 57549b5e25fSSatish Balay MatScalar m37,m38,m39,m40,m41,m42,m43,m44,m45,m46,m47,m48,m49; 57649b5e25fSSatish Balay MatScalar *ba = b->a,*aa = a->a; 57749b5e25fSSatish Balay 57849b5e25fSSatish Balay PetscFunctionBegin; 57949b5e25fSSatish Balay rtmp = (MatScalar*)PetscMalloc(49*(n+1)*sizeof(MatScalar));CHKPTRQ(rtmp); 58049b5e25fSSatish Balay for (i=0; i<n; i++) { 58149b5e25fSSatish Balay nz = bi[i+1] - bi[i]; 58249b5e25fSSatish Balay ajtmp = bj + bi[i]; 58349b5e25fSSatish Balay for (j=0; j<nz; j++) { 58449b5e25fSSatish Balay x = rtmp+49*ajtmp[j]; 58549b5e25fSSatish Balay x[0] = x[1] = x[2] = x[3] = x[4] = x[5] = x[6] = x[7] = x[8] = x[9] = 0.0; 58649b5e25fSSatish Balay x[10] = x[11] = x[12] = x[13] = x[14] = x[15] = x[16] = x[17] = 0.0; 58749b5e25fSSatish Balay x[18] = x[19] = x[20] = x[21] = x[22] = x[23] = x[24] = x[25] = 0.0 ; 58849b5e25fSSatish Balay x[26] = x[27] = x[28] = x[29] = x[30] = x[31] = x[32] = x[33] = 0.0 ; 58949b5e25fSSatish Balay x[34] = x[35] = x[36] = x[37] = x[38] = x[39] = x[40] = x[41] = 0.0 ; 59049b5e25fSSatish Balay x[42] = x[43] = x[44] = x[45] = x[46] = x[47] = x[48] = 0.0 ; 59149b5e25fSSatish Balay } 59249b5e25fSSatish Balay /* load in initial (unfactored row) */ 59349b5e25fSSatish Balay nz = ai[i+1] - ai[i]; 59449b5e25fSSatish Balay ajtmpold = aj + ai[i]; 59549b5e25fSSatish Balay v = aa + 49*ai[i]; 59649b5e25fSSatish Balay for (j=0; j<nz; j++) { 59749b5e25fSSatish Balay x = rtmp+49*ajtmpold[j]; 59849b5e25fSSatish Balay x[0] = v[0]; x[1] = v[1]; x[2] = v[2]; x[3] = v[3]; 59949b5e25fSSatish Balay x[4] = v[4]; x[5] = v[5]; x[6] = v[6]; x[7] = v[7]; 60049b5e25fSSatish Balay x[8] = v[8]; x[9] = v[9]; x[10] = v[10]; x[11] = v[11]; 60149b5e25fSSatish Balay x[12] = v[12]; x[13] = v[13]; x[14] = v[14]; x[15] = v[15]; 60249b5e25fSSatish Balay x[16] = v[16]; x[17] = v[17]; x[18] = v[18]; x[19] = v[19]; 60349b5e25fSSatish Balay x[20] = v[20]; x[21] = v[21]; x[22] = v[22]; x[23] = v[23]; 60449b5e25fSSatish Balay x[24] = v[24]; x[25] = v[25]; x[26] = v[26]; x[27] = v[27]; 60549b5e25fSSatish Balay x[28] = v[28]; x[29] = v[29]; x[30] = v[30]; x[31] = v[31]; 60649b5e25fSSatish Balay x[32] = v[32]; x[33] = v[33]; x[34] = v[34]; x[35] = v[35]; 60749b5e25fSSatish Balay x[36] = v[36]; x[37] = v[37]; x[38] = v[38]; x[39] = v[39]; 60849b5e25fSSatish Balay x[40] = v[40]; x[41] = v[41]; x[42] = v[42]; x[43] = v[43]; 60949b5e25fSSatish Balay x[44] = v[44]; x[45] = v[45]; x[46] = v[46]; x[47] = v[47]; 61049b5e25fSSatish Balay x[48] = v[48]; 61149b5e25fSSatish Balay v += 49; 61249b5e25fSSatish Balay } 61349b5e25fSSatish Balay row = *ajtmp++; 61449b5e25fSSatish Balay while (row < i) { 61549b5e25fSSatish Balay pc = rtmp + 49*row; 61649b5e25fSSatish Balay p1 = pc[0]; p2 = pc[1]; p3 = pc[2]; p4 = pc[3]; 61749b5e25fSSatish Balay p5 = pc[4]; p6 = pc[5]; p7 = pc[6]; p8 = pc[7]; 61849b5e25fSSatish Balay p9 = pc[8]; p10 = pc[9]; p11 = pc[10]; p12 = pc[11]; 61949b5e25fSSatish Balay p13 = pc[12]; p14 = pc[13]; p15 = pc[14]; p16 = pc[15]; 62049b5e25fSSatish Balay p17 = pc[16]; p18 = pc[17]; p19 = pc[18]; p20 = pc[19]; 62149b5e25fSSatish Balay p21 = pc[20]; p22 = pc[21]; p23 = pc[22]; p24 = pc[23]; 62249b5e25fSSatish Balay p25 = pc[24]; p26 = pc[25]; p27 = pc[26]; p28 = pc[27]; 62349b5e25fSSatish Balay p29 = pc[28]; p30 = pc[29]; p31 = pc[30]; p32 = pc[31]; 62449b5e25fSSatish Balay p33 = pc[32]; p34 = pc[33]; p35 = pc[34]; p36 = pc[35]; 62549b5e25fSSatish Balay p37 = pc[36]; p38 = pc[37]; p39 = pc[38]; p40 = pc[39]; 62649b5e25fSSatish Balay p41 = pc[40]; p42 = pc[41]; p43 = pc[42]; p44 = pc[43]; 62749b5e25fSSatish Balay p45 = pc[44]; p46 = pc[45]; p47 = pc[46]; p48 = pc[47]; 62849b5e25fSSatish Balay p49 = pc[48]; 62949b5e25fSSatish Balay if (p1 != 0.0 || p2 != 0.0 || p3 != 0.0 || p4 != 0.0 || 63049b5e25fSSatish Balay p5 != 0.0 || p6 != 0.0 || p7 != 0.0 || p8 != 0.0 || 63149b5e25fSSatish Balay p9 != 0.0 || p10 != 0.0 || p11 != 0.0 || p12 != 0.0 || 63249b5e25fSSatish Balay p13 != 0.0 || p14 != 0.0 || p15 != 0.0 || p16 != 0.0 || 63349b5e25fSSatish Balay p17 != 0.0 || p18 != 0.0 || p19 != 0.0 || p20 != 0.0 || 63449b5e25fSSatish Balay p21 != 0.0 || p22 != 0.0 || p23 != 0.0 || p24 != 0.0 || 63549b5e25fSSatish Balay p25 != 0.0 || p26 != 0.0 || p27 != 0.0 || p28 != 0.0 || 63649b5e25fSSatish Balay p29 != 0.0 || p30 != 0.0 || p31 != 0.0 || p32 != 0.0 || 63749b5e25fSSatish Balay p33 != 0.0 || p34 != 0.0 || p35 != 0.0 || p36 != 0.0 || 63849b5e25fSSatish Balay p37 != 0.0 || p38 != 0.0 || p39 != 0.0 || p40 != 0.0 || 63949b5e25fSSatish Balay p41 != 0.0 || p42 != 0.0 || p43 != 0.0 || p44 != 0.0 || 64049b5e25fSSatish Balay p45 != 0.0 || p46 != 0.0 || p47 != 0.0 || p48 != 0.0 || 64149b5e25fSSatish Balay p49 != 0.0) { 64249b5e25fSSatish Balay pv = ba + 49*diag_offset[row]; 64349b5e25fSSatish Balay pj = bj + diag_offset[row] + 1; 64449b5e25fSSatish Balay x1 = pv[0]; x2 = pv[1]; x3 = pv[2]; x4 = pv[3]; 64549b5e25fSSatish Balay x5 = pv[4]; x6 = pv[5]; x7 = pv[6]; x8 = pv[7]; 64649b5e25fSSatish Balay x9 = pv[8]; x10 = pv[9]; x11 = pv[10]; x12 = pv[11]; 64749b5e25fSSatish Balay x13 = pv[12]; x14 = pv[13]; x15 = pv[14]; x16 = pv[15]; 64849b5e25fSSatish Balay x17 = pv[16]; x18 = pv[17]; x19 = pv[18]; x20 = pv[19]; 64949b5e25fSSatish Balay x21 = pv[20]; x22 = pv[21]; x23 = pv[22]; x24 = pv[23]; 65049b5e25fSSatish Balay x25 = pv[24]; x26 = pv[25]; x27 = pv[26]; x28 = pv[27]; 65149b5e25fSSatish Balay x29 = pv[28]; x30 = pv[29]; x31 = pv[30]; x32 = pv[31]; 65249b5e25fSSatish Balay x33 = pv[32]; x34 = pv[33]; x35 = pv[34]; x36 = pv[35]; 65349b5e25fSSatish Balay x37 = pv[36]; x38 = pv[37]; x39 = pv[38]; x40 = pv[39]; 65449b5e25fSSatish Balay x41 = pv[40]; x42 = pv[41]; x43 = pv[42]; x44 = pv[43]; 65549b5e25fSSatish Balay x45 = pv[44]; x46 = pv[45]; x47 = pv[46]; x48 = pv[47]; 65649b5e25fSSatish Balay x49 = pv[48]; 65749b5e25fSSatish Balay pc[0] = m1 = p1*x1 + p8*x2 + p15*x3 + p22*x4 + p29*x5 + p36*x6 + p43*x7; 65849b5e25fSSatish Balay pc[1] = m2 = p2*x1 + p9*x2 + p16*x3 + p23*x4 + p30*x5 + p37*x6 + p44*x7; 65949b5e25fSSatish Balay pc[2] = m3 = p3*x1 + p10*x2 + p17*x3 + p24*x4 + p31*x5 + p38*x6 + p45*x7; 66049b5e25fSSatish Balay pc[3] = m4 = p4*x1 + p11*x2 + p18*x3 + p25*x4 + p32*x5 + p39*x6 + p46*x7; 66149b5e25fSSatish Balay pc[4] = m5 = p5*x1 + p12*x2 + p19*x3 + p26*x4 + p33*x5 + p40*x6 + p47*x7; 66249b5e25fSSatish Balay pc[5] = m6 = p6*x1 + p13*x2 + p20*x3 + p27*x4 + p34*x5 + p41*x6 + p48*x7; 66349b5e25fSSatish Balay pc[6] = m7 = p7*x1 + p14*x2 + p21*x3 + p28*x4 + p35*x5 + p42*x6 + p49*x7; 66449b5e25fSSatish Balay 66549b5e25fSSatish Balay pc[7] = m8 = p1*x8 + p8*x9 + p15*x10 + p22*x11 + p29*x12 + p36*x13 + p43*x14; 66649b5e25fSSatish Balay pc[8] = m9 = p2*x8 + p9*x9 + p16*x10 + p23*x11 + p30*x12 + p37*x13 + p44*x14; 66749b5e25fSSatish Balay pc[9] = m10 = p3*x8 + p10*x9 + p17*x10 + p24*x11 + p31*x12 + p38*x13 + p45*x14; 66849b5e25fSSatish Balay pc[10] = m11 = p4*x8 + p11*x9 + p18*x10 + p25*x11 + p32*x12 + p39*x13 + p46*x14; 66949b5e25fSSatish Balay pc[11] = m12 = p5*x8 + p12*x9 + p19*x10 + p26*x11 + p33*x12 + p40*x13 + p47*x14; 67049b5e25fSSatish Balay pc[12] = m13 = p6*x8 + p13*x9 + p20*x10 + p27*x11 + p34*x12 + p41*x13 + p48*x14; 67149b5e25fSSatish Balay pc[13] = m14 = p7*x8 + p14*x9 + p21*x10 + p28*x11 + p35*x12 + p42*x13 + p49*x14; 67249b5e25fSSatish Balay 67349b5e25fSSatish Balay pc[14] = m15 = p1*x15 + p8*x16 + p15*x17 + p22*x18 + p29*x19 + p36*x20 + p43*x21; 67449b5e25fSSatish Balay pc[15] = m16 = p2*x15 + p9*x16 + p16*x17 + p23*x18 + p30*x19 + p37*x20 + p44*x21; 67549b5e25fSSatish Balay pc[16] = m17 = p3*x15 + p10*x16 + p17*x17 + p24*x18 + p31*x19 + p38*x20 + p45*x21; 67649b5e25fSSatish Balay pc[17] = m18 = p4*x15 + p11*x16 + p18*x17 + p25*x18 + p32*x19 + p39*x20 + p46*x21; 67749b5e25fSSatish Balay pc[18] = m19 = p5*x15 + p12*x16 + p19*x17 + p26*x18 + p33*x19 + p40*x20 + p47*x21; 67849b5e25fSSatish Balay pc[19] = m20 = p6*x15 + p13*x16 + p20*x17 + p27*x18 + p34*x19 + p41*x20 + p48*x21; 67949b5e25fSSatish Balay pc[20] = m21 = p7*x15 + p14*x16 + p21*x17 + p28*x18 + p35*x19 + p42*x20 + p49*x21; 68049b5e25fSSatish Balay 68149b5e25fSSatish Balay pc[21] = m22 = p1*x22 + p8*x23 + p15*x24 + p22*x25 + p29*x26 + p36*x27 + p43*x28; 68249b5e25fSSatish Balay pc[22] = m23 = p2*x22 + p9*x23 + p16*x24 + p23*x25 + p30*x26 + p37*x27 + p44*x28; 68349b5e25fSSatish Balay pc[23] = m24 = p3*x22 + p10*x23 + p17*x24 + p24*x25 + p31*x26 + p38*x27 + p45*x28; 68449b5e25fSSatish Balay pc[24] = m25 = p4*x22 + p11*x23 + p18*x24 + p25*x25 + p32*x26 + p39*x27 + p46*x28; 68549b5e25fSSatish Balay pc[25] = m26 = p5*x22 + p12*x23 + p19*x24 + p26*x25 + p33*x26 + p40*x27 + p47*x28; 68649b5e25fSSatish Balay pc[26] = m27 = p6*x22 + p13*x23 + p20*x24 + p27*x25 + p34*x26 + p41*x27 + p48*x28; 68749b5e25fSSatish Balay pc[27] = m28 = p7*x22 + p14*x23 + p21*x24 + p28*x25 + p35*x26 + p42*x27 + p49*x28; 68849b5e25fSSatish Balay 68949b5e25fSSatish Balay pc[28] = m29 = p1*x29 + p8*x30 + p15*x31 + p22*x32 + p29*x33 + p36*x34 + p43*x35; 69049b5e25fSSatish Balay pc[29] = m30 = p2*x29 + p9*x30 + p16*x31 + p23*x32 + p30*x33 + p37*x34 + p44*x35; 69149b5e25fSSatish Balay pc[30] = m31 = p3*x29 + p10*x30 + p17*x31 + p24*x32 + p31*x33 + p38*x34 + p45*x35; 69249b5e25fSSatish Balay pc[31] = m32 = p4*x29 + p11*x30 + p18*x31 + p25*x32 + p32*x33 + p39*x34 + p46*x35; 69349b5e25fSSatish Balay pc[32] = m33 = p5*x29 + p12*x30 + p19*x31 + p26*x32 + p33*x33 + p40*x34 + p47*x35; 69449b5e25fSSatish Balay pc[33] = m34 = p6*x29 + p13*x30 + p20*x31 + p27*x32 + p34*x33 + p41*x34 + p48*x35; 69549b5e25fSSatish Balay pc[34] = m35 = p7*x29 + p14*x30 + p21*x31 + p28*x32 + p35*x33 + p42*x34 + p49*x35; 69649b5e25fSSatish Balay 69749b5e25fSSatish Balay pc[35] = m36 = p1*x36 + p8*x37 + p15*x38 + p22*x39 + p29*x40 + p36*x41 + p43*x42; 69849b5e25fSSatish Balay pc[36] = m37 = p2*x36 + p9*x37 + p16*x38 + p23*x39 + p30*x40 + p37*x41 + p44*x42; 69949b5e25fSSatish Balay pc[37] = m38 = p3*x36 + p10*x37 + p17*x38 + p24*x39 + p31*x40 + p38*x41 + p45*x42; 70049b5e25fSSatish Balay pc[38] = m39 = p4*x36 + p11*x37 + p18*x38 + p25*x39 + p32*x40 + p39*x41 + p46*x42; 70149b5e25fSSatish Balay pc[39] = m40 = p5*x36 + p12*x37 + p19*x38 + p26*x39 + p33*x40 + p40*x41 + p47*x42; 70249b5e25fSSatish Balay pc[40] = m41 = p6*x36 + p13*x37 + p20*x38 + p27*x39 + p34*x40 + p41*x41 + p48*x42; 70349b5e25fSSatish Balay pc[41] = m42 = p7*x36 + p14*x37 + p21*x38 + p28*x39 + p35*x40 + p42*x41 + p49*x42; 70449b5e25fSSatish Balay 70549b5e25fSSatish Balay pc[42] = m43 = p1*x43 + p8*x44 + p15*x45 + p22*x46 + p29*x47 + p36*x48 + p43*x49; 70649b5e25fSSatish Balay pc[43] = m44 = p2*x43 + p9*x44 + p16*x45 + p23*x46 + p30*x47 + p37*x48 + p44*x49; 70749b5e25fSSatish Balay pc[44] = m45 = p3*x43 + p10*x44 + p17*x45 + p24*x46 + p31*x47 + p38*x48 + p45*x49; 70849b5e25fSSatish Balay pc[45] = m46 = p4*x43 + p11*x44 + p18*x45 + p25*x46 + p32*x47 + p39*x48 + p46*x49; 70949b5e25fSSatish Balay pc[46] = m47 = p5*x43 + p12*x44 + p19*x45 + p26*x46 + p33*x47 + p40*x48 + p47*x49; 71049b5e25fSSatish Balay pc[47] = m48 = p6*x43 + p13*x44 + p20*x45 + p27*x46 + p34*x47 + p41*x48 + p48*x49; 71149b5e25fSSatish Balay pc[48] = m49 = p7*x43 + p14*x44 + p21*x45 + p28*x46 + p35*x47 + p42*x48 + p49*x49; 71249b5e25fSSatish Balay 71349b5e25fSSatish Balay nz = bi[row+1] - diag_offset[row] - 1; 71449b5e25fSSatish Balay pv += 49; 71549b5e25fSSatish Balay for (j=0; j<nz; j++) { 71649b5e25fSSatish Balay x1 = pv[0]; x2 = pv[1]; x3 = pv[2]; x4 = pv[3]; 71749b5e25fSSatish Balay x5 = pv[4]; x6 = pv[5]; x7 = pv[6]; x8 = pv[7]; 71849b5e25fSSatish Balay x9 = pv[8]; x10 = pv[9]; x11 = pv[10]; x12 = pv[11]; 71949b5e25fSSatish Balay x13 = pv[12]; x14 = pv[13]; x15 = pv[14]; x16 = pv[15]; 72049b5e25fSSatish Balay x17 = pv[16]; x18 = pv[17]; x19 = pv[18]; x20 = pv[19]; 72149b5e25fSSatish Balay x21 = pv[20]; x22 = pv[21]; x23 = pv[22]; x24 = pv[23]; 72249b5e25fSSatish Balay x25 = pv[24]; x26 = pv[25]; x27 = pv[26]; x28 = pv[27]; 72349b5e25fSSatish Balay x29 = pv[28]; x30 = pv[29]; x31 = pv[30]; x32 = pv[31]; 72449b5e25fSSatish Balay x33 = pv[32]; x34 = pv[33]; x35 = pv[34]; x36 = pv[35]; 72549b5e25fSSatish Balay x37 = pv[36]; x38 = pv[37]; x39 = pv[38]; x40 = pv[39]; 72649b5e25fSSatish Balay x41 = pv[40]; x42 = pv[41]; x43 = pv[42]; x44 = pv[43]; 72749b5e25fSSatish Balay x45 = pv[44]; x46 = pv[45]; x47 = pv[46]; x48 = pv[47]; 72849b5e25fSSatish Balay x49 = pv[48]; 72949b5e25fSSatish Balay x = rtmp + 49*pj[j]; 73049b5e25fSSatish Balay x[0] -= m1*x1 + m8*x2 + m15*x3 + m22*x4 + m29*x5 + m36*x6 + m43*x7; 73149b5e25fSSatish Balay x[1] -= m2*x1 + m9*x2 + m16*x3 + m23*x4 + m30*x5 + m37*x6 + m44*x7; 73249b5e25fSSatish Balay x[2] -= m3*x1 + m10*x2 + m17*x3 + m24*x4 + m31*x5 + m38*x6 + m45*x7; 73349b5e25fSSatish Balay x[3] -= m4*x1 + m11*x2 + m18*x3 + m25*x4 + m32*x5 + m39*x6 + m46*x7; 73449b5e25fSSatish Balay x[4] -= m5*x1 + m12*x2 + m19*x3 + m26*x4 + m33*x5 + m40*x6 + m47*x7; 73549b5e25fSSatish Balay x[5] -= m6*x1 + m13*x2 + m20*x3 + m27*x4 + m34*x5 + m41*x6 + m48*x7; 73649b5e25fSSatish Balay x[6] -= m7*x1 + m14*x2 + m21*x3 + m28*x4 + m35*x5 + m42*x6 + m49*x7; 73749b5e25fSSatish Balay 73849b5e25fSSatish Balay x[7] -= m1*x8 + m8*x9 + m15*x10 + m22*x11 + m29*x12 + m36*x13 + m43*x14; 73949b5e25fSSatish Balay x[8] -= m2*x8 + m9*x9 + m16*x10 + m23*x11 + m30*x12 + m37*x13 + m44*x14; 74049b5e25fSSatish Balay x[9] -= m3*x8 + m10*x9 + m17*x10 + m24*x11 + m31*x12 + m38*x13 + m45*x14; 74149b5e25fSSatish Balay x[10] -= m4*x8 + m11*x9 + m18*x10 + m25*x11 + m32*x12 + m39*x13 + m46*x14; 74249b5e25fSSatish Balay x[11] -= m5*x8 + m12*x9 + m19*x10 + m26*x11 + m33*x12 + m40*x13 + m47*x14; 74349b5e25fSSatish Balay x[12] -= m6*x8 + m13*x9 + m20*x10 + m27*x11 + m34*x12 + m41*x13 + m48*x14; 74449b5e25fSSatish Balay x[13] -= m7*x8 + m14*x9 + m21*x10 + m28*x11 + m35*x12 + m42*x13 + m49*x14; 74549b5e25fSSatish Balay 74649b5e25fSSatish Balay x[14] -= m1*x15 + m8*x16 + m15*x17 + m22*x18 + m29*x19 + m36*x20 + m43*x21; 74749b5e25fSSatish Balay x[15] -= m2*x15 + m9*x16 + m16*x17 + m23*x18 + m30*x19 + m37*x20 + m44*x21; 74849b5e25fSSatish Balay x[16] -= m3*x15 + m10*x16 + m17*x17 + m24*x18 + m31*x19 + m38*x20 + m45*x21; 74949b5e25fSSatish Balay x[17] -= m4*x15 + m11*x16 + m18*x17 + m25*x18 + m32*x19 + m39*x20 + m46*x21; 75049b5e25fSSatish Balay x[18] -= m5*x15 + m12*x16 + m19*x17 + m26*x18 + m33*x19 + m40*x20 + m47*x21; 75149b5e25fSSatish Balay x[19] -= m6*x15 + m13*x16 + m20*x17 + m27*x18 + m34*x19 + m41*x20 + m48*x21; 75249b5e25fSSatish Balay x[20] -= m7*x15 + m14*x16 + m21*x17 + m28*x18 + m35*x19 + m42*x20 + m49*x21; 75349b5e25fSSatish Balay 75449b5e25fSSatish Balay x[21] -= m1*x22 + m8*x23 + m15*x24 + m22*x25 + m29*x26 + m36*x27 + m43*x28; 75549b5e25fSSatish Balay x[22] -= m2*x22 + m9*x23 + m16*x24 + m23*x25 + m30*x26 + m37*x27 + m44*x28; 75649b5e25fSSatish Balay x[23] -= m3*x22 + m10*x23 + m17*x24 + m24*x25 + m31*x26 + m38*x27 + m45*x28; 75749b5e25fSSatish Balay x[24] -= m4*x22 + m11*x23 + m18*x24 + m25*x25 + m32*x26 + m39*x27 + m46*x28; 75849b5e25fSSatish Balay x[25] -= m5*x22 + m12*x23 + m19*x24 + m26*x25 + m33*x26 + m40*x27 + m47*x28; 75949b5e25fSSatish Balay x[26] -= m6*x22 + m13*x23 + m20*x24 + m27*x25 + m34*x26 + m41*x27 + m48*x28; 76049b5e25fSSatish Balay x[27] -= m7*x22 + m14*x23 + m21*x24 + m28*x25 + m35*x26 + m42*x27 + m49*x28; 76149b5e25fSSatish Balay 76249b5e25fSSatish Balay x[28] -= m1*x29 + m8*x30 + m15*x31 + m22*x32 + m29*x33 + m36*x34 + m43*x35; 76349b5e25fSSatish Balay x[29] -= m2*x29 + m9*x30 + m16*x31 + m23*x32 + m30*x33 + m37*x34 + m44*x35; 76449b5e25fSSatish Balay x[30] -= m3*x29 + m10*x30 + m17*x31 + m24*x32 + m31*x33 + m38*x34 + m45*x35; 76549b5e25fSSatish Balay x[31] -= m4*x29 + m11*x30 + m18*x31 + m25*x32 + m32*x33 + m39*x34 + m46*x35; 76649b5e25fSSatish Balay x[32] -= m5*x29 + m12*x30 + m19*x31 + m26*x32 + m33*x33 + m40*x34 + m47*x35; 76749b5e25fSSatish Balay x[33] -= m6*x29 + m13*x30 + m20*x31 + m27*x32 + m34*x33 + m41*x34 + m48*x35; 76849b5e25fSSatish Balay x[34] -= m7*x29 + m14*x30 + m21*x31 + m28*x32 + m35*x33 + m42*x34 + m49*x35; 76949b5e25fSSatish Balay 77049b5e25fSSatish Balay x[35] -= m1*x36 + m8*x37 + m15*x38 + m22*x39 + m29*x40 + m36*x41 + m43*x42; 77149b5e25fSSatish Balay x[36] -= m2*x36 + m9*x37 + m16*x38 + m23*x39 + m30*x40 + m37*x41 + m44*x42; 77249b5e25fSSatish Balay x[37] -= m3*x36 + m10*x37 + m17*x38 + m24*x39 + m31*x40 + m38*x41 + m45*x42; 77349b5e25fSSatish Balay x[38] -= m4*x36 + m11*x37 + m18*x38 + m25*x39 + m32*x40 + m39*x41 + m46*x42; 77449b5e25fSSatish Balay x[39] -= m5*x36 + m12*x37 + m19*x38 + m26*x39 + m33*x40 + m40*x41 + m47*x42; 77549b5e25fSSatish Balay x[40] -= m6*x36 + m13*x37 + m20*x38 + m27*x39 + m34*x40 + m41*x41 + m48*x42; 77649b5e25fSSatish Balay x[41] -= m7*x36 + m14*x37 + m21*x38 + m28*x39 + m35*x40 + m42*x41 + m49*x42; 77749b5e25fSSatish Balay 77849b5e25fSSatish Balay x[42] -= m1*x43 + m8*x44 + m15*x45 + m22*x46 + m29*x47 + m36*x48 + m43*x49; 77949b5e25fSSatish Balay x[43] -= m2*x43 + m9*x44 + m16*x45 + m23*x46 + m30*x47 + m37*x48 + m44*x49; 78049b5e25fSSatish Balay x[44] -= m3*x43 + m10*x44 + m17*x45 + m24*x46 + m31*x47 + m38*x48 + m45*x49; 78149b5e25fSSatish Balay x[45] -= m4*x43 + m11*x44 + m18*x45 + m25*x46 + m32*x47 + m39*x48 + m46*x49; 78249b5e25fSSatish Balay x[46] -= m5*x43 + m12*x44 + m19*x45 + m26*x46 + m33*x47 + m40*x48 + m47*x49; 78349b5e25fSSatish Balay x[47] -= m6*x43 + m13*x44 + m20*x45 + m27*x46 + m34*x47 + m41*x48 + m48*x49; 78449b5e25fSSatish Balay x[48] -= m7*x43 + m14*x44 + m21*x45 + m28*x46 + m35*x47 + m42*x48 + m49*x49; 78549b5e25fSSatish Balay pv += 49; 78649b5e25fSSatish Balay } 78749b5e25fSSatish Balay PLogFlops(686*nz+637); 78849b5e25fSSatish Balay } 78949b5e25fSSatish Balay row = *ajtmp++; 79049b5e25fSSatish Balay } 79149b5e25fSSatish Balay /* finished row so stick it into b->a */ 79249b5e25fSSatish Balay pv = ba + 49*bi[i]; 79349b5e25fSSatish Balay pj = bj + bi[i]; 79449b5e25fSSatish Balay nz = bi[i+1] - bi[i]; 79549b5e25fSSatish Balay for (j=0; j<nz; j++) { 79649b5e25fSSatish Balay x = rtmp+49*pj[j]; 79749b5e25fSSatish Balay pv[0] = x[0]; pv[1] = x[1]; pv[2] = x[2]; pv[3] = x[3]; 79849b5e25fSSatish Balay pv[4] = x[4]; pv[5] = x[5]; pv[6] = x[6]; pv[7] = x[7]; 79949b5e25fSSatish Balay pv[8] = x[8]; pv[9] = x[9]; pv[10] = x[10]; pv[11] = x[11]; 80049b5e25fSSatish Balay pv[12] = x[12]; pv[13] = x[13]; pv[14] = x[14]; pv[15] = x[15]; 80149b5e25fSSatish Balay pv[16] = x[16]; pv[17] = x[17]; pv[18] = x[18]; pv[19] = x[19]; 80249b5e25fSSatish Balay pv[20] = x[20]; pv[21] = x[21]; pv[22] = x[22]; pv[23] = x[23]; 80349b5e25fSSatish Balay pv[24] = x[24]; pv[25] = x[25]; pv[26] = x[26]; pv[27] = x[27]; 80449b5e25fSSatish Balay pv[28] = x[28]; pv[29] = x[29]; pv[30] = x[30]; pv[31] = x[31]; 80549b5e25fSSatish Balay pv[32] = x[32]; pv[33] = x[33]; pv[34] = x[34]; pv[35] = x[35]; 80649b5e25fSSatish Balay pv[36] = x[36]; pv[37] = x[37]; pv[38] = x[38]; pv[39] = x[39]; 80749b5e25fSSatish Balay pv[40] = x[40]; pv[41] = x[41]; pv[42] = x[42]; pv[43] = x[43]; 80849b5e25fSSatish Balay pv[44] = x[44]; pv[45] = x[45]; pv[46] = x[46]; pv[47] = x[47]; 80949b5e25fSSatish Balay pv[48] = x[48]; 81049b5e25fSSatish Balay pv += 49; 81149b5e25fSSatish Balay } 81249b5e25fSSatish Balay /* invert diagonal block */ 81349b5e25fSSatish Balay w = ba + 49*diag_offset[i]; 81449b5e25fSSatish Balay ierr = Kernel_A_gets_inverse_A_7(w);CHKERRQ(ierr); 81549b5e25fSSatish Balay } 81649b5e25fSSatish Balay 81749b5e25fSSatish Balay ierr = PetscFree(rtmp);CHKERRQ(ierr); 81849b5e25fSSatish Balay C->factor = FACTOR_LU; 81949b5e25fSSatish Balay C->assembled = PETSC_TRUE; 82049b5e25fSSatish Balay PLogFlops(1.3333*343*b->mbs); /* from inverting diagonal blocks */ 82149b5e25fSSatish Balay PetscFunctionReturn(0); 82249b5e25fSSatish Balay } 82349b5e25fSSatish Balay 82449b5e25fSSatish Balay /* ------------------------------------------------------------*/ 82549b5e25fSSatish Balay /* 82649b5e25fSSatish Balay Version for when blocks are 6 by 6 82749b5e25fSSatish Balay */ 82849b5e25fSSatish Balay #undef __FUNC__ 8296f9a564bSHong Zhang #define __FUNC__ "MatCholeskyFactorNumeric_SeqSBAIJ_6" 8306f9a564bSHong Zhang int MatCholeskyFactorNumeric_SeqSBAIJ_6(Mat A,Mat *B) 83149b5e25fSSatish Balay { 83249b5e25fSSatish Balay Mat C = *B; 83349b5e25fSSatish Balay Mat_SeqBAIJ *a = (Mat_SeqBAIJ*)A->data,*b = (Mat_SeqBAIJ *)C->data; 83449b5e25fSSatish Balay IS isrow = b->row,isicol = b->icol; 83549b5e25fSSatish Balay int *r,*ic,ierr,i,j,n = a->mbs,*bi = b->i,*bj = b->j; 83649b5e25fSSatish Balay int *ajtmpold,*ajtmp,nz,row; 83749b5e25fSSatish Balay int *diag_offset = b->diag,idx,*ai=a->i,*aj=a->j,*pj; 83849b5e25fSSatish Balay MatScalar *pv,*v,*rtmp,*pc,*w,*x; 83949b5e25fSSatish Balay MatScalar p1,p2,p3,p4,m1,m2,m3,m4,m5,m6,m7,m8,m9,x1,x2,x3,x4; 84049b5e25fSSatish Balay MatScalar p5,p6,p7,p8,p9,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,x16; 84149b5e25fSSatish Balay MatScalar x17,x18,x19,x20,x21,x22,x23,x24,x25,p10,p11,p12,p13,p14; 84249b5e25fSSatish Balay MatScalar p15,p16,p17,p18,p19,p20,p21,p22,p23,p24,p25,m10,m11,m12; 84349b5e25fSSatish Balay MatScalar m13,m14,m15,m16,m17,m18,m19,m20,m21,m22,m23,m24,m25; 84449b5e25fSSatish Balay MatScalar p26,p27,p28,p29,p30,p31,p32,p33,p34,p35,p36; 84549b5e25fSSatish Balay MatScalar x26,x27,x28,x29,x30,x31,x32,x33,x34,x35,x36; 84649b5e25fSSatish Balay MatScalar m26,m27,m28,m29,m30,m31,m32,m33,m34,m35,m36; 84749b5e25fSSatish Balay MatScalar *ba = b->a,*aa = a->a; 84849b5e25fSSatish Balay 84949b5e25fSSatish Balay PetscFunctionBegin; 85049b5e25fSSatish Balay ierr = ISGetIndices(isrow,&r);CHKERRQ(ierr); 85149b5e25fSSatish Balay ierr = ISGetIndices(isicol,&ic);CHKERRQ(ierr); 85249b5e25fSSatish Balay rtmp = (MatScalar*)PetscMalloc(36*(n+1)*sizeof(MatScalar));CHKPTRQ(rtmp); 85349b5e25fSSatish Balay 85449b5e25fSSatish Balay for (i=0; i<n; i++) { 85549b5e25fSSatish Balay nz = bi[i+1] - bi[i]; 85649b5e25fSSatish Balay ajtmp = bj + bi[i]; 85749b5e25fSSatish Balay for (j=0; j<nz; j++) { 85849b5e25fSSatish Balay x = rtmp+36*ajtmp[j]; 85949b5e25fSSatish Balay x[0] = x[1] = x[2] = x[3] = x[4] = x[5] = x[6] = x[7] = x[8] = x[9] = 0.0; 86049b5e25fSSatish Balay x[10] = x[11] = x[12] = x[13] = x[14] = x[15] = x[16] = x[17] = 0.0; 86149b5e25fSSatish Balay x[18] = x[19] = x[20] = x[21] = x[22] = x[23] = x[24] = x[25] = 0.0 ; 86249b5e25fSSatish Balay x[26] = x[27] = x[28] = x[29] = x[30] = x[31] = x[32] = x[33] = 0.0 ; 86349b5e25fSSatish Balay x[34] = x[35] = 0.0 ; 86449b5e25fSSatish Balay } 86549b5e25fSSatish Balay /* load in initial (unfactored row) */ 86649b5e25fSSatish Balay idx = r[i]; 86749b5e25fSSatish Balay nz = ai[idx+1] - ai[idx]; 86849b5e25fSSatish Balay ajtmpold = aj + ai[idx]; 86949b5e25fSSatish Balay v = aa + 36*ai[idx]; 87049b5e25fSSatish Balay for (j=0; j<nz; j++) { 87149b5e25fSSatish Balay x = rtmp+36*ic[ajtmpold[j]]; 87249b5e25fSSatish Balay x[0] = v[0]; x[1] = v[1]; x[2] = v[2]; x[3] = v[3]; 87349b5e25fSSatish Balay x[4] = v[4]; x[5] = v[5]; x[6] = v[6]; x[7] = v[7]; 87449b5e25fSSatish Balay x[8] = v[8]; x[9] = v[9]; x[10] = v[10]; x[11] = v[11]; 87549b5e25fSSatish Balay x[12] = v[12]; x[13] = v[13]; x[14] = v[14]; x[15] = v[15]; 87649b5e25fSSatish Balay x[16] = v[16]; x[17] = v[17]; x[18] = v[18]; x[19] = v[19]; 87749b5e25fSSatish Balay x[20] = v[20]; x[21] = v[21]; x[22] = v[22]; x[23] = v[23]; 87849b5e25fSSatish Balay x[24] = v[24]; x[25] = v[25]; x[26] = v[26]; x[27] = v[27]; 87949b5e25fSSatish Balay x[28] = v[28]; x[29] = v[29]; x[30] = v[30]; x[31] = v[31]; 88049b5e25fSSatish Balay x[32] = v[32]; x[33] = v[33]; x[34] = v[34]; x[35] = v[35]; 88149b5e25fSSatish Balay v += 36; 88249b5e25fSSatish Balay } 88349b5e25fSSatish Balay row = *ajtmp++; 88449b5e25fSSatish Balay while (row < i) { 88549b5e25fSSatish Balay pc = rtmp + 36*row; 88649b5e25fSSatish Balay p1 = pc[0]; p2 = pc[1]; p3 = pc[2]; p4 = pc[3]; 88749b5e25fSSatish Balay p5 = pc[4]; p6 = pc[5]; p7 = pc[6]; p8 = pc[7]; 88849b5e25fSSatish Balay p9 = pc[8]; p10 = pc[9]; p11 = pc[10]; p12 = pc[11]; 88949b5e25fSSatish Balay p13 = pc[12]; p14 = pc[13]; p15 = pc[14]; p16 = pc[15]; 89049b5e25fSSatish Balay p17 = pc[16]; p18 = pc[17]; p19 = pc[18]; p20 = pc[19]; 89149b5e25fSSatish Balay p21 = pc[20]; p22 = pc[21]; p23 = pc[22]; p24 = pc[23]; 89249b5e25fSSatish Balay p25 = pc[24]; p26 = pc[25]; p27 = pc[26]; p28 = pc[27]; 89349b5e25fSSatish Balay p29 = pc[28]; p30 = pc[29]; p31 = pc[30]; p32 = pc[31]; 89449b5e25fSSatish Balay p33 = pc[32]; p34 = pc[33]; p35 = pc[34]; p36 = pc[35]; 89549b5e25fSSatish Balay if (p1 != 0.0 || p2 != 0.0 || p3 != 0.0 || p4 != 0.0 || 89649b5e25fSSatish Balay p5 != 0.0 || p6 != 0.0 || p7 != 0.0 || p8 != 0.0 || 89749b5e25fSSatish Balay p9 != 0.0 || p10 != 0.0 || p11 != 0.0 || p12 != 0.0 || 89849b5e25fSSatish Balay p13 != 0.0 || p14 != 0.0 || p15 != 0.0 || p16 != 0.0 || 89949b5e25fSSatish Balay p17 != 0.0 || p18 != 0.0 || p19 != 0.0 || p20 != 0.0 || 90049b5e25fSSatish Balay p21 != 0.0 || p22 != 0.0 || p23 != 0.0 || p24 != 0.0 || 90149b5e25fSSatish Balay p25 != 0.0 || p26 != 0.0 || p27 != 0.0 || p28 != 0.0 || 90249b5e25fSSatish Balay p29 != 0.0 || p30 != 0.0 || p31 != 0.0 || p32 != 0.0 || 90349b5e25fSSatish Balay p33 != 0.0 || p34 != 0.0 || p35 != 0.0 || p36 != 0.0) { 90449b5e25fSSatish Balay pv = ba + 36*diag_offset[row]; 90549b5e25fSSatish Balay pj = bj + diag_offset[row] + 1; 90649b5e25fSSatish Balay x1 = pv[0]; x2 = pv[1]; x3 = pv[2]; x4 = pv[3]; 90749b5e25fSSatish Balay x5 = pv[4]; x6 = pv[5]; x7 = pv[6]; x8 = pv[7]; 90849b5e25fSSatish Balay x9 = pv[8]; x10 = pv[9]; x11 = pv[10]; x12 = pv[11]; 90949b5e25fSSatish Balay x13 = pv[12]; x14 = pv[13]; x15 = pv[14]; x16 = pv[15]; 91049b5e25fSSatish Balay x17 = pv[16]; x18 = pv[17]; x19 = pv[18]; x20 = pv[19]; 91149b5e25fSSatish Balay x21 = pv[20]; x22 = pv[21]; x23 = pv[22]; x24 = pv[23]; 91249b5e25fSSatish Balay x25 = pv[24]; x26 = pv[25]; x27 = pv[26]; x28 = pv[27]; 91349b5e25fSSatish Balay x29 = pv[28]; x30 = pv[29]; x31 = pv[30]; x32 = pv[31]; 91449b5e25fSSatish Balay x33 = pv[32]; x34 = pv[33]; x35 = pv[34]; x36 = pv[35]; 91549b5e25fSSatish Balay pc[0] = m1 = p1*x1 + p7*x2 + p13*x3 + p19*x4 + p25*x5 + p31*x6; 91649b5e25fSSatish Balay pc[1] = m2 = p2*x1 + p8*x2 + p14*x3 + p20*x4 + p26*x5 + p32*x6; 91749b5e25fSSatish Balay pc[2] = m3 = p3*x1 + p9*x2 + p15*x3 + p21*x4 + p27*x5 + p33*x6; 91849b5e25fSSatish Balay pc[3] = m4 = p4*x1 + p10*x2 + p16*x3 + p22*x4 + p28*x5 + p34*x6; 91949b5e25fSSatish Balay pc[4] = m5 = p5*x1 + p11*x2 + p17*x3 + p23*x4 + p29*x5 + p35*x6; 92049b5e25fSSatish Balay pc[5] = m6 = p6*x1 + p12*x2 + p18*x3 + p24*x4 + p30*x5 + p36*x6; 92149b5e25fSSatish Balay 92249b5e25fSSatish Balay pc[6] = m7 = p1*x7 + p7*x8 + p13*x9 + p19*x10 + p25*x11 + p31*x12; 92349b5e25fSSatish Balay pc[7] = m8 = p2*x7 + p8*x8 + p14*x9 + p20*x10 + p26*x11 + p32*x12; 92449b5e25fSSatish Balay pc[8] = m9 = p3*x7 + p9*x8 + p15*x9 + p21*x10 + p27*x11 + p33*x12; 92549b5e25fSSatish Balay pc[9] = m10 = p4*x7 + p10*x8 + p16*x9 + p22*x10 + p28*x11 + p34*x12; 92649b5e25fSSatish Balay pc[10] = m11 = p5*x7 + p11*x8 + p17*x9 + p23*x10 + p29*x11 + p35*x12; 92749b5e25fSSatish Balay pc[11] = m12 = p6*x7 + p12*x8 + p18*x9 + p24*x10 + p30*x11 + p36*x12; 92849b5e25fSSatish Balay 92949b5e25fSSatish Balay pc[12] = m13 = p1*x13 + p7*x14 + p13*x15 + p19*x16 + p25*x17 + p31*x18; 93049b5e25fSSatish Balay pc[13] = m14 = p2*x13 + p8*x14 + p14*x15 + p20*x16 + p26*x17 + p32*x18; 93149b5e25fSSatish Balay pc[14] = m15 = p3*x13 + p9*x14 + p15*x15 + p21*x16 + p27*x17 + p33*x18; 93249b5e25fSSatish Balay pc[15] = m16 = p4*x13 + p10*x14 + p16*x15 + p22*x16 + p28*x17 + p34*x18; 93349b5e25fSSatish Balay pc[16] = m17 = p5*x13 + p11*x14 + p17*x15 + p23*x16 + p29*x17 + p35*x18; 93449b5e25fSSatish Balay pc[17] = m18 = p6*x13 + p12*x14 + p18*x15 + p24*x16 + p30*x17 + p36*x18; 93549b5e25fSSatish Balay 93649b5e25fSSatish Balay pc[18] = m19 = p1*x19 + p7*x20 + p13*x21 + p19*x22 + p25*x23 + p31*x24; 93749b5e25fSSatish Balay pc[19] = m20 = p2*x19 + p8*x20 + p14*x21 + p20*x22 + p26*x23 + p32*x24; 93849b5e25fSSatish Balay pc[20] = m21 = p3*x19 + p9*x20 + p15*x21 + p21*x22 + p27*x23 + p33*x24; 93949b5e25fSSatish Balay pc[21] = m22 = p4*x19 + p10*x20 + p16*x21 + p22*x22 + p28*x23 + p34*x24; 94049b5e25fSSatish Balay pc[22] = m23 = p5*x19 + p11*x20 + p17*x21 + p23*x22 + p29*x23 + p35*x24; 94149b5e25fSSatish Balay pc[23] = m24 = p6*x19 + p12*x20 + p18*x21 + p24*x22 + p30*x23 + p36*x24; 94249b5e25fSSatish Balay 94349b5e25fSSatish Balay pc[24] = m25 = p1*x25 + p7*x26 + p13*x27 + p19*x28 + p25*x29 + p31*x30; 94449b5e25fSSatish Balay pc[25] = m26 = p2*x25 + p8*x26 + p14*x27 + p20*x28 + p26*x29 + p32*x30; 94549b5e25fSSatish Balay pc[26] = m27 = p3*x25 + p9*x26 + p15*x27 + p21*x28 + p27*x29 + p33*x30; 94649b5e25fSSatish Balay pc[27] = m28 = p4*x25 + p10*x26 + p16*x27 + p22*x28 + p28*x29 + p34*x30; 94749b5e25fSSatish Balay pc[28] = m29 = p5*x25 + p11*x26 + p17*x27 + p23*x28 + p29*x29 + p35*x30; 94849b5e25fSSatish Balay pc[29] = m30 = p6*x25 + p12*x26 + p18*x27 + p24*x28 + p30*x29 + p36*x30; 94949b5e25fSSatish Balay 95049b5e25fSSatish Balay pc[30] = m31 = p1*x31 + p7*x32 + p13*x33 + p19*x34 + p25*x35 + p31*x36; 95149b5e25fSSatish Balay pc[31] = m32 = p2*x31 + p8*x32 + p14*x33 + p20*x34 + p26*x35 + p32*x36; 95249b5e25fSSatish Balay pc[32] = m33 = p3*x31 + p9*x32 + p15*x33 + p21*x34 + p27*x35 + p33*x36; 95349b5e25fSSatish Balay pc[33] = m34 = p4*x31 + p10*x32 + p16*x33 + p22*x34 + p28*x35 + p34*x36; 95449b5e25fSSatish Balay pc[34] = m35 = p5*x31 + p11*x32 + p17*x33 + p23*x34 + p29*x35 + p35*x36; 95549b5e25fSSatish Balay pc[35] = m36 = p6*x31 + p12*x32 + p18*x33 + p24*x34 + p30*x35 + p36*x36; 95649b5e25fSSatish Balay 95749b5e25fSSatish Balay nz = bi[row+1] - diag_offset[row] - 1; 95849b5e25fSSatish Balay pv += 36; 95949b5e25fSSatish Balay for (j=0; j<nz; j++) { 96049b5e25fSSatish Balay x1 = pv[0]; x2 = pv[1]; x3 = pv[2]; x4 = pv[3]; 96149b5e25fSSatish Balay x5 = pv[4]; x6 = pv[5]; x7 = pv[6]; x8 = pv[7]; 96249b5e25fSSatish Balay x9 = pv[8]; x10 = pv[9]; x11 = pv[10]; x12 = pv[11]; 96349b5e25fSSatish Balay x13 = pv[12]; x14 = pv[13]; x15 = pv[14]; x16 = pv[15]; 96449b5e25fSSatish Balay x17 = pv[16]; x18 = pv[17]; x19 = pv[18]; x20 = pv[19]; 96549b5e25fSSatish Balay x21 = pv[20]; x22 = pv[21]; x23 = pv[22]; x24 = pv[23]; 96649b5e25fSSatish Balay x25 = pv[24]; x26 = pv[25]; x27 = pv[26]; x28 = pv[27]; 96749b5e25fSSatish Balay x29 = pv[28]; x30 = pv[29]; x31 = pv[30]; x32 = pv[31]; 96849b5e25fSSatish Balay x33 = pv[32]; x34 = pv[33]; x35 = pv[34]; x36 = pv[35]; 96949b5e25fSSatish Balay x = rtmp + 36*pj[j]; 97049b5e25fSSatish Balay x[0] -= m1*x1 + m7*x2 + m13*x3 + m19*x4 + m25*x5 + m31*x6; 97149b5e25fSSatish Balay x[1] -= m2*x1 + m8*x2 + m14*x3 + m20*x4 + m26*x5 + m32*x6; 97249b5e25fSSatish Balay x[2] -= m3*x1 + m9*x2 + m15*x3 + m21*x4 + m27*x5 + m33*x6; 97349b5e25fSSatish Balay x[3] -= m4*x1 + m10*x2 + m16*x3 + m22*x4 + m28*x5 + m34*x6; 97449b5e25fSSatish Balay x[4] -= m5*x1 + m11*x2 + m17*x3 + m23*x4 + m29*x5 + m35*x6; 97549b5e25fSSatish Balay x[5] -= m6*x1 + m12*x2 + m18*x3 + m24*x4 + m30*x5 + m36*x6; 97649b5e25fSSatish Balay 97749b5e25fSSatish Balay x[6] -= m1*x7 + m7*x8 + m13*x9 + m19*x10 + m25*x11 + m31*x12; 97849b5e25fSSatish Balay x[7] -= m2*x7 + m8*x8 + m14*x9 + m20*x10 + m26*x11 + m32*x12; 97949b5e25fSSatish Balay x[8] -= m3*x7 + m9*x8 + m15*x9 + m21*x10 + m27*x11 + m33*x12; 98049b5e25fSSatish Balay x[9] -= m4*x7 + m10*x8 + m16*x9 + m22*x10 + m28*x11 + m34*x12; 98149b5e25fSSatish Balay x[10] -= m5*x7 + m11*x8 + m17*x9 + m23*x10 + m29*x11 + m35*x12; 98249b5e25fSSatish Balay x[11] -= m6*x7 + m12*x8 + m18*x9 + m24*x10 + m30*x11 + m36*x12; 98349b5e25fSSatish Balay 98449b5e25fSSatish Balay x[12] -= m1*x13 + m7*x14 + m13*x15 + m19*x16 + m25*x17 + m31*x18; 98549b5e25fSSatish Balay x[13] -= m2*x13 + m8*x14 + m14*x15 + m20*x16 + m26*x17 + m32*x18; 98649b5e25fSSatish Balay x[14] -= m3*x13 + m9*x14 + m15*x15 + m21*x16 + m27*x17 + m33*x18; 98749b5e25fSSatish Balay x[15] -= m4*x13 + m10*x14 + m16*x15 + m22*x16 + m28*x17 + m34*x18; 98849b5e25fSSatish Balay x[16] -= m5*x13 + m11*x14 + m17*x15 + m23*x16 + m29*x17 + m35*x18; 98949b5e25fSSatish Balay x[17] -= m6*x13 + m12*x14 + m18*x15 + m24*x16 + m30*x17 + m36*x18; 99049b5e25fSSatish Balay 99149b5e25fSSatish Balay x[18] -= m1*x19 + m7*x20 + m13*x21 + m19*x22 + m25*x23 + m31*x24; 99249b5e25fSSatish Balay x[19] -= m2*x19 + m8*x20 + m14*x21 + m20*x22 + m26*x23 + m32*x24; 99349b5e25fSSatish Balay x[20] -= m3*x19 + m9*x20 + m15*x21 + m21*x22 + m27*x23 + m33*x24; 99449b5e25fSSatish Balay x[21] -= m4*x19 + m10*x20 + m16*x21 + m22*x22 + m28*x23 + m34*x24; 99549b5e25fSSatish Balay x[22] -= m5*x19 + m11*x20 + m17*x21 + m23*x22 + m29*x23 + m35*x24; 99649b5e25fSSatish Balay x[23] -= m6*x19 + m12*x20 + m18*x21 + m24*x22 + m30*x23 + m36*x24; 99749b5e25fSSatish Balay 99849b5e25fSSatish Balay x[24] -= m1*x25 + m7*x26 + m13*x27 + m19*x28 + m25*x29 + m31*x30; 99949b5e25fSSatish Balay x[25] -= m2*x25 + m8*x26 + m14*x27 + m20*x28 + m26*x29 + m32*x30; 100049b5e25fSSatish Balay x[26] -= m3*x25 + m9*x26 + m15*x27 + m21*x28 + m27*x29 + m33*x30; 100149b5e25fSSatish Balay x[27] -= m4*x25 + m10*x26 + m16*x27 + m22*x28 + m28*x29 + m34*x30; 100249b5e25fSSatish Balay x[28] -= m5*x25 + m11*x26 + m17*x27 + m23*x28 + m29*x29 + m35*x30; 100349b5e25fSSatish Balay x[29] -= m6*x25 + m12*x26 + m18*x27 + m24*x28 + m30*x29 + m36*x30; 100449b5e25fSSatish Balay 100549b5e25fSSatish Balay x[30] -= m1*x31 + m7*x32 + m13*x33 + m19*x34 + m25*x35 + m31*x36; 100649b5e25fSSatish Balay x[31] -= m2*x31 + m8*x32 + m14*x33 + m20*x34 + m26*x35 + m32*x36; 100749b5e25fSSatish Balay x[32] -= m3*x31 + m9*x32 + m15*x33 + m21*x34 + m27*x35 + m33*x36; 100849b5e25fSSatish Balay x[33] -= m4*x31 + m10*x32 + m16*x33 + m22*x34 + m28*x35 + m34*x36; 100949b5e25fSSatish Balay x[34] -= m5*x31 + m11*x32 + m17*x33 + m23*x34 + m29*x35 + m35*x36; 101049b5e25fSSatish Balay x[35] -= m6*x31 + m12*x32 + m18*x33 + m24*x34 + m30*x35 + m36*x36; 101149b5e25fSSatish Balay 101249b5e25fSSatish Balay pv += 36; 101349b5e25fSSatish Balay } 101449b5e25fSSatish Balay PLogFlops(432*nz+396); 101549b5e25fSSatish Balay } 101649b5e25fSSatish Balay row = *ajtmp++; 101749b5e25fSSatish Balay } 101849b5e25fSSatish Balay /* finished row so stick it into b->a */ 101949b5e25fSSatish Balay pv = ba + 36*bi[i]; 102049b5e25fSSatish Balay pj = bj + bi[i]; 102149b5e25fSSatish Balay nz = bi[i+1] - bi[i]; 102249b5e25fSSatish Balay for (j=0; j<nz; j++) { 102349b5e25fSSatish Balay x = rtmp+36*pj[j]; 102449b5e25fSSatish Balay pv[0] = x[0]; pv[1] = x[1]; pv[2] = x[2]; pv[3] = x[3]; 102549b5e25fSSatish Balay pv[4] = x[4]; pv[5] = x[5]; pv[6] = x[6]; pv[7] = x[7]; 102649b5e25fSSatish Balay pv[8] = x[8]; pv[9] = x[9]; pv[10] = x[10]; pv[11] = x[11]; 102749b5e25fSSatish Balay pv[12] = x[12]; pv[13] = x[13]; pv[14] = x[14]; pv[15] = x[15]; 102849b5e25fSSatish Balay pv[16] = x[16]; pv[17] = x[17]; pv[18] = x[18]; pv[19] = x[19]; 102949b5e25fSSatish Balay pv[20] = x[20]; pv[21] = x[21]; pv[22] = x[22]; pv[23] = x[23]; 103049b5e25fSSatish Balay pv[24] = x[24]; pv[25] = x[25]; pv[26] = x[26]; pv[27] = x[27]; 103149b5e25fSSatish Balay pv[28] = x[28]; pv[29] = x[29]; pv[30] = x[30]; pv[31] = x[31]; 103249b5e25fSSatish Balay pv[32] = x[32]; pv[33] = x[33]; pv[34] = x[34]; pv[35] = x[35]; 103349b5e25fSSatish Balay pv += 36; 103449b5e25fSSatish Balay } 103549b5e25fSSatish Balay /* invert diagonal block */ 103649b5e25fSSatish Balay w = ba + 36*diag_offset[i]; 103749b5e25fSSatish Balay ierr = Kernel_A_gets_inverse_A_6(w);CHKERRQ(ierr); 103849b5e25fSSatish Balay } 103949b5e25fSSatish Balay 104049b5e25fSSatish Balay ierr = PetscFree(rtmp);CHKERRQ(ierr); 104149b5e25fSSatish Balay ierr = ISRestoreIndices(isicol,&ic);CHKERRQ(ierr); 104249b5e25fSSatish Balay ierr = ISRestoreIndices(isrow,&r);CHKERRQ(ierr); 104349b5e25fSSatish Balay C->factor = FACTOR_LU; 104449b5e25fSSatish Balay C->assembled = PETSC_TRUE; 104549b5e25fSSatish Balay PLogFlops(1.3333*216*b->mbs); /* from inverting diagonal blocks */ 104649b5e25fSSatish Balay PetscFunctionReturn(0); 104749b5e25fSSatish Balay } 104849b5e25fSSatish Balay /* 104949b5e25fSSatish Balay Version for when blocks are 6 by 6 Using natural ordering 105049b5e25fSSatish Balay */ 105149b5e25fSSatish Balay #undef __FUNC__ 10526f9a564bSHong Zhang #define __FUNC__ "MatCholeskyFactorNumeric_SeqSBAIJ_6_NaturalOrdering" 10536f9a564bSHong Zhang int MatCholeskyFactorNumeric_SeqSBAIJ_6_NaturalOrdering(Mat A,Mat *B) 105449b5e25fSSatish Balay { 105549b5e25fSSatish Balay Mat C = *B; 105649b5e25fSSatish Balay Mat_SeqBAIJ *a = (Mat_SeqBAIJ*)A->data,*b = (Mat_SeqBAIJ *)C->data; 105749b5e25fSSatish Balay int ierr,i,j,n = a->mbs,*bi = b->i,*bj = b->j; 105849b5e25fSSatish Balay int *ajtmpold,*ajtmp,nz,row; 105949b5e25fSSatish Balay int *diag_offset = b->diag,*ai=a->i,*aj=a->j,*pj; 106049b5e25fSSatish Balay MatScalar *pv,*v,*rtmp,*pc,*w,*x; 106149b5e25fSSatish Balay MatScalar x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15; 106249b5e25fSSatish Balay MatScalar x16,x17,x18,x19,x20,x21,x22,x23,x24,x25; 106349b5e25fSSatish Balay MatScalar p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15; 106449b5e25fSSatish Balay MatScalar p16,p17,p18,p19,p20,p21,p22,p23,p24,p25; 106549b5e25fSSatish Balay MatScalar m1,m2,m3,m4,m5,m6,m7,m8,m9,m10,m11,m12,m13,m14,m15; 106649b5e25fSSatish Balay MatScalar m16,m17,m18,m19,m20,m21,m22,m23,m24,m25; 106749b5e25fSSatish Balay MatScalar p26,p27,p28,p29,p30,p31,p32,p33,p34,p35,p36; 106849b5e25fSSatish Balay MatScalar x26,x27,x28,x29,x30,x31,x32,x33,x34,x35,x36; 106949b5e25fSSatish Balay MatScalar m26,m27,m28,m29,m30,m31,m32,m33,m34,m35,m36; 107049b5e25fSSatish Balay MatScalar *ba = b->a,*aa = a->a; 107149b5e25fSSatish Balay 107249b5e25fSSatish Balay PetscFunctionBegin; 107349b5e25fSSatish Balay rtmp = (MatScalar*)PetscMalloc(36*(n+1)*sizeof(MatScalar));CHKPTRQ(rtmp); 107449b5e25fSSatish Balay for (i=0; i<n; i++) { 107549b5e25fSSatish Balay nz = bi[i+1] - bi[i]; 107649b5e25fSSatish Balay ajtmp = bj + bi[i]; 107749b5e25fSSatish Balay for (j=0; j<nz; j++) { 107849b5e25fSSatish Balay x = rtmp+36*ajtmp[j]; 107949b5e25fSSatish Balay x[0] = x[1] = x[2] = x[3] = x[4] = x[5] = x[6] = x[7] = x[8] = x[9] = 0.0; 108049b5e25fSSatish Balay x[10] = x[11] = x[12] = x[13] = x[14] = x[15] = x[16] = x[17] = 0.0; 108149b5e25fSSatish Balay x[18] = x[19] = x[20] = x[21] = x[22] = x[23] = x[24] = x[25] = 0.0 ; 108249b5e25fSSatish Balay x[26] = x[27] = x[28] = x[29] = x[30] = x[31] = x[32] = x[33] = 0.0 ; 108349b5e25fSSatish Balay x[34] = x[35] = 0.0 ; 108449b5e25fSSatish Balay } 108549b5e25fSSatish Balay /* load in initial (unfactored row) */ 108649b5e25fSSatish Balay nz = ai[i+1] - ai[i]; 108749b5e25fSSatish Balay ajtmpold = aj + ai[i]; 108849b5e25fSSatish Balay v = aa + 36*ai[i]; 108949b5e25fSSatish Balay for (j=0; j<nz; j++) { 109049b5e25fSSatish Balay x = rtmp+36*ajtmpold[j]; 109149b5e25fSSatish Balay x[0] = v[0]; x[1] = v[1]; x[2] = v[2]; x[3] = v[3]; 109249b5e25fSSatish Balay x[4] = v[4]; x[5] = v[5]; x[6] = v[6]; x[7] = v[7]; 109349b5e25fSSatish Balay x[8] = v[8]; x[9] = v[9]; x[10] = v[10]; x[11] = v[11]; 109449b5e25fSSatish Balay x[12] = v[12]; x[13] = v[13]; x[14] = v[14]; x[15] = v[15]; 109549b5e25fSSatish Balay x[16] = v[16]; x[17] = v[17]; x[18] = v[18]; x[19] = v[19]; 109649b5e25fSSatish Balay x[20] = v[20]; x[21] = v[21]; x[22] = v[22]; x[23] = v[23]; 109749b5e25fSSatish Balay x[24] = v[24]; x[25] = v[25]; x[26] = v[26]; x[27] = v[27]; 109849b5e25fSSatish Balay x[28] = v[28]; x[29] = v[29]; x[30] = v[30]; x[31] = v[31]; 109949b5e25fSSatish Balay x[32] = v[32]; x[33] = v[33]; x[34] = v[34]; x[35] = v[35]; 110049b5e25fSSatish Balay v += 36; 110149b5e25fSSatish Balay } 110249b5e25fSSatish Balay row = *ajtmp++; 110349b5e25fSSatish Balay while (row < i) { 110449b5e25fSSatish Balay pc = rtmp + 36*row; 110549b5e25fSSatish Balay p1 = pc[0]; p2 = pc[1]; p3 = pc[2]; p4 = pc[3]; 110649b5e25fSSatish Balay p5 = pc[4]; p6 = pc[5]; p7 = pc[6]; p8 = pc[7]; 110749b5e25fSSatish Balay p9 = pc[8]; p10 = pc[9]; p11 = pc[10]; p12 = pc[11]; 110849b5e25fSSatish Balay p13 = pc[12]; p14 = pc[13]; p15 = pc[14]; p16 = pc[15]; 110949b5e25fSSatish Balay p17 = pc[16]; p18 = pc[17]; p19 = pc[18]; p20 = pc[19]; 111049b5e25fSSatish Balay p21 = pc[20]; p22 = pc[21]; p23 = pc[22]; p24 = pc[23]; 111149b5e25fSSatish Balay p25 = pc[24]; p26 = pc[25]; p27 = pc[26]; p28 = pc[27]; 111249b5e25fSSatish Balay p29 = pc[28]; p30 = pc[29]; p31 = pc[30]; p32 = pc[31]; 111349b5e25fSSatish Balay p33 = pc[32]; p34 = pc[33]; p35 = pc[34]; p36 = pc[35]; 111449b5e25fSSatish Balay if (p1 != 0.0 || p2 != 0.0 || p3 != 0.0 || p4 != 0.0 || 111549b5e25fSSatish Balay p5 != 0.0 || p6 != 0.0 || p7 != 0.0 || p8 != 0.0 || 111649b5e25fSSatish Balay p9 != 0.0 || p10 != 0.0 || p11 != 0.0 || p12 != 0.0 || 111749b5e25fSSatish Balay p13 != 0.0 || p14 != 0.0 || p15 != 0.0 || p16 != 0.0 || 111849b5e25fSSatish Balay p17 != 0.0 || p18 != 0.0 || p19 != 0.0 || p20 != 0.0 || 111949b5e25fSSatish Balay p21 != 0.0 || p22 != 0.0 || p23 != 0.0 || p24 != 0.0 || 112049b5e25fSSatish Balay p25 != 0.0 || p26 != 0.0 || p27 != 0.0 || p28 != 0.0 || 112149b5e25fSSatish Balay p29 != 0.0 || p30 != 0.0 || p31 != 0.0 || p32 != 0.0 || 112249b5e25fSSatish Balay p33 != 0.0 || p34 != 0.0 || p35 != 0.0 || p36 != 0.0) { 112349b5e25fSSatish Balay pv = ba + 36*diag_offset[row]; 112449b5e25fSSatish Balay pj = bj + diag_offset[row] + 1; 112549b5e25fSSatish Balay x1 = pv[0]; x2 = pv[1]; x3 = pv[2]; x4 = pv[3]; 112649b5e25fSSatish Balay x5 = pv[4]; x6 = pv[5]; x7 = pv[6]; x8 = pv[7]; 112749b5e25fSSatish Balay x9 = pv[8]; x10 = pv[9]; x11 = pv[10]; x12 = pv[11]; 112849b5e25fSSatish Balay x13 = pv[12]; x14 = pv[13]; x15 = pv[14]; x16 = pv[15]; 112949b5e25fSSatish Balay x17 = pv[16]; x18 = pv[17]; x19 = pv[18]; x20 = pv[19]; 113049b5e25fSSatish Balay x21 = pv[20]; x22 = pv[21]; x23 = pv[22]; x24 = pv[23]; 113149b5e25fSSatish Balay x25 = pv[24]; x26 = pv[25]; x27 = pv[26]; x28 = pv[27]; 113249b5e25fSSatish Balay x29 = pv[28]; x30 = pv[29]; x31 = pv[30]; x32 = pv[31]; 113349b5e25fSSatish Balay x33 = pv[32]; x34 = pv[33]; x35 = pv[34]; x36 = pv[35]; 113449b5e25fSSatish Balay pc[0] = m1 = p1*x1 + p7*x2 + p13*x3 + p19*x4 + p25*x5 + p31*x6; 113549b5e25fSSatish Balay pc[1] = m2 = p2*x1 + p8*x2 + p14*x3 + p20*x4 + p26*x5 + p32*x6; 113649b5e25fSSatish Balay pc[2] = m3 = p3*x1 + p9*x2 + p15*x3 + p21*x4 + p27*x5 + p33*x6; 113749b5e25fSSatish Balay pc[3] = m4 = p4*x1 + p10*x2 + p16*x3 + p22*x4 + p28*x5 + p34*x6; 113849b5e25fSSatish Balay pc[4] = m5 = p5*x1 + p11*x2 + p17*x3 + p23*x4 + p29*x5 + p35*x6; 113949b5e25fSSatish Balay pc[5] = m6 = p6*x1 + p12*x2 + p18*x3 + p24*x4 + p30*x5 + p36*x6; 114049b5e25fSSatish Balay 114149b5e25fSSatish Balay pc[6] = m7 = p1*x7 + p7*x8 + p13*x9 + p19*x10 + p25*x11 + p31*x12; 114249b5e25fSSatish Balay pc[7] = m8 = p2*x7 + p8*x8 + p14*x9 + p20*x10 + p26*x11 + p32*x12; 114349b5e25fSSatish Balay pc[8] = m9 = p3*x7 + p9*x8 + p15*x9 + p21*x10 + p27*x11 + p33*x12; 114449b5e25fSSatish Balay pc[9] = m10 = p4*x7 + p10*x8 + p16*x9 + p22*x10 + p28*x11 + p34*x12; 114549b5e25fSSatish Balay pc[10] = m11 = p5*x7 + p11*x8 + p17*x9 + p23*x10 + p29*x11 + p35*x12; 114649b5e25fSSatish Balay pc[11] = m12 = p6*x7 + p12*x8 + p18*x9 + p24*x10 + p30*x11 + p36*x12; 114749b5e25fSSatish Balay 114849b5e25fSSatish Balay pc[12] = m13 = p1*x13 + p7*x14 + p13*x15 + p19*x16 + p25*x17 + p31*x18; 114949b5e25fSSatish Balay pc[13] = m14 = p2*x13 + p8*x14 + p14*x15 + p20*x16 + p26*x17 + p32*x18; 115049b5e25fSSatish Balay pc[14] = m15 = p3*x13 + p9*x14 + p15*x15 + p21*x16 + p27*x17 + p33*x18; 115149b5e25fSSatish Balay pc[15] = m16 = p4*x13 + p10*x14 + p16*x15 + p22*x16 + p28*x17 + p34*x18; 115249b5e25fSSatish Balay pc[16] = m17 = p5*x13 + p11*x14 + p17*x15 + p23*x16 + p29*x17 + p35*x18; 115349b5e25fSSatish Balay pc[17] = m18 = p6*x13 + p12*x14 + p18*x15 + p24*x16 + p30*x17 + p36*x18; 115449b5e25fSSatish Balay 115549b5e25fSSatish Balay pc[18] = m19 = p1*x19 + p7*x20 + p13*x21 + p19*x22 + p25*x23 + p31*x24; 115649b5e25fSSatish Balay pc[19] = m20 = p2*x19 + p8*x20 + p14*x21 + p20*x22 + p26*x23 + p32*x24; 115749b5e25fSSatish Balay pc[20] = m21 = p3*x19 + p9*x20 + p15*x21 + p21*x22 + p27*x23 + p33*x24; 115849b5e25fSSatish Balay pc[21] = m22 = p4*x19 + p10*x20 + p16*x21 + p22*x22 + p28*x23 + p34*x24; 115949b5e25fSSatish Balay pc[22] = m23 = p5*x19 + p11*x20 + p17*x21 + p23*x22 + p29*x23 + p35*x24; 116049b5e25fSSatish Balay pc[23] = m24 = p6*x19 + p12*x20 + p18*x21 + p24*x22 + p30*x23 + p36*x24; 116149b5e25fSSatish Balay 116249b5e25fSSatish Balay pc[24] = m25 = p1*x25 + p7*x26 + p13*x27 + p19*x28 + p25*x29 + p31*x30; 116349b5e25fSSatish Balay pc[25] = m26 = p2*x25 + p8*x26 + p14*x27 + p20*x28 + p26*x29 + p32*x30; 116449b5e25fSSatish Balay pc[26] = m27 = p3*x25 + p9*x26 + p15*x27 + p21*x28 + p27*x29 + p33*x30; 116549b5e25fSSatish Balay pc[27] = m28 = p4*x25 + p10*x26 + p16*x27 + p22*x28 + p28*x29 + p34*x30; 116649b5e25fSSatish Balay pc[28] = m29 = p5*x25 + p11*x26 + p17*x27 + p23*x28 + p29*x29 + p35*x30; 116749b5e25fSSatish Balay pc[29] = m30 = p6*x25 + p12*x26 + p18*x27 + p24*x28 + p30*x29 + p36*x30; 116849b5e25fSSatish Balay 116949b5e25fSSatish Balay pc[30] = m31 = p1*x31 + p7*x32 + p13*x33 + p19*x34 + p25*x35 + p31*x36; 117049b5e25fSSatish Balay pc[31] = m32 = p2*x31 + p8*x32 + p14*x33 + p20*x34 + p26*x35 + p32*x36; 117149b5e25fSSatish Balay pc[32] = m33 = p3*x31 + p9*x32 + p15*x33 + p21*x34 + p27*x35 + p33*x36; 117249b5e25fSSatish Balay pc[33] = m34 = p4*x31 + p10*x32 + p16*x33 + p22*x34 + p28*x35 + p34*x36; 117349b5e25fSSatish Balay pc[34] = m35 = p5*x31 + p11*x32 + p17*x33 + p23*x34 + p29*x35 + p35*x36; 117449b5e25fSSatish Balay pc[35] = m36 = p6*x31 + p12*x32 + p18*x33 + p24*x34 + p30*x35 + p36*x36; 117549b5e25fSSatish Balay 117649b5e25fSSatish Balay nz = bi[row+1] - diag_offset[row] - 1; 117749b5e25fSSatish Balay pv += 36; 117849b5e25fSSatish Balay for (j=0; j<nz; j++) { 117949b5e25fSSatish Balay x1 = pv[0]; x2 = pv[1]; x3 = pv[2]; x4 = pv[3]; 118049b5e25fSSatish Balay x5 = pv[4]; x6 = pv[5]; x7 = pv[6]; x8 = pv[7]; 118149b5e25fSSatish Balay x9 = pv[8]; x10 = pv[9]; x11 = pv[10]; x12 = pv[11]; 118249b5e25fSSatish Balay x13 = pv[12]; x14 = pv[13]; x15 = pv[14]; x16 = pv[15]; 118349b5e25fSSatish Balay x17 = pv[16]; x18 = pv[17]; x19 = pv[18]; x20 = pv[19]; 118449b5e25fSSatish Balay x21 = pv[20]; x22 = pv[21]; x23 = pv[22]; x24 = pv[23]; 118549b5e25fSSatish Balay x25 = pv[24]; x26 = pv[25]; x27 = pv[26]; x28 = pv[27]; 118649b5e25fSSatish Balay x29 = pv[28]; x30 = pv[29]; x31 = pv[30]; x32 = pv[31]; 118749b5e25fSSatish Balay x33 = pv[32]; x34 = pv[33]; x35 = pv[34]; x36 = pv[35]; 118849b5e25fSSatish Balay x = rtmp + 36*pj[j]; 118949b5e25fSSatish Balay x[0] -= m1*x1 + m7*x2 + m13*x3 + m19*x4 + m25*x5 + m31*x6; 119049b5e25fSSatish Balay x[1] -= m2*x1 + m8*x2 + m14*x3 + m20*x4 + m26*x5 + m32*x6; 119149b5e25fSSatish Balay x[2] -= m3*x1 + m9*x2 + m15*x3 + m21*x4 + m27*x5 + m33*x6; 119249b5e25fSSatish Balay x[3] -= m4*x1 + m10*x2 + m16*x3 + m22*x4 + m28*x5 + m34*x6; 119349b5e25fSSatish Balay x[4] -= m5*x1 + m11*x2 + m17*x3 + m23*x4 + m29*x5 + m35*x6; 119449b5e25fSSatish Balay x[5] -= m6*x1 + m12*x2 + m18*x3 + m24*x4 + m30*x5 + m36*x6; 119549b5e25fSSatish Balay 119649b5e25fSSatish Balay x[6] -= m1*x7 + m7*x8 + m13*x9 + m19*x10 + m25*x11 + m31*x12; 119749b5e25fSSatish Balay x[7] -= m2*x7 + m8*x8 + m14*x9 + m20*x10 + m26*x11 + m32*x12; 119849b5e25fSSatish Balay x[8] -= m3*x7 + m9*x8 + m15*x9 + m21*x10 + m27*x11 + m33*x12; 119949b5e25fSSatish Balay x[9] -= m4*x7 + m10*x8 + m16*x9 + m22*x10 + m28*x11 + m34*x12; 120049b5e25fSSatish Balay x[10] -= m5*x7 + m11*x8 + m17*x9 + m23*x10 + m29*x11 + m35*x12; 120149b5e25fSSatish Balay x[11] -= m6*x7 + m12*x8 + m18*x9 + m24*x10 + m30*x11 + m36*x12; 120249b5e25fSSatish Balay 120349b5e25fSSatish Balay x[12] -= m1*x13 + m7*x14 + m13*x15 + m19*x16 + m25*x17 + m31*x18; 120449b5e25fSSatish Balay x[13] -= m2*x13 + m8*x14 + m14*x15 + m20*x16 + m26*x17 + m32*x18; 120549b5e25fSSatish Balay x[14] -= m3*x13 + m9*x14 + m15*x15 + m21*x16 + m27*x17 + m33*x18; 120649b5e25fSSatish Balay x[15] -= m4*x13 + m10*x14 + m16*x15 + m22*x16 + m28*x17 + m34*x18; 120749b5e25fSSatish Balay x[16] -= m5*x13 + m11*x14 + m17*x15 + m23*x16 + m29*x17 + m35*x18; 120849b5e25fSSatish Balay x[17] -= m6*x13 + m12*x14 + m18*x15 + m24*x16 + m30*x17 + m36*x18; 120949b5e25fSSatish Balay 121049b5e25fSSatish Balay x[18] -= m1*x19 + m7*x20 + m13*x21 + m19*x22 + m25*x23 + m31*x24; 121149b5e25fSSatish Balay x[19] -= m2*x19 + m8*x20 + m14*x21 + m20*x22 + m26*x23 + m32*x24; 121249b5e25fSSatish Balay x[20] -= m3*x19 + m9*x20 + m15*x21 + m21*x22 + m27*x23 + m33*x24; 121349b5e25fSSatish Balay x[21] -= m4*x19 + m10*x20 + m16*x21 + m22*x22 + m28*x23 + m34*x24; 121449b5e25fSSatish Balay x[22] -= m5*x19 + m11*x20 + m17*x21 + m23*x22 + m29*x23 + m35*x24; 121549b5e25fSSatish Balay x[23] -= m6*x19 + m12*x20 + m18*x21 + m24*x22 + m30*x23 + m36*x24; 121649b5e25fSSatish Balay 121749b5e25fSSatish Balay x[24] -= m1*x25 + m7*x26 + m13*x27 + m19*x28 + m25*x29 + m31*x30; 121849b5e25fSSatish Balay x[25] -= m2*x25 + m8*x26 + m14*x27 + m20*x28 + m26*x29 + m32*x30; 121949b5e25fSSatish Balay x[26] -= m3*x25 + m9*x26 + m15*x27 + m21*x28 + m27*x29 + m33*x30; 122049b5e25fSSatish Balay x[27] -= m4*x25 + m10*x26 + m16*x27 + m22*x28 + m28*x29 + m34*x30; 122149b5e25fSSatish Balay x[28] -= m5*x25 + m11*x26 + m17*x27 + m23*x28 + m29*x29 + m35*x30; 122249b5e25fSSatish Balay x[29] -= m6*x25 + m12*x26 + m18*x27 + m24*x28 + m30*x29 + m36*x30; 122349b5e25fSSatish Balay 122449b5e25fSSatish Balay x[30] -= m1*x31 + m7*x32 + m13*x33 + m19*x34 + m25*x35 + m31*x36; 122549b5e25fSSatish Balay x[31] -= m2*x31 + m8*x32 + m14*x33 + m20*x34 + m26*x35 + m32*x36; 122649b5e25fSSatish Balay x[32] -= m3*x31 + m9*x32 + m15*x33 + m21*x34 + m27*x35 + m33*x36; 122749b5e25fSSatish Balay x[33] -= m4*x31 + m10*x32 + m16*x33 + m22*x34 + m28*x35 + m34*x36; 122849b5e25fSSatish Balay x[34] -= m5*x31 + m11*x32 + m17*x33 + m23*x34 + m29*x35 + m35*x36; 122949b5e25fSSatish Balay x[35] -= m6*x31 + m12*x32 + m18*x33 + m24*x34 + m30*x35 + m36*x36; 123049b5e25fSSatish Balay 123149b5e25fSSatish Balay pv += 36; 123249b5e25fSSatish Balay } 123349b5e25fSSatish Balay PLogFlops(432*nz+396); 123449b5e25fSSatish Balay } 123549b5e25fSSatish Balay row = *ajtmp++; 123649b5e25fSSatish Balay } 123749b5e25fSSatish Balay /* finished row so stick it into b->a */ 123849b5e25fSSatish Balay pv = ba + 36*bi[i]; 123949b5e25fSSatish Balay pj = bj + bi[i]; 124049b5e25fSSatish Balay nz = bi[i+1] - bi[i]; 124149b5e25fSSatish Balay for (j=0; j<nz; j++) { 124249b5e25fSSatish Balay x = rtmp+36*pj[j]; 124349b5e25fSSatish Balay pv[0] = x[0]; pv[1] = x[1]; pv[2] = x[2]; pv[3] = x[3]; 124449b5e25fSSatish Balay pv[4] = x[4]; pv[5] = x[5]; pv[6] = x[6]; pv[7] = x[7]; 124549b5e25fSSatish Balay pv[8] = x[8]; pv[9] = x[9]; pv[10] = x[10]; pv[11] = x[11]; 124649b5e25fSSatish Balay pv[12] = x[12]; pv[13] = x[13]; pv[14] = x[14]; pv[15] = x[15]; 124749b5e25fSSatish Balay pv[16] = x[16]; pv[17] = x[17]; pv[18] = x[18]; pv[19] = x[19]; 124849b5e25fSSatish Balay pv[20] = x[20]; pv[21] = x[21]; pv[22] = x[22]; pv[23] = x[23]; 124949b5e25fSSatish Balay pv[24] = x[24]; pv[25] = x[25]; pv[26] = x[26]; pv[27] = x[27]; 125049b5e25fSSatish Balay pv[28] = x[28]; pv[29] = x[29]; pv[30] = x[30]; pv[31] = x[31]; 125149b5e25fSSatish Balay pv[32] = x[32]; pv[33] = x[33]; pv[34] = x[34]; pv[35] = x[35]; 125249b5e25fSSatish Balay pv += 36; 125349b5e25fSSatish Balay } 125449b5e25fSSatish Balay /* invert diagonal block */ 125549b5e25fSSatish Balay w = ba + 36*diag_offset[i]; 125649b5e25fSSatish Balay ierr = Kernel_A_gets_inverse_A_6(w);CHKERRQ(ierr); 125749b5e25fSSatish Balay } 125849b5e25fSSatish Balay 125949b5e25fSSatish Balay ierr = PetscFree(rtmp);CHKERRQ(ierr); 126049b5e25fSSatish Balay C->factor = FACTOR_LU; 126149b5e25fSSatish Balay C->assembled = PETSC_TRUE; 126249b5e25fSSatish Balay PLogFlops(1.3333*216*b->mbs); /* from inverting diagonal blocks */ 126349b5e25fSSatish Balay PetscFunctionReturn(0); 126449b5e25fSSatish Balay } 126549b5e25fSSatish Balay 126649b5e25fSSatish Balay /* 126749b5e25fSSatish Balay Version for when blocks are 5 by 5 126849b5e25fSSatish Balay */ 126949b5e25fSSatish Balay #undef __FUNC__ 12706f9a564bSHong Zhang #define __FUNC__ "MatCholeskyFactorNumeric_SeqSBAIJ_5" 12716f9a564bSHong Zhang int MatCholeskyFactorNumeric_SeqSBAIJ_5(Mat A,Mat *B) 127249b5e25fSSatish Balay { 127349b5e25fSSatish Balay Mat C = *B; 127449b5e25fSSatish Balay Mat_SeqBAIJ *a = (Mat_SeqBAIJ*)A->data,*b = (Mat_SeqBAIJ *)C->data; 127549b5e25fSSatish Balay IS isrow = b->row,isicol = b->icol; 127649b5e25fSSatish Balay int *r,*ic,ierr,i,j,n = a->mbs,*bi = b->i,*bj = b->j; 127749b5e25fSSatish Balay int *ajtmpold,*ajtmp,nz,row; 127849b5e25fSSatish Balay int *diag_offset = b->diag,idx,*ai=a->i,*aj=a->j,*pj; 127949b5e25fSSatish Balay MatScalar *pv,*v,*rtmp,*pc,*w,*x; 128049b5e25fSSatish Balay MatScalar p1,p2,p3,p4,m1,m2,m3,m4,m5,m6,m7,m8,m9,x1,x2,x3,x4; 128149b5e25fSSatish Balay MatScalar p5,p6,p7,p8,p9,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,x16; 128249b5e25fSSatish Balay MatScalar x17,x18,x19,x20,x21,x22,x23,x24,x25,p10,p11,p12,p13,p14; 128349b5e25fSSatish Balay MatScalar p15,p16,p17,p18,p19,p20,p21,p22,p23,p24,p25,m10,m11,m12; 128449b5e25fSSatish Balay MatScalar m13,m14,m15,m16,m17,m18,m19,m20,m21,m22,m23,m24,m25; 128549b5e25fSSatish Balay MatScalar *ba = b->a,*aa = a->a; 128649b5e25fSSatish Balay 128749b5e25fSSatish Balay PetscFunctionBegin; 128849b5e25fSSatish Balay ierr = ISGetIndices(isrow,&r);CHKERRQ(ierr); 128949b5e25fSSatish Balay ierr = ISGetIndices(isicol,&ic);CHKERRQ(ierr); 129049b5e25fSSatish Balay rtmp = (MatScalar*)PetscMalloc(25*(n+1)*sizeof(MatScalar));CHKPTRQ(rtmp); 129149b5e25fSSatish Balay 129249b5e25fSSatish Balay for (i=0; i<n; i++) { 129349b5e25fSSatish Balay nz = bi[i+1] - bi[i]; 129449b5e25fSSatish Balay ajtmp = bj + bi[i]; 129549b5e25fSSatish Balay for (j=0; j<nz; j++) { 129649b5e25fSSatish Balay x = rtmp+25*ajtmp[j]; 129749b5e25fSSatish Balay x[0] = x[1] = x[2] = x[3] = x[4] = x[5] = x[6] = x[7] = x[8] = x[9] = 0.0; 129849b5e25fSSatish Balay x[10] = x[11] = x[12] = x[13] = x[14] = x[15] = x[16] = x[17] = 0.0; 129949b5e25fSSatish Balay x[18] = x[19] = x[20] = x[21] = x[22] = x[23] = x[24] = 0.0; 130049b5e25fSSatish Balay } 130149b5e25fSSatish Balay /* load in initial (unfactored row) */ 130249b5e25fSSatish Balay idx = r[i]; 130349b5e25fSSatish Balay nz = ai[idx+1] - ai[idx]; 130449b5e25fSSatish Balay ajtmpold = aj + ai[idx]; 130549b5e25fSSatish Balay v = aa + 25*ai[idx]; 130649b5e25fSSatish Balay for (j=0; j<nz; j++) { 130749b5e25fSSatish Balay x = rtmp+25*ic[ajtmpold[j]]; 130849b5e25fSSatish Balay x[0] = v[0]; x[1] = v[1]; x[2] = v[2]; x[3] = v[3]; 130949b5e25fSSatish Balay x[4] = v[4]; x[5] = v[5]; x[6] = v[6]; x[7] = v[7]; x[8] = v[8]; 131049b5e25fSSatish Balay x[9] = v[9]; x[10] = v[10]; x[11] = v[11]; x[12] = v[12]; x[13] = v[13]; 131149b5e25fSSatish Balay x[14] = v[14]; x[15] = v[15]; x[16] = v[16]; x[17] = v[17]; 131249b5e25fSSatish Balay x[18] = v[18]; x[19] = v[19]; x[20] = v[20]; x[21] = v[21]; 131349b5e25fSSatish Balay x[22] = v[22]; x[23] = v[23]; x[24] = v[24]; 131449b5e25fSSatish Balay v += 25; 131549b5e25fSSatish Balay } 131649b5e25fSSatish Balay row = *ajtmp++; 131749b5e25fSSatish Balay while (row < i) { 131849b5e25fSSatish Balay pc = rtmp + 25*row; 131949b5e25fSSatish Balay p1 = pc[0]; p2 = pc[1]; p3 = pc[2]; p4 = pc[3]; 132049b5e25fSSatish Balay p5 = pc[4]; p6 = pc[5]; p7 = pc[6]; p8 = pc[7]; p9 = pc[8]; 132149b5e25fSSatish Balay p10 = pc[9]; p11 = pc[10]; p12 = pc[11]; p13 = pc[12]; p14 = pc[13]; 132249b5e25fSSatish Balay p15 = pc[14]; p16 = pc[15]; p17 = pc[16]; p18 = pc[17]; p19 = pc[18]; 132349b5e25fSSatish Balay p20 = pc[19]; p21 = pc[20]; p22 = pc[21]; p23 = pc[22]; p24 = pc[23]; 132449b5e25fSSatish Balay p25 = pc[24]; 132549b5e25fSSatish Balay if (p1 != 0.0 || p2 != 0.0 || p3 != 0.0 || p4 != 0.0 || p5 != 0.0 || 132649b5e25fSSatish Balay p6 != 0.0 || p7 != 0.0 || p8 != 0.0 || p9 != 0.0 || p10 != 0.0 || 132749b5e25fSSatish Balay p11 != 0.0 || p12 != 0.0 || p13 != 0.0 || p14 != 0.0 || p15 != 0.0 132849b5e25fSSatish Balay || p16 != 0.0 || p17 != 0.0 || p18 != 0.0 || p19 != 0.0 || 132949b5e25fSSatish Balay p20 != 0.0 || p21 != 0.0 || p22 != 0.0 || p23 != 0.0 || 133049b5e25fSSatish Balay p24 != 0.0 || p25 != 0.0) { 133149b5e25fSSatish Balay pv = ba + 25*diag_offset[row]; 133249b5e25fSSatish Balay pj = bj + diag_offset[row] + 1; 133349b5e25fSSatish Balay x1 = pv[0]; x2 = pv[1]; x3 = pv[2]; x4 = pv[3]; 133449b5e25fSSatish Balay x5 = pv[4]; x6 = pv[5]; x7 = pv[6]; x8 = pv[7]; x9 = pv[8]; 133549b5e25fSSatish Balay x10 = pv[9]; x11 = pv[10]; x12 = pv[11]; x13 = pv[12]; x14 = pv[13]; 133649b5e25fSSatish Balay x15 = pv[14]; x16 = pv[15]; x17 = pv[16]; x18 = pv[17]; 133749b5e25fSSatish Balay x19 = pv[18]; x20 = pv[19]; x21 = pv[20]; x22 = pv[21]; 133849b5e25fSSatish Balay x23 = pv[22]; x24 = pv[23]; x25 = pv[24]; 133949b5e25fSSatish Balay pc[0] = m1 = p1*x1 + p6*x2 + p11*x3 + p16*x4 + p21*x5; 134049b5e25fSSatish Balay pc[1] = m2 = p2*x1 + p7*x2 + p12*x3 + p17*x4 + p22*x5; 134149b5e25fSSatish Balay pc[2] = m3 = p3*x1 + p8*x2 + p13*x3 + p18*x4 + p23*x5; 134249b5e25fSSatish Balay pc[3] = m4 = p4*x1 + p9*x2 + p14*x3 + p19*x4 + p24*x5; 134349b5e25fSSatish Balay pc[4] = m5 = p5*x1 + p10*x2 + p15*x3 + p20*x4 + p25*x5; 134449b5e25fSSatish Balay 134549b5e25fSSatish Balay pc[5] = m6 = p1*x6 + p6*x7 + p11*x8 + p16*x9 + p21*x10; 134649b5e25fSSatish Balay pc[6] = m7 = p2*x6 + p7*x7 + p12*x8 + p17*x9 + p22*x10; 134749b5e25fSSatish Balay pc[7] = m8 = p3*x6 + p8*x7 + p13*x8 + p18*x9 + p23*x10; 134849b5e25fSSatish Balay pc[8] = m9 = p4*x6 + p9*x7 + p14*x8 + p19*x9 + p24*x10; 134949b5e25fSSatish Balay pc[9] = m10 = p5*x6 + p10*x7 + p15*x8 + p20*x9 + p25*x10; 135049b5e25fSSatish Balay 135149b5e25fSSatish Balay pc[10] = m11 = p1*x11 + p6*x12 + p11*x13 + p16*x14 + p21*x15; 135249b5e25fSSatish Balay pc[11] = m12 = p2*x11 + p7*x12 + p12*x13 + p17*x14 + p22*x15; 135349b5e25fSSatish Balay pc[12] = m13 = p3*x11 + p8*x12 + p13*x13 + p18*x14 + p23*x15; 135449b5e25fSSatish Balay pc[13] = m14 = p4*x11 + p9*x12 + p14*x13 + p19*x14 + p24*x15; 135549b5e25fSSatish Balay pc[14] = m15 = p5*x11 + p10*x12 + p15*x13 + p20*x14 + p25*x15; 135649b5e25fSSatish Balay 135749b5e25fSSatish Balay pc[15] = m16 = p1*x16 + p6*x17 + p11*x18 + p16*x19 + p21*x20; 135849b5e25fSSatish Balay pc[16] = m17 = p2*x16 + p7*x17 + p12*x18 + p17*x19 + p22*x20; 135949b5e25fSSatish Balay pc[17] = m18 = p3*x16 + p8*x17 + p13*x18 + p18*x19 + p23*x20; 136049b5e25fSSatish Balay pc[18] = m19 = p4*x16 + p9*x17 + p14*x18 + p19*x19 + p24*x20; 136149b5e25fSSatish Balay pc[19] = m20 = p5*x16 + p10*x17 + p15*x18 + p20*x19 + p25*x20; 136249b5e25fSSatish Balay 136349b5e25fSSatish Balay pc[20] = m21 = p1*x21 + p6*x22 + p11*x23 + p16*x24 + p21*x25; 136449b5e25fSSatish Balay pc[21] = m22 = p2*x21 + p7*x22 + p12*x23 + p17*x24 + p22*x25; 136549b5e25fSSatish Balay pc[22] = m23 = p3*x21 + p8*x22 + p13*x23 + p18*x24 + p23*x25; 136649b5e25fSSatish Balay pc[23] = m24 = p4*x21 + p9*x22 + p14*x23 + p19*x24 + p24*x25; 136749b5e25fSSatish Balay pc[24] = m25 = p5*x21 + p10*x22 + p15*x23 + p20*x24 + p25*x25; 136849b5e25fSSatish Balay 136949b5e25fSSatish Balay nz = bi[row+1] - diag_offset[row] - 1; 137049b5e25fSSatish Balay pv += 25; 137149b5e25fSSatish Balay for (j=0; j<nz; j++) { 137249b5e25fSSatish Balay x1 = pv[0]; x2 = pv[1]; x3 = pv[2]; x4 = pv[3]; 137349b5e25fSSatish Balay x5 = pv[4]; x6 = pv[5]; x7 = pv[6]; x8 = pv[7]; x9 = pv[8]; 137449b5e25fSSatish Balay x10 = pv[9]; x11 = pv[10]; x12 = pv[11]; x13 = pv[12]; 137549b5e25fSSatish Balay x14 = pv[13]; x15 = pv[14]; x16 = pv[15]; x17 = pv[16]; 137649b5e25fSSatish Balay x18 = pv[17]; x19 = pv[18]; x20 = pv[19]; x21 = pv[20]; 137749b5e25fSSatish Balay x22 = pv[21]; x23 = pv[22]; x24 = pv[23]; x25 = pv[24]; 137849b5e25fSSatish Balay x = rtmp + 25*pj[j]; 137949b5e25fSSatish Balay x[0] -= m1*x1 + m6*x2 + m11*x3 + m16*x4 + m21*x5; 138049b5e25fSSatish Balay x[1] -= m2*x1 + m7*x2 + m12*x3 + m17*x4 + m22*x5; 138149b5e25fSSatish Balay x[2] -= m3*x1 + m8*x2 + m13*x3 + m18*x4 + m23*x5; 138249b5e25fSSatish Balay x[3] -= m4*x1 + m9*x2 + m14*x3 + m19*x4 + m24*x5; 138349b5e25fSSatish Balay x[4] -= m5*x1 + m10*x2 + m15*x3 + m20*x4 + m25*x5; 138449b5e25fSSatish Balay 138549b5e25fSSatish Balay x[5] -= m1*x6 + m6*x7 + m11*x8 + m16*x9 + m21*x10; 138649b5e25fSSatish Balay x[6] -= m2*x6 + m7*x7 + m12*x8 + m17*x9 + m22*x10; 138749b5e25fSSatish Balay x[7] -= m3*x6 + m8*x7 + m13*x8 + m18*x9 + m23*x10; 138849b5e25fSSatish Balay x[8] -= m4*x6 + m9*x7 + m14*x8 + m19*x9 + m24*x10; 138949b5e25fSSatish Balay x[9] -= m5*x6 + m10*x7 + m15*x8 + m20*x9 + m25*x10; 139049b5e25fSSatish Balay 139149b5e25fSSatish Balay x[10] -= m1*x11 + m6*x12 + m11*x13 + m16*x14 + m21*x15; 139249b5e25fSSatish Balay x[11] -= m2*x11 + m7*x12 + m12*x13 + m17*x14 + m22*x15; 139349b5e25fSSatish Balay x[12] -= m3*x11 + m8*x12 + m13*x13 + m18*x14 + m23*x15; 139449b5e25fSSatish Balay x[13] -= m4*x11 + m9*x12 + m14*x13 + m19*x14 + m24*x15; 139549b5e25fSSatish Balay x[14] -= m5*x11 + m10*x12 + m15*x13 + m20*x14 + m25*x15; 139649b5e25fSSatish Balay 139749b5e25fSSatish Balay x[15] -= m1*x16 + m6*x17 + m11*x18 + m16*x19 + m21*x20; 139849b5e25fSSatish Balay x[16] -= m2*x16 + m7*x17 + m12*x18 + m17*x19 + m22*x20; 139949b5e25fSSatish Balay x[17] -= m3*x16 + m8*x17 + m13*x18 + m18*x19 + m23*x20; 140049b5e25fSSatish Balay x[18] -= m4*x16 + m9*x17 + m14*x18 + m19*x19 + m24*x20; 140149b5e25fSSatish Balay x[19] -= m5*x16 + m10*x17 + m15*x18 + m20*x19 + m25*x20; 140249b5e25fSSatish Balay 140349b5e25fSSatish Balay x[20] -= m1*x21 + m6*x22 + m11*x23 + m16*x24 + m21*x25; 140449b5e25fSSatish Balay x[21] -= m2*x21 + m7*x22 + m12*x23 + m17*x24 + m22*x25; 140549b5e25fSSatish Balay x[22] -= m3*x21 + m8*x22 + m13*x23 + m18*x24 + m23*x25; 140649b5e25fSSatish Balay x[23] -= m4*x21 + m9*x22 + m14*x23 + m19*x24 + m24*x25; 140749b5e25fSSatish Balay x[24] -= m5*x21 + m10*x22 + m15*x23 + m20*x24 + m25*x25; 140849b5e25fSSatish Balay 140949b5e25fSSatish Balay pv += 25; 141049b5e25fSSatish Balay } 141149b5e25fSSatish Balay PLogFlops(250*nz+225); 141249b5e25fSSatish Balay } 141349b5e25fSSatish Balay row = *ajtmp++; 141449b5e25fSSatish Balay } 141549b5e25fSSatish Balay /* finished row so stick it into b->a */ 141649b5e25fSSatish Balay pv = ba + 25*bi[i]; 141749b5e25fSSatish Balay pj = bj + bi[i]; 141849b5e25fSSatish Balay nz = bi[i+1] - bi[i]; 141949b5e25fSSatish Balay for (j=0; j<nz; j++) { 142049b5e25fSSatish Balay x = rtmp+25*pj[j]; 142149b5e25fSSatish Balay pv[0] = x[0]; pv[1] = x[1]; pv[2] = x[2]; pv[3] = x[3]; 142249b5e25fSSatish Balay pv[4] = x[4]; pv[5] = x[5]; pv[6] = x[6]; pv[7] = x[7]; pv[8] = x[8]; 142349b5e25fSSatish Balay pv[9] = x[9]; pv[10] = x[10]; pv[11] = x[11]; pv[12] = x[12]; 142449b5e25fSSatish Balay pv[13] = x[13]; pv[14] = x[14]; pv[15] = x[15]; pv[16] = x[16]; 142549b5e25fSSatish Balay pv[17] = x[17]; pv[18] = x[18]; pv[19] = x[19]; pv[20] = x[20]; 142649b5e25fSSatish Balay pv[21] = x[21]; pv[22] = x[22]; pv[23] = x[23]; pv[24] = x[24]; 142749b5e25fSSatish Balay pv += 25; 142849b5e25fSSatish Balay } 142949b5e25fSSatish Balay /* invert diagonal block */ 143049b5e25fSSatish Balay w = ba + 25*diag_offset[i]; 143149b5e25fSSatish Balay ierr = Kernel_A_gets_inverse_A_5(w);CHKERRQ(ierr); 143249b5e25fSSatish Balay } 143349b5e25fSSatish Balay 143449b5e25fSSatish Balay ierr = PetscFree(rtmp);CHKERRQ(ierr); 143549b5e25fSSatish Balay ierr = ISRestoreIndices(isicol,&ic);CHKERRQ(ierr); 143649b5e25fSSatish Balay ierr = ISRestoreIndices(isrow,&r);CHKERRQ(ierr); 143749b5e25fSSatish Balay C->factor = FACTOR_LU; 143849b5e25fSSatish Balay C->assembled = PETSC_TRUE; 143949b5e25fSSatish Balay PLogFlops(1.3333*125*b->mbs); /* from inverting diagonal blocks */ 144049b5e25fSSatish Balay PetscFunctionReturn(0); 144149b5e25fSSatish Balay } 144249b5e25fSSatish Balay /* 144349b5e25fSSatish Balay Version for when blocks are 5 by 5 Using natural ordering 144449b5e25fSSatish Balay */ 144549b5e25fSSatish Balay #undef __FUNC__ 14466f9a564bSHong Zhang #define __FUNC__ "MatCholeskyFactorNumeric_SeqSBAIJ_5_NaturalOrdering" 14476f9a564bSHong Zhang int MatCholeskyFactorNumeric_SeqSBAIJ_5_NaturalOrdering(Mat A,Mat *B) 144849b5e25fSSatish Balay { 144949b5e25fSSatish Balay Mat C = *B; 145049b5e25fSSatish Balay Mat_SeqBAIJ *a = (Mat_SeqBAIJ*)A->data,*b = (Mat_SeqBAIJ *)C->data; 145149b5e25fSSatish Balay int ierr,i,j,n = a->mbs,*bi = b->i,*bj = b->j; 145249b5e25fSSatish Balay int *ajtmpold,*ajtmp,nz,row; 145349b5e25fSSatish Balay int *diag_offset = b->diag,*ai=a->i,*aj=a->j,*pj; 145449b5e25fSSatish Balay MatScalar *pv,*v,*rtmp,*pc,*w,*x; 145549b5e25fSSatish Balay MatScalar x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15; 145649b5e25fSSatish Balay MatScalar x16,x17,x18,x19,x20,x21,x22,x23,x24,x25; 145749b5e25fSSatish Balay MatScalar p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15; 145849b5e25fSSatish Balay MatScalar p16,p17,p18,p19,p20,p21,p22,p23,p24,p25; 145949b5e25fSSatish Balay MatScalar m1,m2,m3,m4,m5,m6,m7,m8,m9,m10,m11,m12,m13,m14,m15; 146049b5e25fSSatish Balay MatScalar m16,m17,m18,m19,m20,m21,m22,m23,m24,m25; 146149b5e25fSSatish Balay MatScalar *ba = b->a,*aa = a->a; 146249b5e25fSSatish Balay 146349b5e25fSSatish Balay PetscFunctionBegin; 146449b5e25fSSatish Balay rtmp = (MatScalar*)PetscMalloc(25*(n+1)*sizeof(MatScalar));CHKPTRQ(rtmp); 146549b5e25fSSatish Balay for (i=0; i<n; i++) { 146649b5e25fSSatish Balay nz = bi[i+1] - bi[i]; 146749b5e25fSSatish Balay ajtmp = bj + bi[i]; 146849b5e25fSSatish Balay for (j=0; j<nz; j++) { 146949b5e25fSSatish Balay x = rtmp+25*ajtmp[j]; 147049b5e25fSSatish Balay x[0] = x[1] = x[2] = x[3] = x[4] = x[5] = x[6] = x[7] = x[8] = x[9] = 0.0; 147149b5e25fSSatish Balay x[10] = x[11] = x[12] = x[13] = x[14] = x[15] = 0.0; 147249b5e25fSSatish Balay x[16] = x[17] = x[18] = x[19] = x[20] = x[21] = x[22] = x[23] = x[24] = 0.0; 147349b5e25fSSatish Balay } 147449b5e25fSSatish Balay /* load in initial (unfactored row) */ 147549b5e25fSSatish Balay nz = ai[i+1] - ai[i]; 147649b5e25fSSatish Balay ajtmpold = aj + ai[i]; 147749b5e25fSSatish Balay v = aa + 25*ai[i]; 147849b5e25fSSatish Balay for (j=0; j<nz; j++) { 147949b5e25fSSatish Balay x = rtmp+25*ajtmpold[j]; 148049b5e25fSSatish Balay x[0] = v[0]; x[1] = v[1]; x[2] = v[2]; x[3] = v[3]; 148149b5e25fSSatish Balay x[4] = v[4]; x[5] = v[5]; x[6] = v[6]; x[7] = v[7]; x[8] = v[8]; 148249b5e25fSSatish Balay x[9] = v[9]; x[10] = v[10]; x[11] = v[11]; x[12] = v[12]; x[13] = v[13]; 148349b5e25fSSatish Balay x[14] = v[14]; x[15] = v[15]; x[16] = v[16]; x[17] = v[17]; x[18] = v[18]; 148449b5e25fSSatish Balay x[19] = v[19]; x[20] = v[20]; x[21] = v[21]; x[22] = v[22]; x[23] = v[23]; 148549b5e25fSSatish Balay x[24] = v[24]; 148649b5e25fSSatish Balay v += 25; 148749b5e25fSSatish Balay } 148849b5e25fSSatish Balay row = *ajtmp++; 148949b5e25fSSatish Balay while (row < i) { 149049b5e25fSSatish Balay pc = rtmp + 25*row; 149149b5e25fSSatish Balay p1 = pc[0]; p2 = pc[1]; p3 = pc[2]; p4 = pc[3]; 149249b5e25fSSatish Balay p5 = pc[4]; p6 = pc[5]; p7 = pc[6]; p8 = pc[7]; p9 = pc[8]; 149349b5e25fSSatish Balay p10 = pc[9]; p11 = pc[10]; p12 = pc[11]; p13 = pc[12]; p14 = pc[13]; 149449b5e25fSSatish Balay p15 = pc[14]; p16 = pc[15]; p17 = pc[16]; p18 = pc[17]; 149549b5e25fSSatish Balay p19 = pc[18]; p20 = pc[19]; p21 = pc[20]; p22 = pc[21]; p23 = pc[22]; 149649b5e25fSSatish Balay p24 = pc[23]; p25 = pc[24]; 149749b5e25fSSatish Balay if (p1 != 0.0 || p2 != 0.0 || p3 != 0.0 || p4 != 0.0 || p5 != 0.0 || 149849b5e25fSSatish Balay p6 != 0.0 || p7 != 0.0 || p8 != 0.0 || p9 != 0.0 || p10 != 0.0 || 149949b5e25fSSatish Balay p11 != 0.0 || p12 != 0.0 || p13 != 0.0 || p14 != 0.0 || p15 != 0.0 150049b5e25fSSatish Balay || p16 != 0.0 || p17 != 0.0 || p18 != 0.0 || p19 != 0.0 || p20 != 0.0 150149b5e25fSSatish Balay || p21 != 0.0 || p22 != 0.0 || p23 != 0.0 || p24 != 0.0 || p25 != 0.0) { 150249b5e25fSSatish Balay pv = ba + 25*diag_offset[row]; 150349b5e25fSSatish Balay pj = bj + diag_offset[row] + 1; 150449b5e25fSSatish Balay x1 = pv[0]; x2 = pv[1]; x3 = pv[2]; x4 = pv[3]; 150549b5e25fSSatish Balay x5 = pv[4]; x6 = pv[5]; x7 = pv[6]; x8 = pv[7]; x9 = pv[8]; 150649b5e25fSSatish Balay x10 = pv[9]; x11 = pv[10]; x12 = pv[11]; x13 = pv[12]; x14 = pv[13]; 150749b5e25fSSatish Balay x15 = pv[14]; x16 = pv[15]; x17 = pv[16]; x18 = pv[17]; x19 = pv[18]; 150849b5e25fSSatish Balay x20 = pv[19]; x21 = pv[20]; x22 = pv[21]; x23 = pv[22]; x24 = pv[23]; 150949b5e25fSSatish Balay x25 = pv[24]; 151049b5e25fSSatish Balay pc[0] = m1 = p1*x1 + p6*x2 + p11*x3 + p16*x4 + p21*x5; 151149b5e25fSSatish Balay pc[1] = m2 = p2*x1 + p7*x2 + p12*x3 + p17*x4 + p22*x5; 151249b5e25fSSatish Balay pc[2] = m3 = p3*x1 + p8*x2 + p13*x3 + p18*x4 + p23*x5; 151349b5e25fSSatish Balay pc[3] = m4 = p4*x1 + p9*x2 + p14*x3 + p19*x4 + p24*x5; 151449b5e25fSSatish Balay pc[4] = m5 = p5*x1 + p10*x2 + p15*x3 + p20*x4 + p25*x5; 151549b5e25fSSatish Balay 151649b5e25fSSatish Balay pc[5] = m6 = p1*x6 + p6*x7 + p11*x8 + p16*x9 + p21*x10; 151749b5e25fSSatish Balay pc[6] = m7 = p2*x6 + p7*x7 + p12*x8 + p17*x9 + p22*x10; 151849b5e25fSSatish Balay pc[7] = m8 = p3*x6 + p8*x7 + p13*x8 + p18*x9 + p23*x10; 151949b5e25fSSatish Balay pc[8] = m9 = p4*x6 + p9*x7 + p14*x8 + p19*x9 + p24*x10; 152049b5e25fSSatish Balay pc[9] = m10 = p5*x6 + p10*x7 + p15*x8 + p20*x9 + p25*x10; 152149b5e25fSSatish Balay 152249b5e25fSSatish Balay pc[10] = m11 = p1*x11 + p6*x12 + p11*x13 + p16*x14 + p21*x15; 152349b5e25fSSatish Balay pc[11] = m12 = p2*x11 + p7*x12 + p12*x13 + p17*x14 + p22*x15; 152449b5e25fSSatish Balay pc[12] = m13 = p3*x11 + p8*x12 + p13*x13 + p18*x14 + p23*x15; 152549b5e25fSSatish Balay pc[13] = m14 = p4*x11 + p9*x12 + p14*x13 + p19*x14 + p24*x15; 152649b5e25fSSatish Balay pc[14] = m15 = p5*x11 + p10*x12 + p15*x13 + p20*x14 + p25*x15; 152749b5e25fSSatish Balay 152849b5e25fSSatish Balay pc[15] = m16 = p1*x16 + p6*x17 + p11*x18 + p16*x19 + p21*x20; 152949b5e25fSSatish Balay pc[16] = m17 = p2*x16 + p7*x17 + p12*x18 + p17*x19 + p22*x20; 153049b5e25fSSatish Balay pc[17] = m18 = p3*x16 + p8*x17 + p13*x18 + p18*x19 + p23*x20; 153149b5e25fSSatish Balay pc[18] = m19 = p4*x16 + p9*x17 + p14*x18 + p19*x19 + p24*x20; 153249b5e25fSSatish Balay pc[19] = m20 = p5*x16 + p10*x17 + p15*x18 + p20*x19 + p25*x20; 153349b5e25fSSatish Balay 153449b5e25fSSatish Balay pc[20] = m21 = p1*x21 + p6*x22 + p11*x23 + p16*x24 + p21*x25; 153549b5e25fSSatish Balay pc[21] = m22 = p2*x21 + p7*x22 + p12*x23 + p17*x24 + p22*x25; 153649b5e25fSSatish Balay pc[22] = m23 = p3*x21 + p8*x22 + p13*x23 + p18*x24 + p23*x25; 153749b5e25fSSatish Balay pc[23] = m24 = p4*x21 + p9*x22 + p14*x23 + p19*x24 + p24*x25; 153849b5e25fSSatish Balay pc[24] = m25 = p5*x21 + p10*x22 + p15*x23 + p20*x24 + p25*x25; 153949b5e25fSSatish Balay 154049b5e25fSSatish Balay nz = bi[row+1] - diag_offset[row] - 1; 154149b5e25fSSatish Balay pv += 25; 154249b5e25fSSatish Balay for (j=0; j<nz; j++) { 154349b5e25fSSatish Balay x1 = pv[0]; x2 = pv[1]; x3 = pv[2]; x4 = pv[3]; 154449b5e25fSSatish Balay x5 = pv[4]; x6 = pv[5]; x7 = pv[6]; x8 = pv[7]; x9 = pv[8]; 154549b5e25fSSatish Balay x10 = pv[9]; x11 = pv[10]; x12 = pv[11]; x13 = pv[12]; 154649b5e25fSSatish Balay x14 = pv[13]; x15 = pv[14]; x16 = pv[15]; x17 = pv[16]; x18 = pv[17]; 154749b5e25fSSatish Balay x19 = pv[18]; x20 = pv[19]; x21 = pv[20]; x22 = pv[21]; x23 = pv[22]; 154849b5e25fSSatish Balay x24 = pv[23]; x25 = pv[24]; 154949b5e25fSSatish Balay x = rtmp + 25*pj[j]; 155049b5e25fSSatish Balay x[0] -= m1*x1 + m6*x2 + m11*x3 + m16*x4 + m21*x5; 155149b5e25fSSatish Balay x[1] -= m2*x1 + m7*x2 + m12*x3 + m17*x4 + m22*x5; 155249b5e25fSSatish Balay x[2] -= m3*x1 + m8*x2 + m13*x3 + m18*x4 + m23*x5; 155349b5e25fSSatish Balay x[3] -= m4*x1 + m9*x2 + m14*x3 + m19*x4 + m24*x5; 155449b5e25fSSatish Balay x[4] -= m5*x1 + m10*x2 + m15*x3 + m20*x4 + m25*x5; 155549b5e25fSSatish Balay 155649b5e25fSSatish Balay x[5] -= m1*x6 + m6*x7 + m11*x8 + m16*x9 + m21*x10; 155749b5e25fSSatish Balay x[6] -= m2*x6 + m7*x7 + m12*x8 + m17*x9 + m22*x10; 155849b5e25fSSatish Balay x[7] -= m3*x6 + m8*x7 + m13*x8 + m18*x9 + m23*x10; 155949b5e25fSSatish Balay x[8] -= m4*x6 + m9*x7 + m14*x8 + m19*x9 + m24*x10; 156049b5e25fSSatish Balay x[9] -= m5*x6 + m10*x7 + m15*x8 + m20*x9 + m25*x10; 156149b5e25fSSatish Balay 156249b5e25fSSatish Balay x[10] -= m1*x11 + m6*x12 + m11*x13 + m16*x14 + m21*x15; 156349b5e25fSSatish Balay x[11] -= m2*x11 + m7*x12 + m12*x13 + m17*x14 + m22*x15; 156449b5e25fSSatish Balay x[12] -= m3*x11 + m8*x12 + m13*x13 + m18*x14 + m23*x15; 156549b5e25fSSatish Balay x[13] -= m4*x11 + m9*x12 + m14*x13 + m19*x14 + m24*x15; 156649b5e25fSSatish Balay x[14] -= m5*x11 + m10*x12 + m15*x13 + m20*x14 + m25*x15; 156749b5e25fSSatish Balay 156849b5e25fSSatish Balay x[15] -= m1*x16 + m6*x17 + m11*x18 + m16*x19 + m21*x20; 156949b5e25fSSatish Balay x[16] -= m2*x16 + m7*x17 + m12*x18 + m17*x19 + m22*x20; 157049b5e25fSSatish Balay x[17] -= m3*x16 + m8*x17 + m13*x18 + m18*x19 + m23*x20; 157149b5e25fSSatish Balay x[18] -= m4*x16 + m9*x17 + m14*x18 + m19*x19 + m24*x20; 157249b5e25fSSatish Balay x[19] -= m5*x16 + m10*x17 + m15*x18 + m20*x19 + m25*x20; 157349b5e25fSSatish Balay 157449b5e25fSSatish Balay x[20] -= m1*x21 + m6*x22 + m11*x23 + m16*x24 + m21*x25; 157549b5e25fSSatish Balay x[21] -= m2*x21 + m7*x22 + m12*x23 + m17*x24 + m22*x25; 157649b5e25fSSatish Balay x[22] -= m3*x21 + m8*x22 + m13*x23 + m18*x24 + m23*x25; 157749b5e25fSSatish Balay x[23] -= m4*x21 + m9*x22 + m14*x23 + m19*x24 + m24*x25; 157849b5e25fSSatish Balay x[24] -= m5*x21 + m10*x22 + m15*x23 + m20*x24 + m25*x25; 157949b5e25fSSatish Balay pv += 25; 158049b5e25fSSatish Balay } 158149b5e25fSSatish Balay PLogFlops(250*nz+225); 158249b5e25fSSatish Balay } 158349b5e25fSSatish Balay row = *ajtmp++; 158449b5e25fSSatish Balay } 158549b5e25fSSatish Balay /* finished row so stick it into b->a */ 158649b5e25fSSatish Balay pv = ba + 25*bi[i]; 158749b5e25fSSatish Balay pj = bj + bi[i]; 158849b5e25fSSatish Balay nz = bi[i+1] - bi[i]; 158949b5e25fSSatish Balay for (j=0; j<nz; j++) { 159049b5e25fSSatish Balay x = rtmp+25*pj[j]; 159149b5e25fSSatish Balay pv[0] = x[0]; pv[1] = x[1]; pv[2] = x[2]; pv[3] = x[3]; 159249b5e25fSSatish Balay pv[4] = x[4]; pv[5] = x[5]; pv[6] = x[6]; pv[7] = x[7]; pv[8] = x[8]; 159349b5e25fSSatish Balay pv[9] = x[9]; pv[10] = x[10]; pv[11] = x[11]; pv[12] = x[12]; 159449b5e25fSSatish Balay pv[13] = x[13]; pv[14] = x[14]; pv[15] = x[15]; pv[16] = x[16]; pv[17] = x[17]; 159549b5e25fSSatish Balay pv[18] = x[18]; pv[19] = x[19]; pv[20] = x[20]; pv[21] = x[21]; pv[22] = x[22]; 159649b5e25fSSatish Balay pv[23] = x[23]; pv[24] = x[24]; 159749b5e25fSSatish Balay pv += 25; 159849b5e25fSSatish Balay } 159949b5e25fSSatish Balay /* invert diagonal block */ 160049b5e25fSSatish Balay w = ba + 25*diag_offset[i]; 160149b5e25fSSatish Balay ierr = Kernel_A_gets_inverse_A_5(w);CHKERRQ(ierr); 160249b5e25fSSatish Balay } 160349b5e25fSSatish Balay 160449b5e25fSSatish Balay ierr = PetscFree(rtmp);CHKERRQ(ierr); 160549b5e25fSSatish Balay C->factor = FACTOR_LU; 160649b5e25fSSatish Balay C->assembled = PETSC_TRUE; 160749b5e25fSSatish Balay PLogFlops(1.3333*125*b->mbs); /* from inverting diagonal blocks */ 160849b5e25fSSatish Balay PetscFunctionReturn(0); 160949b5e25fSSatish Balay } 161049b5e25fSSatish Balay 161149b5e25fSSatish Balay /* 161249b5e25fSSatish Balay Version for when blocks are 4 by 4 161349b5e25fSSatish Balay */ 161449b5e25fSSatish Balay #undef __FUNC__ 16156f9a564bSHong Zhang #define __FUNC__ "MatCholeskyFactorNumeric_SeqSBAIJ_4" 16166f9a564bSHong Zhang int MatCholeskyFactorNumeric_SeqSBAIJ_4(Mat A,Mat *B) 161749b5e25fSSatish Balay { 161849b5e25fSSatish Balay Mat C = *B; 161949b5e25fSSatish Balay Mat_SeqBAIJ *a = (Mat_SeqBAIJ*)A->data,*b = (Mat_SeqBAIJ *)C->data; 162049b5e25fSSatish Balay IS isrow = b->row,isicol = b->icol; 162149b5e25fSSatish Balay int *r,*ic,ierr,i,j,n = a->mbs,*bi = b->i,*bj = b->j; 162249b5e25fSSatish Balay int *ajtmpold,*ajtmp,nz,row; 162349b5e25fSSatish Balay int *diag_offset = b->diag,idx,*ai=a->i,*aj=a->j,*pj; 162449b5e25fSSatish Balay MatScalar *pv,*v,*rtmp,*pc,*w,*x; 162549b5e25fSSatish Balay MatScalar p1,p2,p3,p4,m1,m2,m3,m4,m5,m6,m7,m8,m9,x1,x2,x3,x4; 162649b5e25fSSatish Balay MatScalar p5,p6,p7,p8,p9,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,x16; 162749b5e25fSSatish Balay MatScalar p10,p11,p12,p13,p14,p15,p16,m10,m11,m12; 162849b5e25fSSatish Balay MatScalar m13,m14,m15,m16; 162949b5e25fSSatish Balay MatScalar *ba = b->a,*aa = a->a; 163049b5e25fSSatish Balay 163149b5e25fSSatish Balay PetscFunctionBegin; 163249b5e25fSSatish Balay ierr = ISGetIndices(isrow,&r);CHKERRQ(ierr); 163349b5e25fSSatish Balay ierr = ISGetIndices(isicol,&ic);CHKERRQ(ierr); 163449b5e25fSSatish Balay rtmp = (MatScalar*)PetscMalloc(16*(n+1)*sizeof(MatScalar));CHKPTRQ(rtmp); 163549b5e25fSSatish Balay 163649b5e25fSSatish Balay for (i=0; i<n; i++) { 163749b5e25fSSatish Balay nz = bi[i+1] - bi[i]; 163849b5e25fSSatish Balay ajtmp = bj + bi[i]; 163949b5e25fSSatish Balay for (j=0; j<nz; j++) { 164049b5e25fSSatish Balay x = rtmp+16*ajtmp[j]; 164149b5e25fSSatish Balay x[0] = x[1] = x[2] = x[3] = x[4] = x[5] = x[6] = x[7] = x[8] = x[9] = 0.0; 164249b5e25fSSatish Balay x[10] = x[11] = x[12] = x[13] = x[14] = x[15] = 0.0; 164349b5e25fSSatish Balay } 164449b5e25fSSatish Balay /* load in initial (unfactored row) */ 164549b5e25fSSatish Balay idx = r[i]; 164649b5e25fSSatish Balay nz = ai[idx+1] - ai[idx]; 164749b5e25fSSatish Balay ajtmpold = aj + ai[idx]; 164849b5e25fSSatish Balay v = aa + 16*ai[idx]; 164949b5e25fSSatish Balay for (j=0; j<nz; j++) { 165049b5e25fSSatish Balay x = rtmp+16*ic[ajtmpold[j]]; 165149b5e25fSSatish Balay x[0] = v[0]; x[1] = v[1]; x[2] = v[2]; x[3] = v[3]; 165249b5e25fSSatish Balay x[4] = v[4]; x[5] = v[5]; x[6] = v[6]; x[7] = v[7]; x[8] = v[8]; 165349b5e25fSSatish Balay x[9] = v[9]; x[10] = v[10]; x[11] = v[11]; x[12] = v[12]; x[13] = v[13]; 165449b5e25fSSatish Balay x[14] = v[14]; x[15] = v[15]; 165549b5e25fSSatish Balay v += 16; 165649b5e25fSSatish Balay } 165749b5e25fSSatish Balay row = *ajtmp++; 165849b5e25fSSatish Balay while (row < i) { 165949b5e25fSSatish Balay pc = rtmp + 16*row; 166049b5e25fSSatish Balay p1 = pc[0]; p2 = pc[1]; p3 = pc[2]; p4 = pc[3]; 166149b5e25fSSatish Balay p5 = pc[4]; p6 = pc[5]; p7 = pc[6]; p8 = pc[7]; p9 = pc[8]; 166249b5e25fSSatish Balay p10 = pc[9]; p11 = pc[10]; p12 = pc[11]; p13 = pc[12]; p14 = pc[13]; 166349b5e25fSSatish Balay p15 = pc[14]; p16 = pc[15]; 166449b5e25fSSatish Balay if (p1 != 0.0 || p2 != 0.0 || p3 != 0.0 || p4 != 0.0 || p5 != 0.0 || 166549b5e25fSSatish Balay p6 != 0.0 || p7 != 0.0 || p8 != 0.0 || p9 != 0.0 || p10 != 0.0 || 166649b5e25fSSatish Balay p11 != 0.0 || p12 != 0.0 || p13 != 0.0 || p14 != 0.0 || p15 != 0.0 166749b5e25fSSatish Balay || p16 != 0.0) { 166849b5e25fSSatish Balay pv = ba + 16*diag_offset[row]; 166949b5e25fSSatish Balay pj = bj + diag_offset[row] + 1; 167049b5e25fSSatish Balay x1 = pv[0]; x2 = pv[1]; x3 = pv[2]; x4 = pv[3]; 167149b5e25fSSatish Balay x5 = pv[4]; x6 = pv[5]; x7 = pv[6]; x8 = pv[7]; x9 = pv[8]; 167249b5e25fSSatish Balay x10 = pv[9]; x11 = pv[10]; x12 = pv[11]; x13 = pv[12]; x14 = pv[13]; 167349b5e25fSSatish Balay x15 = pv[14]; x16 = pv[15]; 167449b5e25fSSatish Balay pc[0] = m1 = p1*x1 + p5*x2 + p9*x3 + p13*x4; 167549b5e25fSSatish Balay pc[1] = m2 = p2*x1 + p6*x2 + p10*x3 + p14*x4; 167649b5e25fSSatish Balay pc[2] = m3 = p3*x1 + p7*x2 + p11*x3 + p15*x4; 167749b5e25fSSatish Balay pc[3] = m4 = p4*x1 + p8*x2 + p12*x3 + p16*x4; 167849b5e25fSSatish Balay 167949b5e25fSSatish Balay pc[4] = m5 = p1*x5 + p5*x6 + p9*x7 + p13*x8; 168049b5e25fSSatish Balay pc[5] = m6 = p2*x5 + p6*x6 + p10*x7 + p14*x8; 168149b5e25fSSatish Balay pc[6] = m7 = p3*x5 + p7*x6 + p11*x7 + p15*x8; 168249b5e25fSSatish Balay pc[7] = m8 = p4*x5 + p8*x6 + p12*x7 + p16*x8; 168349b5e25fSSatish Balay 168449b5e25fSSatish Balay pc[8] = m9 = p1*x9 + p5*x10 + p9*x11 + p13*x12; 168549b5e25fSSatish Balay pc[9] = m10 = p2*x9 + p6*x10 + p10*x11 + p14*x12; 168649b5e25fSSatish Balay pc[10] = m11 = p3*x9 + p7*x10 + p11*x11 + p15*x12; 168749b5e25fSSatish Balay pc[11] = m12 = p4*x9 + p8*x10 + p12*x11 + p16*x12; 168849b5e25fSSatish Balay 168949b5e25fSSatish Balay pc[12] = m13 = p1*x13 + p5*x14 + p9*x15 + p13*x16; 169049b5e25fSSatish Balay pc[13] = m14 = p2*x13 + p6*x14 + p10*x15 + p14*x16; 169149b5e25fSSatish Balay pc[14] = m15 = p3*x13 + p7*x14 + p11*x15 + p15*x16; 169249b5e25fSSatish Balay pc[15] = m16 = p4*x13 + p8*x14 + p12*x15 + p16*x16; 169349b5e25fSSatish Balay 169449b5e25fSSatish Balay nz = bi[row+1] - diag_offset[row] - 1; 169549b5e25fSSatish Balay pv += 16; 169649b5e25fSSatish Balay for (j=0; j<nz; j++) { 169749b5e25fSSatish Balay x1 = pv[0]; x2 = pv[1]; x3 = pv[2]; x4 = pv[3]; 169849b5e25fSSatish Balay x5 = pv[4]; x6 = pv[5]; x7 = pv[6]; x8 = pv[7]; x9 = pv[8]; 169949b5e25fSSatish Balay x10 = pv[9]; x11 = pv[10]; x12 = pv[11]; x13 = pv[12]; 170049b5e25fSSatish Balay x14 = pv[13]; x15 = pv[14]; x16 = pv[15]; 170149b5e25fSSatish Balay x = rtmp + 16*pj[j]; 170249b5e25fSSatish Balay x[0] -= m1*x1 + m5*x2 + m9*x3 + m13*x4; 170349b5e25fSSatish Balay x[1] -= m2*x1 + m6*x2 + m10*x3 + m14*x4; 170449b5e25fSSatish Balay x[2] -= m3*x1 + m7*x2 + m11*x3 + m15*x4; 170549b5e25fSSatish Balay x[3] -= m4*x1 + m8*x2 + m12*x3 + m16*x4; 170649b5e25fSSatish Balay 170749b5e25fSSatish Balay x[4] -= m1*x5 + m5*x6 + m9*x7 + m13*x8; 170849b5e25fSSatish Balay x[5] -= m2*x5 + m6*x6 + m10*x7 + m14*x8; 170949b5e25fSSatish Balay x[6] -= m3*x5 + m7*x6 + m11*x7 + m15*x8; 171049b5e25fSSatish Balay x[7] -= m4*x5 + m8*x6 + m12*x7 + m16*x8; 171149b5e25fSSatish Balay 171249b5e25fSSatish Balay x[8] -= m1*x9 + m5*x10 + m9*x11 + m13*x12; 171349b5e25fSSatish Balay x[9] -= m2*x9 + m6*x10 + m10*x11 + m14*x12; 171449b5e25fSSatish Balay x[10] -= m3*x9 + m7*x10 + m11*x11 + m15*x12; 171549b5e25fSSatish Balay x[11] -= m4*x9 + m8*x10 + m12*x11 + m16*x12; 171649b5e25fSSatish Balay 171749b5e25fSSatish Balay x[12] -= m1*x13 + m5*x14 + m9*x15 + m13*x16; 171849b5e25fSSatish Balay x[13] -= m2*x13 + m6*x14 + m10*x15 + m14*x16; 171949b5e25fSSatish Balay x[14] -= m3*x13 + m7*x14 + m11*x15 + m15*x16; 172049b5e25fSSatish Balay x[15] -= m4*x13 + m8*x14 + m12*x15 + m16*x16; 172149b5e25fSSatish Balay 172249b5e25fSSatish Balay pv += 16; 172349b5e25fSSatish Balay } 172449b5e25fSSatish Balay PLogFlops(128*nz+112); 172549b5e25fSSatish Balay } 172649b5e25fSSatish Balay row = *ajtmp++; 172749b5e25fSSatish Balay } 172849b5e25fSSatish Balay /* finished row so stick it into b->a */ 172949b5e25fSSatish Balay pv = ba + 16*bi[i]; 173049b5e25fSSatish Balay pj = bj + bi[i]; 173149b5e25fSSatish Balay nz = bi[i+1] - bi[i]; 173249b5e25fSSatish Balay for (j=0; j<nz; j++) { 173349b5e25fSSatish Balay x = rtmp+16*pj[j]; 173449b5e25fSSatish Balay pv[0] = x[0]; pv[1] = x[1]; pv[2] = x[2]; pv[3] = x[3]; 173549b5e25fSSatish Balay pv[4] = x[4]; pv[5] = x[5]; pv[6] = x[6]; pv[7] = x[7]; pv[8] = x[8]; 173649b5e25fSSatish Balay pv[9] = x[9]; pv[10] = x[10]; pv[11] = x[11]; pv[12] = x[12]; 173749b5e25fSSatish Balay pv[13] = x[13]; pv[14] = x[14]; pv[15] = x[15]; 173849b5e25fSSatish Balay pv += 16; 173949b5e25fSSatish Balay } 174049b5e25fSSatish Balay /* invert diagonal block */ 174149b5e25fSSatish Balay w = ba + 16*diag_offset[i]; 174249b5e25fSSatish Balay ierr = Kernel_A_gets_inverse_A_4(w);CHKERRQ(ierr); 174349b5e25fSSatish Balay } 174449b5e25fSSatish Balay 174549b5e25fSSatish Balay ierr = PetscFree(rtmp);CHKERRQ(ierr); 174649b5e25fSSatish Balay ierr = ISRestoreIndices(isicol,&ic);CHKERRQ(ierr); 174749b5e25fSSatish Balay ierr = ISRestoreIndices(isrow,&r);CHKERRQ(ierr); 174849b5e25fSSatish Balay C->factor = FACTOR_LU; 174949b5e25fSSatish Balay C->assembled = PETSC_TRUE; 175049b5e25fSSatish Balay PLogFlops(1.3333*64*b->mbs); /* from inverting diagonal blocks */ 175149b5e25fSSatish Balay PetscFunctionReturn(0); 175249b5e25fSSatish Balay } 175349b5e25fSSatish Balay /* 175449b5e25fSSatish Balay Version for when blocks are 4 by 4 Using natural ordering 175549b5e25fSSatish Balay */ 175649b5e25fSSatish Balay #undef __FUNC__ 17576f9a564bSHong Zhang #define __FUNC__ "MatCholeskyFactorNumeric_SeqSBAIJ_4_NaturalOrdering" 17586f9a564bSHong Zhang int MatCholeskyFactorNumeric_SeqSBAIJ_4_NaturalOrdering(Mat A,Mat *B) 175949b5e25fSSatish Balay { 176049b5e25fSSatish Balay Mat C = *B; 176149b5e25fSSatish Balay Mat_SeqBAIJ *a = (Mat_SeqBAIJ*)A->data,*b = (Mat_SeqBAIJ *)C->data; 176249b5e25fSSatish Balay int ierr,i,j,n = a->mbs,*bi = b->i,*bj = b->j; 176349b5e25fSSatish Balay int *ajtmpold,*ajtmp,nz,row; 176449b5e25fSSatish Balay int *diag_offset = b->diag,*ai=a->i,*aj=a->j,*pj; 176549b5e25fSSatish Balay MatScalar *pv,*v,*rtmp,*pc,*w,*x; 176649b5e25fSSatish Balay MatScalar p1,p2,p3,p4,m1,m2,m3,m4,m5,m6,m7,m8,m9,x1,x2,x3,x4; 176749b5e25fSSatish Balay MatScalar p5,p6,p7,p8,p9,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,x16; 176849b5e25fSSatish Balay MatScalar p10,p11,p12,p13,p14,p15,p16,m10,m11,m12; 176949b5e25fSSatish Balay MatScalar m13,m14,m15,m16; 177049b5e25fSSatish Balay MatScalar *ba = b->a,*aa = a->a; 177149b5e25fSSatish Balay 177249b5e25fSSatish Balay PetscFunctionBegin; 177349b5e25fSSatish Balay rtmp = (MatScalar*)PetscMalloc(16*(n+1)*sizeof(MatScalar));CHKPTRQ(rtmp); 177449b5e25fSSatish Balay 177549b5e25fSSatish Balay for (i=0; i<n; i++) { 177649b5e25fSSatish Balay nz = bi[i+1] - bi[i]; 177749b5e25fSSatish Balay ajtmp = bj + bi[i]; 177849b5e25fSSatish Balay for (j=0; j<nz; j++) { 177949b5e25fSSatish Balay x = rtmp+16*ajtmp[j]; 178049b5e25fSSatish Balay x[0] = x[1] = x[2] = x[3] = x[4] = x[5] = x[6] = x[7] = x[8] = x[9] = 0.0; 178149b5e25fSSatish Balay x[10] = x[11] = x[12] = x[13] = x[14] = x[15] = 0.0; 178249b5e25fSSatish Balay } 178349b5e25fSSatish Balay /* load in initial (unfactored row) */ 178449b5e25fSSatish Balay nz = ai[i+1] - ai[i]; 178549b5e25fSSatish Balay ajtmpold = aj + ai[i]; 178649b5e25fSSatish Balay v = aa + 16*ai[i]; 178749b5e25fSSatish Balay for (j=0; j<nz; j++) { 178849b5e25fSSatish Balay x = rtmp+16*ajtmpold[j]; 178949b5e25fSSatish Balay x[0] = v[0]; x[1] = v[1]; x[2] = v[2]; x[3] = v[3]; 179049b5e25fSSatish Balay x[4] = v[4]; x[5] = v[5]; x[6] = v[6]; x[7] = v[7]; x[8] = v[8]; 179149b5e25fSSatish Balay x[9] = v[9]; x[10] = v[10]; x[11] = v[11]; x[12] = v[12]; x[13] = v[13]; 179249b5e25fSSatish Balay x[14] = v[14]; x[15] = v[15]; 179349b5e25fSSatish Balay v += 16; 179449b5e25fSSatish Balay } 179549b5e25fSSatish Balay row = *ajtmp++; 179649b5e25fSSatish Balay while (row < i) { 179749b5e25fSSatish Balay pc = rtmp + 16*row; 179849b5e25fSSatish Balay p1 = pc[0]; p2 = pc[1]; p3 = pc[2]; p4 = pc[3]; 179949b5e25fSSatish Balay p5 = pc[4]; p6 = pc[5]; p7 = pc[6]; p8 = pc[7]; p9 = pc[8]; 180049b5e25fSSatish Balay p10 = pc[9]; p11 = pc[10]; p12 = pc[11]; p13 = pc[12]; p14 = pc[13]; 180149b5e25fSSatish Balay p15 = pc[14]; p16 = pc[15]; 180249b5e25fSSatish Balay if (p1 != 0.0 || p2 != 0.0 || p3 != 0.0 || p4 != 0.0 || p5 != 0.0 || 180349b5e25fSSatish Balay p6 != 0.0 || p7 != 0.0 || p8 != 0.0 || p9 != 0.0 || p10 != 0.0 || 180449b5e25fSSatish Balay p11 != 0.0 || p12 != 0.0 || p13 != 0.0 || p14 != 0.0 || p15 != 0.0 180549b5e25fSSatish Balay || p16 != 0.0) { 180649b5e25fSSatish Balay pv = ba + 16*diag_offset[row]; 180749b5e25fSSatish Balay pj = bj + diag_offset[row] + 1; 180849b5e25fSSatish Balay x1 = pv[0]; x2 = pv[1]; x3 = pv[2]; x4 = pv[3]; 180949b5e25fSSatish Balay x5 = pv[4]; x6 = pv[5]; x7 = pv[6]; x8 = pv[7]; x9 = pv[8]; 181049b5e25fSSatish Balay x10 = pv[9]; x11 = pv[10]; x12 = pv[11]; x13 = pv[12]; x14 = pv[13]; 181149b5e25fSSatish Balay x15 = pv[14]; x16 = pv[15]; 181249b5e25fSSatish Balay pc[0] = m1 = p1*x1 + p5*x2 + p9*x3 + p13*x4; 181349b5e25fSSatish Balay pc[1] = m2 = p2*x1 + p6*x2 + p10*x3 + p14*x4; 181449b5e25fSSatish Balay pc[2] = m3 = p3*x1 + p7*x2 + p11*x3 + p15*x4; 181549b5e25fSSatish Balay pc[3] = m4 = p4*x1 + p8*x2 + p12*x3 + p16*x4; 181649b5e25fSSatish Balay 181749b5e25fSSatish Balay pc[4] = m5 = p1*x5 + p5*x6 + p9*x7 + p13*x8; 181849b5e25fSSatish Balay pc[5] = m6 = p2*x5 + p6*x6 + p10*x7 + p14*x8; 181949b5e25fSSatish Balay pc[6] = m7 = p3*x5 + p7*x6 + p11*x7 + p15*x8; 182049b5e25fSSatish Balay pc[7] = m8 = p4*x5 + p8*x6 + p12*x7 + p16*x8; 182149b5e25fSSatish Balay 182249b5e25fSSatish Balay pc[8] = m9 = p1*x9 + p5*x10 + p9*x11 + p13*x12; 182349b5e25fSSatish Balay pc[9] = m10 = p2*x9 + p6*x10 + p10*x11 + p14*x12; 182449b5e25fSSatish Balay pc[10] = m11 = p3*x9 + p7*x10 + p11*x11 + p15*x12; 182549b5e25fSSatish Balay pc[11] = m12 = p4*x9 + p8*x10 + p12*x11 + p16*x12; 182649b5e25fSSatish Balay 182749b5e25fSSatish Balay pc[12] = m13 = p1*x13 + p5*x14 + p9*x15 + p13*x16; 182849b5e25fSSatish Balay pc[13] = m14 = p2*x13 + p6*x14 + p10*x15 + p14*x16; 182949b5e25fSSatish Balay pc[14] = m15 = p3*x13 + p7*x14 + p11*x15 + p15*x16; 183049b5e25fSSatish Balay pc[15] = m16 = p4*x13 + p8*x14 + p12*x15 + p16*x16; 183149b5e25fSSatish Balay 183249b5e25fSSatish Balay nz = bi[row+1] - diag_offset[row] - 1; 183349b5e25fSSatish Balay pv += 16; 183449b5e25fSSatish Balay for (j=0; j<nz; j++) { 183549b5e25fSSatish Balay x1 = pv[0]; x2 = pv[1]; x3 = pv[2]; x4 = pv[3]; 183649b5e25fSSatish Balay x5 = pv[4]; x6 = pv[5]; x7 = pv[6]; x8 = pv[7]; x9 = pv[8]; 183749b5e25fSSatish Balay x10 = pv[9]; x11 = pv[10]; x12 = pv[11]; x13 = pv[12]; 183849b5e25fSSatish Balay x14 = pv[13]; x15 = pv[14]; x16 = pv[15]; 183949b5e25fSSatish Balay x = rtmp + 16*pj[j]; 184049b5e25fSSatish Balay x[0] -= m1*x1 + m5*x2 + m9*x3 + m13*x4; 184149b5e25fSSatish Balay x[1] -= m2*x1 + m6*x2 + m10*x3 + m14*x4; 184249b5e25fSSatish Balay x[2] -= m3*x1 + m7*x2 + m11*x3 + m15*x4; 184349b5e25fSSatish Balay x[3] -= m4*x1 + m8*x2 + m12*x3 + m16*x4; 184449b5e25fSSatish Balay 184549b5e25fSSatish Balay x[4] -= m1*x5 + m5*x6 + m9*x7 + m13*x8; 184649b5e25fSSatish Balay x[5] -= m2*x5 + m6*x6 + m10*x7 + m14*x8; 184749b5e25fSSatish Balay x[6] -= m3*x5 + m7*x6 + m11*x7 + m15*x8; 184849b5e25fSSatish Balay x[7] -= m4*x5 + m8*x6 + m12*x7 + m16*x8; 184949b5e25fSSatish Balay 185049b5e25fSSatish Balay x[8] -= m1*x9 + m5*x10 + m9*x11 + m13*x12; 185149b5e25fSSatish Balay x[9] -= m2*x9 + m6*x10 + m10*x11 + m14*x12; 185249b5e25fSSatish Balay x[10] -= m3*x9 + m7*x10 + m11*x11 + m15*x12; 185349b5e25fSSatish Balay x[11] -= m4*x9 + m8*x10 + m12*x11 + m16*x12; 185449b5e25fSSatish Balay 185549b5e25fSSatish Balay x[12] -= m1*x13 + m5*x14 + m9*x15 + m13*x16; 185649b5e25fSSatish Balay x[13] -= m2*x13 + m6*x14 + m10*x15 + m14*x16; 185749b5e25fSSatish Balay x[14] -= m3*x13 + m7*x14 + m11*x15 + m15*x16; 185849b5e25fSSatish Balay x[15] -= m4*x13 + m8*x14 + m12*x15 + m16*x16; 185949b5e25fSSatish Balay 186049b5e25fSSatish Balay pv += 16; 186149b5e25fSSatish Balay } 186249b5e25fSSatish Balay PLogFlops(128*nz+112); 186349b5e25fSSatish Balay } 186449b5e25fSSatish Balay row = *ajtmp++; 186549b5e25fSSatish Balay } 186649b5e25fSSatish Balay /* finished row so stick it into b->a */ 186749b5e25fSSatish Balay pv = ba + 16*bi[i]; 186849b5e25fSSatish Balay pj = bj + bi[i]; 186949b5e25fSSatish Balay nz = bi[i+1] - bi[i]; 187049b5e25fSSatish Balay for (j=0; j<nz; j++) { 187149b5e25fSSatish Balay x = rtmp+16*pj[j]; 187249b5e25fSSatish Balay pv[0] = x[0]; pv[1] = x[1]; pv[2] = x[2]; pv[3] = x[3]; 187349b5e25fSSatish Balay pv[4] = x[4]; pv[5] = x[5]; pv[6] = x[6]; pv[7] = x[7]; pv[8] = x[8]; 187449b5e25fSSatish Balay pv[9] = x[9]; pv[10] = x[10]; pv[11] = x[11]; pv[12] = x[12]; 187549b5e25fSSatish Balay pv[13] = x[13]; pv[14] = x[14]; pv[15] = x[15]; 187649b5e25fSSatish Balay pv += 16; 187749b5e25fSSatish Balay } 187849b5e25fSSatish Balay /* invert diagonal block */ 187949b5e25fSSatish Balay w = ba + 16*diag_offset[i]; 188049b5e25fSSatish Balay ierr = Kernel_A_gets_inverse_A_4(w);CHKERRQ(ierr); 188149b5e25fSSatish Balay } 188249b5e25fSSatish Balay 188349b5e25fSSatish Balay ierr = PetscFree(rtmp);CHKERRQ(ierr); 188449b5e25fSSatish Balay C->factor = FACTOR_LU; 188549b5e25fSSatish Balay C->assembled = PETSC_TRUE; 188649b5e25fSSatish Balay PLogFlops(1.3333*64*b->mbs); /* from inverting diagonal blocks */ 188749b5e25fSSatish Balay PetscFunctionReturn(0); 188849b5e25fSSatish Balay } 188949b5e25fSSatish Balay 189049b5e25fSSatish Balay /* 189149b5e25fSSatish Balay Version for when blocks are 3 by 3 189249b5e25fSSatish Balay */ 189349b5e25fSSatish Balay #undef __FUNC__ 18946f9a564bSHong Zhang #define __FUNC__ "MatCholeskyFactorNumeric_SeqSBAIJ_3" 18956f9a564bSHong Zhang int MatCholeskyFactorNumeric_SeqSBAIJ_3(Mat A,Mat *B) 189649b5e25fSSatish Balay { 189749b5e25fSSatish Balay Mat C = *B; 189849b5e25fSSatish Balay Mat_SeqBAIJ *a = (Mat_SeqBAIJ*)A->data,*b = (Mat_SeqBAIJ *)C->data; 189949b5e25fSSatish Balay IS isrow = b->row,isicol = b->icol; 190049b5e25fSSatish Balay int *r,*ic,ierr,i,j,n = a->mbs,*bi = b->i,*bj = b->j; 190149b5e25fSSatish Balay int *ajtmpold,*ajtmp,nz,row,*ai=a->i,*aj=a->j; 190249b5e25fSSatish Balay int *diag_offset = b->diag,idx,*pj; 190349b5e25fSSatish Balay MatScalar *pv,*v,*rtmp,*pc,*w,*x; 190449b5e25fSSatish Balay MatScalar p1,p2,p3,p4,m1,m2,m3,m4,m5,m6,m7,m8,m9,x1,x2,x3,x4; 190549b5e25fSSatish Balay MatScalar p5,p6,p7,p8,p9,x5,x6,x7,x8,x9; 190649b5e25fSSatish Balay MatScalar *ba = b->a,*aa = a->a; 190749b5e25fSSatish Balay 190849b5e25fSSatish Balay PetscFunctionBegin; 190949b5e25fSSatish Balay ierr = ISGetIndices(isrow,&r);CHKERRQ(ierr); 191049b5e25fSSatish Balay ierr = ISGetIndices(isicol,&ic);CHKERRQ(ierr); 191149b5e25fSSatish Balay rtmp = (MatScalar*)PetscMalloc(9*(n+1)*sizeof(MatScalar));CHKPTRQ(rtmp); 191249b5e25fSSatish Balay 191349b5e25fSSatish Balay for (i=0; i<n; i++) { 191449b5e25fSSatish Balay nz = bi[i+1] - bi[i]; 191549b5e25fSSatish Balay ajtmp = bj + bi[i]; 191649b5e25fSSatish Balay for (j=0; j<nz; j++) { 191749b5e25fSSatish Balay x = rtmp + 9*ajtmp[j]; 191849b5e25fSSatish Balay x[0] = x[1] = x[2] = x[3] = x[4] = x[5] = x[6] = x[7] = x[8] = 0.0; 191949b5e25fSSatish Balay } 192049b5e25fSSatish Balay /* load in initial (unfactored row) */ 192149b5e25fSSatish Balay idx = r[i]; 192249b5e25fSSatish Balay nz = ai[idx+1] - ai[idx]; 192349b5e25fSSatish Balay ajtmpold = aj + ai[idx]; 192449b5e25fSSatish Balay v = aa + 9*ai[idx]; 192549b5e25fSSatish Balay for (j=0; j<nz; j++) { 192649b5e25fSSatish Balay x = rtmp + 9*ic[ajtmpold[j]]; 192749b5e25fSSatish Balay x[0] = v[0]; x[1] = v[1]; x[2] = v[2]; x[3] = v[3]; 192849b5e25fSSatish Balay x[4] = v[4]; x[5] = v[5]; x[6] = v[6]; x[7] = v[7]; x[8] = v[8]; 192949b5e25fSSatish Balay v += 9; 193049b5e25fSSatish Balay } 193149b5e25fSSatish Balay row = *ajtmp++; 193249b5e25fSSatish Balay while (row < i) { 193349b5e25fSSatish Balay pc = rtmp + 9*row; 193449b5e25fSSatish Balay p1 = pc[0]; p2 = pc[1]; p3 = pc[2]; p4 = pc[3]; 193549b5e25fSSatish Balay p5 = pc[4]; p6 = pc[5]; p7 = pc[6]; p8 = pc[7]; p9 = pc[8]; 193649b5e25fSSatish Balay if (p1 != 0.0 || p2 != 0.0 || p3 != 0.0 || p4 != 0.0 || p5 != 0.0 || 193749b5e25fSSatish Balay p6 != 0.0 || p7 != 0.0 || p8 != 0.0 || p9 != 0.0) { 193849b5e25fSSatish Balay pv = ba + 9*diag_offset[row]; 193949b5e25fSSatish Balay pj = bj + diag_offset[row] + 1; 194049b5e25fSSatish Balay x1 = pv[0]; x2 = pv[1]; x3 = pv[2]; x4 = pv[3]; 194149b5e25fSSatish Balay x5 = pv[4]; x6 = pv[5]; x7 = pv[6]; x8 = pv[7]; x9 = pv[8]; 194249b5e25fSSatish Balay pc[0] = m1 = p1*x1 + p4*x2 + p7*x3; 194349b5e25fSSatish Balay pc[1] = m2 = p2*x1 + p5*x2 + p8*x3; 194449b5e25fSSatish Balay pc[2] = m3 = p3*x1 + p6*x2 + p9*x3; 194549b5e25fSSatish Balay 194649b5e25fSSatish Balay pc[3] = m4 = p1*x4 + p4*x5 + p7*x6; 194749b5e25fSSatish Balay pc[4] = m5 = p2*x4 + p5*x5 + p8*x6; 194849b5e25fSSatish Balay pc[5] = m6 = p3*x4 + p6*x5 + p9*x6; 194949b5e25fSSatish Balay 195049b5e25fSSatish Balay pc[6] = m7 = p1*x7 + p4*x8 + p7*x9; 195149b5e25fSSatish Balay pc[7] = m8 = p2*x7 + p5*x8 + p8*x9; 195249b5e25fSSatish Balay pc[8] = m9 = p3*x7 + p6*x8 + p9*x9; 195349b5e25fSSatish Balay nz = bi[row+1] - diag_offset[row] - 1; 195449b5e25fSSatish Balay pv += 9; 195549b5e25fSSatish Balay for (j=0; j<nz; j++) { 195649b5e25fSSatish Balay x1 = pv[0]; x2 = pv[1]; x3 = pv[2]; x4 = pv[3]; 195749b5e25fSSatish Balay x5 = pv[4]; x6 = pv[5]; x7 = pv[6]; x8 = pv[7]; x9 = pv[8]; 195849b5e25fSSatish Balay x = rtmp + 9*pj[j]; 195949b5e25fSSatish Balay x[0] -= m1*x1 + m4*x2 + m7*x3; 196049b5e25fSSatish Balay x[1] -= m2*x1 + m5*x2 + m8*x3; 196149b5e25fSSatish Balay x[2] -= m3*x1 + m6*x2 + m9*x3; 196249b5e25fSSatish Balay 196349b5e25fSSatish Balay x[3] -= m1*x4 + m4*x5 + m7*x6; 196449b5e25fSSatish Balay x[4] -= m2*x4 + m5*x5 + m8*x6; 196549b5e25fSSatish Balay x[5] -= m3*x4 + m6*x5 + m9*x6; 196649b5e25fSSatish Balay 196749b5e25fSSatish Balay x[6] -= m1*x7 + m4*x8 + m7*x9; 196849b5e25fSSatish Balay x[7] -= m2*x7 + m5*x8 + m8*x9; 196949b5e25fSSatish Balay x[8] -= m3*x7 + m6*x8 + m9*x9; 197049b5e25fSSatish Balay pv += 9; 197149b5e25fSSatish Balay } 197249b5e25fSSatish Balay PLogFlops(54*nz+36); 197349b5e25fSSatish Balay } 197449b5e25fSSatish Balay row = *ajtmp++; 197549b5e25fSSatish Balay } 197649b5e25fSSatish Balay /* finished row so stick it into b->a */ 197749b5e25fSSatish Balay pv = ba + 9*bi[i]; 197849b5e25fSSatish Balay pj = bj + bi[i]; 197949b5e25fSSatish Balay nz = bi[i+1] - bi[i]; 198049b5e25fSSatish Balay for (j=0; j<nz; j++) { 198149b5e25fSSatish Balay x = rtmp + 9*pj[j]; 198249b5e25fSSatish Balay pv[0] = x[0]; pv[1] = x[1]; pv[2] = x[2]; pv[3] = x[3]; 198349b5e25fSSatish Balay pv[4] = x[4]; pv[5] = x[5]; pv[6] = x[6]; pv[7] = x[7]; pv[8] = x[8]; 198449b5e25fSSatish Balay pv += 9; 198549b5e25fSSatish Balay } 198649b5e25fSSatish Balay /* invert diagonal block */ 198749b5e25fSSatish Balay w = ba + 9*diag_offset[i]; 198849b5e25fSSatish Balay ierr = Kernel_A_gets_inverse_A_3(w);CHKERRQ(ierr); 198949b5e25fSSatish Balay } 199049b5e25fSSatish Balay 199149b5e25fSSatish Balay ierr = PetscFree(rtmp);CHKERRQ(ierr); 199249b5e25fSSatish Balay ierr = ISRestoreIndices(isicol,&ic);CHKERRQ(ierr); 199349b5e25fSSatish Balay ierr = ISRestoreIndices(isrow,&r);CHKERRQ(ierr); 199449b5e25fSSatish Balay C->factor = FACTOR_LU; 199549b5e25fSSatish Balay C->assembled = PETSC_TRUE; 199649b5e25fSSatish Balay PLogFlops(1.3333*27*b->mbs); /* from inverting diagonal blocks */ 199749b5e25fSSatish Balay PetscFunctionReturn(0); 199849b5e25fSSatish Balay } 199949b5e25fSSatish Balay /* 200049b5e25fSSatish Balay Version for when blocks are 3 by 3 Using natural ordering 200149b5e25fSSatish Balay */ 200249b5e25fSSatish Balay #undef __FUNC__ 20036f9a564bSHong Zhang #define __FUNC__ "MatCholeskyFactorNumeric_SeqSBAIJ_3_NaturalOrdering" 20046f9a564bSHong Zhang int MatCholeskyFactorNumeric_SeqSBAIJ_3_NaturalOrdering(Mat A,Mat *B) 200549b5e25fSSatish Balay { 200649b5e25fSSatish Balay Mat C = *B; 200749b5e25fSSatish Balay Mat_SeqBAIJ *a = (Mat_SeqBAIJ*)A->data,*b = (Mat_SeqBAIJ *)C->data; 200849b5e25fSSatish Balay int ierr,i,j,n = a->mbs,*bi = b->i,*bj = b->j; 200949b5e25fSSatish Balay int *ajtmpold,*ajtmp,nz,row; 201049b5e25fSSatish Balay int *diag_offset = b->diag,*ai=a->i,*aj=a->j,*pj; 201149b5e25fSSatish Balay MatScalar *pv,*v,*rtmp,*pc,*w,*x; 201249b5e25fSSatish Balay MatScalar p1,p2,p3,p4,m1,m2,m3,m4,m5,m6,m7,m8,m9,x1,x2,x3,x4; 201349b5e25fSSatish Balay MatScalar p5,p6,p7,p8,p9,x5,x6,x7,x8,x9; 201449b5e25fSSatish Balay MatScalar *ba = b->a,*aa = a->a; 201549b5e25fSSatish Balay 201649b5e25fSSatish Balay PetscFunctionBegin; 201749b5e25fSSatish Balay rtmp = (MatScalar*)PetscMalloc(9*(n+1)*sizeof(MatScalar));CHKPTRQ(rtmp); 201849b5e25fSSatish Balay 201949b5e25fSSatish Balay for (i=0; i<n; i++) { 202049b5e25fSSatish Balay nz = bi[i+1] - bi[i]; 202149b5e25fSSatish Balay ajtmp = bj + bi[i]; 202249b5e25fSSatish Balay for (j=0; j<nz; j++) { 202349b5e25fSSatish Balay x = rtmp+9*ajtmp[j]; 202449b5e25fSSatish Balay x[0] = x[1] = x[2] = x[3] = x[4] = x[5] = x[6] = x[7] = x[8] = 0.0; 202549b5e25fSSatish Balay } 202649b5e25fSSatish Balay /* load in initial (unfactored row) */ 202749b5e25fSSatish Balay nz = ai[i+1] - ai[i]; 202849b5e25fSSatish Balay ajtmpold = aj + ai[i]; 202949b5e25fSSatish Balay v = aa + 9*ai[i]; 203049b5e25fSSatish Balay for (j=0; j<nz; j++) { 203149b5e25fSSatish Balay x = rtmp+9*ajtmpold[j]; 203249b5e25fSSatish Balay x[0] = v[0]; x[1] = v[1]; x[2] = v[2]; x[3] = v[3]; 203349b5e25fSSatish Balay x[4] = v[4]; x[5] = v[5]; x[6] = v[6]; x[7] = v[7]; x[8] = v[8]; 203449b5e25fSSatish Balay v += 9; 203549b5e25fSSatish Balay } 203649b5e25fSSatish Balay row = *ajtmp++; 203749b5e25fSSatish Balay while (row < i) { 203849b5e25fSSatish Balay pc = rtmp + 9*row; 203949b5e25fSSatish Balay p1 = pc[0]; p2 = pc[1]; p3 = pc[2]; p4 = pc[3]; 204049b5e25fSSatish Balay p5 = pc[4]; p6 = pc[5]; p7 = pc[6]; p8 = pc[7]; p9 = pc[8]; 204149b5e25fSSatish Balay if (p1 != 0.0 || p2 != 0.0 || p3 != 0.0 || p4 != 0.0 || p5 != 0.0 || 204249b5e25fSSatish Balay p6 != 0.0 || p7 != 0.0 || p8 != 0.0 || p9 != 0.0) { 204349b5e25fSSatish Balay pv = ba + 9*diag_offset[row]; 204449b5e25fSSatish Balay pj = bj + diag_offset[row] + 1; 204549b5e25fSSatish Balay x1 = pv[0]; x2 = pv[1]; x3 = pv[2]; x4 = pv[3]; 204649b5e25fSSatish Balay x5 = pv[4]; x6 = pv[5]; x7 = pv[6]; x8 = pv[7]; x9 = pv[8]; 204749b5e25fSSatish Balay pc[0] = m1 = p1*x1 + p4*x2 + p7*x3; 204849b5e25fSSatish Balay pc[1] = m2 = p2*x1 + p5*x2 + p8*x3; 204949b5e25fSSatish Balay pc[2] = m3 = p3*x1 + p6*x2 + p9*x3; 205049b5e25fSSatish Balay 205149b5e25fSSatish Balay pc[3] = m4 = p1*x4 + p4*x5 + p7*x6; 205249b5e25fSSatish Balay pc[4] = m5 = p2*x4 + p5*x5 + p8*x6; 205349b5e25fSSatish Balay pc[5] = m6 = p3*x4 + p6*x5 + p9*x6; 205449b5e25fSSatish Balay 205549b5e25fSSatish Balay pc[6] = m7 = p1*x7 + p4*x8 + p7*x9; 205649b5e25fSSatish Balay pc[7] = m8 = p2*x7 + p5*x8 + p8*x9; 205749b5e25fSSatish Balay pc[8] = m9 = p3*x7 + p6*x8 + p9*x9; 205849b5e25fSSatish Balay 205949b5e25fSSatish Balay nz = bi[row+1] - diag_offset[row] - 1; 206049b5e25fSSatish Balay pv += 9; 206149b5e25fSSatish Balay for (j=0; j<nz; j++) { 206249b5e25fSSatish Balay x1 = pv[0]; x2 = pv[1]; x3 = pv[2]; x4 = pv[3]; 206349b5e25fSSatish Balay x5 = pv[4]; x6 = pv[5]; x7 = pv[6]; x8 = pv[7]; x9 = pv[8]; 206449b5e25fSSatish Balay x = rtmp + 9*pj[j]; 206549b5e25fSSatish Balay x[0] -= m1*x1 + m4*x2 + m7*x3; 206649b5e25fSSatish Balay x[1] -= m2*x1 + m5*x2 + m8*x3; 206749b5e25fSSatish Balay x[2] -= m3*x1 + m6*x2 + m9*x3; 206849b5e25fSSatish Balay 206949b5e25fSSatish Balay x[3] -= m1*x4 + m4*x5 + m7*x6; 207049b5e25fSSatish Balay x[4] -= m2*x4 + m5*x5 + m8*x6; 207149b5e25fSSatish Balay x[5] -= m3*x4 + m6*x5 + m9*x6; 207249b5e25fSSatish Balay 207349b5e25fSSatish Balay x[6] -= m1*x7 + m4*x8 + m7*x9; 207449b5e25fSSatish Balay x[7] -= m2*x7 + m5*x8 + m8*x9; 207549b5e25fSSatish Balay x[8] -= m3*x7 + m6*x8 + m9*x9; 207649b5e25fSSatish Balay pv += 9; 207749b5e25fSSatish Balay } 207849b5e25fSSatish Balay PLogFlops(54*nz+36); 207949b5e25fSSatish Balay } 208049b5e25fSSatish Balay row = *ajtmp++; 208149b5e25fSSatish Balay } 208249b5e25fSSatish Balay /* finished row so stick it into b->a */ 208349b5e25fSSatish Balay pv = ba + 9*bi[i]; 208449b5e25fSSatish Balay pj = bj + bi[i]; 208549b5e25fSSatish Balay nz = bi[i+1] - bi[i]; 208649b5e25fSSatish Balay for (j=0; j<nz; j++) { 208749b5e25fSSatish Balay x = rtmp+9*pj[j]; 208849b5e25fSSatish Balay pv[0] = x[0]; pv[1] = x[1]; pv[2] = x[2]; pv[3] = x[3]; 208949b5e25fSSatish Balay pv[4] = x[4]; pv[5] = x[5]; pv[6] = x[6]; pv[7] = x[7]; pv[8] = x[8]; 209049b5e25fSSatish Balay pv += 9; 209149b5e25fSSatish Balay } 209249b5e25fSSatish Balay /* invert diagonal block */ 209349b5e25fSSatish Balay w = ba + 9*diag_offset[i]; 209449b5e25fSSatish Balay ierr = Kernel_A_gets_inverse_A_3(w);CHKERRQ(ierr); 209549b5e25fSSatish Balay } 209649b5e25fSSatish Balay 209749b5e25fSSatish Balay ierr = PetscFree(rtmp);CHKERRQ(ierr); 209849b5e25fSSatish Balay C->factor = FACTOR_LU; 209949b5e25fSSatish Balay C->assembled = PETSC_TRUE; 210049b5e25fSSatish Balay PLogFlops(1.3333*27*b->mbs); /* from inverting diagonal blocks */ 210149b5e25fSSatish Balay PetscFunctionReturn(0); 210249b5e25fSSatish Balay } 210349b5e25fSSatish Balay 210449b5e25fSSatish Balay /* 210591602c66SHong Zhang Numeric (-UT)*D*(-U) factorization for SBAIJ format. Modified from SNF of YSMP. 210691602c66SHong Zhang Version for blocks are 2 by 2. 210749b5e25fSSatish Balay */ 210849b5e25fSSatish Balay #undef __FUNC__ 21096f9a564bSHong Zhang #define __FUNC__ "MatCholeskyFactorNumeric_SeqSBAIJ_2" 21106f9a564bSHong Zhang int MatCholeskyFactorNumeric_SeqSBAIJ_2(Mat A,Mat *B) 211149b5e25fSSatish Balay { 211249b5e25fSSatish Balay Mat C = *B; 211391602c66SHong Zhang Mat_SeqSBAIJ *a = (Mat_SeqSBAIJ*)A->data,*b = (Mat_SeqSBAIJ *)C->data; 211491602c66SHong Zhang IS ip = b->row; 2115351d0355SHong Zhang int *rip,ierr,i,j,mbs = a->mbs,*bi = b->i,*bj = b->j; 211691602c66SHong Zhang int *ai,*aj,*r,bs2 = a->bs2; 211791602c66SHong Zhang MatScalar *rtmp; 2118351d0355SHong Zhang MatScalar *ba = b->a,*aa,*ak,*ap; 21193845f261SHong Zhang MatScalar *dk,*uik; 212091602c66SHong Zhang int k,jmin,jmax,*jl,*il,vj,nexti,juj,ili; 21213845f261SHong Zhang int k1; 21223845f261SHong Zhang MatScalar *up,*diag,*rtmp_ptr; 212349b5e25fSSatish Balay 212449b5e25fSSatish Balay PetscFunctionBegin; 212591602c66SHong Zhang printf("called factornum_2, bs2: %d\n",bs2); 212691602c66SHong Zhang ierr = ISGetIndices(ip,&rip);CHKERRQ(ierr); 212749b5e25fSSatish Balay 212891602c66SHong Zhang if (!a->permute){ 212991602c66SHong Zhang ai = a->i; aj = a->j; aa = a->a; 213091602c66SHong Zhang } else { 213191602c66SHong Zhang ai = a->inew; aj = a->jnew; 213291602c66SHong Zhang aa = (MatScalar*)PetscMalloc(bs2*ai[mbs]*sizeof(MatScalar));CHKPTRQ(aa); 213391602c66SHong Zhang ierr = PetscMemcpy(aa,a->a,bs2*ai[mbs]*sizeof(MatScalar));CHKERRQ(ierr); 213491602c66SHong Zhang r = (int*)PetscMalloc(ai[mbs]*sizeof(int));CHKPTRQ(r); 213591602c66SHong Zhang ierr= PetscMemcpy(r,a->a2anew,(ai[mbs])*sizeof(int));CHKERRQ(ierr); 213691602c66SHong Zhang 213791602c66SHong Zhang ak = (MatScalar*)PetscMalloc(bs2*sizeof(MatScalar));CHKPTRQ(ak); 213891602c66SHong Zhang 21393845f261SHong Zhang for (i=0; i<mbs; i++){ 21403845f261SHong Zhang jmin = ai[i]; jmax = ai[i+1]; 214191602c66SHong Zhang for (j=jmin; j<jmax; j++){ 214291602c66SHong Zhang while (r[j] != j){ 214391602c66SHong Zhang k = r[j]; r[j] = r[k]; r[k] = k; 21443845f261SHong Zhang for (k1=0; k1<bs2; k1++){ 21453845f261SHong Zhang ak[k1] = aa[k*bs2+k1]; 21463845f261SHong Zhang aa[k*bs2+k1] = aa[j*bs2+k1]; 21473845f261SHong Zhang aa[j*bs2+k1] = ak[k1]; 21483845f261SHong Zhang } 214949b5e25fSSatish Balay } 215049b5e25fSSatish Balay } 215149b5e25fSSatish Balay } 2152351d0355SHong Zhang 21533845f261SHong Zhang /* transform columnoriented blocks that lie in the lower triangle to roworiented blocks. 21543845f261SHong Zhang should be combined into the above loops */ 2155351d0355SHong Zhang for (i=0; i<mbs; i++){ 2156351d0355SHong Zhang jmin = ai[i]; jmax = ai[i+1]; 2157351d0355SHong Zhang for (j=jmin; j<jmax; j++){ 2158351d0355SHong Zhang if (i > aj[j]){ 2159351d0355SHong Zhang ap = aa + j*bs2; /* ptr to the beginning of the block */ 2160351d0355SHong Zhang ak[1] = ap[1]; /* swap ap[1] and ap[2] */ 2161351d0355SHong Zhang ap[1] = ap[2]; 2162351d0355SHong Zhang ap[2] = ak[1]; 2163351d0355SHong Zhang } 2164351d0355SHong Zhang } 2165351d0355SHong Zhang } 216691602c66SHong Zhang ierr = PetscFree(r);CHKERRA(ierr); 216791602c66SHong Zhang ierr = PetscFree(ak);CHKERRA(ierr); 216849b5e25fSSatish Balay } 216949b5e25fSSatish Balay 217091602c66SHong Zhang /* initialization */ 217191602c66SHong Zhang /* il and jl record the first nonzero element in each row of the accessing 217291602c66SHong Zhang window U(0:k, k:mbs-1). 217391602c66SHong Zhang jl: list of rows to be added to uneliminated rows 217491602c66SHong Zhang i>= k: jl(i) is the first row to be added to row i 217591602c66SHong Zhang i< k: jl(i) is the row following row i in some list of rows 217691602c66SHong Zhang jl(i) = mbs indicates the end of a list 217791602c66SHong Zhang il(i): points to the first nonzero element in columns k,...,mbs-1 of 217891602c66SHong Zhang row i of U */ 21793845f261SHong Zhang rtmp = (MatScalar*)PetscMalloc(bs2*mbs*sizeof(MatScalar));CHKPTRQ(rtmp); 21803845f261SHong Zhang ierr = PetscMemzero(rtmp,bs2*sizeof(MatScalar));CHKERRQ(ierr); 218191602c66SHong Zhang il = (int*)PetscMalloc(mbs*sizeof(int));CHKPTRQ(il); 218291602c66SHong Zhang jl = (int*)PetscMalloc(mbs*sizeof(int));CHKPTRQ(jl); 21833845f261SHong Zhang dk = (MatScalar*)PetscMalloc(bs2*sizeof(MatScalar));CHKPTRQ(dk); 21843845f261SHong Zhang uik= (MatScalar*)PetscMalloc(bs2*sizeof(MatScalar));CHKPTRQ(uik); 21853845f261SHong Zhang 218691602c66SHong Zhang for (i=0; i<mbs; i++) { 21873845f261SHong Zhang jl[i] = mbs; il[0] = 0; 218891602c66SHong Zhang } 21893845f261SHong Zhang 219091602c66SHong Zhang /* for each row k */ 219191602c66SHong Zhang for (k = 0; k<mbs; k++){ 219291602c66SHong Zhang 219391602c66SHong Zhang /*initialize k-th row with elements nonzero in row perm(k) of A */ 219491602c66SHong Zhang jmin = ai[rip[k]]; jmax = ai[rip[k]+1]; 219591602c66SHong Zhang if (jmin < jmax) { 219691602c66SHong Zhang for (j = jmin; j < jmax; j++){ 21973845f261SHong Zhang vj = rip[aj[j]]; /* block col. index */ 21983845f261SHong Zhang if (k <= vj) { 21993845f261SHong Zhang ap = aa + j*bs2; /* ptr to the beginning of the block */ 22003845f261SHong Zhang for (i=0; i<bs2; i++){ 22013845f261SHong Zhang rtmp[vj*bs2 + i] = *ap; ap++; 22023845f261SHong Zhang } 22033845f261SHong Zhang } 220491602c66SHong Zhang } 220591602c66SHong Zhang } 220691602c66SHong Zhang 220791602c66SHong Zhang /* modify k-th row by adding in those rows i with U(i,k) != 0 */ 22083845f261SHong Zhang ierr = PetscMemcpy(dk,rtmp+k*bs2,bs2*sizeof(MatScalar));CHKERRQ(ierr); /* dk = rtmp[k]; */ 220991602c66SHong Zhang i = jl[k]; /* first row to be added to k_th row */ 221091602c66SHong Zhang /* printf(" k=%d, pivot row = %d\n",k,i); */ 221191602c66SHong Zhang 221291602c66SHong Zhang while (i < mbs){ 221391602c66SHong Zhang nexti = jl[i]; /* next row to be added to k_th row */ 221491602c66SHong Zhang 22153845f261SHong Zhang /* compute multiplier */ 221691602c66SHong Zhang ili = il[i]; /* index of first nonzero element in U(i,k:bms-1) */ 22173845f261SHong Zhang 22183845f261SHong Zhang /* uik = -inv(Di)*U_bar(i,k): - ba[ili]*ba[i] */ 22193845f261SHong Zhang diag = ba + i*bs2; 22203845f261SHong Zhang up = ba + ili*bs2; 22213845f261SHong Zhang uik[0] = -(diag[0]*up[0] + diag[2]*up[1]); 22223845f261SHong Zhang uik[1] = -(diag[1]*up[0] + diag[3]*up[1]); 22233845f261SHong Zhang uik[2] = -(diag[0]*up[2] + diag[2]*up[3]); 22243845f261SHong Zhang uik[3] = -(diag[1]*up[2] + diag[3]*up[3]); 22253845f261SHong Zhang 22263845f261SHong Zhang /* update D(k) += -U(i,k)^T * U_bar(i,k): dk += uik*ba[ili] */ 22273845f261SHong Zhang dk[0] += uik[0]*up[0] + uik[1]*up[1]; 22283845f261SHong Zhang dk[1] += uik[2]*up[0] + uik[3]*up[1]; 22293845f261SHong Zhang dk[2] += uik[0]*up[2] + uik[1]*up[3]; 22303845f261SHong Zhang dk[3] += uik[2]*up[2] + uik[3]*up[3]; 22313845f261SHong Zhang 22323845f261SHong Zhang /* update -U(i,k): ba[ili] = uik */ 22333845f261SHong Zhang ierr = PetscMemcpy(ba+ili*bs2,uik,bs2*sizeof(MatScalar));CHKERRQ(ierr); 223491602c66SHong Zhang 223591602c66SHong Zhang /* add multiple of row i to k-th row ... */ 223691602c66SHong Zhang jmin = ili + 1; jmax = bi[i+1]; 223791602c66SHong Zhang if (jmin < jmax){ 22383845f261SHong Zhang for (j=jmin; j<jmax; j++) { 22393845f261SHong Zhang /* rtmp += -U(i,k)^T * U_bar(i,j): rtmp[bj[j]] += uik*ba[j]; */ 22403845f261SHong Zhang rtmp_ptr = rtmp + bj[j]*bs2; 22413845f261SHong Zhang up = ba + j*bs2; 22423845f261SHong Zhang rtmp_ptr[0] += uik[0]*up[0] + uik[1]*up[1]; 22433845f261SHong Zhang rtmp_ptr[1] += uik[2]*up[0] + uik[3]*up[1]; 22443845f261SHong Zhang rtmp_ptr[2] += uik[0]*up[2] + uik[1]*up[3]; 22453845f261SHong Zhang rtmp_ptr[3] += uik[2]*up[2] + uik[3]*up[3]; 22463845f261SHong Zhang } 22473845f261SHong Zhang 224891602c66SHong Zhang /* ... add i to row list for next nonzero entry */ 224991602c66SHong Zhang il[i] = jmin; /* update il(i) in column k+1, ... mbs-1 */ 225091602c66SHong Zhang j = bj[jmin]; 225191602c66SHong Zhang jl[i] = jl[j]; jl[j] = i; /* update jl */ 225291602c66SHong Zhang } 225391602c66SHong Zhang i = nexti; /* printf(" pivot row i=%d\n",i); */ 225491602c66SHong Zhang } 22553845f261SHong Zhang #ifdef CONT 225691602c66SHong Zhang /* check for zero pivot and save diagoanl element */ 225791602c66SHong Zhang if (dk == 0.0){ 225891602c66SHong Zhang SETERRQ(PETSC_ERR_MAT_LU_ZRPVT,"Zero pivot"); 225991602c66SHong Zhang }else if (PetscRealPart(dk) < 0){ 226091602c66SHong Zhang ierr = PetscPrintf(PETSC_COMM_SELF,"Negative pivot: d[%d] = %g\n",k,dk); 226191602c66SHong Zhang } 22623845f261SHong Zhang #endif 226391602c66SHong Zhang /* save nonzero entries in k-th row of U ... */ 22643845f261SHong Zhang 22653845f261SHong Zhang /* invert diagonal block: ba[k] = 1.0/dk */ 22663845f261SHong Zhang diag = ba+k*bs2; 22673845f261SHong Zhang ierr = PetscMemcpy(diag,dk,bs2*sizeof(MatScalar));CHKERRQ(ierr); 22683845f261SHong Zhang ierr = Kernel_A_gets_inverse_A_2(diag);CHKERRQ(ierr); 22693845f261SHong Zhang 227091602c66SHong Zhang jmin = bi[k]; jmax = bi[k+1]; 227191602c66SHong Zhang if (jmin < jmax) { 227291602c66SHong Zhang for (j=jmin; j<jmax; j++){ 22733845f261SHong Zhang juj = bj[j]; 22743845f261SHong Zhang 22753845f261SHong Zhang /* ba[j] = rtmp[juj]; rtmp[juj] = 0.0; */ 22763845f261SHong Zhang up = ba + j*bs2; 22773845f261SHong Zhang rtmp_ptr = rtmp + juj*bs2; 22783845f261SHong Zhang for (k1=0; k1<bs2; k1++){ 22793845f261SHong Zhang *up = *rtmp_ptr; *rtmp_ptr = 0.0; 22803845f261SHong Zhang up++; rtmp_ptr++; 22813845f261SHong Zhang } 228291602c66SHong Zhang } 228391602c66SHong Zhang /* ... add k to row list for first nonzero entry in k-th row */ 228491602c66SHong Zhang il[k] = jmin; 228591602c66SHong Zhang i = bj[jmin]; 228691602c66SHong Zhang jl[k] = jl[i]; jl[i] = k; 228791602c66SHong Zhang } 228891602c66SHong Zhang } 22893845f261SHong Zhang 229049b5e25fSSatish Balay ierr = PetscFree(rtmp);CHKERRQ(ierr); 229191602c66SHong Zhang ierr = PetscFree(il);CHKERRQ(ierr); 229291602c66SHong Zhang ierr = PetscFree(jl);CHKERRQ(ierr); 22933845f261SHong Zhang ierr = PetscFree(dk);CHKERRQ(ierr); 22943845f261SHong Zhang ierr = PetscFree(uik);CHKERRQ(ierr); 229591602c66SHong Zhang if (a->permute){ 229691602c66SHong Zhang ierr = PetscFree(aa);CHKERRQ(ierr); 229791602c66SHong Zhang } 229891602c66SHong Zhang 229991602c66SHong Zhang ierr = ISRestoreIndices(ip,&rip);CHKERRQ(ierr); 230091602c66SHong Zhang C->factor = FACTOR_CHOLESKY; 230191602c66SHong Zhang /* C->factor = FACTOR_LU; */ 230249b5e25fSSatish Balay C->assembled = PETSC_TRUE; 230391602c66SHong Zhang PLogFlops(b->mbs); 230449b5e25fSSatish Balay PetscFunctionReturn(0); 230549b5e25fSSatish Balay } 230691602c66SHong Zhang 230749b5e25fSSatish Balay /* 230849b5e25fSSatish Balay Version for when blocks are 2 by 2 Using natural ordering 230949b5e25fSSatish Balay */ 231049b5e25fSSatish Balay #undef __FUNC__ 23116f9a564bSHong Zhang #define __FUNC__ "MatCholeskyFactorNumeric_SeqSBAIJ_2_NaturalOrdering" 23126f9a564bSHong Zhang int MatCholeskyFactorNumeric_SeqSBAIJ_2_NaturalOrdering(Mat A,Mat *B) 231349b5e25fSSatish Balay { 231449b5e25fSSatish Balay Mat C = *B; 231549b5e25fSSatish Balay Mat_SeqBAIJ *a = (Mat_SeqBAIJ*)A->data,*b = (Mat_SeqBAIJ *)C->data; 231649b5e25fSSatish Balay int ierr,i,j,n = a->mbs,*bi = b->i,*bj = b->j; 231749b5e25fSSatish Balay int *ajtmpold,*ajtmp,nz,row; 231849b5e25fSSatish Balay int *diag_offset = b->diag,*ai=a->i,*aj=a->j,*pj; 231949b5e25fSSatish Balay MatScalar *pv,*v,*rtmp,*pc,*w,*x; 232049b5e25fSSatish Balay MatScalar p1,p2,p3,p4,m1,m2,m3,m4,x1,x2,x3,x4; 232149b5e25fSSatish Balay MatScalar *ba = b->a,*aa = a->a; 232249b5e25fSSatish Balay 232349b5e25fSSatish Balay PetscFunctionBegin; 232449b5e25fSSatish Balay rtmp = (MatScalar*)PetscMalloc(4*(n+1)*sizeof(MatScalar));CHKPTRQ(rtmp); 232549b5e25fSSatish Balay 232649b5e25fSSatish Balay for (i=0; i<n; i++) { 232749b5e25fSSatish Balay nz = bi[i+1] - bi[i]; 232849b5e25fSSatish Balay ajtmp = bj + bi[i]; 232949b5e25fSSatish Balay for (j=0; j<nz; j++) { 233049b5e25fSSatish Balay x = rtmp+4*ajtmp[j]; 233149b5e25fSSatish Balay x[0] = x[1] = x[2] = x[3] = 0.0; 233249b5e25fSSatish Balay } 233349b5e25fSSatish Balay /* load in initial (unfactored row) */ 233449b5e25fSSatish Balay nz = ai[i+1] - ai[i]; 233549b5e25fSSatish Balay ajtmpold = aj + ai[i]; 233649b5e25fSSatish Balay v = aa + 4*ai[i]; 233749b5e25fSSatish Balay for (j=0; j<nz; j++) { 233849b5e25fSSatish Balay x = rtmp+4*ajtmpold[j]; 233949b5e25fSSatish Balay x[0] = v[0]; x[1] = v[1]; x[2] = v[2]; x[3] = v[3]; 234049b5e25fSSatish Balay v += 4; 234149b5e25fSSatish Balay } 234249b5e25fSSatish Balay row = *ajtmp++; 234349b5e25fSSatish Balay while (row < i) { 234449b5e25fSSatish Balay pc = rtmp + 4*row; 234549b5e25fSSatish Balay p1 = pc[0]; p2 = pc[1]; p3 = pc[2]; p4 = pc[3]; 234649b5e25fSSatish Balay if (p1 != 0.0 || p2 != 0.0 || p3 != 0.0 || p4 != 0.0) { 234749b5e25fSSatish Balay pv = ba + 4*diag_offset[row]; 234849b5e25fSSatish Balay pj = bj + diag_offset[row] + 1; 234949b5e25fSSatish Balay x1 = pv[0]; x2 = pv[1]; x3 = pv[2]; x4 = pv[3]; 235049b5e25fSSatish Balay pc[0] = m1 = p1*x1 + p3*x2; 235149b5e25fSSatish Balay pc[1] = m2 = p2*x1 + p4*x2; 235249b5e25fSSatish Balay pc[2] = m3 = p1*x3 + p3*x4; 235349b5e25fSSatish Balay pc[3] = m4 = p2*x3 + p4*x4; 235449b5e25fSSatish Balay nz = bi[row+1] - diag_offset[row] - 1; 235549b5e25fSSatish Balay pv += 4; 235649b5e25fSSatish Balay for (j=0; j<nz; j++) { 235749b5e25fSSatish Balay x1 = pv[0]; x2 = pv[1]; x3 = pv[2]; x4 = pv[3]; 235849b5e25fSSatish Balay x = rtmp + 4*pj[j]; 235949b5e25fSSatish Balay x[0] -= m1*x1 + m3*x2; 236049b5e25fSSatish Balay x[1] -= m2*x1 + m4*x2; 236149b5e25fSSatish Balay x[2] -= m1*x3 + m3*x4; 236249b5e25fSSatish Balay x[3] -= m2*x3 + m4*x4; 236349b5e25fSSatish Balay pv += 4; 236449b5e25fSSatish Balay } 236549b5e25fSSatish Balay PLogFlops(16*nz+12); 236649b5e25fSSatish Balay } 236749b5e25fSSatish Balay row = *ajtmp++; 236849b5e25fSSatish Balay } 236949b5e25fSSatish Balay /* finished row so stick it into b->a */ 237049b5e25fSSatish Balay pv = ba + 4*bi[i]; 237149b5e25fSSatish Balay pj = bj + bi[i]; 237249b5e25fSSatish Balay nz = bi[i+1] - bi[i]; 237349b5e25fSSatish Balay for (j=0; j<nz; j++) { 237449b5e25fSSatish Balay x = rtmp+4*pj[j]; 237549b5e25fSSatish Balay pv[0] = x[0]; pv[1] = x[1]; pv[2] = x[2]; pv[3] = x[3]; 237649b5e25fSSatish Balay pv += 4; 237749b5e25fSSatish Balay } 237849b5e25fSSatish Balay /* invert diagonal block */ 237949b5e25fSSatish Balay w = ba + 4*diag_offset[i]; 238049b5e25fSSatish Balay ierr = Kernel_A_gets_inverse_A_2(w);CHKERRQ(ierr); 238149b5e25fSSatish Balay /*Kernel_A_gets_inverse_A(bs,w,v_pivots,v_work);*/ 238249b5e25fSSatish Balay } 238349b5e25fSSatish Balay 238449b5e25fSSatish Balay ierr = PetscFree(rtmp);CHKERRQ(ierr); 238549b5e25fSSatish Balay C->factor = FACTOR_LU; 238649b5e25fSSatish Balay C->assembled = PETSC_TRUE; 238749b5e25fSSatish Balay PLogFlops(1.3333*8*b->mbs); /* from inverting diagonal blocks */ 238849b5e25fSSatish Balay PetscFunctionReturn(0); 238949b5e25fSSatish Balay } 239049b5e25fSSatish Balay 239149b5e25fSSatish Balay /* 2392658e7b3eSHong Zhang Numeric (-UT)*D*(-U) factorization for SBAIJ format. Modified from SNF of YSMP. 239391602c66SHong Zhang Version for blocks are 1 by 1. 239449b5e25fSSatish Balay */ 239549b5e25fSSatish Balay #undef __FUNC__ 23966f9a564bSHong Zhang #define __FUNC__ "MatCholeskyFactorNumeric_SeqSBAIJ_1" 23976f9a564bSHong Zhang int MatCholeskyFactorNumeric_SeqSBAIJ_1(Mat A,Mat *B) 239849b5e25fSSatish Balay { 239949b5e25fSSatish Balay Mat C = *B; 240049b5e25fSSatish Balay Mat_SeqSBAIJ *a = (Mat_SeqSBAIJ*)A->data,*b = (Mat_SeqSBAIJ *)C->data; 240149b5e25fSSatish Balay IS ip = b->row; 2402351d0355SHong Zhang int *rip,ierr,i,j,mbs = a->mbs,*bi = b->i,*bj = b->j; 2403cb718733SHong Zhang int *ai,*aj,*r; 2404066653e3SSatish Balay MatScalar *rtmp; 24052d007305SHong Zhang MatScalar *ba = b->a,*aa,ak; 240649b5e25fSSatish Balay MatScalar dk,uikdi; 240749b5e25fSSatish Balay int k,jmin,jmax,*jl,*il,vj,nexti,juj,ili; 240849b5e25fSSatish Balay 240949b5e25fSSatish Balay PetscFunctionBegin; 241049b5e25fSSatish Balay ierr = ISGetIndices(ip,&rip);CHKERRQ(ierr); 241149b5e25fSSatish Balay 2412cb718733SHong Zhang if (!a->permute){ 24132d007305SHong Zhang ai = a->i; aj = a->j; aa = a->a; 24142d007305SHong Zhang } else { 24152d007305SHong Zhang ai = a->inew; aj = a->jnew; 24162d007305SHong Zhang aa = (MatScalar*)PetscMalloc(ai[mbs]*sizeof(MatScalar));CHKPTRQ(aa); 2417cb718733SHong Zhang ierr = PetscMemcpy(aa,a->a,ai[mbs]*sizeof(MatScalar));CHKERRQ(ierr); 24182d007305SHong Zhang r = (int*)PetscMalloc(ai[mbs]*sizeof(int));CHKPTRQ(r); 24192d007305SHong Zhang ierr= PetscMemcpy(r,a->a2anew,(ai[mbs])*sizeof(int));CHKERRQ(ierr); 24202d007305SHong Zhang 24212d007305SHong Zhang jmin = ai[0]; jmax = ai[mbs]; 24222d007305SHong Zhang for (j=jmin; j<jmax; j++){ 2423cb718733SHong Zhang while (r[j] != j){ 24242d007305SHong Zhang k = r[j]; r[j] = r[k]; r[k] = k; 24252d007305SHong Zhang ak = aa[k]; aa[k] = aa[j]; aa[j] = ak; 24262d007305SHong Zhang } 24272d007305SHong Zhang } 24282d007305SHong Zhang ierr = PetscFree(r);CHKERRA(ierr); 24292d007305SHong Zhang } 24302d007305SHong Zhang 243191602c66SHong Zhang /* initialization */ 243249b5e25fSSatish Balay /* il and jl record the first nonzero element in each row of the accessing 243349b5e25fSSatish Balay window U(0:k, k:mbs-1). 243449b5e25fSSatish Balay jl: list of rows to be added to uneliminated rows 243549b5e25fSSatish Balay i>= k: jl(i) is the first row to be added to row i 243649b5e25fSSatish Balay i< k: jl(i) is the row following row i in some list of rows 243749b5e25fSSatish Balay jl(i) = mbs indicates the end of a list 243849b5e25fSSatish Balay il(i): points to the first nonzero element in columns k,...,mbs-1 of 243949b5e25fSSatish Balay row i of U */ 244049b5e25fSSatish Balay rtmp = (MatScalar*)PetscMalloc(mbs*sizeof(MatScalar));CHKPTRQ(rtmp); 244149b5e25fSSatish Balay il = (int*)PetscMalloc(mbs*sizeof(int));CHKPTRQ(il); 244249b5e25fSSatish Balay jl = (int*)PetscMalloc(mbs*sizeof(int));CHKPTRQ(jl); 244349b5e25fSSatish Balay for (i=0; i<mbs; i++) { 244449b5e25fSSatish Balay rtmp[i] = 0.0; jl[i] = mbs; il[0] = 0; 244549b5e25fSSatish Balay } 244649b5e25fSSatish Balay 244791602c66SHong Zhang /* for each row k */ 244849b5e25fSSatish Balay for (k = 0; k<mbs; k++){ 244949b5e25fSSatish Balay 245091602c66SHong Zhang /*initialize k-th row with elements nonzero in row perm(k) of A */ 245149b5e25fSSatish Balay jmin = ai[rip[k]]; jmax = ai[rip[k]+1]; 245249b5e25fSSatish Balay if (jmin < jmax) { 245349b5e25fSSatish Balay for (j = jmin; j < jmax; j++){ 2454351d0355SHong Zhang vj = rip[aj[j]]; 245549b5e25fSSatish Balay if (k <= vj) rtmp[vj] = aa[j]; 245649b5e25fSSatish Balay } 245749b5e25fSSatish Balay } 245849b5e25fSSatish Balay 245991602c66SHong Zhang /* modify k-th row by adding in those rows i with U(i,k) != 0 */ 246049b5e25fSSatish Balay dk = rtmp[k]; 246149b5e25fSSatish Balay i = jl[k]; /* first row to be added to k_th row */ 246249b5e25fSSatish Balay /* printf(" k=%d, pivot row = %d\n",k,i); */ 246349b5e25fSSatish Balay 246449b5e25fSSatish Balay while (i < mbs){ 246549b5e25fSSatish Balay nexti = jl[i]; /* next row to be added to k_th row */ 246649b5e25fSSatish Balay 246791602c66SHong Zhang /* compute multiplier, update D(k) and U(i,k) */ 246849b5e25fSSatish Balay ili = il[i]; /* index of first nonzero element in U(i,k:bms-1) */ 246949b5e25fSSatish Balay uikdi = - ba[ili]*ba[i]; 247049b5e25fSSatish Balay dk += uikdi*ba[ili]; 2471658e7b3eSHong Zhang ba[ili] = uikdi; /* -U(i,k) */ 247249b5e25fSSatish Balay 247391602c66SHong Zhang /* add multiple of row i to k-th row ... */ 247449b5e25fSSatish Balay jmin = ili + 1; jmax = bi[i+1]; 247549b5e25fSSatish Balay if (jmin < jmax){ 247649b5e25fSSatish Balay for (j=jmin; j<jmax; j++) rtmp[bj[j]] += uikdi*ba[j]; 247791602c66SHong Zhang /* ... add i to row list for next nonzero entry */ 247849b5e25fSSatish Balay il[i] = jmin; /* update il(i) in column k+1, ... mbs-1 */ 247949b5e25fSSatish Balay j = bj[jmin]; 248049b5e25fSSatish Balay jl[i] = jl[j]; jl[j] = i; /* update jl */ 248149b5e25fSSatish Balay } 24828be8c0c7SHong Zhang i = nexti; /* printf(" pivot row i=%d\n",i); */ 248349b5e25fSSatish Balay } 248449b5e25fSSatish Balay 248591602c66SHong Zhang /* check for zero pivot and save diagoanl element */ 248649b5e25fSSatish Balay if (dk == 0.0){ 248729bbc08cSBarry Smith SETERRQ(PETSC_ERR_MAT_LU_ZRPVT,"Zero pivot"); 24888be8c0c7SHong Zhang }else if (PetscRealPart(dk) < 0){ 24898be8c0c7SHong Zhang ierr = PetscPrintf(PETSC_COMM_SELF,"Negative pivot: d[%d] = %g\n",k,dk); 249049b5e25fSSatish Balay } 249149b5e25fSSatish Balay 249291602c66SHong Zhang /* save nonzero entries in k-th row of U ... */ 2493f3dd7b2dSKris Buschelman ba[k] = 1.0/dk; 249449b5e25fSSatish Balay jmin = bi[k]; jmax = bi[k+1]; 249549b5e25fSSatish Balay if (jmin < jmax) { 249649b5e25fSSatish Balay for (j=jmin; j<jmax; j++){ 249749b5e25fSSatish Balay juj = bj[j]; ba[j] = rtmp[juj]; rtmp[juj] = 0.0; 249849b5e25fSSatish Balay } 249991602c66SHong Zhang /* ... add k to row list for first nonzero entry in k-th row */ 250049b5e25fSSatish Balay il[k] = jmin; 250149b5e25fSSatish Balay i = bj[jmin]; 250249b5e25fSSatish Balay jl[k] = jl[i]; jl[i] = k; 250349b5e25fSSatish Balay } 250449b5e25fSSatish Balay } 250549b5e25fSSatish Balay 250649b5e25fSSatish Balay ierr = PetscFree(rtmp);CHKERRQ(ierr); 250749b5e25fSSatish Balay ierr = PetscFree(il);CHKERRQ(ierr); 250849b5e25fSSatish Balay ierr = PetscFree(jl);CHKERRQ(ierr); 2509cb718733SHong Zhang if (a->permute){ 2510cb718733SHong Zhang ierr = PetscFree(aa);CHKERRQ(ierr); 2511cb718733SHong Zhang } 251249b5e25fSSatish Balay 251349b5e25fSSatish Balay ierr = ISRestoreIndices(ip,&rip);CHKERRQ(ierr); 25148be8c0c7SHong Zhang C->factor = FACTOR_CHOLESKY; 25158be8c0c7SHong Zhang /* C->factor = FACTOR_LU; */ 251649b5e25fSSatish Balay C->assembled = PETSC_TRUE; 251749b5e25fSSatish Balay PLogFlops(b->mbs); 251849b5e25fSSatish Balay PetscFunctionReturn(0); 251949b5e25fSSatish Balay } 252049b5e25fSSatish Balay 252149b5e25fSSatish Balay #undef __FUNC__ 25226f9a564bSHong Zhang #define __FUNC__ "MatCholeskyFactor_SeqSBAIJ" 2523b8b23757SHong Zhang int MatCholeskyFactor_SeqSBAIJ(Mat A,IS perm,PetscReal f) 252449b5e25fSSatish Balay { 2525*4445ddedSHong Zhang int ierr; 252649b5e25fSSatish Balay Mat C; 252749b5e25fSSatish Balay 252849b5e25fSSatish Balay PetscFunctionBegin; 2529b8b23757SHong Zhang ierr = MatCholeskyFactorSymbolic(A,perm,f,&C);CHKERRQ(ierr); 2530a4ada70bSHong Zhang ierr = MatCholeskyFactorNumeric(A,&C);CHKERRQ(ierr); 2531*4445ddedSHong Zhang ierr = MatHeaderCopy(A,C);CHKERRQ(ierr); 253249b5e25fSSatish Balay PetscFunctionReturn(0); 253349b5e25fSSatish Balay } 253449b5e25fSSatish Balay 253549b5e25fSSatish Balay 2536