From 771b4bdbc3473a9c90fc8d11d3382608e50ef669 Mon Sep 17 00:00:00 2001 From: Chris Dyer Date: Sat, 16 Apr 2011 02:40:31 -0400 Subject: llh computer --- training/Makefile.am | 5 +---- training/compute_cllh.cc | 24 +++++++++++++++++++----- 2 files changed, 20 insertions(+), 9 deletions(-) (limited to 'training') diff --git a/training/Makefile.am b/training/Makefile.am index 5f3b9bc4..5697043b 100644 --- a/training/Makefile.am +++ b/training/Makefile.am @@ -12,6 +12,7 @@ bin_PROGRAMS = \ mpi_online_optimize \ mpi_batch_optimize \ mpi_em_optimize \ + compute_cllh \ augment_grammar noinst_PROGRAMS = \ @@ -29,12 +30,8 @@ mpi_batch_optimize_LDADD = $(top_srcdir)/decoder/libcdec.a $(top_srcdir)/mteval/ mpi_em_optimize_SOURCES = mpi_em_optimize.cc optimize.cc mpi_em_optimize_LDADD = $(top_srcdir)/decoder/libcdec.a $(top_srcdir)/mteval/libmteval.a $(top_srcdir)/utils/libutils.a ../klm/lm/libklm.a ../klm/util/libklm_util.a -lz -if MPI -bin_PROGRAMS += compute_cllh - compute_cllh_SOURCES = compute_cllh.cc compute_cllh_LDADD = $(top_srcdir)/decoder/libcdec.a $(top_srcdir)/mteval/libmteval.a $(top_srcdir)/utils/libutils.a ../klm/lm/libklm.a ../klm/util/libklm_util.a -lz -endif cllh_filter_grammar_SOURCES = cllh_filter_grammar.cc cllh_filter_grammar_LDADD = $(top_srcdir)/decoder/libcdec.a $(top_srcdir)/mteval/libmteval.a $(top_srcdir)/utils/libutils.a ../klm/lm/libklm.a ../klm/util/libklm_util.a -lz diff --git a/training/compute_cllh.cc b/training/compute_cllh.cc index f25e17c3..332f6d0c 100644 --- a/training/compute_cllh.cc +++ b/training/compute_cllh.cc @@ -5,8 +5,10 @@ #include #include -#include +#include "config.h" +#ifdef HAVE_MPI #include +#endif #include #include @@ -22,7 +24,7 @@ using namespace std; namespace po = boost::program_options; -void InitCommandLine(int argc, char** argv, po::variables_map* conf) { +bool InitCommandLine(int argc, char** argv, po::variables_map* conf) { po::options_description opts("Configuration options"); opts.add_options() ("weights,w",po::value(),"Input feature weights file") @@ -45,9 +47,9 @@ void InitCommandLine(int argc, char** argv, po::variables_map* conf) { if (conf->count("help") || !conf->count("training_data") || !conf->count("decoder_config")) { cerr << dcmdline_options << endl; - MPI::Finalize(); - exit(1); + return false; } + return true; } void ReadTrainingCorpus(const string& fname, int rank, int size, vector* c, vector* ids) { @@ -125,18 +127,26 @@ struct TrainingObserver : public DecoderObserver { int state; }; +#ifdef HAVE_MPI namespace mpi = boost::mpi; +#endif int main(int argc, char** argv) { +#ifdef HAVE_MPI mpi::environment env(argc, argv); mpi::communicator world; const int size = world.size(); const int rank = world.rank(); +#else + const int size = 1; + const int rank = 0; +#endif if (size > 1) SetSilent(true); // turn off verbose decoder output register_feature_functions(); po::variables_map conf; - InitCommandLine(argc, argv, &conf); + if (!InitCommandLine(argc, argv, &conf)) + return false; // load initial weights Weights weights; @@ -176,7 +186,11 @@ int main(int argc, char** argv) { decoder.Decode(corpus[i], &observer); } +#ifdef HAVE_MPI reduce(world, observer.acc_obj, objective, std::plus(), 0); +#else + objective = observer.acc_obj; +#endif if (rank == 0) cout << "OBJECTIVE: " << objective << endl; -- cgit v1.2.3