When I run a given application and monitor its cpu usage with the windows
task manager I see that it uses 50% of the available cpu resources (the other
50% going to the system idle process).
In an attempt to speed-up the process I split into two threads but still the
entire process only consumes 50% of cpu resources.
How can I make my application consume a significantly higher percentage of
resources.
Here's my actual code for the threaded process (my processor is a
hyperthreading model).
Public Function Hypermultiply(ByVal A_matrix As Double(,), ByVal
B_matrix As Double(,)) As Double(,)
Dim task1 As New threadmultiply
task1.set_matrixA(A_matrix)
task1.set_matrixB(B_matrix)
Dim m As Integer = A_matrix.GetLength(0) - 2
Dim n As Integer = B_matrix.GetLength(1) - 2
Dim p As Integer = A_matrix.GetLength(1) - 2
If (A_matrix.GetLength(1) - 2) <> (B_matrix.GetLength(0) -
2) Then
Throw (New ApplicationException("for A X B, columns in A
and rows in B must be equal"))
End If
task1.Dimension_matrixC(m, n)
'Dim result(m + 1, n + 1) As Double
Dim result As Double(,)
Dim thread1 As New Threading.Thread(AddressOf
task1.process_i_the_1st_half)
Dim thread2 As New Threading.Thread(AddressOf
task1.process_i_the_2nd_half)
thread1.Start()
thread2.Start()
thread1.Join()
thread2.Join()
result = task1.resultC
Return result
End Function
Public Class threadmultiply
Dim arrA As Double(,)
Dim arrB As Double(,)
Dim m As Integer
Dim n As Integer
Dim p As Integer
Dim result As Double(,)
Public ReadOnly Property arrayA() As Double(,)
Get
Return arrA
End Get
End Property
Public Sub set_matrixA(ByVal Source_array As Double(,))
m = Source_array.GetLength(0) - 2
p = Source_array.GetLength(1) - 2
ReDim arrA(m + 1, p + 1)
Array.Copy(Source_array, arrayA(), Source_array.Length)
End Sub
Public ReadOnly Property arrayB() As Double(,)
Get
Return arrB
End Get
End Property
Public Sub set_matrixB(ByVal Source_array As Double(,))
p = Source_array.GetLength(0) - 2
n = Source_array.GetLength(1) - 2
ReDim arrB(p + 1, n + 1)
Array.Copy(Source_array, arrayB(), Source_array.Length)
End Sub
Public ReadOnly Property resultC() As Double(,)
Get
Return result
End Get
End Property
Public Sub Dimension_matrixC(ByVal m As Integer, ByVal n As
Integer)
ReDim result(m + 1, n + 1)
End Sub
Public Sub process_i_the_1st_half()
Dim i, j, k As Integer
For i = 1 To CInt(Floor(m / 2))
For k = 1 To p
For j = 1 To n
result(i, j) = arrayA(i, k) * arrayB(k, j) +
result(i, j)
Next
Next
Next
End Sub
Public Sub process_i_the_2nd_half()
Dim i, j, k As Integer
For i = CInt(Floor(m / 2) + 1) To m
For k = 1 To p
For j = 1 To n
result(i, j) = arrayA(i, k) * arrayB(k, j) +
result(i, j)
Next
Next
Next
End Sub
End Class
--
mark b