void ComputeFillIn(graph_t *graph, idx_t *perm, idx_t *iperm, size_t *r_maxlnz, size_t *r_opc) { idx_t i, j, k, nvtxs, maxlnz, maxsub; idx_t *xadj, *adjncy; idx_t *xlnz, *xnzsub, *nzsub; size_t opc; /* printf("\nSymbolic factorization... --------------------------------------------\n"); */ nvtxs = graph->nvtxs; xadj = graph->xadj; adjncy = graph->adjncy; maxsub = 8*(nvtxs+xadj[nvtxs]); /* Relabel the vertices so that it starts from 1 */ for (i=0; i<xadj[nvtxs]; i++) adjncy[i]++; for (i=0; i<nvtxs+1; i++) xadj[i]++; for (i=0; i<nvtxs; i++) { iperm[i]++; perm[i]++; } /* Allocate the required memory */ xlnz = imalloc(nvtxs+2, "ComputeFillIn: xlnz"); xnzsub = imalloc(nvtxs+2, "ComputeFillIn: xnzsub"); nzsub = imalloc(maxsub+1, "ComputeFillIn: nzsub"); /* Call sparspak's routine. */ if (smbfct(nvtxs, xadj, adjncy, perm, iperm, xlnz, &maxlnz, xnzsub, nzsub, &maxsub)) { printf("Realocating nzsub...\n"); gk_free((void **)&nzsub, LTERM); maxsub *= 2; nzsub = imalloc(maxsub+1, "ComputeFillIn: nzsub"); if (smbfct(nvtxs, xadj, adjncy, perm, iperm, xlnz, &maxlnz, xnzsub, nzsub, &maxsub)) errexit("MAXSUB is too small!"); } for (i=0; i<nvtxs; i++) xlnz[i]--; for (opc=0, i=0; i<nvtxs; i++) opc += (xlnz[i+1]-xlnz[i])*(xlnz[i+1]-xlnz[i]) - (xlnz[i+1]-xlnz[i]); *r_maxlnz = maxlnz; *r_opc = opc; gk_free((void **)&xlnz, &xnzsub, &nzsub, LTERM); /* Relabel the vertices so that it starts from 0 */ for (i=0; i<nvtxs; i++) { iperm[i]--; perm[i]--; } for (i=0; i<nvtxs+1; i++) xadj[i]--; for (i=0; i<xadj[nvtxs]; i++) adjncy[i]--; }
/************************************************************************* * This function sets up data structures for fill-in computations **************************************************************************/ idxtype ComputeFillIn2(GraphType *graph, idxtype *iperm) { int i, j, k, nvtxs, maxlnz, maxsub; idxtype *xadj, *adjncy; idxtype *perm, *xlnz, *xnzsub, *nzsub; double opc; nvtxs = graph->nvtxs; xadj = graph->xadj; adjncy = graph->adjncy; maxsub = 4*xadj[nvtxs]; /* Relabel the vertices so that it starts from 1 */ k = xadj[nvtxs]; for (i=0; i<k; i++) adjncy[i]++; for (i=0; i<nvtxs+1; i++) xadj[i]++; /* Allocate the required memory */ perm = idxmalloc(nvtxs+1, "ComputeFillIn: perm"); xlnz = idxmalloc(nvtxs+1, "ComputeFillIn: xlnz"); xnzsub = idxmalloc(nvtxs+1, "ComputeFillIn: xnzsub"); nzsub = idxmalloc(maxsub, "ComputeFillIn: nzsub"); /* Construct perm from iperm and change the numbering of iperm */ for (i=0; i<nvtxs; i++) perm[iperm[i]] = i; for (i=0; i<nvtxs; i++) { iperm[i]++; perm[i]++; } /* * Call sparspak routine. */ if (smbfct(nvtxs, xadj, adjncy, perm, iperm, xlnz, &maxlnz, xnzsub, nzsub, &maxsub)) { free(nzsub); maxsub = 4*maxsub; nzsub = idxmalloc(maxsub, "ComputeFillIn: nzsub"); if (smbfct(nvtxs, xadj, adjncy, perm, iperm, xlnz, &maxlnz, xnzsub, nzsub, &maxsub)) errexit("MAXSUB is too small!"); } opc = 0; for (i=0; i<nvtxs; i++) xlnz[i]--; for (i=0; i<nvtxs; i++) opc += (xlnz[i+1]-xlnz[i])*(xlnz[i+1]-xlnz[i]) - (xlnz[i+1]-xlnz[i]); GKfree(&perm, &xlnz, &xnzsub, &nzsub, LTERM); /* Relabel the vertices so that it starts from 0 */ for (i=0; i<nvtxs; i++) iperm[i]--; for (i=0; i<nvtxs+1; i++) xadj[i]--; k = xadj[nvtxs]; for (i=0; i<k; i++) adjncy[i]--; return maxlnz; }