/* * Copyright 1997, Regents of the University of Minnesota * * mtest.c * * This file is a comprehensive tester for all the graph partitioning/ordering * routines of METIS * * Started 9/18/98 * George * * $Id: mtest.c,v 1.1 2002/08/10 04:34:53 karypis Exp $ * */ #include #include #include "../libmetis/proto.h" #include "proto.h" /************************************************************************* * Let the game begin **************************************************************************/ int main(int argc, char *argv[]) { idxtype i, nparts, options[10]; idxtype *part; float lbvec[MAXNCON], rubvec[MAXNCON]; GraphType graph; idxtype numflag = 0, wgtflag = 0, edgecut; if (argc != 2) { mprintf("Usage: %s \n",argv[0]); exit(0); } ReadGraph(&graph, argv[1], &wgtflag); mprintf("**********************************************************************\n"); mprintf("%s", METISTITLE); mprintf("Graph Information ---------------------------------------------------\n"); mprintf(" Name: %s, #Vertices: %D, #Edges: %D\n", argv[1], graph.nvtxs, graph.nedges/2); Test_PartGraph(graph.nvtxs, graph.xadj, graph.adjncy); Test_PartGraphV(graph.nvtxs, graph.xadj, graph.adjncy); Test_PartGraphmC(graph.nvtxs, graph.xadj, graph.adjncy); Test_ND(graph.nvtxs, graph.xadj, graph.adjncy); mprintf("\n---------------------------------------------------------------------\n"); mprintf(" Testing completed.\n"); mprintf("**********************************************************************\n"); gk_free((void **)&graph.xadj, &graph.adjncy, &graph.vwgt, &graph.adjwgt, LTERM); } /************************************************************************* * This function tests the regular graph partitioning routines **************************************************************************/ void Test_PartGraph(idxtype nvtxs, idxtype *xadj, idxtype *adjncy) { idxtype i, j, jj, k, tstnum, rcode; idxtype nparts, numflag, wgtflag, edgecut, options[10]; idxtype *part, *vwgt, *adjwgt; float tpwgts[256]; vwgt = idxmalloc(nvtxs, "vwgt"); for (i=0; i 1.10*idxsum(nparts, pwgts, 1)) rcode = 3; if (vfree) gk_free((void **)&vwgt, LTERM); if (efree) gk_free((void **)&adjwgt, LTERM); gk_free((void **)&pwgts, LTERM); MALLOC_CHECK(NULL); return rcode; } /************************************************************************* * This function verifies that the partitioning was computed correctly **************************************************************************/ int VerifyWPart(idxtype nvtxs, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, idxtype *adjwgt, idxtype nparts, float *tpwgts, idxtype edgecut, idxtype *part) { idxtype i, j, k, tvwgt, cut, vfree=0, efree=0, rcode=0; idxtype *pwgts; if (part[idxargmax(nvtxs, part)] != nparts-1) return 1; /* the total number of partitions is different than nparts */ /* compute the cut and the pwgts */ if (vwgt == NULL) { vfree = 1; vwgt = idxsmalloc(nvtxs, 1, "vwgt"); } if (adjwgt == NULL) { efree = 1; adjwgt = idxsmalloc(xadj[nvtxs], 1, "adjwgt"); } pwgts = idxsmalloc(nparts, 0, "pwgts"); for (cut=0, i=0; i 1.10*tpwgts[i]*tvwgt) { rcode = 3; break; } } if (vfree) gk_free((void **)&vwgt, LTERM); if (efree) gk_free((void **)&adjwgt, LTERM); gk_free((void **)&pwgts, LTERM); MALLOC_CHECK(NULL); return rcode; } /************************************************************************* * This function tests the regular graph partitioning routines **************************************************************************/ void Test_PartGraphV(idxtype nvtxs, idxtype *xadj, idxtype *adjncy) { idxtype i, j, jj, k, tstnum, rcode; idxtype nparts, numflag, wgtflag, totalv, options[10]; idxtype *part, *vwgt, *vsize; float tpwgts[256]; vwgt = idxmalloc(nvtxs, "vwgt"); for (i=0; i 1.05*idxsum(nparts, pwgts, 1)) rcode = 3; if (vfree) gk_free((void **)&vwgt, LTERM); if (efree) gk_free((void **)&vsize, LTERM); gk_free((void **)&pwgts, &marker, LTERM); MALLOC_CHECK(NULL); return rcode; } /************************************************************************* * This function verifies that the partitioning was computed correctly **************************************************************************/ int VerifyWPartV(idxtype nvtxs, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, idxtype *vsize, idxtype nparts, float *tpwgts, idxtype totalv, idxtype *part) { idxtype i, j, k, tvwgt, ttlv, vfree=0, efree=0, rcode=0; idxtype *pwgts, *marker; if (part[idxargmax(nvtxs, part)] != nparts-1) return 1; /* the total number of partitions is different than nparts */ /* compute the cut and the pwgts */ if (vwgt == NULL) { vfree = 1; vwgt = idxsmalloc(nvtxs, 1, "vwgt"); } if (vsize == NULL) { efree = 1; vsize = idxsmalloc(nvtxs, 1, "vsize"); } pwgts = idxsmalloc(nparts, 0, "pwgts"); marker = idxsmalloc(nparts, -1, "htable"); for (ttlv=0, i=0; i 1.05*tpwgts[i]*tvwgt) { rcode = 3; break; } } if (vfree) gk_free((void **)&vwgt, LTERM); if (efree) gk_free((void **)&vsize, LTERM); gk_free((void **)&pwgts, &marker, LTERM); MALLOC_CHECK(NULL); return rcode; } /************************************************************************* * This function tests the regular graph partitioning routines **************************************************************************/ void Test_PartGraphmC(idxtype nvtxs, idxtype *xadj, idxtype *adjncy) { idxtype i, j, jj, k, tstnum, rcode; idxtype nparts, ncon, numflag, wgtflag, edgecut, options[10]; idxtype *part, *vwgt, *adjwgt; float ubvec[MAXNCON]; ncon = 3; vwgt = idxmalloc(nvtxs*ncon, "vwgt"); for (i=0; i ubvec[i]) rcode = 3; } if (efree) gk_free((void **)&adjwgt, LTERM); gk_free((void **)&pwgts, LTERM); MALLOC_CHECK(NULL); return rcode; } /************************************************************************* * This function tests the regular graph partitioning routines **************************************************************************/ void Test_ND(idxtype nvtxs, idxtype *xadj, idxtype *adjncy) { idxtype i, j, jj, k, tstnum, rcode; idxtype numflag, wgtflag, options[10]; idxtype *perm, *iperm, *vwgt; vwgt = idxmalloc(nvtxs, "vwgt"); for (i=0; i