mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-12-27 22:14:57 +03:00
start of multithreading in moses2
This commit is contained in:
parent
c0d74aa1bd
commit
3040fe57b0
@ -33,16 +33,20 @@ int main(int argc, char** argv)
|
||||
|
||||
istream &inStream = GetInputStream(params);
|
||||
|
||||
Moses::ThreadPool pool(4);
|
||||
cerr << "system.numThreads=" << system.numThreads << endl;
|
||||
|
||||
Moses::ThreadPool pool(system.numThreads);
|
||||
|
||||
string line;
|
||||
while (getline(inStream, line)) {
|
||||
boost::shared_ptr<TranslationTask> task(new TranslationTask(system, line));
|
||||
|
||||
//pool.Submit(task);
|
||||
task->Run();
|
||||
pool.Submit(task);
|
||||
//task->Run();
|
||||
}
|
||||
|
||||
pool.Stop(true);
|
||||
|
||||
if (inStream != cin) {
|
||||
delete &inStream;
|
||||
}
|
||||
|
@ -64,6 +64,8 @@ const Hypothesis *Manager::GetBestHypothesis() const
|
||||
|
||||
void Manager::Decode()
|
||||
{
|
||||
Init();
|
||||
|
||||
const Moses::Bitmap &initBitmap = m_bitmaps->GetInitialBitmap();
|
||||
Hypothesis *initHypo = Hypothesis::Create(*this);
|
||||
initHypo->Init(*m_initPhrase, m_initRange, initBitmap);
|
||||
|
@ -32,9 +32,6 @@ public:
|
||||
,m_initRange(NOT_FOUND, NOT_FOUND)
|
||||
{}
|
||||
|
||||
// must be run in same thread as Decode()
|
||||
void Init();
|
||||
|
||||
virtual ~Manager();
|
||||
|
||||
MemPool &GetPool() const
|
||||
@ -73,6 +70,9 @@ protected:
|
||||
Stacks m_stacks;
|
||||
SearchNormal *m_search;
|
||||
|
||||
// must be run in same thread as Decode()
|
||||
void Init();
|
||||
|
||||
void CalcFutureScore();
|
||||
};
|
||||
|
||||
|
@ -7,6 +7,8 @@
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <boost/foreach.hpp>
|
||||
#include <boost/thread.hpp>
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include "System.h"
|
||||
#include "FF/FeatureFunction.h"
|
||||
#include "TranslationModel/UnknownWordPenalty.h"
|
||||
@ -20,7 +22,8 @@ System::System(const Moses::Parameter ¶msArg)
|
||||
,featureFunctions(*this)
|
||||
|
||||
{
|
||||
params.SetParameter(stackSize, "stack", Moses::DEFAULT_MAX_HYPOSTACK_SIZE);
|
||||
ini_performance_options();
|
||||
params.SetParameter(stackSize, "stack", Moses::DEFAULT_MAX_HYPOSTACK_SIZE);
|
||||
params.SetParameter(maxDistortion, "distortion-limit", -1);
|
||||
params.SetParameter(maxPhraseLength, "max-phrase-length",
|
||||
Moses::DEFAULT_MAX_PHRASE_LENGTH);
|
||||
@ -95,3 +98,42 @@ Recycler<Hypothesis*> &System::GetHypoRecycle() const
|
||||
return *pool;
|
||||
}
|
||||
|
||||
void
|
||||
System
|
||||
::ini_performance_options()
|
||||
{
|
||||
const Moses::PARAM_VEC *paramsVec;
|
||||
// m_parameter->SetParameter<size_t>(m_timeout_threshold, "time-out", -1);
|
||||
// m_timeout = (GetTimeoutThreshold() == (size_t)-1) ? false : true;
|
||||
|
||||
numThreads = 1;
|
||||
paramsVec = params.GetParam("threads");
|
||||
if (paramsVec && paramsVec->size()) {
|
||||
if (paramsVec->at(0) == "all") {
|
||||
#ifdef WITH_THREADS
|
||||
numThreads = boost::thread::hardware_concurrency();
|
||||
if (!numThreads) {
|
||||
std::cerr << "-threads all specified but Boost doesn't know how many cores there are";
|
||||
throw;
|
||||
}
|
||||
#else
|
||||
std::cerr << "-threads all specified but moses not built with thread support";
|
||||
return false;
|
||||
#endif
|
||||
} else {
|
||||
numThreads = Moses::Scan<int>(paramsVec->at(0));
|
||||
if (numThreads < 1) {
|
||||
std::cerr << "Specify at least one thread.";
|
||||
throw;
|
||||
}
|
||||
#ifndef WITH_THREADS
|
||||
if (numThreads > 1) {
|
||||
std::cerr << "Error: Thread count of " << params->at(0)
|
||||
<< " but moses not built with thread support";
|
||||
throw
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -39,11 +39,15 @@ public:
|
||||
size_t stackSize;
|
||||
int maxDistortion;
|
||||
size_t maxPhraseLength;
|
||||
int numThreads;
|
||||
|
||||
protected:
|
||||
mutable boost::thread_specific_ptr<MemPool> m_managerPool;
|
||||
mutable boost::thread_specific_ptr<Recycler<Hypothesis*> > m_hypoRecycle;
|
||||
|
||||
void LoadWeights();
|
||||
void LoadMappings();
|
||||
|
||||
void ini_performance_options();
|
||||
};
|
||||
|
||||
|
@ -15,7 +15,6 @@ TranslationTask::~TranslationTask()
|
||||
|
||||
void TranslationTask::Run()
|
||||
{
|
||||
m_mgr->Init();
|
||||
m_mgr->Decode();
|
||||
|
||||
const Hypothesis *bestHypo = m_mgr->GetBestHypothesis();
|
||||
|
Loading…
Reference in New Issue
Block a user