Skip to content

Commit

Permalink
Merge branch 'master' of github.com:jshun/ligra
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian Shun committed Mar 15, 2016
2 parents fe2249b + 672724f commit f1ed257
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 15 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ file stores in binary the offsets for the vertices in the CSR format
the CSR format (the <e>'s above).

Weighted graphs: For format (1), the weights are listed at the end of
the file (after <e(m-1)>). Currently for format (2), the weights
are all set to 1.
the file (after <e(m-1)>). For format (2), the weights
are stored after all of the edge targets in the .adj file.

By default, format (1) is used. To run an input with format (2), pass
the "-b" flag as a command line argument.
Expand Down
2 changes: 1 addition & 1 deletion apps/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ endif

COMMON= ligra.h graph.h compressedVertex.h vertex.h utils.h IO.h parallel.h gettime.h quickSort.h blockRadixSort.h transpose.h parseCommandLine.h byte.h byteRLE.h nibble.h byte-pd.h byteRLE-pd.h nibble-pd.h vertexSubset.h encoder.C

ALL= encoder BFS BC BellmanFord Components Radii PageRank PageRankDelta BFSCC BFS-Bitvector KCore MIS
ALL= encoder BFS BC BellmanFord Components Radii PageRank PageRankDelta BFSCC BFS-Bitvector KCore MIS Triangle

all: $(ALL)

Expand Down
6 changes: 3 additions & 3 deletions apps/Triangle.C
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@
// Triangle counting code (assumes a symmetric graph, so pass the "-s"
// flag). This is not optimized (no ordering heuristic is used)--for
// optimized code, see "Multicore Triangle Computations Without
// Tuning", ICDE 2015. Currently only works with Ligra, and not
// Ligra+.
// Tuning", ICDE 2015. Currently only works with uncompressed graphs,
// and not with compressed graphs.
#include "ligra.h"

//assumes sorted neighbor lists
template <class vertex>
long countCommon(vertex& A, vertex& B, uintE a, uintE b) {
uintT i=0,j=0,nA = A.getOutDegree(), nB = B.getOutDegree();
uintE* nghA = A.getOutNeighbors(), *nghB = B.getOutNeighbors();
uintE* nghA = (uintE*) A.getOutNeighbors(), *nghB = (uintE*) B.getOutNeighbors();
long ans=0;
while (i < nA && j < nB && nghA[i] < a && nghB[j] < b) { //count "directed" triangles
if (nghA[i]==nghB[j]) i++, j++, ans++;
Expand Down
34 changes: 25 additions & 9 deletions ligra/IO.h
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ graph<vertex> readGraphFromBinary(char* iFile, bool isSymmetric) {
in2.seekg(0, ios::end);
long size = in2.tellg();
in2.seekg(0);
long m = size/sizeof(uint);
long m = size/(2*sizeof(uint));
char* s = (char *) malloc(size);
in2.read(s,size);
in2.close();
Expand All @@ -318,9 +318,9 @@ graph<vertex> readGraphFromBinary(char* iFile, bool isSymmetric) {
intE* edgesAndWeights = newA(intE,2*m);
{parallel_for(long i=0;i<m;i++) {
edgesAndWeights[2*i] = edges[i];
edgesAndWeights[2*i+1] = 1; //give them unit weight
edgesAndWeights[2*i+1] = edges[i+m];
}}
free(edges);
//free(edges);
#endif

{parallel_for(long i=0;i<n;i++) {
Expand All @@ -339,31 +339,47 @@ graph<vertex> readGraphFromBinary(char* iFile, bool isSymmetric) {
{parallel_for(long i=0;i<n;i++) tOffsets[i] = INT_T_MAX;}
#ifndef WEIGHTED
uintE* inEdges = newA(uintE,m);
intPair* temp = newA(intPair,m);
#else
intE* inEdges = newA(intE,2*m);
intTriple* temp = newA(intTriple,m);
#endif
intPair* temp = newA(intPair,m);
{parallel_for(intT i=0;i<n;i++){
uintT o = offsets[i];
for(uintT j=0;j<v[i].getOutDegree();j++){
#ifndef WEIGHTED
temp[o+j] = make_pair(v[i].getOutNeighbor(j),i);
#else
temp[o+j] = make_pair(v[i].getOutNeighbor(j),make_pair(i,v[i].getOutWeight(j)));
#endif
//temp[o+j] = make_pair(v[i].getOutNeighbor(j),i);
}
}}
free(offsets);
//quickSort(temp,m,pairFirstCmp<uintE>());

#ifndef WEIGHTED
//quickSort(temp,m,pairFirstCmp<uintE>());
intSort::iSort(temp,m,n+1,getFirst<uintE>());

#else
//quickSort(temp,m,pairFirstCmp<intPair>());
intSort::iSort(temp,m,n+1,getFirst<intPair>());
#endif

tOffsets[temp[0].first] = 0;
#ifndef WEIGHTED
inEdges[0] = temp[0].second;
#ifdef WEIGHTED
inEdges[1] = 1;
#else
inEdges[0] = temp[0].second.first;
inEdges[1] = temp[0].second.second;
#endif
{parallel_for(long i=1;i<m;i++) {
#ifndef WEIGHTED
inEdges[i] = temp[i].second;
#else
inEdges[2*i] = temp[i].second;
inEdges[2*i+1] = 1;
inEdges[2*i] = temp[i].second.first;
inEdges[2*i+1] = temp[i].second.second;
#endif
if(temp[i].first != temp[i-1].first) {
tOffsets[temp[i].first] = i;
Expand All @@ -390,7 +406,7 @@ graph<vertex> readGraphFromBinary(char* iFile, bool isSymmetric) {
Uncompressed_Mem<vertex>* mem = new Uncompressed_Mem<vertex>(v,n,m,edges,inEdges);
return graph<vertex>(v,n,m,mem);
#else
Uncompressed_Mem<vertex>* mem = new Uncompressed_Mem<vertex>(v,n,m,edges,inEdges);
Uncompressed_Mem<vertex>* mem = new Uncompressed_Mem<vertex>(v,n,m,edgesAndWeights,inEdges);
return graph<vertex>(v,n,m,mem);
#endif
}
Expand Down

0 comments on commit f1ed257

Please sign in to comment.