00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include <parmetislib.h>
00016
00017
00018
00019
00020
00021
00022
00023
00024 void ParMETIS_V3_RefineKway(idxtype *vtxdist, idxtype *xadj, idxtype *adjncy,
00025 idxtype *vwgt, idxtype *adjwgt, int *wgtflag, int *numflag, int *ncon,
00026 int *nparts, floattype *tpwgts, floattype *ubvec, int *options, int *edgecut,
00027 idxtype *part, MPI_Comm *comm)
00028 {
00029 int h, i;
00030 int npes, mype;
00031 CtrlType ctrl;
00032 WorkSpaceType wspace;
00033 GraphType *graph;
00034 int tewgt, tvsize, nmoved, maxin, maxout;
00035 floattype gtewgt, gtvsize, avg, maximb;
00036 int ps_relation, seed, dbglvl = 0;
00037 int iwgtflag, inumflag, incon, inparts, ioptions[10];
00038 floattype *itpwgts, iubvec[MAXNCON];
00039
00040 MPI_Comm_size(*comm, &npes);
00041 MPI_Comm_rank(*comm, &mype);
00042
00043
00044
00045
00046 if (options != NULL && options[0] == 1)
00047 dbglvl = options[PMV3_OPTION_DBGLVL];
00048 CheckInputs(REFINE_PARTITION, npes, dbglvl, wgtflag, &iwgtflag, numflag, &inumflag,
00049 ncon, &incon, nparts, &inparts, tpwgts, &itpwgts, ubvec, iubvec,
00050 NULL, NULL, options, ioptions, part, comm);
00051
00052
00053
00054
00055
00056
00057 if (inparts <= 1) {
00058 idxset(vtxdist[mype+1]-vtxdist[mype], 0, part);
00059 *edgecut = 0;
00060 return;
00061 }
00062
00063
00064
00065
00066 if (inumflag == 1)
00067 ChangeNumbering(vtxdist, xadj, adjncy, part, npes, mype, 1);
00068
00069
00070
00071
00072 if (ioptions[0] == 1) {
00073 dbglvl = ioptions[PMV3_OPTION_DBGLVL];
00074 seed = ioptions[PMV3_OPTION_SEED];
00075 ps_relation = (npes == inparts) ? ioptions[PMV3_OPTION_PSR] : DISCOUPLED;
00076 }
00077 else {
00078 dbglvl = GLOBAL_DBGLVL;
00079 seed = GLOBAL_SEED;
00080 ps_relation = (npes == inparts) ? COUPLED : DISCOUPLED;
00081 }
00082
00083 SetUpCtrl(&ctrl, inparts, dbglvl, *comm);
00084 ctrl.CoarsenTo = amin(vtxdist[npes]+1, 50*incon*amax(npes, inparts));
00085 ctrl.ipc_factor = 1000.0;
00086 ctrl.redist_factor = 1.0;
00087 ctrl.redist_base = 1.0;
00088 ctrl.seed = (seed == 0) ? mype : seed*mype;
00089 ctrl.sync = GlobalSEMax(&ctrl, seed);
00090 ctrl.partType = REFINE_PARTITION;
00091 ctrl.ps_relation = ps_relation;
00092 ctrl.tpwgts = itpwgts;
00093
00094 graph = Moc_SetUpGraph(&ctrl, incon, vtxdist, xadj, vwgt, adjncy, adjwgt, &iwgtflag);
00095 graph->vsize = idxsmalloc(graph->nvtxs, 1, "vsize");
00096
00097 graph->home = idxmalloc(graph->nvtxs, "home");
00098 if (ctrl.ps_relation == COUPLED)
00099 idxset(graph->nvtxs, mype, graph->home);
00100 else
00101 idxcopy(graph->nvtxs, part, graph->home);
00102
00103 tewgt = idxsum(graph->nedges, graph->adjwgt);
00104 tvsize = idxsum(graph->nvtxs, graph->vsize);
00105 gtewgt = (floattype) GlobalSESum(&ctrl, tewgt) + 1.0/graph->gnvtxs;
00106 gtvsize = (floattype) GlobalSESum(&ctrl, tvsize) + 1.0/graph->gnvtxs;
00107 ctrl.edge_size_ratio = gtewgt/gtvsize;
00108 scopy(incon, iubvec, ctrl.ubvec);
00109
00110 PreAllocateMemory(&ctrl, graph, &wspace);
00111
00112
00113
00114
00115 IFSET(ctrl.dbglvl, DBG_TIME, InitTimers(&ctrl));
00116 IFSET(ctrl.dbglvl, DBG_TIME, MPI_Barrier(ctrl.gcomm));
00117 IFSET(ctrl.dbglvl, DBG_TIME, starttimer(ctrl.TotalTmr));
00118
00119 Adaptive_Partition(&ctrl, graph, &wspace);
00120 ParallelReMapGraph(&ctrl, graph, &wspace);
00121
00122 IFSET(ctrl.dbglvl, DBG_TIME, MPI_Barrier(ctrl.gcomm));
00123 IFSET(ctrl.dbglvl, DBG_TIME, stoptimer(ctrl.TotalTmr));
00124
00125 idxcopy(graph->nvtxs, graph->where, part);
00126 if (edgecut != NULL)
00127 *edgecut = graph->mincut;
00128
00129
00130
00131
00132 IFSET(ctrl.dbglvl, DBG_TIME, PrintTimingInfo(&ctrl));
00133 IFSET(ctrl.dbglvl, DBG_TIME, MPI_Barrier(ctrl.gcomm));
00134
00135 if (ctrl.dbglvl&DBG_INFO) {
00136 Mc_ComputeMoveStatistics(&ctrl, graph, &nmoved, &maxin, &maxout);
00137 rprintf(&ctrl, "Final %3d-way Cut: %6d \tBalance: ", inparts, graph->mincut);
00138 avg = 0.0;
00139 for (h=0; h<incon; h++) {
00140 maximb = 0.0;
00141 for (i=0; i<inparts; i++)
00142 maximb = amax(maximb, graph->gnpwgts[i*incon+h]/itpwgts[i*incon+h]);
00143 avg += maximb;
00144 rprintf(&ctrl, "%.3f ", maximb);
00145 }
00146 rprintf(&ctrl, "\nNMoved: %d %d %d %d\n", nmoved, maxin, maxout, maxin+maxout);
00147 }
00148
00149
00150
00151
00152 GKfree((void **)&graph->lnpwgts, (void **)&graph->gnpwgts, (void **)&graph->nvwgt, (void **)(&graph->home), (void **)(&graph->vsize), LTERM);
00153
00154 GKfree((void **)&itpwgts, LTERM);
00155 FreeInitialGraphAndRemap(graph, iwgtflag);
00156 FreeWSpace(&wspace);
00157 FreeCtrl(&ctrl);
00158
00159 if (inumflag == 1)
00160 ChangeNumbering(vtxdist, xadj, adjncy, part, npes, mype, 0);
00161
00162 return;
00163 }
00164
00165