1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322
|
/* Copyright 2007 ENSEIRB, INRIA & CNRS
**
** This file is part of the Scotch software package for static mapping,
** graph partitioning and sparse matrix ordering.
**
** This software is governed by the CeCILL-C license under French law
** and abiding by the rules of distribution of free software. You can
** use, modify and/or redistribute the software under the terms of the
** CeCILL-C license as circulated by CEA, CNRS and INRIA at the following
** URL: "http://www.cecill.info".
**
** As a counterpart to the access to the source code and rights to copy,
** modify and redistribute granted by the license, users are provided
** only with a limited warranty and the software's author, the holder of
** the economic rights, and the successive licensors have only limited
** liability.
**
** In this respect, the user's attention is drawn to the risks associated
** with loading, using, modifying and/or developing or reproducing the
** software by the user in light of its specific status of free software,
** that may mean that it is complicated to manipulate, and that also
** therefore means that it is reserved for developers and experienced
** professionals having in-depth computer knowledge. Users are therefore
** encouraged to load and test the software's suitability as regards
** their requirements in conditions enabling the security of their
** systems and/or data to be ensured and, more generally, to use and
** operate it in the same conditions as regards security.
**
** The fact that you are presently reading this means that you have had
** knowledge of the CeCILL-C license and that you accept its terms.
*/
/************************************************************/
/** **/
/** NAME : library_dgraph_stat.c **/
/** **/
/** AUTHOR : Francois PELLEGRINI **/
/** **/
/** FUNCTION : This module is the API for the source **/
/** graph handling routines of the **/
/** libSCOTCH library. **/
/** **/
/** DATES : # Version 5.0 : from : 23 jun 2007 **/
/** to 24 jun 2007 **/
/** **/
/************************************************************/
/*
** The defines and includes.
*/
#define LIBRARY
#include "module.h"
#include "common.h"
#include "dgraph.h"
#include "library_dgraph_stat.h"
#include "scotch.h"
/*
** The static variables.
*/
static int dgraphstatblentab[2] = { 7, 3 };
static MPI_Datatype dgraphstattypetab[2] = { GNUM_MPI, MPI_DOUBLE };
/************************************/
/* */
/* These routines are the C API for */
/* the graph handling routines. */
/* */
/************************************/
/* This routine is the reduction-loc operator which
** returns in inout[2] the rank of the process which
** holds the best partition.
** It returns:
** - void : in all cases.
*/
static
void
dgraphStatReduceAll (
const DgraphStatData * const in, /* First operand */
DgraphStatData * const inout, /* Second and output operand */
const int * const len, /* Number of instances; should be 1, not used */
const MPI_Datatype * const typedat) /* MPI datatype; not used */
{
if (inout->velomin > in->velomin)
inout->velomin = in->velomin;
if (inout->velomax < in->velomax)
inout->velomax = in->velomax;
if (inout->degrmin > in->degrmin)
inout->degrmin = in->degrmin;
if (inout->degrmax < in->degrmax)
inout->degrmax = in->degrmax;
if (inout->edlomin > in->edlomin)
inout->edlomin = in->edlomin;
if (inout->edlomax < in->edlomax)
inout->edlomax = in->edlomax;
inout->edlosum += in->edlosum;
inout->velodlt += in->velodlt;
inout->degrdlt += in->degrdlt;
inout->edlodlt += in->edlodlt;
}
/*+ This routine computes statistics
*** on the given distributed graph.
*** It returns:
*** - VOID : in all cases.
+*/
int
SCOTCH_dgraphStat (
const SCOTCH_Dgraph * const grafptr,
SCOTCH_Num * const velominptr,
SCOTCH_Num * const velomaxptr,
SCOTCH_Num * const velosumptr,
double * veloavgptr,
double * velodltptr,
SCOTCH_Num * const degrminptr,
SCOTCH_Num * const degrmaxptr,
double * degravgptr,
double * degrdltptr,
SCOTCH_Num * const edlominptr,
SCOTCH_Num * const edlomaxptr,
SCOTCH_Num * const edlosumptr,
double * edloavgptr,
double * edlodltptr)
{
const Dgraph * srcgrafptr;
DgraphStatData srcgstadat;
DgraphStatData srclstadat;
MPI_Datatype srctypedat;
MPI_Aint srcdisptab[2];
MPI_Op srcoperdat;
Gnum vertlocnum;
double veloglbavg;
double velolocdlt;
Gnum degrlocmin;
Gnum degrlocmax;
double degrglbavg;
double degrlocdlt;
Gnum edloglbsum;
double edloglbavg;
double edlolocdlt;
int o;
srcgrafptr = (Dgraph *) grafptr;
velolocdlt = 0.0L;
if (srcgrafptr->vertglbnbr > 0) {
if (srcgrafptr->veloloctax != NULL) { /* If graph has vertex loads */
const Gnum * restrict veloloctax;
Gnum velolocmin;
Gnum velolocmax;
veloloctax = srcgrafptr->veloloctax;
velolocmin = GNUMMAX;
velolocmax = 0;
veloglbavg = (double) srcgrafptr->veloglbsum / (double) srcgrafptr->vertglbnbr;
for (vertlocnum = srcgrafptr->baseval; vertlocnum < srcgrafptr->vertlocnnd; vertlocnum ++) {
Gnum velolocval;
velolocval = veloloctax[vertlocnum];
if (velolocval < velolocmin)
velolocmin = velolocval;
if (velolocval > velolocmax)
velolocmax = velolocval;
velolocdlt += fabs ((double) velolocval - veloglbavg);
}
srclstadat.velomin = velolocmin;
srclstadat.velomax = velolocmax;
}
else {
srclstadat.velomin =
srclstadat.velomax = 1;
veloglbavg = 1.0L;
}
}
else {
srclstadat.velomin =
srclstadat.velomax = 0;
veloglbavg = 0.0L;
}
srclstadat.velodlt = velolocdlt;
degrlocmax = 0;
degrlocdlt = 0.0L;
if (srcgrafptr->vertglbnbr > 0) {
degrlocmin = GNUMMAX;
degrglbavg = (double) srcgrafptr->edgeglbnbr / (double) srcgrafptr->vertglbnbr;
for (vertlocnum = srcgrafptr->baseval; vertlocnum < srcgrafptr->vertlocnnd; vertlocnum ++) {
Gnum degrlocval;
degrlocval = srcgrafptr->vendloctax[vertlocnum] - srcgrafptr->vertloctax[vertlocnum]; /* Get vertex degree */
if (degrlocval < degrlocmin)
degrlocmin = degrlocval;
if (degrlocval > degrlocmax)
degrlocmax = degrlocval;
degrlocdlt += fabs ((double) degrlocval - degrglbavg);
}
}
else {
degrlocmin = 0;
degrglbavg = 0.0L;
}
srclstadat.degrmin = degrlocmin;
srclstadat.degrmax = degrlocmax;
srclstadat.degrdlt = degrlocdlt;
edlolocdlt = 0.0L;
if (srcgrafptr->edgeglbnbr > 0) {
if (srcgrafptr->edloloctax != NULL) { /* If graph has edge loads */
Gnum edlolocmin;
Gnum edlolocmax;
Gnum edlolocsum;
edlolocmin = INT_MAX;
edlolocmax = 0;
edlolocsum = 0;
for (vertlocnum = srcgrafptr->baseval; vertlocnum < srcgrafptr->vertlocnnd; vertlocnum ++) {
Gnum edgelocnum;
for (edgelocnum = srcgrafptr->vertloctax[vertlocnum];
edgelocnum < srcgrafptr->vendloctax[vertlocnum]; edgelocnum ++) {
Gnum edlolocval;
edlolocval = srcgrafptr->edloloctax[edgelocnum];
edlolocsum += edlolocval;
if (edlolocval < edlolocmin) /* Account for edge load */
edlolocmin = edlolocval;
if (edlolocval > edlolocmax)
edlolocmax = edlolocval;
}
}
if (MPI_Allreduce (&edlolocsum, &edloglbsum, 1, GNUM_MPI, MPI_SUM, srcgrafptr->proccomm) != MPI_SUCCESS) {
errorPrint ("SCOTCH_dgraphStat: communication error (1)");
return (1);
}
edloglbavg = (double) edloglbsum / (double) (2 * srcgrafptr->edgeglbnbr);
for (vertlocnum = srcgrafptr->baseval; vertlocnum < srcgrafptr->vertlocnnd; vertlocnum ++) {
Gnum edgelocnum;
for (edgelocnum = srcgrafptr->vertloctax[vertlocnum];
edgelocnum < srcgrafptr->vendloctax[vertlocnum]; edgelocnum ++)
edlolocdlt += fabs ((double) srcgrafptr->edloloctax[edgelocnum] - edloglbavg);
}
}
else {
srclstadat.edlomin =
srclstadat.edlomax = 1;
edloglbsum = srcgrafptr->edgeglbnbr / 2;
edloglbavg = 1.0L;
}
}
else {
srclstadat.edlomin =
srclstadat.edlomax = 0;
edloglbsum = 0;
edloglbavg = 0.0L;
}
srclstadat.edlodlt = edlolocdlt;
MPI_Address (&srclstadat.velomin, &srcdisptab[0]);
MPI_Address (&srclstadat.velodlt, &srcdisptab[1]);
srcdisptab[1] -= srcdisptab[0];
srcdisptab[0] -= srcdisptab[0];
o = 1; /* Assume something will go wrong */
if ((MPI_Type_struct (2, dgraphstatblentab, srcdisptab, dgraphstattypetab, &srctypedat) == MPI_SUCCESS) &&
(MPI_Type_commit (&srctypedat) == MPI_SUCCESS)) {
if (MPI_Op_create ((MPI_User_function *) dgraphStatReduceAll, 0, &srcoperdat) == MPI_SUCCESS) {
if (MPI_Allreduce (&srclstadat, &srcgstadat, 1, srctypedat, srcoperdat, srcgrafptr->proccomm) == MPI_SUCCESS)
o = 0;
MPI_Op_free (&srcoperdat);
}
MPI_Type_free (&srctypedat);
}
if (o != 0) {
errorPrint ("SCOTCH_dgraphStat: communication error (2)");
return (1);
}
if (velominptr != NULL)
*velominptr = (SCOTCH_Num) srcgstadat.velomin;
if (velomaxptr != NULL)
*velomaxptr = (SCOTCH_Num) srcgstadat.velomax;
if (velosumptr != NULL)
*velosumptr = (SCOTCH_Num) srcgrafptr->veloglbsum;
if (veloavgptr != NULL)
*veloavgptr = (double) veloglbavg;
if (velodltptr != NULL)
*velodltptr = srcgstadat.velodlt / (double) srcgrafptr->vertglbnbr;
if (degrminptr != NULL)
*degrminptr = (SCOTCH_Num) srcgstadat.degrmin;
if (degrmaxptr != NULL)
*degrmaxptr = (SCOTCH_Num) srcgstadat.degrmax;
if (degravgptr != NULL)
*degravgptr = (double) degrglbavg;
if (degrdltptr != NULL)
*degrdltptr = srcgstadat.degrdlt / (double) srcgrafptr->vertglbnbr;
if (edlominptr != NULL)
*edlominptr = (SCOTCH_Num) srcgstadat.edlomin;
if (edlomaxptr != NULL)
*edlomaxptr = (SCOTCH_Num) srcgstadat.edlomax;
if (edlosumptr != NULL)
*edlosumptr = (SCOTCH_Num) edloglbsum;
if (edloavgptr != NULL)
*edloavgptr = (double) edloglbavg;
if (edlodltptr != NULL)
*edlodltptr = srcgstadat.edlodlt / (double) srcgrafptr->edgeglbnbr;
return (0);
}
|