1
/* This software was developed by Bruce Hendrickson and Robert Leland *
2
* at Sandia National Laboratories under US Department of Energy *
3
* contract DE-AC04-76DP00789 and is copyrighted by Sandia Corporation. */
10
/* Sparse linked A(matrix) times x(vector), double precision. */
11
void splarax(result, mat, n, vec, vwsqrt, work)
12
double *result; /* result of matrix vector multiplication */
13
struct vtx_data **mat; /* graph data structure */
14
int n; /* number of rows/columns in matrix */
15
double *vec; /* vector being multiplied by matrix */
16
double *vwsqrt; /* square roots of vertex weights */
17
double *work; /* work vector from 1-n */
19
extern int PERTURB; /* perturb matrix? */
20
extern int NPERTURB; /* if so, number of edges to perturb */
21
extern double PERTURB_MAX; /* maximum value of perturbation */
22
struct vtx_data *mat_i; /* an entry in "mat" */
23
double sum; /* sums inner product of matrix-row & vector */
24
int *colpntr; /* loops through indices of nonzeros in a row */
25
float *wgtpntr; /* loops through values of nonzeros */
26
int i, j; /* loop counters */
27
double *wrkpntr; /* loops through indices of work vector */
28
double *vwsqpntr; /* loops through indices of vwsqrt */
29
double *vecpntr; /* loops through indices of vec */
30
double *respntr; /* loops through indices of result */
31
int last_edge; /* last edge in edge list */
34
if (vwsqrt == NULL) { /* No vertex weights */
35
if (mat[1]->ewgts == NULL) { /* No edge weights */
37
for (i = 1; i <= n; i++) {
39
colpntr = mat_i->edges;
40
last_edge = mat_i->nedges - 1;
41
sum = last_edge * vec[*colpntr++];
42
for (j = last_edge; j; j--) {
43
sum -= vec[*colpntr++];
48
else { /* Edge weights */
50
for (i = 1; i <= n; i++) {
52
colpntr = mat_i->edges;
53
wgtpntr = mat_i->ewgts;
55
for (j = mat_i->nedges; j; j--) {
56
sum -= *wgtpntr++ * vec[*colpntr++];
58
*(++respntr) = sum; /* -sum if want -Ax */
61
if (PERTURB && NPERTURB > 0 && PERTURB_MAX > 0.0)
64
else { /* Vertex weights */
70
*(++wrkpntr) = *(++vecpntr) / *(++vwsqpntr);
74
if (mat[1]->ewgts == NULL) { /* No edge weights. */
76
for (i = 1; i <= n; i++) {
78
colpntr = mat_i->edges;
79
last_edge = mat_i->nedges - 1;
80
sum = (last_edge) * work[*colpntr++];
81
for (j = last_edge; j; j--) {
82
sum -= work[*colpntr++];
87
else { /* Edge weights. */
89
for (i = 1; i <= n; i++) {
91
colpntr = mat_i->edges;
92
wgtpntr = mat_i->ewgts;
94
for (j = mat_i->nedges; j; j--) {
95
sum -= *wgtpntr++ * work[*colpntr++];
97
*(++respntr) = sum; /* -sum if want -Ax */
100
if (PERTURB && NPERTURB > 0 && PERTURB_MAX > 0.0)
101
perturb(result, work);
103
if (vwsqrt != NULL) {
106
for (i = n; i; i--) {
107
*(++respntr) /= *(++vwsqpntr);
113
/* Sparse linked A(matrix) times x(vector)i, float version. */
114
void splarax_float(result, mat, n, vec, vwsqrt, work)
115
float *result; /* result of matrix vector multiplication */
116
struct vtx_data **mat; /* graph data structure */
117
int n; /* number of rows/columns in matrix */
118
float *vec; /* vector being multiplied by matrix */
119
float *vwsqrt; /* square roots of vertex weights */
120
float *work; /* work vector from 1-n */
122
extern int PERTURB; /* perturb matrix? */
123
extern int NPERTURB; /* if so, number of edges to perturb */
124
extern double PERTURB_MAX; /* maximum value of perturbation */
125
struct vtx_data *mat_i; /* an entry in "mat" */
126
double sum; /* sums inner product of matrix-row & vector */
127
int *colpntr; /* loops through indices of nonzeros in a row */
128
float *wgtpntr; /* loops through values of nonzeros */
129
int i, j; /* loop counters */
130
float *wrkpntr; /* loops through indices of work vector */
131
float *vwsqpntr; /* loops through indices of vwsqrt */
132
float *vecpntr; /* loops through indices of vec */
133
float *respntr; /* loops through indices of result */
134
int last_edge; /* last edge in edge list */
135
void perturb_float();
137
if (vwsqrt == NULL) { /* No vertex weights */
138
if (mat[1]->ewgts == NULL) { /* No edge weights */
140
for (i = 1; i <= n; i++) {
142
colpntr = mat_i->edges;
143
last_edge = mat_i->nedges - 1;
144
sum = (last_edge) * vec[*colpntr++];
145
for (j = last_edge; j; j--) {
146
sum -= vec[*colpntr++];
151
else { /* Edge weights */
153
for (i = 1; i <= n; i++) {
155
colpntr = mat_i->edges;
156
wgtpntr = mat_i->ewgts;
158
for (j = mat_i->nedges; j; j--) {
159
sum -= *wgtpntr++ * vec[*colpntr++];
161
*(++respntr) = sum; /* -sum if want -Ax */
164
if (PERTURB && NPERTURB > 0 && PERTURB_MAX > 0.0)
165
perturb_float(result, vec);
167
else { /* Vertex weights */
168
if (vwsqrt != NULL) {
172
for (i = n; i; i--) {
173
*(++wrkpntr) = *(++vecpntr) / *(++vwsqpntr);
177
if (mat[1]->ewgts == NULL) { /* No edge weights. */
179
for (i = 1; i <= n; i++) {
181
colpntr = mat_i->edges;
182
last_edge = mat_i->nedges - 1;
183
sum = (last_edge) * work[*colpntr++];
184
for (j = last_edge; j; j--) {
185
sum -= work[*colpntr++];
190
else { /* Edge weights. */
192
for (i = 1; i <= n; i++) {
194
colpntr = mat_i->edges;
195
wgtpntr = mat_i->ewgts;
197
for (j = mat_i->nedges; j; j--) {
198
sum -= *wgtpntr++ * work[*colpntr++];
200
*(++respntr) = sum; /* -sum if want -Ax */
203
if (PERTURB && NPERTURB > 0 && PERTURB_MAX > 0.0)
204
perturb_float(result, work);
206
if (vwsqrt != NULL) {
209
for (i = n; i; i--) {
210
*(++respntr) /= *(++vwsqpntr);