VS2010で並列パターンライブラリを使い始めましたが、アプリケーションは期待どおりの結果をもたらしますが、デバッグバージョンとリリースバージョンをベンチマークすると、次のようにリリースバージョンで奇妙な実行時間が発生します。デバッグバージョン: "シーケンシャルデュレーション:1014" "パラレルデュレーション:437 "リリースバージョン"シーケンシャルデュレーション:31 ""パラレルデュレーション:484 "
これは私のアプリケーションコードです
double DoWork(int workload)
{
double result=0;
for(int i =0 ; i < workload;i++)
{
result +=sqrt((double)i * 4*3) + i* i;
}
return result;
}
vector<double> Seqential()
{
vector<double> results(100);
for(int i = 0 ; i <100 ; i++)
{
results[i] = DoWork(1000000);
}
return results;
}
vector<double> Parallel()
{
vector<double> results(100);
parallel_for(0,(int)100,1,[&results](int i)
{
results[i] = DoWork(1000000);
});
return results;
}
double Sum(const vector<double>& results)
{
double result =0;
for(int i = 0 ; i < results.size();i++)
result += results[i];
return result;
}
int main()
{
DWORD start = GetTickCount();
vector<double> results = Seqential();
DWORD duration = GetTickCount() - start;
cout<<"Sequential Duration : "<<duration <<" Result : " <<Sum(results) << endl;
start = GetTickCount();
results = Parallel();
duration = GetTickCount() - start;
cout<<"Prallel Duration : "<<duration <<" Result : " <<Sum(results) << endl;
system("PAUSE");
return 0;
}