From 224352edcc2b1bf90c0812dcd6b3e5c9051c60ca Mon Sep 17 00:00:00 2001 From: Julian Shun Date: Wed, 24 Sep 2014 16:54:49 -0400 Subject: [PATCH] fix in symmetrization process --- IO.h | 42 ++++++++++++++++++------------------------ utils.h | 15 +++++++++++++++ 2 files changed, 33 insertions(+), 24 deletions(-) diff --git a/IO.h b/IO.h index 6e966c7..116203b 100644 --- a/IO.h +++ b/IO.h @@ -150,7 +150,7 @@ graph readGraphFromFile(char* fname, bool isSymmetric) { quickSort(temp,m,pairFirstCmp()); - tOffsets[0] = 0; inEdges[0] = temp[0].second; + tOffsets[temp[0].first] = 0; inEdges[0] = temp[0].second; {parallel_for(intT i=1;i readGraphFromFile(char* fname, bool isSymmetric) { }} free(temp); - uintT currOffset = m; - for(intT i=n-1;i>=0;i--) { - if(tOffsets[i] == INT_T_MAX) tOffsets[i] = currOffset; - else currOffset = tOffsets[i]; - } + + //fill in offsets of degree 0 vertices by taking closest non-zero + //offset to the right + sequence::scanIBack(tOffsets,tOffsets,n,minF(),(intT)m); {parallel_for(uintT i=0;i readWghGraphFromFile(char* fname, bool isSymmetric) { quickSort(temp,m,pairFirstCmp()); - tOffsets[0] = 0; + tOffsets[temp[0].first] = 0; inEdgesAndWghs[0] = temp[0].second.first; inEdgesAndWghs[1] = temp[0].second.second; {parallel_for(intT i=1;i readWghGraphFromFile(char* fname, bool isSymmetric) { free(temp); - uintT currOffset = m; - for(intT i=n-1;i>=0;i--) { - if(tOffsets[i] == INT_T_MAX) tOffsets[i] = currOffset; - else currOffset = tOffsets[i]; - } + //fill in offsets of degree 0 vertices by taking closest non-zero + //offset to the right + sequence::scanIBack(tOffsets,tOffsets,n,minF(),(intT)m); {parallel_for(uintT i=0;i readGraphFromBinary(char* iFile, bool isSymmetric) { quickSort(temp,m,pairFirstCmp()); - tOffsets[0] = 0; inEdges[0] = temp[0].second; + tOffsets[temp[0].first] = 0; inEdges[0] = temp[0].second; {parallel_for(intT i=1;i readGraphFromBinary(char* iFile, bool isSymmetric) { }} free(temp); - uintT currOffset = m; - for(intT i=n-1;i>=0;i--) { - if(tOffsets[i] == INT_T_MAX) tOffsets[i] = currOffset; - else currOffset = tOffsets[i]; - } + //fill in offsets of degree 0 vertices by taking closest non-zero + //offset to the right + sequence::scanIBack(tOffsets,tOffsets,n,minF(),(intT)m); {parallel_for(uintT i=0;i readWghGraphFromBinary(char* iFile, bool isSymmetric) { free(offsets); quickSort(temp,m,pairFirstCmp()); - tOffsets[0] = 0; + tOffsets[temp[0].first] = 0; inEdgesAndWghs[0] = temp[0].second; inEdgesAndWghs[1] = 1; {parallel_for(intT i=1;i readWghGraphFromBinary(char* iFile, bool isSymmetric) { } }} free(temp); - uintT currOffset = m; - for(intT i=n-1;i>=0;i--) { - if(tOffsets[i] == INT_T_MAX) tOffsets[i] = currOffset; - else currOffset = tOffsets[i]; - } + + //fill in offsets of degree 0 vertices by taking closest non-zero + //offset to the right + sequence::scanIBack(tOffsets,tOffsets,n,minF(),(intT)m); {parallel_for(uintT i=0;i struct addF { E operator() (const E& a, const E& b) const {return a+b;}}; +template +struct minF { E operator() (const E& a, const E& b) const {return (a < b) ? a : b;}}; + #define _BSIZE 2048 #define _SCAN_LOG_BSIZE 10 #define _SCAN_BSIZE (1 << _SCAN_LOG_BSIZE) @@ -167,6 +170,18 @@ namespace sequence { ET scan(ET *In, ET* Out, intT n, F f, ET zero) { return scan(Out, (intT) 0, n, f, getA(In), zero, false, false);} + template + ET scanI(ET *In, ET* Out, intT n, F f, ET zero) { + return scan(Out, (intT) 0, n, f, getA(In), zero, true, false);} + + template + ET scanBack(ET *In, ET* Out, intT n, F f, ET zero) { + return scan(Out, (intT) 0, n, f, getA(In), zero, false, true);} + + template + ET scanIBack(ET *In, ET* Out, intT n, F f, ET zero) { + return scan(Out, (intT) 0, n, f, getA(In), zero, true, true);} + template ET plusScan(ET *In, ET* Out, intT n) { return scan(Out, (intT) 0, n, addF(), getA(In),