Providing a Callback for the Host Application#

oneDAL provides a possibility for the host application to register a callback interface to be called by the library, e.g. for the purposes of computation interruption. It is done by means of an abstract interface for the host application of the library HostAppIface. In order to use it, the application should define an instance of the class derived from the abstract interface and set its pointer to an instance of Algorithm class.

Following methods of the Algorithm class are used:

Algorithm class methods#



setHostApp(const services::HostAppIfacePtr& pHost)

Set pHost as the callback interface


Get current value of the callback interface set on the Algorithm

HostAppIface class includes following methods:

HostAppIface class Methods#




Enables computation cancelling. The method is called by the owning algorithm when computation is in progress. If the method returns true then computation stops and returns ErrorUserCancelled status. Since the method can be called from parallel threads when running with oneDAL threaded version, it is application responsibility to make its implementation thread-safe. It is not recommended for this method to throw exceptions.

Currently HostAppIface is supported in C++ only, cancelling is available with limited number of algorithms as follows: decision forest, gradient boosted trees.