Look for solution to do data processing simultaneously for Inventor using VB.NET

Look for solution to do data processing simultaneously for Inventor using VB.NET

liminma8458
Collaborator Collaborator
192 Views
2 Replies
Message 1 of 3

Look for solution to do data processing simultaneously for Inventor using VB.NET

liminma8458
Collaborator
Collaborator

Hi, experts,

 

I am doing some path planning within map-network using inventor and VB.NET. The map is always the same with massive fixed points in a data base. And the pair of start and end points for paths can be hundreds. Through a math algorithm I can calculation shortest path in the map from start to end point for each point pair.  The pseudo code in my current processing is as below:

 

For each Start_End_Point_Set in Start_End_Point_Set_Collection

              Create_Path_Point_List(Start_End_Point_Set, Map_Data, ByRef Point_List_for_Path)

              oCollection(Point_List_for_path)

Next For

 

Right now, because the code runs in single thread and process sequentially, with hundreds of point sets, it may take tens of minutes to calculate all the paths.

Because Start_End_Point_Set_Collection and Map_Data are all in pure math format and pre-known, I wonder whether it is possible to utilize any of multiple thread calculation or parallel calculation or Async Function or Parallel.For loopin VB.NET to make call to Create_Path_Point_List() simultaneously, so to speed up to get the result of path collection much faster?

 

Very appreciated that you can shed some light or give recommendation on this, even better if there is some sample code in VB.NET.

Thanks
Limin
Inventor pro 2026 64 bit; Windows 11 pro 64 bit version 24H2; Office 2016 64 bit

Check into My Apps:
iCable : Create Cables, Hoses, Tubes and Pipes Easily.
iCable Professional : Create and Edit Them, Quick, Easy and Much More.
iCable Electrical : Auto Router to Create Massive Cables Automatically for Electrical Cabinet.
0 Likes
193 Views
2 Replies
Replies (2)
Message 2 of 3

Michael.Navara
Advisor
Advisor

Hello @liminma8458 

I don't know if this is a general question about parallel processing or it depends on Inventor API. If it doesn't depend on API, you can use tasks for parallel processing of your data.

Stupid sample bellow demonstrates usage of Task.Run method. It just calculates count of primes up to given value. It emulates some useful long-time calculations.

The main difference is in methods ProcessSingleThread and ProcessMultiThread .

In the second one I start new Task for each element in testingArgs and finally wait until all tasks are finished.

In this case the performance is significantly improved. SingleThread spend about 11.5 sec and MultiThread only 2.8 sec (approx.)

But don't rejoice prematurely because Task management requires some resources and works well only when you can split your work to independent pieces of work. Communication between tasks are very complicated.

 

Private Sub ProcessSingleThread(testingArgs As Integer())
    Dim i As Integer = 0
    For Each testArg As Integer In testingArgs
        Dim arg = testArg
        Dim id = i
        ProcessArg(id, arg)
        i = i + 1
    Next
End Sub

 

Private Sub ProcessMultiThread(testingArgs As Integer())

    Dim tasks = New List(Of Task)

    Dim i As Integer = 0
    For Each testArg As Integer In testingArgs
        Dim arg = testArg
        Dim id = i
        tasks.Add(Task.Run(Async Function() ProcessArg(id, arg)))
        i = i + 1
    Next

    Task.WaitAll(tasks.ToArray())
End Sub

 

Complete iLogic code sample

Imports System.Threading.Tasks
Imports System.Text

Sub Main()

    Dim testingArgs = {1, 2, 3, 1, 2, 3, 1, 2, 3}

    Logger.Debug("Working...")
    Dim sw = Stopwatch.StartNew()

    'ProcessSingleThread(testingArgs)
    ProcessMultiThread(testingArgs)

    sw.Stop()
    Dim duration = sw.Elapsed.TotalSeconds

    Logger.Debug(taskLog.ToString())
    Logger.Debug("Done in {0:N2} sec", duration)

End Sub

Private taskLog As New StringBuilder()

Private Sub ProcessSingleThread(testingArgs As Integer())
    Dim i As Integer = 0
    For Each testArg As Integer In testingArgs
        Dim arg = testArg
        Dim id = i
        ProcessArg(id, arg)
        i = i + 1
    Next
End Sub

Private Sub ProcessMultiThread(testingArgs As Integer())

    Dim tasks = New List(Of Task)

    Dim i As Integer = 0
    For Each testArg As Integer In testingArgs
        Dim arg = testArg
        Dim id = i
        tasks.Add(Task.Run(Async Function() ProcessArg(id, arg)))
        i = i + 1
    Next

    Task.WaitAll(tasks.ToArray())
End Sub


Private Function ProcessArg(ByVal id As Integer, ByVal arg As Integer) As Integer
    Dim primesCount As Integer = CalcPrimesCount(arg * 100000)
    taskLog.AppendLine()
    taskLog.AppendFormat("completed id={0} arg={1} count={2}", id, arg, primesCount)
    Return primesCount
End Function

Function CalcPrimesCount(max As Integer) As Integer
    Dim primesCount = 0
    For i As Integer = 2 To max
        Dim isPrime As Boolean = True
        For j As Integer = 2 To i / 2
            If i Mod j = 0 Then
                isPrime = False
                Exit For
            End If
            If isPrime Then primesCount += 1
        Next
    Next
    Return primesCount
End Function

 

0 Likes
Message 3 of 3

liminma8458
Collaborator
Collaborator

Hi, Michael,

Thank you so much!

I will try it out and dig into it.

Thanks
Limin
Inventor pro 2026 64 bit; Windows 11 pro 64 bit version 24H2; Office 2016 64 bit

Check into My Apps:
iCable : Create Cables, Hoses, Tubes and Pipes Easily.
iCable Professional : Create and Edit Them, Quick, Easy and Much More.
iCable Electrical : Auto Router to Create Massive Cables Automatically for Electrical Cabinet.
0 Likes