Commit 523a545d authored by karius's avatar karius

test threading

parent f0e07011
......@@ -18,10 +18,7 @@ Engine::Engine() {
_workerthreads[i] = new WorkerThread(worker_name.c_str());
}
std::cout << "Created Worker threads for " << _gpumanager.numGPUS() << " gpus ..." << std::endl;
for (int i = 0;i<_gpumanager.numGPUS();i++){
_workerthreads[i]->ExitThread();
std::cout << "Killing worker " << i << "..." << std::endl;
}
}
void Engine::submitTask(std::shared_ptr<Task> task,int gpu_index){
......@@ -29,6 +26,21 @@ void Engine::submitTask(std::shared_ptr<Task> task,int gpu_index){
_workerthreads[gpu_index]->PostTask(task);
}
void Engine::startWorkers(){
for (int i = 0;i<_gpumanager.numGPUS();i++){
_workerthreads[i]->CreateThread();
std::cout << "Starting worker " << i << "..." << std::endl;
}
}
void Engine::killWorkers(){
for (int i = 0;i<_gpumanager.numGPUS();i++){
_workerthreads[i]->ExitThread();
std::cout << "Killing worker " << i << "..." << std::endl;
}
}
Engine::~Engine() {
// TODO Auto-generated destructor stub
}
......
......@@ -19,6 +19,8 @@ class Engine {
public:
Engine();
void submitTask(std::shared_ptr<Task> task,int gpu_index);
void killWorkers();
void startWorkers();
virtual ~Engine();
private:
......
No preview for this file type
No preview for this file type
......@@ -7,11 +7,6 @@
#include <Task.h>
Task::Task() {
// TODO Auto-generated constructor stub
}
Task::~Task() {
// TODO Auto-generated destructor stub
}
......
......@@ -8,12 +8,14 @@
#ifndef TASK_H_
#define TASK_H_
enum TASK_TYPE {SCORING,KILL};
enum TASK_TYPE {SCORING,KILL,MESSAGE};
class Task {
public:
Task();
Task():msg(""){};
Task(const char * msg):type(MESSAGE),msg(msg){};
virtual ~Task();
const char * msg;
TASK_TYPE type = KILL;
private:
};
......
......@@ -8,6 +8,7 @@
#include <WorkerThread.h>
#include <assert.h>
#include <chrono>
#include <iostream>
WorkerThread::WorkerThread(const char * thread_name) {
// TODO Auto-generated constructor stub
......@@ -16,6 +17,7 @@ WorkerThread::WorkerThread(const char * thread_name) {
bool WorkerThread::CreateThread()
{
printf("");
if (!m_thread)
m_thread = std::unique_ptr<std::thread>(new std::thread(&WorkerThread::Process, this));
return true;
......@@ -50,6 +52,9 @@ void WorkerThread::Process()
timerThread.join();
return;
}
case MESSAGE:{
std::cout << "Task with message " << task->msg << " is being processed ..." << std::endl;
}
}
// switch (msg->id)
// {
......@@ -82,9 +87,6 @@ void WorkerThread::Process()
void WorkerThread::PostTask(std::shared_ptr<Task> task)
{
assert(m_thread);
// Create a new ThreadMsg
// Add user data msg to queue and notify worker thread
std::unique_lock<std::mutex> lk(m_mutex);
m_queue.push(task);
m_cv.notify_one();
......
......@@ -25,17 +25,24 @@
//#include <TransformationGrid.h>
//
//#include <fstream>
#include <Engine.h>
#include <thread>
#include <chrono>
#include <GPUManager.h>
#include <Density.h>
BOOST_AUTO_TEST_CASE(gpu_management_test)
using namespace std::chrono_literals;
BOOST_AUTO_TEST_CASE(general_engine_test)
{
printf(" ==================================== GPU Management Test =================================\n");
printf(" ======================================== Engine Test =====================================\n");
printf(" ============================= ++++++++++++++++++++++++++++++++ ===========================\n");
GPUManager manager;
Density density = Density::from_mrc(&manager,"test/TauA_3.47A_map.mrc",0);
// std::pair<float3,float3> effective_translational_shift;
Engine engine;
engine.startWorkers();
engine.submitTask(std::shared_ptr<Task>(new Task("Yay0")),0);
engine.submitTask(std::shared_ptr<Task>(new Task("Yay1")),1);
engine.submitTask(std::shared_ptr<Task>(new Task("Yay2")),2);
engine.submitTask(std::shared_ptr<Task>(new Task("Yay3")),3);
std::this_thread::sleep_for(1s);
engine.killWorkers();
// std::pair<float3,float3> effective_translational_shift;
// effective_translational_shift.first = {0,0,0};
// effective_translational_shift.second = {2,2,2};
// float trans_offset[3] = {1,1,1};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment