1 /****************************************************************/
2 /* Parallel Combinatorial BLAS Library (for Graph Computations) */
3 /* version 1.4 -------------------------------------------------*/
4 /* date: 1/17/2014 ---------------------------------------------*/
5 /* authors: Aydin Buluc (abuluc@lbl.gov), Adam Lugowski --------*/
6 /****************************************************************/
7 /*
8 Copyright (c) 2010-2014, The Regents of the University of California
9
10 Permission is hereby granted, free of charge, to any person obtaining a copy
11 of this software and associated documentation files (the "Software"), to deal
12 in the Software without restriction, including without limitation the rights
13 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 copies of the Software, and to permit persons to whom the Software is
15 furnished to do so, subject to the following conditions:
16
17 The above copyright notice and this permission notice shall be included in
18 all copies or substantial portions of the Software.
19
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26 THE SOFTWARE.
27 */
28
29 #ifndef _DIST_EDGE_LIST_H_
30 #define _DIST_EDGE_LIST_H_
31
32 #include <iostream>
33 #include <fstream>
34 #include <cmath>
35 #include <mpi.h>
36 #include <vector>
37 #include <iterator>
38 #include "CombBLAS.h"
39 #include "SpMat.h"
40 #include "SpTuples.h"
41 #include "SpDCCols.h"
42 #include "CommGrid.h"
43 #include "MPIType.h"
44 #include "LocArr.h"
45 #include "SpDefs.h"
46 #include "Deleter.h"
47 #include "SpHelper.h"
48 #include "SpParHelper.h"
49 #include "DenseParMat.h"
50 #include "FullyDistVec.h"
51 #include "Friends.h"
52 #include "Operations.h"
53
54 namespace combblas {
55
56 /**
57 * From Graph 500 reference implementation v2.1.1
58 **/
59 typedef struct packed_edge {
60 uint32_t v0_low;
61 uint32_t v1_low;
62 uint32_t high; /* v1 in high half, v0 in low half */
63 } packed_edge;
64
get_v0_from_edge(const packed_edge * p)65 static inline int64_t get_v0_from_edge(const packed_edge* p) {
66 return (p->v0_low | ((int64_t)((int16_t)(p->high & 0xFFFF)) << 32));
67 }
68
get_v1_from_edge(const packed_edge * p)69 static inline int64_t get_v1_from_edge(const packed_edge* p) {
70 return (p->v1_low | ((int64_t)((int16_t)(p->high >> 16)) << 32));
71 }
72
write_edge(packed_edge * p,int64_t v0,int64_t v1)73 static inline void write_edge(packed_edge* p, int64_t v0, int64_t v1) {
74 p->v0_low = (uint32_t)v0;
75 p->v1_low = (uint32_t)v1;
76 p->high = ((v0 >> 32) & 0xFFFF) | (((v1 >> 32) & 0xFFFF) << 16);
77 }
78
79
80 template <typename IT>
81 class DistEdgeList
82 {
83 public:
84 // Constructors
85 DistEdgeList ();
86 DistEdgeList(MPI_Comm & myWorld);
87 DistEdgeList (const char * filename, IT globaln, IT globalm); // read from binary in parallel
88 ~DistEdgeList ();
89
90 void Dump64bit(std::string filename);
91 void Dump32bit(std::string filename);
92 void GenGraph500Data(double initiator[4], int log_numverts, int edgefactor, bool scramble =false, bool packed=false);
93 void CleanupEmpties();
94
getGlobalV()95 int64_t getGlobalV() const { return globalV; }
getNumLocalEdges()96 IT getNumLocalEdges() const { return nedges; }
getEdges()97 IT* getEdges() const {return edges;}
getPackedEdges()98 packed_edge * getPackedEdges() const { return pedges; }
99 std::shared_ptr<CommGrid> commGrid;
100
101 private:
102
103 IT* edges; // edge list composed of pairs of edge endpoints.
104 // Edge i goes from edges[2*i+0] to edges[2*i+1]
105 packed_edge * pedges;
106
107 IT nedges; // number of local edges
108 IT memedges; // number of edges for which there is space. nedges <= memedges
109 int64_t globalV;
110
111 void SetMemSize(IT ne);
112
113 template<typename IU>
114 friend void PermEdges(DistEdgeList<IU> & DEL);
115
116 template <typename IU>
117 friend void RenameVertices(DistEdgeList<IU> & DEL);
118
119 template <class IU, class NU, class UDER>
120 friend class SpParMat;
121 };
122
123 template<typename IU>
124 void PermEdges(DistEdgeList<IU> & DEL);
125
126
127 }
128
129 #include "DistEdgeList.cpp"
130
131 #endif
132