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