设为首页 加入收藏

TOP

2.2.2 parallel_for_each版的Credit Review
2013-10-07 15:22:19 来源: 作者: 【 】 浏览:66
Tags:2.2.2 parallel_for_each Credit Review

2.2.2   parallel_for_each版的Credit Review

并行版的信用度分析程序与串行版本几乎相差无几:

  1. void UpdatePredictionsParallel(AccountRepository& accounts)  
  2. {  
  3.     parallel_for_each(accounts.begin(), accounts.end(),  
  4.     [   ]  
  5.     (AccountRepository::value_type& record)  
  6.     {  
  7.         Account& account = record.second;  
  8.         Trend trend = Fit(account.Balances());  
  9.         double prediction = PredictIntercept(trend,  
  10.             (account.Balances().size() + g_predictionWindow));  
  11.         account.ParPrediction() = prediction;  
  12.         account.ParWarning() = prediction < account.GetOverdraft();  
  13.     });  

如你所见,除了用parallel_for_each替代for_each外,UpdatePredictionsParallel方法的代码与UpdatePredictionsSequential几乎完全一致。

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇1.2.1 理解任务 下一篇2.1.2 parallel_for_each

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: