Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Global MPMC Queue #38

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 7 additions & 16 deletions src/thread_pool_pppcsr/thread_pool_pppcsr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ using namespace std;
*/
ThreadPoolPPPCSR::ThreadPoolPPPCSR(const int NUM_OF_THREADS, bool lock_search, uint32_t init_num_nodes,
int partitions_per_domain, bool use_numa)
: tasks(NUM_OF_THREADS),
: tasks(),
finished(false),
available_nodes(std::min(numa_max_node() + 1, NUM_OF_THREADS)),
indeces(available_nodes, 0),
Expand Down Expand Up @@ -52,17 +52,14 @@ ThreadPoolPPPCSR::ThreadPoolPPPCSR(const int NUM_OF_THREADS, bool lock_search, u
// Finishes when finished is set to true and there are no outstanding tasks
template <bool isMasterThread>
void ThreadPoolPPPCSR::execute(const int thread_id) {
cout << "Thread " << thread_id << " has " << tasks[thread_id].size() << " tasks, runs on domain "
<< threadToDomain[thread_id] << endl;
if (numa_available() >= 0) {
numa_run_on_node(threadToDomain[thread_id]);
}
int registered = -1;

while (!tasks[thread_id].empty() || (!isMasterThread && !finished)) {
if (!tasks[thread_id].empty()) {
task t = tasks[thread_id].front();
tasks[thread_id].pop();
while (!tasks.empty() || (!isMasterThread && !finished)) {
if (!tasks.empty()) {
task t = tasks.front();

int currentPar = pcsr->get_partiton(t.src);

Expand Down Expand Up @@ -95,25 +92,19 @@ void ThreadPoolPPPCSR::execute(const int thread_id) {
// Submit an update for edge {src, target} to thread with number thread_id
void ThreadPoolPPPCSR::submit_add(int thread_id, int src, int target) {
(void)thread_id;
auto par = pcsr->get_partiton(src) / partitions_per_domain;
auto index = (indeces[par]++) % numThreadsDomain[par];
tasks[firstThreadDomain[par] + index].push(task{true, false, src, target});
tasks.push(task{true, false, src, target});
}

// Submit a delete edge task for edge {src, target} to thread with number thread_id
void ThreadPoolPPPCSR::submit_delete(int thread_id, int src, int target) {
(void)thread_id;
auto par = pcsr->get_partiton(src) / partitions_per_domain;
auto index = (indeces[par]++) % numThreadsDomain[par];
tasks[firstThreadDomain[par] + index].push(task{false, false, src, target});
tasks.push(task{false, false, src, target});
}

// Submit a read neighbourhood task for vertex src to thread with number thread_id
void ThreadPoolPPPCSR::submit_read(int thread_id, int src) {
(void)thread_id;
auto par = pcsr->get_partiton(src) / partitions_per_domain;
auto index = (indeces[par]++) % numThreadsDomain[par];
tasks[firstThreadDomain[par] + index].push(task{false, true, src, src});
tasks.push(task{false, true, src, src});
}

// starts a new number of threads
Expand Down
3 changes: 2 additions & 1 deletion src/thread_pool_pppcsr/thread_pool_pppcsr.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <vector>

#include "../pppcsr/PPPCSR.h"
#include "../utility/concurrentqueue.h"
#include "task.h"

using namespace std;
Expand All @@ -30,7 +31,7 @@ class ThreadPoolPPPCSR {

private:
vector<thread> thread_pool;
vector<queue<task>> tasks;
moodycamel::ConcurrentQueue<task> tasks;
chrono::steady_clock::time_point s;
chrono::steady_clock::time_point end;
std::atomic_bool finished;
Expand Down
Loading