我有一個小程序,使用各種卡片計數策略實現了BlackJack的蒙特卡羅模擬。我的主要功能基本上是這樣的:Boost.Thread沒有加速?
int bankroll = 50000;
int hands = 100;
int tests = 10000;
Simulation::strategy = hi_lo;
for(int i = 0; i < simulations; ++i)
runSimulation(bankroll, hands, tests, strategy);
整個程序在我的機器上運行一個線程大約需要10秒。
我想帶3芯我的處理器已經所以我決定重寫程序,只需執行在單獨的線程的各種戰略這樣的優勢:
int bankroll = 50000;
int hands = 100;
int tests = 10000;
Simulation::strategy = hi_lo;
boost::thread threads[simulations];
for(int i = 0; i < simulations; ++i)
threads[i] = boost::thread(boost::bind(runSimulation, bankroll, hands, tests, strategy));
for(int i = 0; i < simulations; ++i)
threads[i].join();
然而,當我跑這個程序,即使我得到了相同的結果,但大約需要24秒才能完成。我在這裏錯過了什麼嗎?
您是否檢查程序是否實際上使用了所有內核? – 2011-05-20 03:34:09