Repository: incubator-singa Updated Branches: refs/heads/master 809798a09 -> 316c65bcd
SINGA-94 Move call to google::InitGoogleLogging() from Driver::Init() to main(). It appears that google::InitGoogleLogging() was never intended to be called inside a library. The reason is because calling google::InitGoogleLogging() twice results in program termination with the error log "You called InitGoogleLogging() twice!". Calling google::InitGoogleLogging() inside Driver::Init() prevents users of the Singa library from making this call in their own main() function, as recommended by glog documentation. Project: http://git-wip-us.apache.org/repos/asf/incubator-singa/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-singa/commit/4abee35a Tree: http://git-wip-us.apache.org/repos/asf/incubator-singa/tree/4abee35a Diff: http://git-wip-us.apache.org/repos/asf/incubator-singa/diff/4abee35a Branch: refs/heads/master Commit: 4abee35a1aa2b9425c4a823a4c37ded641c00115 Parents: f66bf46 Author: Yee Fan <[email protected]> Authored: Tue Oct 20 03:59:55 2015 +0800 Committer: Yee Fan <[email protected]> Committed: Tue Oct 20 03:59:55 2015 +0800 ---------------------------------------------------------------------- src/driver.cc | 7 +++---- src/main.cc | 6 ++++++ 2 files changed, 9 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/4abee35a/src/driver.cc ---------------------------------------------------------------------- diff --git a/src/driver.cc b/src/driver.cc index ba65d3e..336a2b5 100644 --- a/src/driver.cc +++ b/src/driver.cc @@ -64,17 +64,16 @@ extern "C" void openblas_set_num_threads(int num); namespace singa { void Driver::Init(int argc, char **argv) { - google::InitGoogleLogging(argv[0]); - // unique job ID generated from singa-run.sh, passed in as "-singa_job <id>" + // unique job ID generated from singa-run.sh, passed in as "-singa_job <id>" int arg_pos = ArgPos(argc, argv, "-singa_job"); job_id_ = (arg_pos != -1) ? atoi(argv[arg_pos+1]) : -1; - // global signa conf passed by singa-run.sh as "-singa_conf <path>" + // global signa conf passed by singa-run.sh as "-singa_conf <path>" arg_pos = ArgPos(argc, argv, "-singa_conf"); if (arg_pos != -1) ReadProtoFromTextFile(argv[arg_pos+1], &singa_conf_); else ReadProtoFromTextFile("conf/singa.conf", &singa_conf_); - // job conf passed by users as "-conf <path>" + // job conf passed by users as "-conf <path>" arg_pos = ArgPos(argc, argv, "-conf"); CHECK_NE(arg_pos, -1); ReadProtoFromTextFile(argv[arg_pos+1], &job_conf_); http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/4abee35a/src/main.cc ---------------------------------------------------------------------- diff --git a/src/main.cc b/src/main.cc index 53b3a4c..fc094ad 100644 --- a/src/main.cc +++ b/src/main.cc @@ -20,7 +20,9 @@ *************************************************************/ #include <iostream> +#include <glog/logging.h> #include "singa/singa.h" + /** * \file main.cc provides an example main function. * @@ -51,6 +53,10 @@ int main(int argc, char **argv) { << "-test\t test performance or extract features\n"; return 0; } + + // initialize glog before creating the driver + google::InitGoogleLogging(argv[0]); + // must create driver at the beginning and call its Init method. singa::Driver driver; driver.Init(argc, argv);
