1 /*
2 * mutil.c
3 *
4 * This file contains various utility functions for the MOC portion of the
5 * code
6 *
7 * Started 2/15/98
8 * George
9 *
10 * $Id: mutil.c,v 1.1 1998/11/27 17:59:27 karypis Exp $
11 *
12 */
13
14 #include "metis.h"
15
16
17 /*************************************************************************
18 * This function checks if the vertex weights of two vertices are below
19 * a given set of values
20 **************************************************************************/
AreAllVwgtsBelow(int ncon,float alpha,float * vwgt1,float beta,float * vwgt2,float limit)21 int AreAllVwgtsBelow(int ncon, float alpha, float *vwgt1, float beta, float *vwgt2, float limit)
22 {
23 int i;
24
25 for (i=0; i<ncon; i++)
26 if (alpha*vwgt1[i] + beta*vwgt2[i] > limit)
27 return 0;
28
29 return 1;
30 }
31
32
33 /*************************************************************************
34 * This function checks if the vertex weights of two vertices are below
35 * a given set of values
36 **************************************************************************/
AreAnyVwgtsBelow(int ncon,float alpha,float * vwgt1,float beta,float * vwgt2,float limit)37 int AreAnyVwgtsBelow(int ncon, float alpha, float *vwgt1, float beta, float *vwgt2, float limit)
38 {
39 int i;
40
41 for (i=0; i<ncon; i++)
42 if (alpha*vwgt1[i] + beta*vwgt2[i] < limit)
43 return 1;
44
45 return 0;
46 }
47
48
49
50 /*************************************************************************
51 * This function checks if the vertex weights of two vertices are above
52 * a given set of values
53 **************************************************************************/
AreAllVwgtsAbove(int ncon,float alpha,float * vwgt1,float beta,float * vwgt2,float limit)54 int AreAllVwgtsAbove(int ncon, float alpha, float *vwgt1, float beta, float *vwgt2, float limit)
55 {
56 int i;
57
58 for (i=0; i<ncon; i++)
59 if (alpha*vwgt1[i] + beta*vwgt2[i] < limit)
60 return 0;
61
62 return 1;
63 }
64
65
66 /*************************************************************************
67 * This function computes the load imbalance over all the constrains
68 * For now assume that we just want balanced partitionings
69 **************************************************************************/
ComputeLoadImbalance(int ncon,int nparts,float * npwgts,float * tpwgts)70 float ComputeLoadImbalance(int ncon, int nparts, float *npwgts, float *tpwgts)
71 {
72 int i, j;
73 float max, lb=0.0;
74
75 for (i=0; i<ncon; i++) {
76 max = 0.0;
77 for (j=0; j<nparts; j++) {
78 if (npwgts[j*ncon+i] > max)
79 max = npwgts[j*ncon+i];
80 }
81 if (max*nparts > lb)
82 lb = max*nparts;
83 }
84
85 return lb;
86 }
87
88 /*************************************************************************
89 * This function checks if the vertex weights of two vertices are below
90 * a given set of values
91 **************************************************************************/
AreAllBelow(int ncon,float * v1,float * v2)92 int AreAllBelow(int ncon, float *v1, float *v2)
93 {
94 int i;
95
96 for (i=0; i<ncon; i++)
97 if (v1[i] > v2[i])
98 return 0;
99
100 return 1;
101 }
102