Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/moses-smt/mgiza.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoredwardgao <edwardgao@9a26d1b7-1c8f-445c-8fdd-6576f508279d>2012-06-09 07:46:10 +0400
committeredwardgao <edwardgao@9a26d1b7-1c8f-445c-8fdd-6576f508279d>2012-06-09 07:46:10 +0400
commit2ae875d34ba2c372eb9cb56dc0445c8542a71df8 (patch)
tree4bca939198592c23d826c6c9ae5b5382e9426bb0
parentb0140cf4052ba8454cf0e116c92bd06c8b9d9042 (diff)
Add support for automatic detecting number of threads
-rw-r--r--mgizapp/src/main.cpp17
1 files changed, 15 insertions, 2 deletions
diff --git a/mgizapp/src/main.cpp b/mgizapp/src/main.cpp
index dc46822..cd44526 100644
--- a/mgizapp/src/main.cpp
+++ b/mgizapp/src/main.cpp
@@ -39,6 +39,7 @@
#include "D5Tables.h"
#include "transpair_model4.h"
#include "transpair_model5.h"
+#include <boost/thread/thread.hpp>
#define ITER_M2 0
#define ITER_MH 5
@@ -85,7 +86,7 @@ bool Transfer2to3=0;
short NoEmptyWord=0;
bool FEWDUMPS=0;
GLOBAL_PARAMETER(bool,ONLYALDUMPS,"ONLYALDUMPS","1: do not write any files",PARLEV_OUTPUT,0);
-GLOBAL_PARAMETER(short,NCPUS,"NCPUS","Number of CPUS",PARLEV_EM,2);
+GLOBAL_PARAMETER(short,NCPUS,"NCPUS","Number of threads to be executed, use 0 if you just want all CPUs to be used",PARLEV_EM,0);
GLOBAL_PARAMETER(short,CompactAlignmentFormat,"CompactAlignmentFormat","0: detailled alignment format, 1: compact alignment format ",PARLEV_OUTPUT,0);
GLOBAL_PARAMETER2(bool,NODUMPS,"NODUMPS","NO FILE DUMPS? (Y/N)","1: do not write any files",PARLEV_OUTPUT,0);
@@ -1073,7 +1074,6 @@ int main(int argc, char* argv[]) {
time_t st1, fn;
st1 = time(NULL); // starting time
-// cerr << "---------------- " << endl;
// Program Name
string temp(argv[0]);
@@ -1092,6 +1092,19 @@ int main(int argc, char* argv[]) {
//
parseArguments(argc, argv);
+ // Determine number of threads
+
+ if(NCPUS == 0){
+ cerr << "Trying to detect number of CPUS...";
+ NCPUS = boost::thread::hardware_concurrency();
+ if(NCPUS==0){
+ cerr << "failed, default to 2 threads" << std::endl;
+ NCPUS = 2;
+ }
+ else{
+ cerr << NCPUS << std::endl;
+ }
+ }
cerr << "Opening Log File " << endl;
if (Log) {