/* * Copyright 1997, Regents of the University of Minnesota * * stat.c * * This file computes various statistics * * Started 7/25/97 * George * * $Id: stat.c,v 1.2 2002/08/10 06:29:34 karypis Exp $ * */ #include /************************************************************************* * This function computes cuts and balance information **************************************************************************/ void ComputePartitionInfo(GraphType *graph, idxtype nparts, idxtype *where) { idxtype i, j, k, nvtxs, ncon, mustfree=0; idxtype *xadj, *adjncy, *vwgt, *adjwgt, *kpwgts, *tmpptr; idxtype *padjncy, *padjwgt, *padjcut; nvtxs = graph->nvtxs; ncon = graph->ncon; xadj = graph->xadj; adjncy = graph->adjncy; vwgt = graph->vwgt; adjwgt = graph->adjwgt; if (vwgt == NULL) { vwgt = graph->vwgt = idxsmalloc(nvtxs, 1, "vwgt"); mustfree = 1; } if (adjwgt == NULL) { adjwgt = graph->adjwgt = idxsmalloc(xadj[nvtxs], 1, "adjwgt"); mustfree += 2; } mprintf("%D-way Cut: %5D, Vol: %5D, ", nparts, ComputeCut(graph, where), ComputeVolume(graph, where)); /* Compute balance information */ kpwgts = idxsmalloc(ncon*nparts, 0, "ComputePartitionInfo: kpwgts"); for (i=0; iwhere; graph->where = where; for (i=0; iwhere = tmpptr; if (mustfree == 1 || mustfree == 3) { gk_free((void **)&vwgt, LTERM); graph->vwgt = NULL; } if (mustfree == 2 || mustfree == 3) { gk_free((void **)&adjwgt, LTERM); graph->adjwgt = NULL; } gk_free((void **)&kpwgts, &padjncy, &padjwgt, &padjcut, LTERM); } /************************************************************************* * This function computes cuts and balance information **************************************************************************/ void ComputePartitionInfoBipartite(GraphType *graph, idxtype nparts, idxtype *where) { idxtype i, j, k, nvtxs, ncon, mustfree=0; idxtype *xadj, *adjncy, *vwgt, *vsize, *adjwgt, *kpwgts, *tmpptr; idxtype *padjncy, *padjwgt, *padjcut; nvtxs = graph->nvtxs; ncon = graph->ncon; xadj = graph->xadj; adjncy = graph->adjncy; vwgt = graph->vwgt; vsize = graph->vsize; adjwgt = graph->adjwgt; if (vwgt == NULL) { vwgt = graph->vwgt = idxsmalloc(nvtxs, 1, "vwgt"); mustfree = 1; } if (adjwgt == NULL) { adjwgt = graph->adjwgt = idxsmalloc(xadj[nvtxs], 1, "adjwgt"); mustfree += 2; } mprintf("%D-way Cut: %5D, Vol: %5D, ", nparts, ComputeCut(graph, where), ComputeVolume(graph, where)); /* Compute balance information */ kpwgts = idxsmalloc(ncon*nparts, 0, "ComputePartitionInfo: kpwgts"); for (i=0; ivwgt = NULL; } if (mustfree == 2 || mustfree == 3) { gk_free((void **)&adjwgt, LTERM); graph->adjwgt = NULL; } gk_free((void **)&kpwgts, &padjncy, &padjwgt, &padjcut, LTERM); } /************************************************************************* * This function computes the balance of the partitioning **************************************************************************/ void ComputePartitionBalance(GraphType *graph, idxtype nparts, idxtype *where, float *ubvec) { idxtype i, j, nvtxs, ncon; idxtype *kpwgts, *vwgt; float balance; nvtxs = graph->nvtxs; ncon = graph->ncon; vwgt = graph->vwgt; kpwgts = idxsmalloc(nparts, 0, "ComputePartitionInfo: kpwgts"); if (vwgt == NULL) { for (i=0; invtxs; i++) kpwgts[where[i]] += vwgt[i*ncon+j]; ubvec[j] = 1.0*nparts*kpwgts[idxargmax(nparts, kpwgts)]/(1.0*idxsum(nparts, kpwgts, 1)); } } gk_free((void **)&kpwgts, LTERM); } /************************************************************************* * This function computes the balance of the element partitioning **************************************************************************/ float ComputeElementBalance(idxtype ne, idxtype nparts, idxtype *where) { idxtype i; idxtype *kpwgts; float balance; kpwgts = idxsmalloc(nparts, 0, "ComputeElementBalance: kpwgts"); for (i=0; invtxs; ncon = graph->ncon; nvwgt = graph->nvwgt; kpwgts = gk_fmalloc(nparts, "ComputePartitionInfo: kpwgts"); for (j=0; jnvtxs; i++) kpwgts[where[i]] += nvwgt[i*ncon+j]; ubvec[j] = (float)nparts*kpwgts[gk_fargmax(nparts, kpwgts)]/gk_fsum(nparts, kpwgts, 1); } gk_free((void **)&kpwgts, LTERM); }