2.1   Automatic Parallelization

If HALCON is used on multi-processor or multi-core hardware, it will automatically parallelize image processing operators. Section “Initializing HALCON” describes how to initialize HALCON in order to use this mechanism. Section “The Methods of Automatic Parallelization” explains the different methods which are used by HALCON operators for their automatic parallelization.

2.1.1   Initializing HALCON

In order to adapt the parallelization mechanism optimally to the actual hardware, HALCON needs to examine this hardware once. Afterwards, HALCON programs will be automatically parallelized without needing any further action on your part. Even existing HALCON programs will run and be parallelized without needing to be changed.

You trigger this initial examination by calling the operator optimize_aop (see the corresponding entry in the HALCON Reference Manuals for further information). Note, that this operator will only work correctly if called on a multi-core or multi-processor hardware; if you call the operator on a single-processor or single-core computer, it will return an error message. As a shortcut, you may call the executable hcheck_parallel which resides in the directory %HALCONROOT%\bin\%HALCONARCH%.

Upon calling optimize_aop, HALCON examines every operator that can be sped up in principle by an automatic parallelization. Each examined operator is processed several times - both sequentially and in parallel - with a changing set of input parameter values, e.g., images. The latter helps to evaluate dependencies between an operator's input parameter characteristics (e.g. the size of an input image) and the efficiency of its parallel processing. Note that this examination may take some hours, depending on your computer and the optimization parameters!

The extracted information is stored in the file .aop_info in the common application data folder (under Windows) or in the HALCON installation directory $HALCONROOT (under Linux). Please note, that on some operating systems you need special privileges to initialize HALCON successfully, otherwise the operator optimize_aop is not able to store the extracted information. Note that in order to execute command line tools with administrator privileges under Windows Vista and higher, you will need to select “Run as Administrator” (even if you are already logged in as administrator).

Please refer to the examples in the directory %HALCONEXAMPLES%\hdevelop\System\Parallelization for more information about optimize_aop and about other operators that allow to query and modify the parallelization information.

2.1.2   The Methods of Automatic Parallelization

For the automatic parallelization of operators, HALCON exploits data parallelism, i.e., the property that parts of the input data of an operator can be processed independently of each other. Data parallelism can be found at four levels:

  1. tuple level
    If an operator is called with iconic input parameters containing tuples, i.e., arrays of images, regions, or XLDs, it can be parallelized by distributing the tuple elements, i.e., the individual images, regions, or XLDs, on parallel threads. This method requires that all input parameters contain the same number of tuple elements (or contain a single iconic object or value).

  2. channel level
    If an operator is called with input images containing multiple channels, it can be parallelized by distributing the channels on parallel threads. This method requires that all input image objects contain the same number of channels or a single channel image.

  3. domain level
    An operator supporting this level can be parallelized by dividing its domain and distributing its parts on parallel threads.

  4. internal data level
    Only parts of the operator are parallelized. The actual degree of parallelization depends on the implementation of the operator. As a result, the potential speedup on multi-core systems varies among operators utilizing this parallelization method.

The description of a HALCON operator in the Reference Manuals contains an entry called 'Execution Information', which specifies its behavior when using HALCON on a multi-core or multi-processor hardware. This entry indicates whether the operator will be automatically parallelized by HALCON and by which method (tuple, channel, domain, internal data).

The parallelization method of an arbitrary operator opname can also be determined using get_operator_info:

  get_operator_info('opname', 'parallel_method', Information)