/************************************************************************* * Let the game begin **************************************************************************/ main(int argc, char *argv[]) { int i, j, ne, nn, etype, numflag=0; idxtype *elmnts, *xadj, *adjncy; timer IOTmr, DUALTmr; char fileout[256], etypestr[4][5] = {"TRI", "TET", "HEX", "QUAD"}; if (argc != 2) { printf("Usage: %s <meshfile>\n",argv[0]); exit(0); } cleartimer(IOTmr); cleartimer(DUALTmr); starttimer(IOTmr); elmnts = ReadMesh(argv[1], &ne, &nn, &etype); stoptimer(IOTmr); printf("**********************************************************************\n"); printf("%s", METISTITLE); printf("Mesh Information ----------------------------------------------------\n"); printf(" Name: %s, #Elements: %d, #Nodes: %d, Etype: %s\n\n", argv[1], ne, nn, etypestr[etype-1]); printf("Forming Dual Graph... -----------------------------------------------\n"); xadj = idxmalloc(ne+1, "main: xadj"); adjncy = idxmalloc(10*ne, "main: adjncy"); starttimer(DUALTmr); METIS_MeshToDual(&ne, &nn, elmnts, &etype, &numflag, xadj, adjncy); stoptimer(DUALTmr); printf(" Dual Information: #Vertices: %d, #Edges: %d\n", ne, xadj[ne]/2); sprintf(fileout, "%s.dgraph", argv[1]); starttimer(IOTmr); WriteGraph(fileout, ne, xadj, adjncy); stoptimer(IOTmr); printf("\nTiming Information --------------------------------------------------\n"); printf(" I/O: \t\t %7.3f\n", gettimer(IOTmr)); printf(" Dual Creation:\t\t %7.3f\n", gettimer(DUALTmr)); printf("**********************************************************************\n"); GKfree(&elmnts, &xadj, &adjncy, LTERM); }
/*********************************************************************************** * This function is the testing routine for the adaptive multilevel partitioning code. * It computes a partition from scratch, it then moves the graph and changes some * of the vertex weights and then call the adaptive code. ************************************************************************************/ void TestParMGridGen(char *filename, int *options, int minsize, int maxsize, MPI_Comm comm) { int i, nparts, npes, mype; MGridGraphType graph; idxtype *part; double tmr; MPI_Comm_size(comm, &npes); MPI_Comm_rank(comm, &mype); MGridReadTestGraph(&graph, filename, comm); part = idxmalloc(graph.nvtxs, "TestParMGridGen: part"); /*====================================================================== / ParMETIS_AspectRatio /=======================================================================*/ if (mype==0) printf("------------------------ PARAMETERS --------------------------------------\n"); for (i=0; i<npes; i++) if (mype == i) printf("%s, Dim=%d [%2d %2d] CType=%d RType=%d Nvtxs=%d Nedges=%d\n", filename, options[OPTION_DIM], minsize, maxsize, options[OPTION_CTYPE], options[OPTION_RTYPE], graph.nvtxs, graph.nedges); cleartimer(tmr); MPI_Barrier(comm); starttimer(tmr); ParMGridGen(graph.vtxdist, graph.xadj, graph.vvol, graph.vsurf, graph.adjncy, graph.adjwgt, &nparts, minsize, maxsize, options, part, &comm); MPI_Barrier(comm); stoptimer(tmr); printf("Total Time = %lf\n", gettimer(tmr)); WriteParallelPartition(filename, part, graph.vtxdist, nparts, mype, npes); IMfree(&graph.vtxdist, &graph.xadj, &graph.vvol, &graph.vsurf, &graph.vwgt, &graph.adjncy, &graph.adjwgt, &part, LTERM); }
int main(int argc, char *argv[]) { int i, npart; idxtype *part; float ncut=0; GraphType graph; char filename[256],outputFile[256]; int wgtflag = 0, addSelfLoop=1, outputFileGiven=0, txtFormat=0 ; int randomInit = 0; idxtype minEdgeWeight = 0; Options opt; timer TOTALTmr, METISTmr, IOTmr; initOptions(&opt); if (argc < 2) { print_help(argv[0]); exit(0); } for (argv++; *argv != NULL; argv++){ if ((*argv)[0] == '-') { int temp; switch ((*argv)[1]) { case 'b': case 'B': opt.penalty_power=atof(*(++argv)); break; case 'i': case 'I': opt.gamma=atof(*(++argv)); break; case 'o': case 'O': strcpy(outputFile,*(++argv)); outputFileGiven=1; break; case 'D'://quality threshold. This is a post-processing step proposed in SR-MCL. If you dont want post-processing (this is what original MLR-MCL, R-MCL, MCL do, please set "-d 0" case 'd': opt.quality_threshold = atof(*(++argv)); break; case 'w': case 'W': opt.weighted_density = true; break; case 'c': case 'C': opt.coarsenTo= atoi(*(++argv)); break; default: printf("Invalid option %s\n", *argv); print_help(argv[0]); exit(0); } } else { strcpy(filename, *argv); } } if ( randomInit > 0 ) InitRandom(time(NULL)); else InitRandom(-1); cleartimer(TOTALTmr); cleartimer(METISTmr); cleartimer(IOTmr); starttimer(TOTALTmr); starttimer(IOTmr); ReadGraph(&graph, filename, &wgtflag, addSelfLoop, txtFormat); if ( opt.matchType == MATCH_UNSPECIFIED ) { // opt.matchType = (graph.nvtxs>50000) ? MATCH_POWERLAW_FC : // MATCH_SHEMN; opt.matchType = MATCH_SHEMN; } stoptimer(IOTmr); if (graph.nvtxs <= 0) { printf("Empty graph. Nothing to do.\n"); exit(0); } int noOfSingletons = 0; GraphType *noSingletonGraph ; idxtype* nodeMap = lookForSingletons(&graph, &noOfSingletons); if ( noOfSingletons > 0 ) { getSubgraph(&graph, nodeMap, graph.nvtxs-noOfSingletons, wgtflag, &noSingletonGraph); GKfree((void**)&(graph.xadj), (void**)&(graph.adjncy), LTERM); if ( wgtflag&1 > 0 ) GKfree( (void**)&(graph.adjwgt), LTERM); // free(graph.gdata); printf("Found %d singleton nodes in the", noOfSingletons); printf(" input graph. Removing them.\n"); } if ( !outputFileGiven ) { strcpy(outputFile, filename); sprintf(outputFile,"%s.c%d.i%1.1f.b%1.1f",outputFile,opt.coarsenTo,opt.gamma,opt.penalty_power); } printf("Input graph information ---------------------------------------------------\n"); printf(" Name: %s, #Vertices: %d, #Edges: %d\n", filename, graph.nvtxs, graph.nedges/2); printf("Output shall be placed in the file %s\n", outputFile); fflush(stdout); part = idxmalloc(graph.nvtxs, "main: part"); printf("------------------------------------------------\n"); printf("Clustering....\n"); fflush(stdout); starttimer(METISTmr); //YK: main algorithm starts here! if ( noOfSingletons > 0 ) { mlmcl(&(noSingletonGraph->nvtxs), noSingletonGraph->xadj, noSingletonGraph->adjncy, noSingletonGraph->vwgt,noSingletonGraph->adjwgt, &wgtflag, part, opt ); } else { mlmcl(&graph.nvtxs, graph.xadj, graph.adjncy,graph.vwgt, graph.adjwgt, &wgtflag, part, opt ); } stoptimer(METISTmr); printf("------------------------------------------------\n"); if ( noOfSingletons > 0 ) { npart=mapPartition(part,noSingletonGraph->nvtxs); ncut=ComputeNCut(noSingletonGraph, part,npart); // printf("In graph that does not include singletons,"); // printf("No. of Clusters: %d, N-Cut value: %.2f\n",npart,ncut); idxtype *clusterSizes = histogram(part, graph.nvtxs-noOfSingletons, npart); int maxSize = clusterSizes[idxamax(npart, clusterSizes)]; float avgClusterSize = (graph.nvtxs-noOfSingletons)*1.0/(npart); float balance = (maxSize*1.0) / ((graph.nvtxs-noOfSingletons)*1.0/npart); float stdDevn = stdDeviation(clusterSizes, npart); float avgNcut = ncut * 1.0/npart; float normStdDevn = stdDevn/avgClusterSize; // Warning: This computation only works if the singletons // have been placed in their own clusters. This works for // MLR-MCL, in other words, because it is guaranteed to // place singletons in their own clusters. printf("Output statistics for graph without singletons\n"); printf("Clusters: %d N-Cut: %.3f", npart, ncut); printf(" AvgN-Cut: %.3f Balance in cluster sizes: %.2f ",avgNcut, balance); printf("Std_Deviation in cluster sizes: %.2f ", stdDevn); printf("Coefficient_of_Variation: %.2f\n", normStdDevn); free( clusterSizes ); npart += noOfSingletons; // ncut += noOfSingletons; printf("Output statistics for original graph\n"); mapIndices(part, nodeMap, graph.nvtxs, npart-noOfSingletons); } else { npart=mapPartition(part,graph.nvtxs); ncut=ComputeNCut(&graph, part,npart); } idxtype* clusterSizes = histogram(part, graph.nvtxs, npart); int maxSize = clusterSizes[idxamax(npart, clusterSizes)]; float avgClusterSize = (graph.nvtxs)*1.0/(npart); float balance = (maxSize*1.0)/(graph.nvtxs*1.0/npart); float stdDevn = stdDeviation(clusterSizes, npart); float avgNcut = ncut * 1.0/npart; float normStdDevn = stdDevn/avgClusterSize; printf("Clusters: %d N-Cut: %.3f AvgN-Cut: %.3f", npart, ncut, avgNcut ); printf(" Balance in cluster sizes: %.2f Std.Deviation in cluster sizes: %.2f ", balance, stdDevn); printf("Coefficient_of_Variation: %.2f\n", normStdDevn); starttimer(IOTmr); my_WritePartition(outputFile, part, graph.nvtxs, opt.gamma); if ( noOfSingletons > 0 ) { free(nodeMap); nodeMap = NULL; } printf("\nOutput is written to file: %s\n", outputFile); stoptimer(IOTmr); stoptimer(TOTALTmr); printf("\nTiming Information --------------------------------------------------\n"); printf(" I/O: \t\t %7.3f\n", gettimer(IOTmr)); printf(" Partitioning: \t\t %7.3f (MLR-MCL time)\n", gettimer(METISTmr)); printf(" Total: \t\t %7.3f\n", gettimer(TOTALTmr)); printf("**********************************************************************\n"); GKfree((void**)&graph.xadj, (void**)&graph.adjncy, (void**)&graph.vwgt, (void**)&graph.adjwgt, (void**)&part, LTERM); }
void MLKKMRefine(CtrlType *ctrl, GraphType *orggraph, GraphType *graph, int nparts, int chain_length, float *tpwgts, float ubfactor) { int i, nlevels, mustfree=0, temp_cl; GraphType *ptr; IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->UncoarsenTmr)); /* Compute the parameters of the coarsest graph */ ComputeKWayPartitionParams(ctrl, graph, nparts); temp_cl = chain_length; /* Determine how many levels are there */ for (ptr=graph, nlevels=0; ptr!=orggraph; ptr=ptr->finer, nlevels++); //printf("Number of levels is %d\n", nlevels); for (i=0; ;i++) { timer tmr; float result; cleartimer(tmr); starttimer(tmr); //pingpong(ctrl, graph, nparts, chain_length, tpwgts, ubfactor); //chain_length /= 1.5; //printf("Level: %d\n", i+1); if (graph == orggraph){ //chain_length = chain_length>0 ? chain_length : 1; pingpong(ctrl, graph, nparts, chain_length, tpwgts, ubfactor, 1); break; } else{ //pingpong(ctrl, graph, nparts, 0, tpwgts, ubfactor, 0); pingpong(ctrl, graph, nparts, chain_length, tpwgts, ubfactor, 0); //chain_length /= 2; } //pingpong(ctrl, graph, nparts, chain_length, tpwgts, ubfactor); // /* for time and quality each level stoptimer(tmr); //printf("Level %d: %7.3f", i+1, tmr); if (cutType == NCUT){ result = ComputeNCut(graph, graph->where, nparts); //printf(" %7f", result); } else{ result = ComputeRAsso(graph, graph->where, nparts); //printf(" %7f", result); } //printf(" (%d)\n\n", graph->nvtxs); //ends here*/ if (graph == orggraph) break; /* if(i>1) chain_length /= 10; */ GKfree((void **) &graph->gdata, LTERM); /* Deallocate the graph related arrays */ graph = graph->finer; IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->ProjectTmr)); if (graph->vwgt == NULL) { graph->vwgt = idxsmalloc(graph->nvtxs, 1, "RefineKWay: graph->vwgt"); graph->adjwgt = idxsmalloc(graph->nedges, 1, "RefineKWay: graph->adjwgt"); mustfree = 1; } ProjectKWayPartition(ctrl, graph, nparts); IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->ProjectTmr)); } if (mustfree) GKfree((void **) &graph->vwgt, (void **) &graph->adjwgt, LTERM); IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->UncoarsenTmr)); }
/************************************************************************* * Let the game begin **************************************************************************/ main(int argc, char *argv[]) { int i, options[10]; idxtype *perm, *iperm; GraphType graph; char filename[256]; int numflag = 0, wgtflag; timer TOTALTmr, METISTmr, IOTmr, SMBTmr; if (argc != 2) { printf("Usage: %s <GraphFile>\n",argv[0]); exit(0); } strcpy(filename, argv[1]); cleartimer(TOTALTmr); cleartimer(METISTmr); cleartimer(IOTmr); cleartimer(SMBTmr); starttimer(TOTALTmr); starttimer(IOTmr); ReadGraph(&graph, filename, &wgtflag); if (graph.nvtxs <= 0) { printf("Empty graph. Nothing to do.\n"); exit(0); } if (graph.ncon != 1) { printf("Ordering can only be applied to graphs with one constraint.\n"); exit(0); } stoptimer(IOTmr); /* Ordering does not use weights! */ GKfree(&graph.vwgt, &graph.adjwgt, LTERM); printf("**********************************************************************\n"); printf("%s", METISTITLE); printf("Graph Information ---------------------------------------------------\n"); printf(" Name: %s, #Vertices: %d, #Edges: %d\n\n", filename, graph.nvtxs, graph.nedges/2); printf("Node-Based Ordering... ----------------------------------------------\n"); perm = idxmalloc(graph.nvtxs, "main: perm"); iperm = idxmalloc(graph.nvtxs, "main: iperm"); options[0] = 0; starttimer(METISTmr); METIS_NodeND(&graph.nvtxs, graph.xadj, graph.adjncy, &numflag, options, perm, iperm); stoptimer(METISTmr); starttimer(IOTmr); WritePermutation(filename, iperm, graph.nvtxs); stoptimer(IOTmr); starttimer(SMBTmr); ComputeFillIn(&graph, iperm); stoptimer(SMBTmr); stoptimer(TOTALTmr); printf("\nTiming Information --------------------------------------------------\n"); printf(" I/O: \t %7.3f\n", gettimer(IOTmr)); printf(" Ordering: \t %7.3f (ONMETIS time)\n", gettimer(METISTmr)); printf(" Symbolic Factorization: \t %7.3f\n", gettimer(SMBTmr)); printf(" Total: \t %7.3f\n", gettimer(TOTALTmr)); printf("**********************************************************************\n"); GKfree(&graph.xadj, &graph.adjncy, &perm, &iperm, LTERM); }
/************************************************************************* * Let the game begin **************************************************************************/ main(int argc, char *argv[]) { int i, j, ne, nn, etype, numflag=0, nparts, edgecut; idxtype *elmnts, *epart, *npart; timer IOTmr, DUALTmr; char etypestr[4][5] = {"TRI", "TET", "HEX", "QUAD"}; GraphType graph; if (argc != 3) { printf("Usage: %s <meshfile> <nparts>\n",argv[0]); exit(0); } nparts = atoi(argv[2]); if (nparts < 2) { printf("nparts must be greater than one.\n"); exit(0); } cleartimer(IOTmr); cleartimer(DUALTmr); starttimer(IOTmr); elmnts = ReadMesh(argv[1], &ne, &nn, &etype); stoptimer(IOTmr); epart = idxmalloc(ne, "main: epart"); npart = idxmalloc(nn, "main: npart"); printf("**********************************************************************\n"); printf("%s", METISTITLE); printf("Mesh Information ----------------------------------------------------\n"); printf(" Name: %s, #Elements: %d, #Nodes: %d, Etype: %s\n\n", argv[1], ne, nn, etypestr[etype-1]); printf("Partitioning Nodal Graph... -----------------------------------------\n"); starttimer(DUALTmr); METIS_PartMeshNodal(&ne, &nn, elmnts, &etype, &numflag, &nparts, &edgecut, epart, npart); stoptimer(DUALTmr); printf(" %d-way Edge-Cut: %7d, Balance: %5.2f\n", nparts, edgecut, ComputeElementBalance(ne, nparts, epart)); starttimer(IOTmr); WriteMeshPartition(argv[1], nparts, ne, epart, nn, npart); stoptimer(IOTmr); printf("\nTiming Information --------------------------------------------------\n"); printf(" I/O: \t\t %7.3f\n", gettimer(IOTmr)); printf(" Partitioning: \t\t %7.3f\n", gettimer(DUALTmr)); printf("**********************************************************************\n"); /* graph.nvtxs = ne; graph.xadj = idxmalloc(ne+1, "xadj"); graph.vwgt = idxsmalloc(ne, 1, "vwgt"); graph.adjncy = idxmalloc(10*ne, "adjncy"); graph.adjwgt = idxsmalloc(10*ne, 1, "adjncy"); METIS_MeshToDual(&ne, &nn, elmnts, &etype, &numflag, graph.xadj, graph.adjncy); ComputePartitionInfo(&graph, nparts, epart); GKfree(&graph.xadj, &graph.adjncy, &graph.vwgt, &graph.adjwgt, LTERM); */ GKfree(&elmnts, &epart, &npart, LTERM); }
/************************************************************************* * Let the game begin **************************************************************************/ main(int argc, char *argv[]) { int i, nparts, options[10]; idxtype *part; float rubvec[MAXNCON], lbvec[MAXNCON]; GraphType graph; char filename[256]; int numflag = 0, wgtflag = 0, edgecut; timer TOTALTmr, METISTmr, IOTmr; if (argc != 3) { printf("Usage: %s <GraphFile> <Nparts>\n",argv[0]); exit(0); } strcpy(filename, argv[1]); nparts = atoi(argv[2]); if (nparts < 2) { printf("The number of partitions should be greater than 1!\n"); exit(0); } cleartimer(TOTALTmr); cleartimer(METISTmr); cleartimer(IOTmr); starttimer(TOTALTmr); starttimer(IOTmr); ReadGraph(&graph, filename, &wgtflag); if (graph.nvtxs <= 0) { printf("Empty graph. Nothing to do.\n"); exit(0); } stoptimer(IOTmr); printf("**********************************************************************\n"); printf("%s", METISTITLE); printf("Graph Information ---------------------------------------------------\n"); printf(" Name: %s, #Vertices: %d, #Edges: %d, #Parts: %d\n", filename, graph.nvtxs, graph.nedges/2, nparts); if (graph.ncon > 1) printf(" Balancing Constraints: %d\n", graph.ncon); printf("\nK-way Partitioning... -----------------------------------------------\n"); part = idxmalloc(graph.nvtxs, "main: part"); options[0] = 0; starttimer(METISTmr); if (graph.ncon == 1) { METIS_PartGraphKway(&graph.nvtxs, graph.xadj, graph.adjncy, graph.vwgt, graph.adjwgt, &wgtflag, &numflag, &nparts, options, &edgecut, part); } else { for (i=0; i<graph.ncon; i++) rubvec[i] = HORIZONTAL_IMBALANCE; METIS_mCPartGraphKway(&graph.nvtxs, &graph.ncon, graph.xadj, graph.adjncy, graph.vwgt, graph.adjwgt, &wgtflag, &numflag, &nparts, rubvec, options, &edgecut, part); } stoptimer(METISTmr); ComputePartitionBalance(&graph, nparts, part, lbvec); printf(" %d-way Edge-Cut: %7d, Balance: ", nparts, edgecut); for (i=0; i<graph.ncon; i++) printf("%5.2f ", lbvec[i]); printf("\n"); starttimer(IOTmr); WritePartition(filename, part, graph.nvtxs, nparts); stoptimer(IOTmr); stoptimer(TOTALTmr); printf("\nTiming Information --------------------------------------------------\n"); printf(" I/O: \t\t %7.3f\n", gettimer(IOTmr)); printf(" Partitioning: \t\t %7.3f (KMETIS time)\n", gettimer(METISTmr)); printf(" Total: \t\t %7.3f\n", gettimer(TOTALTmr)); printf("**********************************************************************\n"); GKfree(&graph.xadj, &graph.adjncy, &graph.vwgt, &graph.adjwgt, &part, LTERM); }
/************************************************************************* * This function clears the timers **************************************************************************/ void InitTimers(CtrlType *ctrl) { cleartimer(ctrl->TotalTmr); cleartimer(ctrl->InitPartTmr); cleartimer(ctrl->MatchTmr); cleartimer(ctrl->ContractTmr); cleartimer(ctrl->CoarsenTmr); cleartimer(ctrl->UncoarsenTmr); cleartimer(ctrl->RefTmr); cleartimer(ctrl->ProjectTmr); cleartimer(ctrl->SplitTmr); cleartimer(ctrl->SepTmr); cleartimer(ctrl->AuxTmr1); cleartimer(ctrl->AuxTmr2); cleartimer(ctrl->AuxTmr3); cleartimer(ctrl->AuxTmr4); cleartimer(ctrl->AuxTmr5); cleartimer(ctrl->AuxTmr6); }
/************************************************************************* * This function initializes the various timers **************************************************************************/ void InitTimers(CtrlType *ctrl) { cleartimer(ctrl->TotalTmr); cleartimer(ctrl->InitPartTmr); cleartimer(ctrl->MatchTmr); cleartimer(ctrl->ContractTmr); cleartimer(ctrl->CoarsenTmr); cleartimer(ctrl->RefTmr); cleartimer(ctrl->SetupTmr); cleartimer(ctrl->ProjectTmr); cleartimer(ctrl->KWayInitTmr); cleartimer(ctrl->KWayTmr); cleartimer(ctrl->MoveTmr); cleartimer(ctrl->RemapTmr); cleartimer(ctrl->AuxTmr1); cleartimer(ctrl->AuxTmr2); cleartimer(ctrl->AuxTmr3); cleartimer(ctrl->AuxTmr4); cleartimer(ctrl->AuxTmr5); cleartimer(ctrl->AuxTmr6); }