Symmetric Multi-Processing In Parasolid   

<<< Calling Parasolid From Multiple Threads Chapters Session Support >>>

Contents

[back to top]


114.1 What is Symmetric Multi-Processing?

Symmetric Multi-Processing (or SMP) allows algorithms beneath the Parasolid API to make use of multiple processors if they are present on a host machine. A number of functional areas within Parasolid have been adapted for SMP, making it possible to reduce the execution time of certain operations, thereby improving the performance of Parasolid when running on multi-processor systems.

Parasolid SMP is enabled on the most widely used Parasolid platforms. For a complete list, see Section 5.6, “Symmetric Multi-Processing (SMP)”, in the Parasolid Installation Notes. Parasolid makes use of Win32 threads on Microsoft Windows platforms, and POSIX threads on UNIX and Linux platforms.

This chapter describes:

For information on how to call multiple PK functions simultaneously from different application threads, and the restrictions that apply when doing so, see Chapter 113, “Calling Parasolid From Multiple Threads”.

[back to top]


114.2 Setting up and using Parasolid SMP

This section explains how to switch SMP on in a Parasolid session, how to configure it best for your own use, and discusses issues related to your application source code that you need to consider when making use of Parasolid’s SMP.

For more information on many of the issues described in this section, See Section 5.6, “Symmetric Multi-Processing (SMP)”, of the Parasolid Installation Notes.

114.2.1 Enabling SMP within Parasolid

SMP operation within Parasolid is controlled via the following functions:

 

Function

Description

PK_SESSION_set_smp

Enable and disable Parasolid SMP

PK_SESSION_ask_smp

Return the current session’s SMP parameters

You use PK_SESSION_set_smp to enable SMP in Parasolid. By default, Parasolid SMP is configured to:

These are the recommended settings for Parasolid SMP and will be sufficient for most cases. Section 5.6.1, “Guidelines for setting the number of threads” in the Parasolid Installation Notes, contains further information on how you can choose the optimum number of threads for your platform and application.

 

Note: Currently, Parasolid can create a maximum of 8 threads for SMP work.

Parasolid SMP can be enabled or disabled at any time during a session. Once SMP has been enabled in a Parasolid session, most functional areas that can benefit from SMP will do so automatically. However, some specific PK functions may also require certain options to be set within the function in addition to SMP being enabled at the session level: for example, PK_TOPOL_facet_2 requires you to set options.choice.smp to PK_facet_smp_body_c (see Section 109.3, “Tabular faceting and threads”). For specific details on a per function basis, see the PK Interface Programming Reference Manual.

114.2.2 Determining the maximum number of SMP threads used in a session

You can use PK_SESSION_ask_max_threads to determine the maximum number of SMP threads that Parasolid can use in a current session. Knowing the number of threads that Parasolid can use in a session allows you to determine how many threads are available for your application to use.

The number of threads returned depends on the maximum number of SMP threads that Parasolid can work with (currently 8) and the values returned in the thread_format , n_threads , and n_processors options of PK_SESSION_ask_smp. For more information on how this number is calculated, see the reference documentation for PK_SESSION_ask_max_threads.

 

Note: If SMP is disabled then the maximum number of threads is 1.

114.2.3 Setting the stack size of SMP threads

Depending on the platform that your application runs on, you may need to specify the stack size of threads used by Parasolid SMP. Although the default stack size for the system is usually sufficient, this is not always the case.

The following functions allow you to set and enquire the stack size of Parasolid SMP threads:

 

Function

Description

PK_SESSION_set_smp_stacksize

Sets the size of the stack allocated to Parasolid SMP threads.

PK_SESSION_ask_smp_stacksize

Returns the size of the stack allocated to Parasolid SMP threads.

For both functions, a zero value means that the platform default stack size is used.

Guidelines for setting appropriate stack sizes on different supported platforms can be found in Section 5.5, “Stack sizes”, of the Installation Notes.

114.2.4 Memory usage with Parasolid SMP

When using SMP in Parasolid, expect to need more memory than you would for a single-processor machine. With SMP enabled, Parasolid generally requires more temporary workspace in main memory during SMP-accelerated operations. For example, with two threads, it can require twice as much workspace.

If this extra space causes Parasolid’s requirements to exceed the physical memory of the machine - thus causing the operating system to start swapping data between disk and main memory - the resulting performance is normally worse than if Parasolid was running with a single thread.

 

Note: This only applies to temporary workspace used during calls to Parasolid; the memory needed to hold a given model is essentially the same for single- or multi-threaded operation.

114.2.5 Order of returned entities

Whether Parasolid SMP is enabled or not, the vast majority of PK functions do not guarantee the order of returned entities. Enabling SMP in a session is likely to result in the order of returned entities being different compared to the order if SMP is not enabled. The table below describes some examples:

 

Functional area

Description

Booleans

If a boolean operation results in several distinct bodies being created, the order of the bodies returned may vary when SMP is enabled. This also applies to the tag persistence rules with respect to the value of the target body tag being applied to any one of the returned bodies.

For example, if Parasolid SMP is enabled and a boolean subtract operation returns more than one resultant body, Parasolid does not guarantee:

  • the order of the returned bodies;
  • which resultant body inherits the value of the target body tag.

Body checking

If PK_BODY_check returns several errors, the order of the errors in the return structure may vary if SMP is enabled in a Parasolid session.

Wire-frame sketching

When generating wire-frame data via the Graphical Output (GO) with SMP enabled, Parasolid does not guarantee the order of information output via the GO. More specifically:

  • The state of Parasolid SMP has no effect on the sequence of calls to the GO functions GOOPSG and GOCLSG to open and close a hierarchical data segment.
  • The order of calls to the GO function GOSGMT to output a non-hierarchical data segment may vary depending on the state of SMP within Parasolid.

For example, when sketching a body:

  • GOOPSG is invoked to indicate the start of the segment;
  • GOSGMT is invoked for each line segment drawn (edges, hatching of faces and silhouettes). If SMP is enabled, the line segments of one face may be interspersed with the line segments from another face;
  • GOCLSG is invoked to indicate the end of the segment.

Regardless of whether or not you use Parasolid SMP, you should ensure that your application code is sufficiently robust to deal with changes to the order of returned entities. You can use the debug functions PK_DEBUG_shuffle_start and PK_DEBUG_shuffle_stop to help test the robustness of your code in this area.

Whenever reporting faults to Parasolid Support, always specify whether or not Parasolid SMP is enabled.

[back to top]


114.3 Expectations from Parasolid SMP

In general, it is not possible to quote a figure for the general performance improvement achieved by using SMP, since this improvement depends on the nature of the operations you are performing.

SMP is implemented beneath the API level, typically in low-level internal algorithms. These algorithms typically only form part of the code path called by a given PK function and may be invoked to different degrees depending on the nature of the received arguments passed by the application to the PK function. The reduction in execution time is affected accordingly. For these reasons, you should not expect an automatic 50% speed up at the PK function level when enabling SMP on a two processor machine.

Similarly, due to the nature of SMP, the scaling of performance with an increased number of processors is not expected to be linear. For example, if you see a 20% performance improvement for a particular function call on a 2 processor machine, this does not automatically mean that you would see a 40% performance improvement on a 4 processor machine.

Finally, the entity level at which SMP has an effect varies from one functional area to another. For example:

114.3.1 Thread locking

The overhead of thread locking can mean that some functions on some platforms will actually run slightly slower with SMP enabled than with SMP disabled. We strive to minimise this in our implementation and work in collaboration with hardware vendors to do the same. If you do find functions that run excessively slowly, the Parasolid team is happy to investigate these on a case by case basis.

114.3.2 Functional areas that are SMP-enabled

The following table shows the main functional areas and/or PK functions that can benefit from Parasolid SMP being enabled.

 

Note: The presence of a PK function or functional area in this list does not guarantee a performance improvement when SMP is enabled. Conversely, the absence of a PK function or functional area does not preclude a benefit being seen from enabling SMP.

 

Functional area

PK function where applicable

Notes

Validity checking

PK_BODY_check and where checking is called internally as part of a PK function call.

Implemented at the face level.

Boolean operations

Various.

Implemented for face-face clashing portion of algorithm.

Wireframe rendering

PK_TOPOL_render_line

Implemented at the body occurrence level

Hidden line rendering

PK_TOPOL_render_line

Implemented at the body level during initial processing and at an intersection level during line/line intersection.

Closest approach

PK_GEOM_range_vector_many

Multiple points must be supplied.

PK_TOPOL_range

Computing distance between two bodies.

Faceting

PK_TOPOL_facet_2, PK_TOPOL_render_facet

Implemented at the body level. You must set the smp option (PK_TOPOL_facet_2) or the go_interleaved option (PK_TOPOL_render_facet) to enable SMP.

Mass properties

PK_TOPOL_eval_mass_props

 

Spline creation

PK_BCURVE_create_spline_2

Must fit at least one position to a tolerance, or set have_chordal_tol to PK_LOGICAL_true.

Isocline generation

PK_FACE_imprint_cus_isoclin, PK_SURF_make_cus_isocline

Generating isocline curves.

B-geometry creation

PK_CURVE_make_bcurve_array
PK_SURF_make_bsurf_array

 

114.3.3 Failure to create worker threads

If at any time the operating system cannot create worker threads for Parasolid SMP, this is reported using a PK_REPORT_1_osthread_fail_c record in the Parasolid report.

If the operating system subsequently resumes creating worker threads, this is reported using a PK_REPORT_1_osthread_ok_c record.

If worker threads cannot be created, Parasolid performs the work they would have done in the thread used to call Parasolid. This is slower than using worker threads, but permits the operation to complete successfully.

See Chapter 11, “Using Reports”, for information about using the Parasolid report mechanism.

 

[back to top]

<<< Calling Parasolid From Multiple Threads Chapters Session Support >>>