-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbellman_ford.c
63 lines (55 loc) · 1.26 KB
/
bellman_ford.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
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <assert.h>
#include "defs.h"
#include "globals.h"
#if !defined(__MTA__)
#include "compat/xmt-ops.h"
#endif
#include "stinger-atomics.h"
int64_t bellman_ford (graph *G, int64_t * d, int64_t s, int64_t * cs)
{
int64_t i;
int64_t NV = G->numVertices;
int64_t NE = G->numEdges;
int64_t * startV = G->startVertex;
int64_t * endV = G->endVertex;
int64_t * W = G->intWeight;
int64_t INFTY;
fprintf(stderr, "source: %ld\n", s);
INFTY = INT64_MAX;
for (i = 0; i < NV; i++) {
d[i] = INFTY;
}
d[s] = 0;
for (i = 0; i < NV-1; i++) {
int64_t j;
MTA("mta assert nodep")
MTA("mta interleave schedule")
for (j = 0; j < NE; j++) {
int64_t u = startV[j];
int64_t v = endV[j];
int64_t du = d[u];
int64_t w = W[j];
int64_t dv = readfe(&d[v]);
if (du + w < dv)
writeef(&d[v], du + w);
else
writeef(&d[v], dv);
}
}
/* Compute d checksum */
int64_t checksum = 0;
int64_t not_connected = 0;
MTA("mta assert parallel")
for (i = 0; i < NV; i++) {
if (d[i] < INFTY)
checksum = checksum + d[i];
else
stinger_int64_fetch_add(¬_connected, 1);
}
*cs = checksum;
return not_connected;
}