MCPcopy Create free account
hub / github.com/alibaba/libgrape-lite / ForEach

Method ForEach

grape/parallel/parallel_engine.h:46–65  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

44
45 template <typename ITER_FUNC_T>
46 inline void ForEach(int from, int to, const ITER_FUNC_T& iter_func) {
47 std::atomic<int> cur(from);
48
49 std::vector<std::future<void>> results(thread_num_);
50 for (uint32_t tid = 0; tid < thread_num_; ++tid) {
51 results[tid] = thread_pool_.enqueue(
52 [&cur, &iter_func, to](int tid) {
53 while (true) {
54 int got = cur.fetch_add(1);
55 if (got >= to) {
56 break;
57 }
58 iter_func(tid, got);
59 }
60 },
61 tid);
62 }
63
64 thread_pool_.WaitEnd(results);
65 }
66
67 /**
68 * @brief Iterate on vertexes of a VertexRange concurrently.

Callers

nothing calls this directly

Calls 11

ForEachFunction · 0.85
enqueueMethod · 0.80
WaitEndMethod · 0.80
begin_valueMethod · 0.80
end_valueMethod · 0.80
headMethod · 0.80
tailMethod · 0.80
get_wordMethod · 0.80
sizeMethod · 0.45
RangeMethod · 0.45
ExistMethod · 0.45

Tested by

no test coverage detected