summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Dyer <cdyer@cs.cmu.edu>2011-04-16 02:40:31 -0400
committerChris Dyer <cdyer@cs.cmu.edu>2011-04-16 02:40:31 -0400
commit771b4bdbc3473a9c90fc8d11d3382608e50ef669 (patch)
treef4734afc672e6c93e9227a835575e334126ff9ff
parentfb205d034960c42c37475318d39631ff6e2c7357 (diff)
llh computer
-rw-r--r--training/Makefile.am5
-rw-r--r--training/compute_cllh.cc24
2 files changed, 20 insertions, 9 deletions
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 <cassert>
#include <cmath>
-#include <mpi.h>
+#include "config.h"
+#ifdef HAVE_MPI
#include <boost/mpi.hpp>
+#endif
#include <boost/program_options.hpp>
#include <boost/program_options/variables_map.hpp>
@@ -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<string>(),"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<string>* c, vector<int>* 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<double>(), 0);
+#else
+ objective = observer.acc_obj;
+#endif
if (rank == 0)
cout << "OBJECTIVE: " << objective << endl;