6 #ifndef TURI_SGRAPH_HILBERT_PARALLE_FOR_HPP 7 #define TURI_SGRAPH_HILBERT_PARALLE_FOR_HPP 10 #include <core/parallel/lambda_omp.hpp> 11 #include <core/storage/sgraph_data/hilbert_curve.hpp> 12 #include <core/storage/sgraph_data/sgraph_constants.hpp> 13 #include <core/util/blocking_queue.hpp> 28 namespace sgraph_compute {
55 std::function<
void(std::vector<std::pair<size_t, size_t> >) > preamble,
56 std::function<
void(std::pair<size_t, size_t>)> fn,
58 for (
size_t i = 0;i < n*n; i += parallel_limit) {
59 std::vector<std::pair<size_t, size_t> > coordinates;
61 size_t lastcoord_this_pass = std::min(i + parallel_limit, n*n);
62 for(
size_t j = i; j < lastcoord_this_pass; ++j) {
65 preamble(coordinates);
66 parallel_for(coordinates.begin(), coordinates.end(), fn);
74 std::function<
void(std::vector<std::pair<size_t, size_t> >) > preamble,
75 std::function<
void(std::pair<size_t, size_t>)> fn) {
78 std::vector<std::pair<size_t, size_t> > coordinates;
79 for (
size_t i = 0;i < n*n; i ++) {
81 coordinates_queue.
enqueue(coord);
82 coordinates.push_back(coord);
84 preamble(coordinates);
87 auto coord_success_pair = coordinates_queue.
dequeue();
89 fn(coord_success_pair.first);
97 #endif // TURI_SGRAPH_HILBERT_PARALLE_FOR_HPP void parallel_for(size_t begin, size_t end, const FunctionType &fn)
Implements a blocking queue useful for producer/consumer models.
void hilbert_parallel_for(size_t n, std::function< void(std::vector< std::pair< size_t, size_t > >) > preamble, std::function< void(std::pair< size_t, size_t >)> fn)
#define ASSERT_TRUE(cond)
std::pair< T, bool > dequeue()
size_t SGRAPH_HILBERT_CURVE_PARALLEL_FOR_NUM_THREADS
void hilbert_blocked_parallel_for(size_t n, std::function< void(std::vector< std::pair< size_t, size_t > >) > preamble, std::function< void(std::pair< size_t, size_t >)> fn, size_t parallel_limit=SGRAPH_HILBERT_CURVE_PARALLEL_FOR_NUM_THREADS)
std::pair< size_t, size_t > hilbert_index_to_coordinate(size_t s, size_t n)
void enqueue(const T &elem)
Add an element to the blocking queue.