From d76ae7353bb988de9e7cbb56ff41fb02a467fe0e Mon Sep 17 00:00:00 2001 From: "lperron@google.com" Date: Sat, 31 Mar 2012 00:35:19 +0000 Subject: [PATCH] scale mtsearch_test --- examples/tests/mtsearch_test.cc | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/examples/tests/mtsearch_test.cc b/examples/tests/mtsearch_test.cc index d8a7c202ef..7fab67edf4 100644 --- a/examples/tests/mtsearch_test.cc +++ b/examples/tests/mtsearch_test.cc @@ -13,6 +13,8 @@ #include "constraint_solver/constraint_solver.h" #include "constraint_solver/constraint_solveri.h" +DEFINE_int32(workers, 4, "Number of workers for tests"); + namespace operations_research { class UpVar : public BaseLNS { public: @@ -56,7 +58,7 @@ void BuildModelWithSolution(int* const active, solution->SetValue(x, 2); solution->SetValue(y, 4); support->RegisterInitialSolution(solution); - ThreadSafeIncrement(active, mutex, 1); + ThreadSafeIncrement(active, mutex, 2); VLOG(1) << "Master initial solution sent"; } else { VLOG(1) << "Slave " << worker; @@ -76,7 +78,7 @@ void BuildModelWithoutSolution(int* const active, Solver s(StringPrintf("Worker_%i", worker)); if (master) { support->RegisterNoInitialSolution(); - ThreadSafeIncrement(active, mutex, 1); + ThreadSafeIncrement(active, mutex, 2); } else { Assignment* const solution = s.MakeAssignment(); CHECK(!support->WaitForInitialSolution(solution, worker)); @@ -156,11 +158,10 @@ void BuildModelWithSearch(int workers, void TestInitialSolution() { LOG(INFO) << "TestInitialSolution"; - const int kWorkers = 4; int work_done = 0; Mutex mutex; scoped_ptr support( - MakeMtSolveSupport(kWorkers, + MakeMtSolveSupport(FLAGS_workers, false, NewPermanentCallback( &BuildModelWithSolution, @@ -168,34 +169,32 @@ void TestInitialSolution() { &mutex))); support->Run(); - CHECK_EQ(kWorkers + 1, work_done); + CHECK_EQ(FLAGS_workers + 2, work_done); } void TestNoInitialSolution() { LOG(INFO) << "TestNoInitialSolution"; - const int kWorkers = 4; int work_done = 0; Mutex mutex; scoped_ptr support( - MakeMtSolveSupport(kWorkers, + MakeMtSolveSupport(FLAGS_workers, false, NewPermanentCallback( &BuildModelWithoutSolution, &work_done, &mutex))); support->Run(); - CHECK_EQ(kWorkers + 1, work_done); + CHECK_EQ(FLAGS_workers + 2, work_done); } void TestModelWithSearch() { LOG(INFO) << "TestModelWithSearch"; - const int kSlaves = 4; scoped_ptr support( - MakeMtSolveSupport(kSlaves, + MakeMtSolveSupport(FLAGS_workers, true, NewPermanentCallback( &BuildModelWithSearch, - kSlaves))); + FLAGS_workers))); support->Run(); } } // namespace operations_research