加速(Speedup)是在多核機器上運行應用程式(相比單核機器)所能夠預期的性能收益。
基本介紹
- 中文名:加速
- 外文名:Speedup
- 適用範圍:多核心或者多個硬體執行緒的CPU
- 適用領域:計算機並行編程
定義
應用程式加速定律
阿姆德爾定律
古斯塔夫森定律
程式示例
Imports System.Threading.TasksModule MainConWin32 Private Sum As UInteger = 0 Sub Main() Dim serialFor As Action = Sub() Console.WriteLine(New String(vbCrLf & "[" & Now & "] Serial Operation...")) For Number As UInteger = 2 To UInteger.MaxValue Step 1 For Div As UInteger = 1 To Number - 1 Step 1 If Number Mod Div = 0 Then Sum = Sum + Div End If Next Div If Sum = Number Then Console.WriteLine(Number & Space(3) & "Time=" & TimeOfDay) Sum = 0 Next Number End Sub Dim parallelFor As Action = Sub() Console.WriteLine(New String(vbCrLf & "[" & Now & "] Parallel Operation...")) Parallel.For(2, UInteger.MaxValue + 1, _ Sub(index) Parallel.For(1, index, Sub(s_index) If index Mod s_index = 0 Then Sum = Sum + s_index End If End Sub) If Sum = index Then Console.WriteLine(index & Space(3) & "Time=" & TimeOfDay) Sum = 0 End Sub) End Sub Console.WriteLine(New String("找完數" & vbCrLf)) Console.Write(New String("請選擇執行操作的方式 ( 0=並行計算,1=串列計算 ):")) Dim readChar As Char = ChrW(Console.Read) If readChar = "0" Then Task.Factory.StartNew(parallelFor).Wait() ElseIf readChar = "1" Then Task.Factory.StartNew(serialFor).Wait() Else Console.WriteLine(New String(vbCrLf & "選擇錯誤,默認將執行串列操作!!!")) Task.Factory.StartNew(serialFor).Wait() End If End SubEnd Module