Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
43 Views

SharedPtr

I see that DAAL comes with its own smart pointer implementation (daal::SharedPtr). I have a couple of questions about this:

1. It appears not to be thread-safe - is this correct?

2. Sometimes I have a SharedPtr<NumericTable> that I would like to cast to a SharedPtr<HomogenNumericTable> so that I can use the getArray method (for example). With a C++11 shared_pointer, I would use dynamic_pointer_cast. Is there a way to do something similar here?

3. Are there any plans to make changes to the SharedPtr implementation between the beta and the release?

Many thanks!

0 Kudos
8 Replies
Highlighted
Employee
43 Views

For question 2, there is a 'dynamicPointerCast' function available. See its details in 'daal_shared_ptr.h':

We are checking questions 1 and 3 and will provide answers here soon.

0 Kudos
Highlighted
Employee
43 Views

1. That is true, current implementation is not thread-safe. That was a design decision because of performance considerations.

Do you have a usecase in which you need this property?

3. Due to active development stage and implementing of feedbacks from first beta releases, changes in implementation of SharedPtr are possible.

0 Kudos
Highlighted
Beginner
43 Views

Hi Ilya and Zhang,

Thanks for the responses!

Regarding 2, thanks for pointing me to dynamicPointerCast - I had not spotted it.

Regarding 1, I'm attempting to use DAAL within another codebase which makes use of threads. It would be more convenient if SharedPtr were thread-safe, to avoid having to do something to ensure that operations on shared pointers are serialised.

Though I'm not working in Java, I wonder how this is handled in the Java API (as I understand it is quite common to use threads to perform tasks in Java applications) - is there some convenient workaround used there? Or is it a requirement also for Java applications to only use a single thread in their interactions with DAAL as well?

0 Kudos
Highlighted
Employee
43 Views

Thanks, Graham, for your comments.

We have taken your inputs into considerations and analyze approaches to implement thread-safety support in the Shared Pointer.

We will keep you updated on the results of the analysis and next steps.

0 Kudos
Highlighted
Beginner
43 Views

Hi Ilya,

Many thanks!

0 Kudos
Highlighted
Beginner
43 Views

Hi I am trying to use dynamicPointerCast to convert from result of PCA analysis to HomogenNumericTable so that i can use getArray.

But it doesn't seem to work. The sharedPtr returned is a null pointer. Can anyone please shed some light? The code is written as below. 

 

services::SharedPtr<HomogenNumericTable<float> > eigenvals = services::dynamicPointerCast<HomogenNumericTable<float>, NumericTable>(result->get(pca::eigenvalues));

 

 

Many Thanks!

0 Kudos
Highlighted
Beginner
43 Views

Okay I figured it out.

The result of PCA is of double format, even though the input is of float format. So following changes make it work:

 

services::SharedPtr<HomogenNumericTable<double> > eigenvals = services::dynamicPointerCast<HomogenNumericTable<double>, NumericTable>(result->get(pca::eigenvalues));

0 Kudos
Highlighted
Employee
43 Views

Hello,

I assume you use double precision version of PCA algorithm by declaring pca::Batch<> algorithm; By default, the algorithm allocates the double precision Homogeneous Tables for results. At the same time the interface of the library is flexible enough to choose the precision of either algorithm or the result of the algorithm. Say, if you need the computations to be done in single precision  pca::Batch<float> algorithm; By default, the algorithm allocates single precision Homogeneous Tables for results. If you need computations in double precision and single precision results, please use double precision version of the algorithm, allocate PCA Result object, create and register respective single precision tables for eigen- values and eigen-vectors in it and pass respective Result object into PCA algorithm using its setResult() method. Please, let me know, if you need more details and code samples that demonstrate this use case.

Andrey

0 Kudos