| 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" |
| 10 |
#include "structs.h" |
| 11 |
#include <stdio.h> // for printf |
| 12 |
|
| 13 |
void assign(struct vtx_data **graph, /* data structure with vtx weights */ |
| 14 |
double **yvecs, /* ptr to list of y-vectors (lengths nvtxs+1) */ |
| 15 |
int nvtxs, /* number of vertices in graph */ |
| 16 |
int ndims, /* number of vectors for dividing */ |
| 17 |
int cube_or_mesh, /* 0 => hypercube, d => d-dimensional mesh */ |
| 18 |
int nsets, /* number of sets to divide into */ |
| 19 |
double *wsqrt, /* sqrt of vertex weights */ |
| 20 |
int *sets, /* processor assignment for my vtxs */ |
| 21 |
int *active, /* space for nvtxs integers */ |
| 22 |
int mediantype, /* which partitioning strategy to use */ |
| 23 |
double *goal, /* desired set sizes */ |
| 24 |
int vwgt_max /* largest vertex weight */ |
| 25 |
) |
| 26 |
{ |
| 27 |
extern int DEBUG_TRACE; /* trace execution path of code */ |
| 28 |
extern int DEBUG_ASSIGN; /* turn on debugging in assignment */ |
| 29 |
double theta, phi, gamma; /* angles for optimal rotation */ |
| 30 |
double temp; |
| 31 |
int using_vwgts; /* are vertex weights active? */ |
| 32 |
|
| 33 |
if (DEBUG_TRACE > 0) { |
| 34 |
printf("<Entering assign, nvtxs = %d, ndims = %d>\n", nvtxs, ndims); |
| 35 |
} |
| 36 |
|
| 37 |
using_vwgts = (vwgt_max != 1); |
| 38 |
|
| 39 |
if (ndims == 1) { |
| 40 |
/* Unscale yvecs to get xvecs. */ |
| 41 |
y2x(yvecs, ndims, nvtxs, wsqrt); |
| 42 |
|
| 43 |
mapper(graph, yvecs, nvtxs, active, sets, ndims, cube_or_mesh, nsets, mediantype, goal, |
| 44 |
vwgt_max); |
| 45 |
} |
| 46 |
|
| 47 |
else if (ndims == 2) { |
| 48 |
theta = opt2d(graph, yvecs, nvtxs, nvtxs); |
| 49 |
|
| 50 |
rotate2d(yvecs, nvtxs, theta); |
| 51 |
|
| 52 |
y2x(yvecs, ndims, nvtxs, wsqrt); |
| 53 |
|
| 54 |
mapper(graph, yvecs, nvtxs, active, sets, ndims, cube_or_mesh, nsets, mediantype, goal, |
| 55 |
vwgt_max); |
| 56 |
} |
| 57 |
|
| 58 |
else if (ndims == 3) { |
| 59 |
|
| 60 |
if (DEBUG_ASSIGN > 0) { |
| 61 |
temp = tri_prod(yvecs[1], yvecs[2], yvecs[3], wsqrt, nvtxs); |
| 62 |
printf("Before rotation, 3-way orthogonality = %e\n", temp); |
| 63 |
} |
| 64 |
|
| 65 |
opt3d(graph, yvecs, nvtxs, nvtxs, wsqrt, &theta, &phi, &gamma, using_vwgts); |
| 66 |
|
| 67 |
rotate3d(yvecs, nvtxs, theta, phi, gamma); |
| 68 |
|
| 69 |
if (DEBUG_ASSIGN > 0) { |
| 70 |
temp = tri_prod(yvecs[1], yvecs[2], yvecs[3], wsqrt, nvtxs); |
| 71 |
printf("After rotation (%f,%f,%f), 3-way orthogonality = %e\n", theta, phi, gamma, temp); |
| 72 |
} |
| 73 |
|
| 74 |
y2x(yvecs, ndims, nvtxs, wsqrt); |
| 75 |
|
| 76 |
mapper(graph, yvecs, nvtxs, active, sets, ndims, cube_or_mesh, nsets, mediantype, goal, |
| 77 |
vwgt_max); |
| 78 |
} |
| 79 |
} |