Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/elmergrid/src/metis-5.1.0/libmetis/util.c
3206 views
1
/*
2
* Copyright 1997, Regents of the University of Minnesota
3
*
4
* util.c
5
*
6
* This function contains various utility routines
7
*
8
* Started 9/28/95
9
* George
10
*
11
* $Id: util.c 10495 2011-07-06 16:04:45Z karypis $
12
*/
13
14
#include "metislib.h"
15
16
17
/*************************************************************************/
18
/*! This function initializes the random number generator
19
*/
20
/*************************************************************************/
21
void InitRandom(idx_t seed)
22
{
23
isrand((seed == -1 ? 4321 : seed));
24
}
25
26
27
/*************************************************************************/
28
/*! Returns the highest weight index of x[i]*y[i]
29
*/
30
/*************************************************************************/
31
idx_t iargmax_nrm(size_t n, idx_t *x, real_t *y)
32
{
33
idx_t i, max=0;
34
35
for (i=1; i<n; i++)
36
max = (x[i]*y[i] > x[max]*y[max] ? i : max);
37
38
return max;
39
}
40
41
42
/*************************************************************************/
43
/*! These functions return the index of the maximum element in a vector
44
*/
45
/*************************************************************************/
46
idx_t iargmax_strd(size_t n, idx_t *x, idx_t incx)
47
{
48
size_t i, max=0;
49
50
n *= incx;
51
for (i=incx; i<n; i+=incx)
52
max = (x[i] > x[max] ? i : max);
53
54
return max/incx;
55
}
56
57
58
/*************************************************************************/
59
/*! These functions return the index of the almost maximum element in a
60
vector
61
*/
62
/*************************************************************************/
63
idx_t rargmax2(size_t n, real_t *x)
64
{
65
size_t i, max1, max2;
66
67
if (x[0] > x[1]) {
68
max1 = 0;
69
max2 = 1;
70
}
71
else {
72
max1 = 1;
73
max2 = 0;
74
}
75
76
for (i=2; i<n; i++) {
77
if (x[i] > x[max1]) {
78
max2 = max1;
79
max1 = i;
80
}
81
else if (x[i] > x[max2])
82
max2 = i;
83
}
84
85
return max2;
86
}
87
88
89
/*************************************************************************/
90
/*! These functions return the index of the second largest elements in the
91
vector formed by x.y where '.' is element-wise multiplication */
92
/*************************************************************************/
93
idx_t iargmax2_nrm(size_t n, idx_t *x, real_t *y)
94
{
95
size_t i, max1, max2;
96
97
if (x[0]*y[0] > x[1]*y[1]) {
98
max1 = 0;
99
max2 = 1;
100
}
101
else {
102
max1 = 1;
103
max2 = 0;
104
}
105
106
for (i=2; i<n; i++) {
107
if (x[i]*y[i] > x[max1]*y[max1]) {
108
max2 = max1;
109
max1 = i;
110
}
111
else if (x[i]*y[i] > x[max2]*y[max2])
112
max2 = i;
113
}
114
115
return max2;
116
}
117
118
119
/*************************************************************************/
120
/*! converts a signal code into a Metis return code
121
*/
122
/*************************************************************************/
123
int metis_rcode(int sigrval)
124
{
125
switch (sigrval) {
126
case 0:
127
return METIS_OK;
128
break;
129
case SIGMEM:
130
return METIS_ERROR_MEMORY;
131
break;
132
default:
133
return METIS_ERROR;
134
break;
135
}
136
}
137
138
139
140