2010-05-20 20:02:06 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2010 Thorsten Liebig (Thorsten.Liebig@gmx.de)
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef OPERATOR_MULTITHREAD_H
|
|
|
|
#define OPERATOR_MULTITHREAD_H
|
|
|
|
|
|
|
|
#include "operator_sse_compressed.h"
|
|
|
|
|
2010-06-05 09:50:13 +00:00
|
|
|
#include <boost/thread.hpp>
|
|
|
|
|
2010-05-20 20:02:06 +00:00
|
|
|
class Operator_Multithread : public Operator_SSE_Compressed
|
|
|
|
{
|
2010-09-02 20:16:37 +00:00
|
|
|
friend class Engine_Multithread;
|
2010-06-05 09:50:13 +00:00
|
|
|
friend class Operator_Thread;
|
2010-05-20 20:02:06 +00:00
|
|
|
public:
|
|
|
|
//! Create a new operator
|
2010-06-05 09:50:13 +00:00
|
|
|
static Operator_Multithread* New(unsigned int numThreads = 0);
|
2010-05-20 20:02:06 +00:00
|
|
|
virtual ~Operator_Multithread();
|
|
|
|
|
2010-10-27 12:49:16 +00:00
|
|
|
virtual int CalcECOperator( DebugFlags debugFlags = None );
|
2010-06-05 09:50:13 +00:00
|
|
|
|
|
|
|
virtual void setNumThreads( unsigned int numThreads );
|
|
|
|
|
2010-05-20 20:02:06 +00:00
|
|
|
virtual Engine* CreateEngine() const;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
Operator_Multithread();
|
2010-06-05 09:50:13 +00:00
|
|
|
virtual void Init();
|
|
|
|
virtual void Reset();
|
|
|
|
|
|
|
|
virtual bool Calc_EC(); //this method is using multi-threading
|
|
|
|
|
2010-06-05 23:47:32 +00:00
|
|
|
unsigned int (*m_Nr_PEC_thread)[3]; //count PEC edges per thread
|
|
|
|
virtual bool CalcPEC(); //this method is using multi-threading
|
|
|
|
|
|
|
|
//Calc_EC barrier
|
2010-06-05 09:50:13 +00:00
|
|
|
boost::barrier* m_CalcEC_Start;
|
|
|
|
boost::barrier* m_CalcEC_Stop;
|
2010-06-05 23:47:32 +00:00
|
|
|
//CalcPEC barrier
|
|
|
|
boost::barrier* m_CalcPEC_Start;
|
|
|
|
boost::barrier* m_CalcPEC_Stop;
|
|
|
|
|
2010-06-05 09:50:13 +00:00
|
|
|
boost::thread_group m_thread_group;
|
|
|
|
unsigned int m_numThreads; // number of worker threads
|
2010-09-03 10:14:25 +00:00
|
|
|
|
|
|
|
//! Calculate the start/stop lines for the multithreading operator and engine.
|
|
|
|
/*!
|
|
|
|
It depends on the number of threads and number of lines to simulate.
|
|
|
|
This method is also used by the multithreading engine!
|
|
|
|
This method may also reduce the usable number of thread in case of too few lines or otherwise bad utilization.
|
|
|
|
*/
|
|
|
|
virtual void CalcStartStopLines(unsigned int &numThreads, vector<unsigned int> &start, vector<unsigned int> &stop) const;
|
2010-06-05 09:50:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class Operator_Thread
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Operator_Thread( Operator_Multithread* ptr, unsigned int start, unsigned int stop, unsigned int threadID );
|
|
|
|
void operator()();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
unsigned int m_start, m_stop, m_threadID;
|
|
|
|
Operator_Multithread *m_OpPtr;
|
2010-05-20 20:02:06 +00:00
|
|
|
};
|
|
|
|
|
2010-06-05 09:50:13 +00:00
|
|
|
|
2010-05-20 20:02:06 +00:00
|
|
|
#endif // OPERATOR_MULTITHREAD_H
|