Skip to content

Commit 73e91c6

Browse files
authored
use serial prefix sum in lscsr (#37)
1 parent 1cad580 commit 73e91c6

2 files changed

Lines changed: 15 additions & 18 deletions

File tree

libgalois/include/galois/graphs/LS_LC_CSR_Graph.h

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -97,31 +97,19 @@ class LS_LC_CSR_Graph : private boost::noncopyable {
9797
* Prefix Sum utilities
9898
*/
9999
std::vector<uint64_t> m_pfx_sum_cache;
100-
static uint64_t transmute(const VertexMetadata& vertex_meta) {
101-
return vertex_meta.degree();
102-
}
103-
static uint64_t scan_op(const VertexMetadata& p, const uint64_t& l) {
104-
return p.degree() + l;
105-
}
106-
static uint64_t combiner(const uint64_t& f, const uint64_t& s) {
107-
return f + s;
108-
}
109-
PrefixSum<VertexMetadata, uint64_t, transmute, scan_op, combiner,
110-
CacheLinePaddedArr>
111-
m_pfx{&m_vertices[0], &m_pfx_sum_cache[0]};
112100

113101
alignas(hardware_destructive_interference_size)
114102
std::atomic<bool> m_prefix_valid = ATOMIC_VAR_INIT(false);
115103

116-
void resetPrefixSum() {
117-
m_pfx_sum_cache.resize(m_vertices.size());
118-
m_pfx.src = &m_vertices[0];
119-
m_pfx.dst = &m_pfx_sum_cache[0];
120-
}
104+
void resetPrefixSum() { m_pfx_sum_cache.resize(m_vertices.size()); }
121105

122106
// Compute the prefix sum using the two level method
123107
void computePrefixSum() {
124-
m_pfx.computePrefixSum(m_vertices.size());
108+
// todo: switch to parallel prefix sum when `galois::PrefixSum` is fixed
109+
std::transform_inclusive_scan(
110+
m_vertices.begin(), m_vertices.end(), m_pfx_sum_cache.begin(),
111+
std::plus<uint64_t>(),
112+
[](VertexMetadata const& v) { return v.degree(); }, 0ul);
125113
m_prefix_valid.store(true, std::memory_order_release);
126114
}
127115

libgalois/test/graph-compile-lscsr.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,5 +116,14 @@ int main() {
116116
// ...
117117
GALOIS_ASSERT(g[8] == 7);
118118

119+
uint64_t num_vertices = (1 << 22) + 67;
120+
galois::graphs::LS_LC_CSR_Graph<void, void> big(num_vertices);
121+
for (uint64_t i = 0; i < num_vertices; ++i) {
122+
big.addEdgesTopologyOnly(i, {(i + 1) % num_vertices});
123+
}
124+
for (uint64_t i = 0; i < num_vertices; ++i) {
125+
GALOIS_ASSERT(big[i] == i + 1);
126+
}
127+
119128
return 0;
120129
}

0 commit comments

Comments
 (0)