|
|
#include <iostream> |
|
|
#include <memory> |
|
|
#include <boost/pool/pool_alloc.hpp> |
|
|
#include "Main.h" |
|
|
#include "System.h" |
|
|
#include "Phrase.h" |
|
|
#include "TranslationTask.h" |
|
|
#include "MemPoolAllocator.h" |
|
|
#ifdef HAVE_XMLRPC_C |
|
|
#include "server/Server.h" |
|
|
#endif |
|
|
|
|
|
#include "legacy/InputFileStream.h" |
|
|
#include "legacy/Parameter.h" |
|
|
#include "legacy/ThreadPool.h" |
|
|
#include "legacy/Timer.h" |
|
|
#include "legacy/Util2.h" |
|
|
#include "util/usage.hh" |
|
|
|
|
|
using namespace std; |
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char** argv) |
|
|
{ |
|
|
cerr << "Starting..." << endl; |
|
|
|
|
|
Moses2::Timer timer; |
|
|
timer.start(); |
|
|
|
|
|
|
|
|
Moses2::Parameter params; |
|
|
if (!params.LoadParam(argc, argv)) { |
|
|
return EXIT_FAILURE; |
|
|
} |
|
|
Moses2::System system(params); |
|
|
timer.check("Loaded"); |
|
|
|
|
|
if (params.GetParam("show-weights")) { |
|
|
return EXIT_SUCCESS; |
|
|
} |
|
|
|
|
|
|
|
|
Moses2::ThreadPool pool(system.options.server.numThreads, system.cpuAffinityOffset, system.cpuAffinityOffsetIncr); |
|
|
|
|
|
|
|
|
if (params.GetParam("server")) { |
|
|
std::cerr << "RUN SERVER" << std::endl; |
|
|
run_as_server(system); |
|
|
} |
|
|
else { |
|
|
std::cerr << "RUN BATCH" << std::endl; |
|
|
batch_run(params, system, pool); |
|
|
} |
|
|
|
|
|
cerr << "Decoding took " << timer.get_elapsed_time() << endl; |
|
|
|
|
|
cerr << "Finished" << endl; |
|
|
return EXIT_SUCCESS; |
|
|
} |
|
|
|
|
|
|
|
|
void run_as_server(Moses2::System& system) |
|
|
{ |
|
|
#ifdef HAVE_XMLRPC_C |
|
|
Moses2::Server server(system.options.server, system); |
|
|
server.run(system); |
|
|
#else |
|
|
UTIL_THROW2("Moses2 was compiled without xmlrpc-c. " |
|
|
<< "No server functionality available."); |
|
|
#endif |
|
|
} |
|
|
|
|
|
|
|
|
istream &GetInputStream(Moses2::Parameter ¶ms) |
|
|
{ |
|
|
const Moses2::PARAM_VEC *vec = params.GetParam("input-file"); |
|
|
if (vec && vec->size()) { |
|
|
Moses2::InputFileStream *stream = new Moses2::InputFileStream(vec->at(0)); |
|
|
return *stream; |
|
|
} else { |
|
|
return cin; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void batch_run(Moses2::Parameter& params, Moses2::System& system, Moses2::ThreadPool& pool) |
|
|
{ |
|
|
istream& inStream = GetInputStream(params); |
|
|
|
|
|
long translationId = 0; |
|
|
string line; |
|
|
while (getline(inStream, line)) { |
|
|
|
|
|
boost::shared_ptr<Moses2::TranslationTask> task(new Moses2::TranslationTask(system, line, translationId)); |
|
|
|
|
|
|
|
|
pool.Submit(task); |
|
|
|
|
|
++translationId; |
|
|
} |
|
|
|
|
|
pool.Stop(true); |
|
|
|
|
|
if (&inStream != &cin) { |
|
|
delete& inStream; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
void Temp() |
|
|
{ |
|
|
Moses2::MemPool pool; |
|
|
Moses2::MemPoolAllocator<int> a(pool); |
|
|
|
|
|
boost::unordered_set<int, boost::hash<int>, std::equal_to<int>, Moses2::MemPoolAllocator<int> > s(a); |
|
|
s.insert(3); |
|
|
s.insert(4); |
|
|
s.insert(3); |
|
|
s.erase(3); |
|
|
|
|
|
boost::pool_allocator<int> alloc; |
|
|
std::vector<int, boost::pool_allocator<int> > v(alloc); |
|
|
for (int i = 0; i < 1000; ++i) |
|
|
v.push_back(i); |
|
|
|
|
|
v.clear(); |
|
|
boost::singleton_pool<boost::pool_allocator_tag, sizeof(int)>:: |
|
|
purge_memory(); |
|
|
|
|
|
abort(); |
|
|
} |
|
|
|