Path: blob/devel/elmergrid/src/metis-5.1.0/libmetis/debug.c
3206 views
/*1* Copyright 1997, Regents of the University of Minnesota2*3* debug.c4*5* This file contains code that performs self debuging6*7* Started 7/24/978* George9*10*/1112#include "metislib.h"13141516/*************************************************************************/17/*! This function computes the total edgecut18*/19/*************************************************************************/20idx_t ComputeCut(graph_t *graph, idx_t *where)21{22idx_t i, j, cut;2324if (graph->adjwgt == NULL) {25for (cut=0, i=0; i<graph->nvtxs; i++) {26for (j=graph->xadj[i]; j<graph->xadj[i+1]; j++)27if (where[i] != where[graph->adjncy[j]])28cut++;29}30}31else {32for (cut=0, i=0; i<graph->nvtxs; i++) {33for (j=graph->xadj[i]; j<graph->xadj[i+1]; j++)34if (where[i] != where[graph->adjncy[j]])35cut += graph->adjwgt[j];36}37}3839return cut/2;40}414243/*************************************************************************/44/*! This function computes the total volume45*/46/*************************************************************************/47idx_t ComputeVolume(graph_t *graph, idx_t *where)48{49idx_t i, j, k, me, nvtxs, nparts, totalv;50idx_t *xadj, *adjncy, *vsize, *marker;515253nvtxs = graph->nvtxs;54xadj = graph->xadj;55adjncy = graph->adjncy;56vsize = graph->vsize;5758nparts = where[iargmax(nvtxs, where)]+1;59marker = ismalloc(nparts, -1, "ComputeVolume: marker");6061totalv = 0;6263for (i=0; i<nvtxs; i++) {64marker[where[i]] = i;65for (j=xadj[i]; j<xadj[i+1]; j++) {66k = where[adjncy[j]];67if (marker[k] != i) {68marker[k] = i;69totalv += (vsize ? vsize[i] : 1);70}71}72}7374gk_free((void **)&marker, LTERM);7576return totalv;77}787980/*************************************************************************/81/*! This function computes the cut given the graph and a where vector82*/83/*************************************************************************/84idx_t ComputeMaxCut(graph_t *graph, idx_t nparts, idx_t *where)85{86idx_t i, j, maxcut;87idx_t *cuts;8889cuts = ismalloc(nparts, 0, "ComputeMaxCut: cuts");9091if (graph->adjwgt == NULL) {92for (i=0; i<graph->nvtxs; i++) {93for (j=graph->xadj[i]; j<graph->xadj[i+1]; j++)94if (where[i] != where[graph->adjncy[j]])95cuts[where[i]]++;96}97}98else {99for (i=0; i<graph->nvtxs; i++) {100for (j=graph->xadj[i]; j<graph->xadj[i+1]; j++)101if (where[i] != where[graph->adjncy[j]])102cuts[where[i]] += graph->adjwgt[j];103}104}105106maxcut = cuts[iargmax(nparts, cuts)];107108printf("%zu => %"PRIDX"\n", iargmax(nparts, cuts), maxcut);109110gk_free((void **)&cuts, LTERM);111112return maxcut;113}114115116/*************************************************************************/117/*! This function checks whether or not the boundary information is correct118*/119/*************************************************************************/120idx_t CheckBnd(graph_t *graph)121{122idx_t i, j, nvtxs, nbnd;123idx_t *xadj, *adjncy, *where, *bndptr, *bndind;124125nvtxs = graph->nvtxs;126xadj = graph->xadj;127adjncy = graph->adjncy;128where = graph->where;129bndptr = graph->bndptr;130bndind = graph->bndind;131132for (nbnd=0, i=0; i<nvtxs; i++) {133if (xadj[i+1]-xadj[i] == 0)134nbnd++; /* Islands are considered to be boundary vertices */135136for (j=xadj[i]; j<xadj[i+1]; j++) {137if (where[i] != where[adjncy[j]]) {138nbnd++;139ASSERT(bndptr[i] != -1);140ASSERT(bndind[bndptr[i]] == i);141break;142}143}144}145146ASSERTP(nbnd == graph->nbnd, ("%"PRIDX" %"PRIDX"\n", nbnd, graph->nbnd));147148return 1;149}150151152153/*************************************************************************/154/*! This function checks whether or not the boundary information is correct155*/156/*************************************************************************/157idx_t CheckBnd2(graph_t *graph)158{159idx_t i, j, nvtxs, nbnd, id, ed;160idx_t *xadj, *adjncy, *where, *bndptr, *bndind;161162nvtxs = graph->nvtxs;163xadj = graph->xadj;164adjncy = graph->adjncy;165where = graph->where;166bndptr = graph->bndptr;167bndind = graph->bndind;168169for (nbnd=0, i=0; i<nvtxs; i++) {170id = ed = 0;171for (j=xadj[i]; j<xadj[i+1]; j++) {172if (where[i] != where[adjncy[j]])173ed += graph->adjwgt[j];174else175id += graph->adjwgt[j];176}177if (ed - id >= 0 && xadj[i] < xadj[i+1]) {178nbnd++;179ASSERTP(bndptr[i] != -1, ("%"PRIDX" %"PRIDX" %"PRIDX"\n", i, id, ed));180ASSERT(bndind[bndptr[i]] == i);181}182}183184ASSERTP(nbnd == graph->nbnd, ("%"PRIDX" %"PRIDX"\n", nbnd, graph->nbnd));185186return 1;187}188189190/*************************************************************************/191/*! This function checks whether or not the boundary information is correct192*/193/*************************************************************************/194idx_t CheckNodeBnd(graph_t *graph, idx_t onbnd)195{196idx_t i, j, nvtxs, nbnd;197idx_t *xadj, *adjncy, *where, *bndptr, *bndind;198199nvtxs = graph->nvtxs;200xadj = graph->xadj;201adjncy = graph->adjncy;202where = graph->where;203bndptr = graph->bndptr;204bndind = graph->bndind;205206for (nbnd=0, i=0; i<nvtxs; i++) {207if (where[i] == 2)208nbnd++;209}210211ASSERTP(nbnd == onbnd, ("%"PRIDX" %"PRIDX"\n", nbnd, onbnd));212213for (i=0; i<nvtxs; i++) {214if (where[i] != 2) {215ASSERTP(bndptr[i] == -1, ("%"PRIDX" %"PRIDX"\n", i, bndptr[i]));216}217else {218ASSERTP(bndptr[i] != -1, ("%"PRIDX" %"PRIDX"\n", i, bndptr[i]));219}220}221222return 1;223}224225226227/*************************************************************************/228/*! This function checks whether or not the rinfo of a vertex is consistent229*/230/*************************************************************************/231idx_t CheckRInfo(ctrl_t *ctrl, ckrinfo_t *rinfo)232{233idx_t i, j;234cnbr_t *nbrs;235236nbrs = ctrl->cnbrpool + rinfo->inbr;237238for (i=0; i<rinfo->nnbrs; i++) {239for (j=i+1; j<rinfo->nnbrs; j++)240ASSERTP(nbrs[i].pid != nbrs[j].pid,241("%"PRIDX" %"PRIDX" %"PRIDX" %"PRIDX"\n",242i, j, nbrs[i].pid, nbrs[j].pid));243}244245return 1;246}247248249250/*************************************************************************/251/*! This function checks the correctness of the NodeFM data structures252*/253/*************************************************************************/254idx_t CheckNodePartitionParams(graph_t *graph)255{256idx_t i, j, k, l, nvtxs, me, other;257idx_t *xadj, *adjncy, *adjwgt, *vwgt, *where;258idx_t edegrees[2], pwgts[3];259260nvtxs = graph->nvtxs;261xadj = graph->xadj;262vwgt = graph->vwgt;263adjncy = graph->adjncy;264adjwgt = graph->adjwgt;265where = graph->where;266267/*------------------------------------------------------------268/ Compute now the separator external degrees269/------------------------------------------------------------*/270pwgts[0] = pwgts[1] = pwgts[2] = 0;271for (i=0; i<nvtxs; i++) {272me = where[i];273pwgts[me] += vwgt[i];274275if (me == 2) { /* If it is on the separator do some computations */276edegrees[0] = edegrees[1] = 0;277278for (j=xadj[i]; j<xadj[i+1]; j++) {279other = where[adjncy[j]];280if (other != 2)281edegrees[other] += vwgt[adjncy[j]];282}283if (edegrees[0] != graph->nrinfo[i].edegrees[0] ||284edegrees[1] != graph->nrinfo[i].edegrees[1]) {285printf("Something wrong with edegrees: %"PRIDX" %"PRIDX" %"PRIDX" %"PRIDX" %"PRIDX"\n",286i, edegrees[0], edegrees[1],287graph->nrinfo[i].edegrees[0], graph->nrinfo[i].edegrees[1]);288return 0;289}290}291}292293if (pwgts[0] != graph->pwgts[0] ||294pwgts[1] != graph->pwgts[1] ||295pwgts[2] != graph->pwgts[2]) {296printf("Something wrong with part-weights: %"PRIDX" %"PRIDX" %"PRIDX" %"PRIDX" %"PRIDX" %"PRIDX"\n", pwgts[0], pwgts[1], pwgts[2], graph->pwgts[0], graph->pwgts[1], graph->pwgts[2]);297return 0;298}299300return 1;301}302303304/*************************************************************************/305/*! This function checks if the separator is indeed a separator306*/307/*************************************************************************/308idx_t IsSeparable(graph_t *graph)309{310idx_t i, j, nvtxs, other;311idx_t *xadj, *adjncy, *where;312313nvtxs = graph->nvtxs;314xadj = graph->xadj;315adjncy = graph->adjncy;316where = graph->where;317318for (i=0; i<nvtxs; i++) {319if (where[i] == 2)320continue;321other = (where[i]+1)%2;322for (j=xadj[i]; j<xadj[i+1]; j++) {323ASSERTP(where[adjncy[j]] != other,324("%"PRIDX" %"PRIDX" %"PRIDX" %"PRIDX" %"PRIDX" %"PRIDX"\n",325i, where[i], adjncy[j], where[adjncy[j]], xadj[i+1]-xadj[i],326xadj[adjncy[j]+1]-xadj[adjncy[j]]));327}328}329330return 1;331}332333334/*************************************************************************/335/*! This function recomputes the vrinfo fields and checks them against336those in the graph->vrinfo structure */337/*************************************************************************/338void CheckKWayVolPartitionParams(ctrl_t *ctrl, graph_t *graph)339{340idx_t i, ii, j, k, kk, l, nvtxs, nbnd, mincut, minvol, me, other, pid;341idx_t *xadj, *vsize, *adjncy, *pwgts, *where, *bndind, *bndptr;342vkrinfo_t *rinfo, *myrinfo, *orinfo, tmprinfo;343vnbr_t *mynbrs, *onbrs, *tmpnbrs;344345WCOREPUSH;346347nvtxs = graph->nvtxs;348xadj = graph->xadj;349vsize = graph->vsize;350adjncy = graph->adjncy;351where = graph->where;352rinfo = graph->vkrinfo;353354tmpnbrs = (vnbr_t *)wspacemalloc(ctrl, ctrl->nparts*sizeof(vnbr_t));355356/*------------------------------------------------------------357/ Compute now the iv/ev degrees358/------------------------------------------------------------*/359for (i=0; i<nvtxs; i++) {360me = where[i];361362myrinfo = rinfo+i;363mynbrs = ctrl->vnbrpool + myrinfo->inbr;364365for (k=0; k<myrinfo->nnbrs; k++)366tmpnbrs[k] = mynbrs[k];367368tmprinfo.nnbrs = myrinfo->nnbrs;369tmprinfo.nid = myrinfo->nid;370tmprinfo.ned = myrinfo->ned;371372myrinfo = &tmprinfo;373mynbrs = tmpnbrs;374375for (k=0; k<myrinfo->nnbrs; k++)376mynbrs[k].gv = 0;377378for (j=xadj[i]; j<xadj[i+1]; j++) {379ii = adjncy[j];380other = where[ii];381orinfo = rinfo+ii;382onbrs = ctrl->vnbrpool + orinfo->inbr;383384if (me == other) {385/* Find which domains 'i' is connected and 'ii' is not and update their gain */386for (k=0; k<myrinfo->nnbrs; k++) {387pid = mynbrs[k].pid;388for (kk=0; kk<orinfo->nnbrs; kk++) {389if (onbrs[kk].pid == pid)390break;391}392if (kk == orinfo->nnbrs)393mynbrs[k].gv -= vsize[ii];394}395}396else {397/* Find the orinfo[me].ed and see if I'm the only connection */398for (k=0; k<orinfo->nnbrs; k++) {399if (onbrs[k].pid == me)400break;401}402403if (onbrs[k].ned == 1) { /* I'm the only connection of 'ii' in 'me' */404for (k=0; k<myrinfo->nnbrs; k++) {405if (mynbrs[k].pid == other) {406mynbrs[k].gv += vsize[ii];407break;408}409}410411/* Increase the gains for all the common domains between 'i' and 'ii' */412for (k=0; k<myrinfo->nnbrs; k++) {413if ((pid = mynbrs[k].pid) == other)414continue;415for (kk=0; kk<orinfo->nnbrs; kk++) {416if (onbrs[kk].pid == pid) {417mynbrs[k].gv += vsize[ii];418break;419}420}421}422423}424else {425/* Find which domains 'i' is connected and 'ii' is not and update their gain */426for (k=0; k<myrinfo->nnbrs; k++) {427if ((pid = mynbrs[k].pid) == other)428continue;429for (kk=0; kk<orinfo->nnbrs; kk++) {430if (onbrs[kk].pid == pid)431break;432}433if (kk == orinfo->nnbrs)434mynbrs[k].gv -= vsize[ii];435}436}437}438}439440myrinfo = rinfo+i;441mynbrs = ctrl->vnbrpool + myrinfo->inbr;442443for (k=0; k<myrinfo->nnbrs; k++) {444pid = mynbrs[k].pid;445for (kk=0; kk<tmprinfo.nnbrs; kk++) {446if (tmpnbrs[kk].pid == pid) {447if (tmpnbrs[kk].gv != mynbrs[k].gv)448printf("[%8"PRIDX" %8"PRIDX" %8"PRIDX" %+8"PRIDX" %+8"PRIDX"]\n",449i, where[i], pid, mynbrs[k].gv, tmpnbrs[kk].gv);450break;451}452}453}454455}456457WCOREPOP;458}459460461462463