diff --git a/CMakeLists.txt b/CMakeLists.txt index e58bd39..3b9a2ca 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,7 @@ # ------------------------------------------------------------------- cmake_minimum_required(VERSION 3.14) -project(PARLAY VERSION 2.2.3 +project(PARLAY VERSION 2.2.4 DESCRIPTION "A collection of parallel algorithms and other support for parallelism in C++" LANGUAGES CXX) diff --git a/examples/3d_range.cpp b/examples/3d_range.cpp index 5eeb023..8567a21 100644 --- a/examples/3d_range.cpp +++ b/examples/3d_range.cpp @@ -2,8 +2,9 @@ #include #include -#include "parlay/primitives.h" -#include "parlay/random.h" +#include +#include +#include #include "3d_range.h" diff --git a/examples/BFS_ligra.cpp b/examples/BFS_ligra.cpp index 9e1dab3..234e5f6 100644 --- a/examples/BFS_ligra.cpp +++ b/examples/BFS_ligra.cpp @@ -3,6 +3,7 @@ #include #include +#include #include "BFS_ligra.h" #include "helper/graph_utils.h" diff --git a/examples/betweenness_centrality.cpp b/examples/betweenness_centrality.cpp index effef7a..1ed363b 100644 --- a/examples/betweenness_centrality.cpp +++ b/examples/betweenness_centrality.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include "betweenness_centrality.h" #include "helper/graph_utils.h" diff --git a/examples/bigint_add.cpp b/examples/bigint_add.cpp index 3b0597b..d284bcc 100644 --- a/examples/bigint_add.cpp +++ b/examples/bigint_add.cpp @@ -5,6 +5,7 @@ #include #include +#include #include "bigint_add.h" diff --git a/examples/box_kdtree.cpp b/examples/box_kdtree.cpp index 9ee1a5a..1dda6a6 100644 --- a/examples/box_kdtree.cpp +++ b/examples/box_kdtree.cpp @@ -2,9 +2,10 @@ #include #include -#include "parlay/primitives.h" -#include "parlay/random.h" -#include "parlay/io.h" +#include +#include +#include +#include #include "box_kdtree.h" diff --git a/examples/counting_sort.cpp b/examples/counting_sort.cpp index 3f8cb98..c96bacb 100644 --- a/examples/counting_sort.cpp +++ b/examples/counting_sort.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include "counting_sort.h" diff --git a/examples/counting_sort.h b/examples/counting_sort.h index 82b94df..b8c63f6 100644 --- a/examples/counting_sort.h +++ b/examples/counting_sort.h @@ -4,6 +4,7 @@ #include #include #include +#include // ************************************************************** // Counting sort diff --git a/examples/delaunay.cpp b/examples/delaunay.cpp index 476d100..136a541 100644 --- a/examples/delaunay.cpp +++ b/examples/delaunay.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include "delaunay.h" diff --git a/examples/filter.cpp b/examples/filter.cpp index f11e1d7..94ab550 100644 --- a/examples/filter.cpp +++ b/examples/filter.cpp @@ -3,6 +3,7 @@ #include #include +#include // ************************************************************** // Driver code diff --git a/examples/find_if.cpp b/examples/find_if.cpp index b46b520..82201ce 100644 --- a/examples/find_if.cpp +++ b/examples/find_if.cpp @@ -4,6 +4,7 @@ #include #include +#include #include "find_if.h" diff --git a/examples/flatten.cpp b/examples/flatten.cpp index 16dc93f..90a131a 100644 --- a/examples/flatten.cpp +++ b/examples/flatten.cpp @@ -1,7 +1,9 @@ #include #include +#include #include +#include #include "flatten.h" diff --git a/examples/integer_sort.cpp b/examples/integer_sort.cpp index 48d603d..680dea3 100644 --- a/examples/integer_sort.cpp +++ b/examples/integer_sort.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include "integer_sort.h" @@ -21,23 +22,23 @@ int main(int argc, char* argv[]) { try { n = std::stol(argv[1]); } catch (...) { std::cout << usage << std::endl; return 1; } - using int_type = int; + using int_type = unsigned int; parlay::random_generator gen; std::uniform_int_distribution dis(0, n-1); int bits = std::ceil(std::log2(n)); - // generate random long values + // generate random int_type values between 0 and n parlay::sequence data = parlay::tabulate(n, [&] (long i) { auto r = gen[i]; return dis(r);}); parlay::internal::timer t("Time"); parlay::sequence result; - for (int i=0; i < 5; i++) { - result.clear(); + for (int i = 0; i < 5; i++) { + result = data; t.start(); - result = ::integer_sort(data,bits); + ::integer_sort(result, bits); t.next("integer_sort"); } diff --git a/examples/integer_sort.h b/examples/integer_sort.h index 066116d..2eb99b0 100644 --- a/examples/integer_sort.h +++ b/examples/integer_sort.h @@ -17,6 +17,7 @@ // buckets based on the high bits and then recurses on each bucket. // The bottom up is a standard radix sort starting on low-order bits // and taking advantage of the stability of each counting sort. +// Uses counting_sort for each block of the radix. // // Flips back and forth between in and out, with "inplace" keeping track // of whether the result should be in in (or if false, in out). @@ -49,22 +50,22 @@ void radix_sort(Range in, Range out, long bits, bool inplace) { if (n < cutoff) bottom_up_radix_sort(in, out, bits, 0, inplace); else { - // number of bits in bucket count (e.g. 8 would mean 256 buckets) - long radix_bits = std::min(bits, std::ceil(std::log2(2*n/cutoff))); + // number of bits in radix + long radix_bits = std::min(bits, std::min(10l, std::ceil(std::log2(2*n/cutoff)))); long num_buckets = 1l << radix_bits; // extract the needed bits for the keys auto keys = parlay::delayed::tabulate(n, [&] (long i) { return (in[i] >> bits - radix_bits) & (num_buckets-1);}); - // sort into the buckets + // sort in into the out based on keys auto offsets = counting_sort(in.begin(), in.end(), out.begin(), keys.begin(), num_buckets); // now recursively sort each bucket parlay::parallel_for(0, num_buckets, [&] (long i) { - long first = offsets[i]; // start of region - long last = offsets[i+1]; // end of region + long first = offsets[i]; // start of bucket + long last = offsets[i+1]; // end of bucket // note that order of in and out is flipped (as is inplace) radix_sort(out.cut(first,last), in.cut(first,last), bits - radix_bits, !inplace); @@ -72,12 +73,12 @@ void radix_sort(Range in, Range out, long bits, bool inplace) { } } +// An inplace (i.e., result is in the same place as the input) integer_sort +// Requires O(n) temp space template -parlay::sequence -integer_sort(Range& in, long bits) { - auto out = parlay::sequence::uninitialized(in.size()); +void integer_sort(Range& in, long bits) { + auto tmp = parlay::sequence::uninitialized(in.size()); auto in_slice = parlay::make_slice(in); - auto out_slice = parlay::make_slice(out); - radix_sort(in_slice, out_slice, bits, false); - return out; + auto tmp_slice = parlay::make_slice(tmp); + radix_sort(in_slice, tmp_slice, bits, true); } diff --git a/examples/karatsuba.cpp b/examples/karatsuba.cpp index 89afaa8..02a2a38 100644 --- a/examples/karatsuba.cpp +++ b/examples/karatsuba.cpp @@ -5,6 +5,7 @@ #include #include +#include #include "karatsuba.h" diff --git a/examples/kmeans_pp.cpp b/examples/kmeans_pp.cpp index b5150de..ac19006 100644 --- a/examples/kmeans_pp.cpp +++ b/examples/kmeans_pp.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include "kmeans_pp.h" diff --git a/examples/knn.cpp b/examples/knn.cpp index 51ae0d2..21ed34e 100644 --- a/examples/knn.cpp +++ b/examples/knn.cpp @@ -2,9 +2,10 @@ #include #include -#include "parlay/primitives.h" -#include "parlay/random.h" -#include "parlay/io.h" +#include +#include +#include +#include #include "knn.h" diff --git a/examples/knuth_shuffle.cpp b/examples/knuth_shuffle.cpp index 3bd8b7d..f7d2b00 100644 --- a/examples/knuth_shuffle.cpp +++ b/examples/knuth_shuffle.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include "knuth_shuffle.h" diff --git a/examples/kth_smallest.cpp b/examples/kth_smallest.cpp index 44a4b5f..184f8a8 100644 --- a/examples/kth_smallest.cpp +++ b/examples/kth_smallest.cpp @@ -4,6 +4,7 @@ #include #include +#include #include "kth_smallest.h" diff --git a/examples/ldd_connectivity.cpp b/examples/ldd_connectivity.cpp index 735f04d..043c6b6 100644 --- a/examples/ldd_connectivity.cpp +++ b/examples/ldd_connectivity.cpp @@ -3,6 +3,7 @@ #include #include +#include #include "ldd_connectivity.h" #include "helper/graph_utils.h" diff --git a/examples/ldd_connectivity.h b/examples/ldd_connectivity.h index 426b497..4b6c8f5 100644 --- a/examples/ldd_connectivity.h +++ b/examples/ldd_connectivity.h @@ -8,7 +8,13 @@ #include "star_connectivity.h" // ************************************************************** -// Graph Connectivity using Low Diameter Decomposition +// Graph Connectivity using Low Diameter Decomposition (LDD) +// From the paper: +// A simple and practical linear-work parallel algorithm for connectivity +// Shun, Dhulipala, Blelloch +// SPAA '14 +// The theoretical algorithms applied LDD recursively. This implementation +// just uses one level, then switches to star contraction. // ************************************************************** template using graph = parlay::sequence>; @@ -29,7 +35,7 @@ ldd_connectivity(const graph& G, float beta = .5) { // Extract the remaining vertices parlay::sequence V_r = parlay::pack_index(parlay::tabulate(n, [&] (vertex v) { - return P[v] == v;})); + return P[v] == v;})); // Finish off with star contraction on remaining graph auto roots = star_contract(E_r, V_r, P, parlay::random_generator(0)); diff --git a/examples/low_diameter_decomposition.cpp b/examples/low_diameter_decomposition.cpp index 3f76cef..9bd31da 100644 --- a/examples/low_diameter_decomposition.cpp +++ b/examples/low_diameter_decomposition.cpp @@ -3,6 +3,7 @@ #include #include +#include #include "low_diameter_decomposition.h" #include "helper/graph_utils.h" diff --git a/examples/maximal_independent_set.cpp b/examples/maximal_independent_set.cpp index 09e7157..32a8a37 100644 --- a/examples/maximal_independent_set.cpp +++ b/examples/maximal_independent_set.cpp @@ -3,6 +3,7 @@ #include #include +#include #include "maximal_independent_set.h" #include "helper/graph_utils.h" diff --git a/examples/maximal_matching.cpp b/examples/maximal_matching.cpp index 2394cb6..8aeeb30 100644 --- a/examples/maximal_matching.cpp +++ b/examples/maximal_matching.cpp @@ -5,6 +5,7 @@ #include #include +#include #include "maximal_matching.h" #include "helper/graph_utils.h" diff --git a/examples/mcss.cpp b/examples/mcss.cpp index 4604238..9d2ddd9 100644 --- a/examples/mcss.cpp +++ b/examples/mcss.cpp @@ -4,6 +4,7 @@ #include #include +#include #include "mcss.h" diff --git a/examples/mergesort.cpp b/examples/mergesort.cpp index aa9fcc8..841cb54 100644 --- a/examples/mergesort.cpp +++ b/examples/mergesort.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include "mergesort.h" diff --git a/examples/minimum_edit_distance.cpp b/examples/minimum_edit_distance.cpp index e6e3561..a9c74df 100644 --- a/examples/minimum_edit_distance.cpp +++ b/examples/minimum_edit_distance.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include "minimum_edit_distance.h" diff --git a/examples/oct_tree.cpp b/examples/oct_tree.cpp index f6512f0..59d2a2f 100644 --- a/examples/oct_tree.cpp +++ b/examples/oct_tree.cpp @@ -2,8 +2,9 @@ #include #include -#include "parlay/primitives.h" -#include "parlay/random.h" +#include +#include +#include #include "oct_tree.h" diff --git a/examples/pagerank.cpp b/examples/pagerank.cpp index 5459aec..9fdad24 100644 --- a/examples/pagerank.cpp +++ b/examples/pagerank.cpp @@ -4,6 +4,7 @@ #include #include +#include #include "pagerank.h" #include "helper/graph_utils.h" diff --git a/examples/primes.cpp b/examples/primes.cpp index 1155bcc..317558f 100644 --- a/examples/primes.cpp +++ b/examples/primes.cpp @@ -2,6 +2,7 @@ #include #include +#include #include "primes.h" diff --git a/examples/ray_trace.cpp b/examples/ray_trace.cpp index c0a5ae8..7019344 100644 --- a/examples/ray_trace.cpp +++ b/examples/ray_trace.cpp @@ -2,9 +2,10 @@ #include #include -#include "parlay/primitives.h" -#include "parlay/random.h" -#include "parlay/io.h" +#include +#include +#include +#include #include "ray_trace.h" diff --git a/examples/rectangle_intersection.cpp b/examples/rectangle_intersection.cpp index fe4abfe..97f4d86 100644 --- a/examples/rectangle_intersection.cpp +++ b/examples/rectangle_intersection.cpp @@ -2,8 +2,9 @@ #include #include -#include "parlay/primitives.h" -#include "parlay/random.h" +#include +#include +#include #include "rectangle_intersection.h" diff --git a/examples/reduce.cpp b/examples/reduce.cpp index cd528a9..f6f3337 100644 --- a/examples/reduce.cpp +++ b/examples/reduce.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include "reduce.h" diff --git a/examples/samplesort.cpp b/examples/samplesort.cpp index a44639e..6c924d0 100644 --- a/examples/samplesort.cpp +++ b/examples/samplesort.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include "samplesort.h" diff --git a/examples/set_cover.cpp b/examples/set_cover.cpp index b44818d..46215bd 100644 --- a/examples/set_cover.cpp +++ b/examples/set_cover.cpp @@ -1,9 +1,10 @@ #include #include -#include "parlay/parallel.h" -#include "parlay/primitives.h" -#include "parlay/sequence.h" +#include +#include +#include +#include #include "set_cover.h" #include "helper/graph_utils.h" diff --git a/examples/spanning_tree.cpp b/examples/spanning_tree.cpp index ffeb277..e6236f2 100644 --- a/examples/spanning_tree.cpp +++ b/examples/spanning_tree.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include "spanning_tree.h" #include "helper/graph_utils.h" diff --git a/examples/spectral_separator.cpp b/examples/spectral_separator.cpp index 68708d0..6f10dc2 100644 --- a/examples/spectral_separator.cpp +++ b/examples/spectral_separator.cpp @@ -3,6 +3,7 @@ #include #include +#include #include "spectral_separator.h" #include "helper/graph_utils.h" diff --git a/examples/star_connectivity.cpp b/examples/star_connectivity.cpp index 9b9950a..787e4e3 100644 --- a/examples/star_connectivity.cpp +++ b/examples/star_connectivity.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include "star_connectivity.h" #include "helper/graph_utils.h" diff --git a/examples/triangle_count.cpp b/examples/triangle_count.cpp index e7cf591..7a65199 100644 --- a/examples/triangle_count.cpp +++ b/examples/triangle_count.cpp @@ -3,6 +3,7 @@ #include #include +#include #include "triangle_count.h" #include "helper/graph_utils.h" diff --git a/include/parlay/internal/get_time.h b/include/parlay/internal/get_time.h index b81a7ca..6401a54 100644 --- a/include/parlay/internal/get_time.h +++ b/include/parlay/internal/get_time.h @@ -1,4 +1,5 @@ -#pragma once +#ifndef PARLAY_GET_TIME_H_ +#define PARLAY_GET_TIME_H_ #include #include @@ -84,3 +85,5 @@ struct timer { } } + +#endif // PARLAY_GET_TIME_H_ diff --git a/include/parlay/internal/memory_size.h b/include/parlay/internal/memory_size.h index 5243e25..c918dcf 100644 --- a/include/parlay/internal/memory_size.h +++ b/include/parlay/internal/memory_size.h @@ -5,7 +5,8 @@ * http://creativecommons.org/licenses/by/3.0/deed.en_US */ -#pragma once +#ifndef PARLAY_MEMORY_SIZE_H_ +#define PARLAY_MEMORY_SIZE_H_ #if defined(_WIN32) @@ -102,3 +103,5 @@ static size_t getMemorySize() { return 0L; /* Unknown OS. */ #endif } + +#endif // PARLAY_MEMORY_SIZE_H_