COMBINATORIAL_BLAS 1.6
 
Loading...
Searching...
No Matches
Node.h
Go to the documentation of this file.
1#ifndef NODE_H
2#define NODE_H
3
4#include <iostream>
5#include <math.h>
6#include <set>
7#include <limits>
8#include "Ft.h"
9#include "../../trunk/CombBLAS/CombBLAS.h"
10
11using namespace std;
12
14
15struct Node {
16 int id;
17 double dist;
18 int parent;
19
20 Node(): id(-1), dist(numeric_limits<double>::infinity()), parent(-1) { }
21
22 Node(int _id): id(_id), dist(numeric_limits<double>::infinity()), parent(-1) { }
23
24 Node(double _dist): id(-1), dist(_dist), parent(-1) { }
25
26 Node(double _dist, int _parent): id(-1), dist(_dist), parent(_parent) { }
27
28 Node(int _id, double _dist, int _parent): id(_id), dist(_dist), parent(_parent) { }
29
30 Node(const Node & _node): id(_node.id), dist(_node.dist), parent(_node.parent) { }
31
32 operator double() const {
33 return dist;
34 }
35
36 Node& operator= (const Node& _node) {
37 id = _node.id;
38 dist = _node.dist;
39 parent = _node.parent;
40 return *this;
41 }
42
43 Node& operator-= (const Node& _node) {
44 dist -= _node.dist;
45 parent-=_node.parent;
46 return *this;
47 }
48
49 Node operator- (const Node& _node) {
50 Node ret = *this;
51 ret -= _node;
52 return ret;
53 }
54
55 Node& operator= (const int & _id) {
56 id = _id;
57 return *this;
58 }
59};
60
61struct SPSRing {
62 static MPI_Op mpi_op() {
63 return staticMPIop;
64 }
65
66 static bool returnedSAID() {
67 return false;
68 }
69
70 // select the shorter distance
71 static Node add(const Node & arg1, const Node & arg2) {
72 // TODO: add self loop check?
73 if(arg1.dist <= arg2.dist)
74 return arg1;
75 else
76 return arg2;
77 }
78
79 // add the length of the current edge to the parent's distance.
80 static Node multiply(const Ft& arg1, const Node & arg2) {
81 return Node(arg1.arrivalTime(arg2.dist), arg2.id);
82 }
83};
84
85template <typename c, typename t>
86inline std::basic_ostream<c,t>& operator<<
87(std::basic_ostream<c,t>& lhs, const Node& rhs) {
88 return lhs << "(node: id = " << rhs.id+1 << ", dist = " << rhs.dist <<
89 ", parent = " << rhs.parent+1 << ")";
90}
91
92MPI::Datatype Node_MPI_datatype;
93template<> MPI::Datatype MPIType< Node > ( void ) {
94 return Node_MPI_datatype;
95}
96
97template <> struct promote_trait<Node, Node> {
98 typedef Node T_promote;
99};
100
101template <> struct promote_trait<double, Node> {
102 typedef Node T_promote;
103};
104
105template <> struct promote_trait<Node, double> {
106 typedef Node T_promote;
107};
108
109template <> struct promote_trait<Ft, Node> {
110 typedef Node T_promote;
111};
112
113// define SRing ops...
114void apply(void* invec, void* inoutvec, int* len, MPI_Datatype* datatype) {
115 Node* in = (Node*)invec;
116 Node* inout = (Node*)inoutvec;
117
118 for (int i = 0; i < *len; i++) {
119 inout[i] = SPSRing::add(in[i], inout[i]);
120 }
121}
122
123#endif
Definition Ft.h:14
double arrivalTime(double t) const
Definition Ft.h:30
Definition Node.h:14
Node(double _dist, int _parent)
Definition Node.h:26
int parent
Definition Node.h:17
Node(int _id, double _dist, int _parent)
Definition Node.h:28
Node(double _dist)
Definition Node.h:24
Node operator-(const Node &_node)
Definition Node.h:48
int id
Definition Node.h:15
Node & operator=(const Node &_node)
Definition Node.h:35
Node(int _id)
Definition Node.h:22
Node & operator-=(const Node &_node)
Definition Node.h:42
Node(const Node &_node)
Definition Node.h:30
double dist
Definition Node.h:16
Node()
Definition Node.h:20
Definition Node.h:60
static bool returnedSAID()
Definition Node.h:66
static MPI_Op mpi_op()
Definition Node.h:62
static Node multiply(const Ft &arg1, const Node &arg2)
Definition Node.h:80
static Node add(const Node &arg1, const Node &arg2)
Definition Node.h:71
MPI::Datatype MPIType< Node >(void)
Definition Node.h:93
MPI::Datatype Node_MPI_datatype
Definition Node.h:92
MPI_Op staticMPIop
Definition Node.h:13
void apply(void *invec, void *inoutvec, int *len, MPI_Datatype *datatype)
Definition Node.h:114