我寫了Wpf代碼來使用隨機變量生成正態分佈。c#中的Parallel.for不起作用
using System.Threading.Tasks;
using System.Threading;
private void Button_Click(object sender, RoutedEventArgs e)
{ .....
for (int t = 0; t < normalx.Count; t++)
{
normaly.Insert(t, (2/((Math.Pow(2 * Math.PI, 0.5)) * rmsnormalvalue)) * Math.Exp(-0.5 * Math.Pow(standardnormalx.ElementAt(t), 2)));
}
...
}
這是後綴代碼。
要作爲並行線程運行,我把它改爲
Parallel.For(0, normalx.Count, t =>
{
normaly.Insert(t, (2/((Math.Pow(2 * Math.PI, 0.5)) * rmsnormalvalue)) * Math.Exp(-0.5 * Math.Pow(standardnormalx.ElementAt(t), 2)));
});
但建設是好的,但在運行時只有一個線程區域(normalx.Count/8
< - 我的電腦是I7)
是工作和計算。
什麼問題?
什麼是'正常',它是線程安全的? – 2012-04-04 06:38:25