none
Can I make this faster - Parallel RRS feed

  • Question

  •                         Dim skPoints As New List(Of SketchPoint)
                            Dim skPointsCache As New List(Of Point)
                            For Each sl As SketchLine In skLines
                                sl.Construction = True
                                Dim booDuplicate As Boolean = False
                                Dim startPoint As Point = sl.StartSketchPoint.Geometry3d
                                Dim endPoint As Point = sl.EndSketchPoint.Geometry3d
                                For i As Integer = skPointsCache.Count - 1 To 0 Step -1
                                    Dim skp As Point = skPointsCache(i)
                                    If Distance(skp, startPoint) < 0.0625 Then
                                        booDuplicate = True
                                        Exit For
                                    End If
                                Next
                                If booDuplicate = False Then
                                    skPoints.Add(sl.StartSketchPoint)
                                    skPointsCache.Add(startPoint)
                                End If
                                booDuplicate = False
                                For i As Integer = skPointsCache.Count - 1 To 0 Step -1
                                    Dim skp As Point = skPointsCache(i)
                                    If Distance(skp, endPoint) < 0.0625 Then
                                        booDuplicate = True
                                        Exit For
                                    End If
                                Next
                                If booDuplicate = False Then
                                    skPoints.Add(sl.EndSketchPoint)
                                    skPointsCache.Add(endPoint)
                                End If
                            Next

    I have a loop for lines (2 points = 1 line) that compares start/endpoints on a junk distance (< 1/16 unit), then adds the unique points to a list.  Each loop is taking over 1000ms(still!).  I am looking for ways to speed things up, because it shouldn't take this long.  Time is lost using the Inventor API to get the points (approx. 30-60ms), so I cached them, and used my own distance formula (approx. 7ms) to get the distance between 3d points.  Overall that didn't really help.

    Can anybody see a pattern where I can use some parallel computing to get a unique list of points?

    Thanks,

    jvj

    Friday, May 25, 2018 8:17 PM

Answers

  • I guess it can be made faster:

    Dim skPoints As New List(Of SketchPoint)
                            Dim skPointsCache As New List(Of Point)
                            System.Threading.Tasks.Parallel.ForEach(skLines,
                                Sub(sl)
                                    Dim booDuplicate As Boolean = False
                                    Dim startPoint As Point = sl.StartSketchPoint.Geometry3d
                                    Dim endPoint As Point = sl.EndSketchPoint.Geometry3d
                                    For i As Integer = skPointsCache.Count - 1 To 0 Step -1
                                        Dim skp As Point = skPointsCache(i)
                                        If Distance(skp, startPoint) < 0.0625 Then
                                            booDuplicate = True
                                            Exit For
                                        End If
                                    Next
                                    If booDuplicate = False Then
                                        SyncLock skPoints
                                            skPoints.Add(sl.StartSketchPoint)
                                        End SyncLock
                                        SyncLock skPointsCache
                                            skPointsCache.Add(startPoint)
                                        End SyncLock
                                    End If
                                    booDuplicate = False
                                    For i As Integer = skPointsCache.Count - 1 To 0 Step -1
                                        Dim skp As Point = skPointsCache(i)
                                        If Distance(skp, endPoint) < 0.0625 Then
                                            booDuplicate = True
                                            Exit For
                                        End If
                                    Next
                                    If booDuplicate = False Then
                                        SyncLock skPoints
                                            skPoints.Add(sl.EndSketchPoint)
                                        End SyncLock
                                        SyncLock skPointsCache
                                            skPointsCache.Add(endPoint)
                                        End SyncLock
                                    End If
                                End Sub)
    It worked better than I thought it would putting the entire first loop into a parallel foreach.

    Friday, May 25, 2018 9:00 PM