| 1 |
/* |
| 2 |
* Copyright(C) 1999-2020, 2023 National Technology & Engineering Solutions |
| 3 |
* of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with |
| 4 |
* NTESS, the U.S. Government retains certain rights in this software. |
| 5 |
* |
| 6 |
* See packages/seacas/LICENSE for details |
| 7 |
*/ |
| 8 |
|
| 9 |
#include "defs.h" // for TRUE |
| 10 |
#include "smalloc.h" // for smalloc, sfree |
| 11 |
#include "structs.h" // for vtx_data |
| 12 |
|
| 13 |
void mapper(struct vtx_data **graph, /* data structure with vertex weights */ |
| 14 |
double **xvecs, /* continuous indicator vectors */ |
| 15 |
int nvtxs, /* number of vtxs in graph */ |
| 16 |
int *active, /* space for nmyvals ints */ |
| 17 |
int *sets, /* returned processor assignment for my vtxs */ |
| 18 |
int ndims, /* number of dimensions being divided into */ |
| 19 |
int cube_or_mesh, /* 0 => hypercube, d => d-dimensional mesh */ |
| 20 |
int nsets, /* number of sets to divide into */ |
| 21 |
int mediantype, /* type of eigenvector partitioning to use */ |
| 22 |
double *goal, /* desired set sizes */ |
| 23 |
int vwgt_max /* largest vertex weight */ |
| 24 |
) |
| 25 |
{ |
| 26 |
double temp_goal[2]; /* combined set goals if using option 1. */ |
| 27 |
double wbelow; /* weight of vertices with negative values */ |
| 28 |
double wabove; /* weight of vertices with positive values */ |
| 29 |
int *temp_sets; /* sets vertices get assigned to */ |
| 30 |
int vweight; /* weight of a vertex */ |
| 31 |
int using_vwgts; /* are vertex weights being used? */ |
| 32 |
int bits; /* bits for assigning set numbers */ |
| 33 |
int i, j; /* loop counters */ |
| 34 |
|
| 35 |
/* NOTE: THIS EXPECTS XVECS, NOT YVECS! */ |
| 36 |
|
| 37 |
using_vwgts = (vwgt_max != 1); |
| 38 |
|
| 39 |
if (ndims == 1 && mediantype == 1) { |
| 40 |
mediantype = 3; /* simpler call than normal option 1. */ |
| 41 |
} |
| 42 |
|
| 43 |
if (mediantype == 0) { /* Divide at zero instead of median. */ |
| 44 |
bits = 1; |
| 45 |
temp_sets = smalloc((nvtxs + 1) * sizeof(int)); |
| 46 |
for (j = 1; j <= nvtxs; j++) { |
| 47 |
sets[j] = 0; |
| 48 |
} |
| 49 |
|
| 50 |
for (i = 1; i <= ndims; i++) { |
| 51 |
temp_goal[0] = temp_goal[1] = 0; |
| 52 |
for (j = 0; j < (1 << ndims); j++) { |
| 53 |
if (bits & j) { |
| 54 |
temp_goal[1] += goal[j]; |
| 55 |
} |
| 56 |
else { |
| 57 |
temp_goal[0] += goal[j]; |
| 58 |
} |
| 59 |
} |
| 60 |
bits <<= 1; |
| 61 |
|
| 62 |
wbelow = wabove = 0; |
| 63 |
vweight = 1; |
| 64 |
for (j = 1; j <= nvtxs; j++) { |
| 65 |
if (using_vwgts) { |
| 66 |
vweight = graph[j]->vwgt; |
| 67 |
} |
| 68 |
if (xvecs[i][j] < 0) { |
| 69 |
wbelow += vweight; |
| 70 |
} |
| 71 |
else if (xvecs[i][j] > 0) { |
| 72 |
wabove += vweight; |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
median_assign(graph, xvecs[i], nvtxs, temp_goal, using_vwgts, temp_sets, wbelow, wabove, 0.0); |
| 77 |
|
| 78 |
for (j = 1; j <= nvtxs; j++) { |
| 79 |
sets[j] = (sets[j] << 1) + temp_sets[j]; |
| 80 |
} |
| 81 |
} |
| 82 |
sfree(temp_sets); |
| 83 |
} |
| 84 |
|
| 85 |
else if (mediantype == 1) { /* Divide using min-cost assignment. */ |
| 86 |
if (ndims == 2) { |
| 87 |
map2d(graph, xvecs, nvtxs, sets, goal, vwgt_max); |
| 88 |
} |
| 89 |
else if (ndims == 3) { |
| 90 |
map3d(graph, xvecs, nvtxs, sets, goal, vwgt_max); |
| 91 |
} |
| 92 |
} |
| 93 |
|
| 94 |
else if (mediantype == 2) { /* Divide recursively using medians. */ |
| 95 |
rec_median_k(graph, xvecs, nvtxs, active, ndims, cube_or_mesh, goal, using_vwgts, sets); |
| 96 |
} |
| 97 |
|
| 98 |
else if (mediantype == 3) { /* Cut with independent medians => unbalanced. */ |
| 99 |
bits = 1; |
| 100 |
temp_sets = smalloc((nvtxs + 1) * sizeof(int)); |
| 101 |
for (j = 1; j <= nvtxs; j++) { |
| 102 |
sets[j] = 0; |
| 103 |
} |
| 104 |
|
| 105 |
for (i = 1; i <= ndims; i++) { |
| 106 |
temp_goal[0] = temp_goal[1] = 0; |
| 107 |
for (j = 0; j < (1 << ndims); j++) { |
| 108 |
if (bits & j) { |
| 109 |
temp_goal[1] += goal[j]; |
| 110 |
} |
| 111 |
else { |
| 112 |
temp_goal[0] += goal[j]; |
| 113 |
} |
| 114 |
} |
| 115 |
bits <<= 1; |
| 116 |
|
| 117 |
median(graph, xvecs[i], nvtxs, active, temp_goal, using_vwgts, temp_sets); |
| 118 |
for (j = 1; j <= nvtxs; j++) { |
| 119 |
sets[j] = (sets[j] << 1) + temp_sets[j]; |
| 120 |
} |
| 121 |
} |
| 122 |
sfree(temp_sets); |
| 123 |
} |
| 124 |
|
| 125 |
if (mediantype == 4) { /* Stripe the domain. */ |
| 126 |
rec_median_1(graph, xvecs[1], nvtxs, active, cube_or_mesh, nsets, goal, using_vwgts, sets, |
| 127 |
TRUE); |
| 128 |
} |
| 129 |
} |