2.2.2 parallel_for_each版的Credit Review

2013-10-07 15:22:19 · 作者: · 浏览: 67

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几乎完全一致。