/* * 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.8 1998/09/20 17:36:14 karypis Exp $ * */ #include /************************************************************************* * Let the game begin **************************************************************************/ main(int argc, char *argv[]) { int i, nparts, options[10]; idxtype *part; float lbvec[MAXNCON], rubvec[MAXNCON]; GraphType graph; int numflag = 0, wgtflag = 0, edgecut; if (argc != 2) { printf("Usage: %s \n",argv[0]); exit(0); } ReadGraph(&graph, argv[1], &wgtflag); printf("**********************************************************************\n"); printf("%s", METISTITLE); printf("Graph Information ---------------------------------------------------\n"); printf(" 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); printf("\n---------------------------------------------------------------------\n"); printf(" Testing completed.\n"); printf("**********************************************************************\n"); GKfree(&graph.xadj, &graph.adjncy, &graph.vwgt, &graph.adjwgt, LTERM); } /************************************************************************* * This function tests the regular graph partitioning routines **************************************************************************/ void Test_PartGraph(int nvtxs, idxtype *xadj, idxtype *adjncy) { int i, j, jj, k, tstnum, rcode; int 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)) rcode = 3; if (vfree) free(vwgt); if (efree) free(adjwgt); free(pwgts); MALLOC_CHECK(NULL); return rcode; } /************************************************************************* * This function verifies that the partitioning was computed correctly **************************************************************************/ int VerifyWPart(int nvtxs, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, idxtype *adjwgt, int nparts, float *tpwgts, int edgecut, idxtype *part) { int i, j, k, tvwgt, cut, vfree=0, efree=0, rcode=0; idxtype *pwgts; if (part[idxamax(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) free(vwgt); if (efree) free(adjwgt); free(pwgts); MALLOC_CHECK(NULL); return rcode; } /************************************************************************* * This function tests the regular graph partitioning routines **************************************************************************/ void Test_PartGraphV(int nvtxs, idxtype *xadj, idxtype *adjncy) { int i, j, jj, k, tstnum, rcode; int 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)) rcode = 3; if (vfree) free(vwgt); if (efree) free(vsize); free(pwgts); free(marker); MALLOC_CHECK(NULL); return rcode; } /************************************************************************* * This function verifies that the partitioning was computed correctly **************************************************************************/ int VerifyWPartV(int nvtxs, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, idxtype *vsize, int nparts, float *tpwgts, int totalv, idxtype *part) { int i, j, k, tvwgt, ttlv, vfree=0, efree=0, rcode=0; idxtype *pwgts, *marker; if (part[idxamax(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) free(vwgt); if (efree) free(vsize); free(pwgts); free(marker); MALLOC_CHECK(NULL); return rcode; } /************************************************************************* * This function tests the regular graph partitioning routines **************************************************************************/ void Test_PartGraphmC(int nvtxs, idxtype *xadj, idxtype *adjncy) { int i, j, jj, k, tstnum, rcode; int 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) free(adjwgt); free(pwgts); MALLOC_CHECK(NULL); return rcode; } /************************************************************************* * This function tests the regular graph partitioning routines **************************************************************************/ void Test_ND(int nvtxs, idxtype *xadj, idxtype *adjncy) { int i, j, jj, k, tstnum, rcode; int numflag, wgtflag, options[10]; idxtype *perm, *iperm, *vwgt; vwgt = idxmalloc(nvtxs, "vwgt"); for (i=0; i