/
op_a.c
79 lines (63 loc) · 1.29 KB
/
op_a.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
Compute A(X).
*/
#include <stdlib.h>
#include "declarations.h"
void op_a(k,constraints,X,result)
int k;
struct constraintmatrix *constraints;
struct blockmatrix X;
double *result;
{
int i,j;
int p,q;
int blk;
double ent;
double *mat;
double *vec;
int nume;
struct sparseblock *ptr;
double contrib;
#pragma omp parallel for schedule(dynamic,64) default(none) private(i,contrib,ptr,blk,nume,vec,j,p,mat,ent,q) shared(k,constraints,result,X)
for (i=1; i<=k; i++)
{
result[i]=0.0;
contrib=0.0;
ptr=constraints[i].blocks;
while (ptr != NULL)
{
blk=ptr->blocknum;
nume=ptr->numentries;
if (X.blocks[blk].blockcategory == DIAG)
{
vec=X.blocks[blk].data.vec;
for (j=1; j<=nume; j++)
{
ent=ptr->entries[j];
p=ptr->iindices[j];
contrib += ent*vec[p];
};
}
else
{
mat=X.blocks[blk].data.mat;
for (j=1; j<=nume; j++)
{
ent=ptr->entries[j];
p=ijtok(ptr->iindices[j],ptr->jindices[j],ptr->blocksize);
q=ijtok(ptr->jindices[j],ptr->iindices[j],ptr->blocksize);
if (p == q)
{
contrib += ent*mat[p];
}
else
{
contrib += ent*(mat[p]+mat[q]);
};
};
};
ptr=ptr->next;
};
result[i] += contrib;
};
}