Skip to content

Instantly share code, notes, and snippets.

@mryoshio
Created July 5, 2014 11:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mryoshio/4f81cb9f96d84dca731a to your computer and use it in GitHub Desktop.
Save mryoshio/4f81cb9f96d84dca731a to your computer and use it in GitHub Desktop.
double comp4(vector<double>& v) // vが十分大きい場合に多くのタスクを開始
{
if (v.size() < 10000) // concurrencyにする価値があるか?
return;
accum(v.begin(), v.end(), 0.0);
auto v0 = &v[0];
auto sz = v.size();
auto f0 = async(accum, v0, v0 + sz/4, 0.0); // 1st quarter
auto f1 = async(accum, v0 + sz/4, v0 + sz/2, 0.0); // 2nd quarter
auto f2 = async(accum, v0 + sz/2, v0 + sz*3/4, 0.0); // 3rd quarter
auto f3 = async(accum, v0 + sz*3/4, v0 + sz, 0.0); // 4th quarter
return f0.get() + f1.get() + f2.get() + f3.get(); // 結果を集めて結合
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment