18 int new_tot_wht = P[
"ij"];
21 if (r == n+1)
return false;
24 P[
"i"] += A[
"ij"]*P[
"j"];
25 tot_wht = new_tot_wht;
26 new_tot_wht = P[
"ij"];
27 assert(new_tot_wht <= tot_wht);
28 }
while (new_tot_wht < tot_wht);
38 [](
int a,
int b){
return std::min(a,b); },
41 [](
int a,
int b){
return a+
b; });
46 A.fill_random(0, n*n);
50 A.sparsify([=](
int a){
return a<5*n; });
56 v.
write(1, &idx, &val);
57 }
else v.
write(0, NULL, NULL);
66 v.
write(1, &idx, &val);
67 }
else v.
write(0, NULL, NULL);
72 int64_t idx[] = {1,n+2,2*n+0};
73 int val[] = {1, -1, -1};
75 }
else A.write(0, NULL, NULL);
82 MPI_Reduce(MPI_IN_PLACE, &pass, 1, MPI_INT, MPI_MIN, 0, MPI_COMM_WORLD);
84 printf(
"{ negative cycle check via Bellman-Ford } passed \n");
86 printf(
"{ negative cycle check via Bellman-Ford } failed \n");
88 MPI_Reduce(&pass, MPI_IN_PLACE, 1, MPI_INT, MPI_MIN, 0, MPI_COMM_WORLD);
97 char ** itr = std::find(begin, end, option);
98 if (itr != end && ++itr != end){
105 int main(
int argc,
char ** argv){
107 int const in_num = argc;
108 char ** input_str = argv;
110 MPI_Init(&argc, &argv);
111 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
112 MPI_Comm_size(MPI_COMM_WORLD, &np);
115 n = atoi(
getCmdOption(input_str, input_str+in_num,
"-n"));
120 World dw(argc, argv);
123 printf(
"Computing SSSP on sparse graph with %d nodes using the Bellman-Ford algorithm\n",n);
Matrix class which encapsulates a 2D tensor.
Semiring is a Monoid with an addition multiplicaton function addition must have an identity and be as...
Vector class which encapsulates a 1D tensor.
an instance of the CTF library (world) on a MPI communicator
int rank
rank of local processor
bool Bellman_Ford(Matrix< t > A, Vector< t > P, int n)
int sssp(int n, World &dw)
int main(int argc, char **argv)
char * getCmdOption(char **begin, char **end, const std::string &option)
void write(int64_t npair, int64_t const *global_idx, dtype const *data)
writes in values associated with any set of indices The sparse data is defined in coordinate format...