C++ API Reference for Intel® Data Analytics Acceleration Library 2019 Update 5

svd_distributed.h
1 /* file: svd_distributed.h */
2 /*******************************************************************************
3 * Copyright 2014-2019 Intel Corporation.
4 *
5 * This software and the related documents are Intel copyrighted materials, and
6 * your use of them is governed by the express license under which they were
7 * provided to you (License). Unless the License provides otherwise, you may not
8 * use, modify, copy, publish, distribute, disclose or transmit this software or
9 * the related documents without Intel's prior written permission.
10 *
11 * This software and the related documents are provided as is, with no express
12 * or implied warranties, other than those that are expressly stated in the
13 * License.
14 *******************************************************************************/
15 
16 /*
17 //++
18 // Implementation of the interface of the SVD algorithm in the distributed processing mode
19 //--
20 */
21 
22 #ifndef __SVD_DISTRIBUTED_H__
23 #define __SVD_DISTRIBUTED_H__
24 
25 #include "algorithms/algorithm.h"
26 #include "data_management/data/numeric_table.h"
27 #include "services/daal_defines.h"
28 #include "algorithms/svd/svd_types.h"
29 #include "algorithms/svd/svd_online.h"
30 
31 namespace daal
32 {
33 namespace algorithms
34 {
35 namespace svd
36 {
37 
38 namespace interface1
39 {
54 template<ComputeStep step, typename algorithmFPType, Method method, CpuType cpu>
55 class DAAL_EXPORT DistributedContainer
56 {};
57 
66 template<typename algorithmFPType, Method method, CpuType cpu>
67 class DAAL_EXPORT DistributedContainer<step1Local, algorithmFPType, method, cpu> : public
68  OnlineContainer<algorithmFPType, method, cpu>
69 {
70 public:
72  DistributedContainer(daal::services::Environment::env *daalEnv) : OnlineContainer<algorithmFPType, method, cpu>(daalEnv) {}
74  virtual ~DistributedContainer() {}
75 };
76 
85 template<typename algorithmFPType, Method method, CpuType cpu>
86 class DAAL_EXPORT DistributedContainer<step2Master, algorithmFPType, method, cpu> :
87  public daal::algorithms::AnalysisContainerIface<distributed>
88 {
89 public:
95  DistributedContainer(daal::services::Environment::env *daalEnv);
97  virtual ~DistributedContainer();
102  virtual services::Status compute() DAAL_C11_OVERRIDE;
107  virtual services::Status finalizeCompute() DAAL_C11_OVERRIDE;
108 };
109 
118 template<typename algorithmFPType, Method method, CpuType cpu>
119 class DAAL_EXPORT DistributedContainer<step3Local, algorithmFPType, method, cpu> :
120  public daal::algorithms::AnalysisContainerIface<distributed>
121 {
122 public:
128  DistributedContainer(daal::services::Environment::env *daalEnv);
130  virtual ~DistributedContainer();
135  virtual services::Status compute() DAAL_C11_OVERRIDE;
140  virtual services::Status finalizeCompute() DAAL_C11_OVERRIDE;
141 };
142 
155 template<ComputeStep step, typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = defaultDense>
156 class DAAL_EXPORT Distributed : public daal::algorithms::Analysis<distributed> {};
157 
169 template<typename algorithmFPType, Method method>
170 class DAAL_EXPORT Distributed<step1Local, algorithmFPType, method> : public Online<algorithmFPType, method>
171 {
172 public:
173  typedef Online<algorithmFPType, method> super;
174 
175  typedef typename super::InputType InputType;
176  typedef typename super::ParameterType ParameterType;
177  typedef typename super::ResultType ResultType;
178  typedef typename super::PartialResultType PartialResultType;
179 
180  Distributed() : Online<algorithmFPType, method>() {}
181 
188  Distributed(const Distributed<step1Local, algorithmFPType, method> &other) :
189  Online<algorithmFPType, method>(other)
190  {}
191 
197  services::SharedPtr<Distributed<step1Local, algorithmFPType, method> > clone() const
198  {
199  return services::SharedPtr<Distributed<step1Local, algorithmFPType, method> >(cloneImpl());
200  }
201 
202 protected:
203  virtual Distributed<step1Local, algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
204  {
205  return new Distributed<step1Local, algorithmFPType, method>(*this);
206  }
207 };
208 
220 template<typename algorithmFPType, Method method>
221 class DAAL_EXPORT Distributed<step2Master, algorithmFPType, method> : public daal::algorithms::Analysis<distributed>
222 {
223 public:
224  typedef algorithms::svd::DistributedStep2Input InputType;
225  typedef algorithms::svd::Parameter ParameterType;
226  typedef algorithms::svd::Result ResultType;
227  typedef algorithms::svd::DistributedPartialResult PartialResultType;
228 
229  InputType input;
230  ParameterType parameter;
232  Distributed()
233  {
234  initialize();
235  }
236 
243  Distributed(const Distributed<step2Master, algorithmFPType, method> &other) : input(other.input), parameter(other.parameter)
244  {
245  initialize();
246  }
247 
252  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int)method; }
253 
258  ResultPtr getResult()
259  {
260  return _partialResult->get(finalResultFromStep2Master);
261  }
262 
267  DistributedPartialResultPtr getPartialResult()
268  {
269  return _partialResult;
270  }
271 
275  services::Status setPartialResult(const DistributedPartialResultPtr& partialRes)
276  {
277  DAAL_CHECK(partialRes, services::ErrorNullPartialResult);
278  DAAL_CHECK(partialRes->get(finalResultFromStep2Master), services::ErrorNullResult)
279  _partialResult = partialRes;
280  _pres = _partialResult.get();
281  return services::Status();
282  }
283 
287  services::Status checkFinalizeComputeParams() DAAL_C11_OVERRIDE
288  {
289  if(!_partialResult)
290  return services::Status(services::ErrorNullResult);
291  return _partialResult->check(_par, method);
292  }
293 
299  services::SharedPtr<Distributed<step2Master, algorithmFPType, method> > clone() const
300  {
301  return services::SharedPtr<Distributed<step2Master, algorithmFPType, method> >(cloneImpl());
302  }
303 
304 protected:
305  virtual Distributed<step2Master, algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
306  {
307  return new Distributed<step2Master, algorithmFPType, method>(*this);
308  }
309 
310  virtual services::Status allocateResult() DAAL_C11_OVERRIDE{ return services::Status(); }
311 
312  virtual services::Status allocatePartialResult() DAAL_C11_OVERRIDE
313  {
314  _partialResult.reset(new PartialResultType());
315  services::Status s = _partialResult->allocate<algorithmFPType>(_in, 0, 0);
316  _pres = _partialResult.get();
317  return s;
318  }
319 
320  virtual services::Status initializePartialResult() DAAL_C11_OVERRIDE
321  {
322  _pres = _partialResult.get();
323  return services::Status();
324  }
325 
326  void initialize()
327  {
328  Analysis<distributed>::_ac = new __DAAL_ALGORITHM_CONTAINER(distributed, DistributedContainer, step2Master, algorithmFPType, method)(&_env);
329  _in = &input;
330  _par = &parameter;
331  }
332 
333 private:
334  DistributedPartialResultPtr _partialResult;
335 };
336 
348 template<typename algorithmFPType, Method method>
349 class DAAL_EXPORT Distributed<step3Local, algorithmFPType, method> : public
350  daal::algorithms::Analysis<distributed>
351 {
352 public:
353  typedef algorithms::svd::DistributedStep3Input InputType;
354  typedef algorithms::svd::Parameter ParameterType;
355  typedef algorithms::svd::Result ResultType;
356  typedef algorithms::svd::DistributedPartialResultStep3 PartialResultType;
357 
358  InputType input;
359  ParameterType parameter;
361  Distributed()
362  {
363  initialize();
364  }
365 
372  Distributed(const Distributed<step3Local, algorithmFPType, method> &other) : input(other.input), parameter(other.parameter)
373  {
374  initialize();
375  }
376 
381  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int)method; }
382 
387  ResultPtr getResult()
388  {
389  return _partialResult->get(finalResultFromStep3);
390  }
391 
396  DistributedPartialResultStep3Ptr getPartialResult()
397  {
398  return _partialResult;
399  }
400 
405  services::Status setPartialResult(const DistributedPartialResultStep3Ptr& partialRes)
406  {
407  DAAL_CHECK(partialRes, services::ErrorNullPartialResult);
408  DAAL_CHECK(partialRes->get(finalResultFromStep3), services::ErrorNullResult)
409  _partialResult = partialRes;
410  _pres = _partialResult.get();
411  return services::Status();
412  }
413 
418  services::Status setResult(const ResultPtr& res) { return services::Status(); }
419 
423  services::Status checkFinalizeComputeParams() DAAL_C11_OVERRIDE
424  {
425  if(!_partialResult)
426  return services::Status(services::ErrorNullResult);
427  return _partialResult->check(_par, method);
428  }
429 
435  services::SharedPtr<Distributed<step3Local, algorithmFPType, method> > clone() const
436  {
437  return services::SharedPtr<Distributed<step3Local, algorithmFPType, method> >(cloneImpl());
438  }
439 
440 protected:
441  virtual Distributed<step3Local, algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
442  {
443  return new Distributed<step3Local, algorithmFPType, method>(*this);
444  }
445 
446  virtual services::Status allocatePartialResult() DAAL_C11_OVERRIDE
447  {
448  _partialResult.reset(new PartialResultType());
449 
450  services::Status s = _partialResult->allocate<algorithmFPType>(_in, 0, 0);
451  if(!s)
452  return s;
453 
454  data_management::DataCollectionPtr qCollection = input.get(inputOfStep3FromStep1);
455 
456  s = _partialResult->setPartialResultStorage<algorithmFPType>(qCollection.get());
457 
458  _pres = _partialResult.get();
459  return s;
460  }
461 
462  virtual services::Status allocateResult() DAAL_C11_OVERRIDE{ return services::Status(); }
463 
464  virtual services::Status initializePartialResult() DAAL_C11_OVERRIDE{ return services::Status(); }
465 
466  void initialize()
467  {
468  Analysis<distributed>::_ac = new __DAAL_ALGORITHM_CONTAINER(distributed, DistributedContainer, step3Local, algorithmFPType, method)(&_env);
469  _in = &input;
470  _par = &parameter;
471  }
472 
473 private:
474  DistributedPartialResultStep3Ptr _partialResult;
475 };
477 } // namespace interface1
478 using interface1::DistributedContainer;
479 using interface1::Distributed;
480 
481 } // namespace daal::algorithms::svd
482 } // namespace daal::algorithms
483 } // namespace daal
484 #endif
daal::algorithms::svd::interface1::Distributed< step1Local, algorithmFPType, method >::clone
services::SharedPtr< Distributed< step1Local, algorithmFPType, method > > clone() const
Definition: svd_distributed.h:197
daal::algorithms::svd::interface1::Distributed< step3Local, algorithmFPType, method >::setResult
services::Status setResult(const ResultPtr &res)
Definition: svd_distributed.h:418
daal::algorithms::svd::interface1::Distributed< step3Local, algorithmFPType, method >::clone
services::SharedPtr< Distributed< step3Local, algorithmFPType, method > > clone() const
Definition: svd_distributed.h:435
daal::algorithms::svd::interface1::Distributed< step1Local, algorithmFPType, method >
Runs the first step of the SVD algorithm in the distributed processing mode.
Definition: svd_distributed.h:170
daal
Definition: algorithm_base_common.h:31
daal::algorithms::AnalysisContainerIface
Abstract interface class that provides virtual methods to access and run implementations of the analy...
Definition: analysis.h:53
daal::algorithms::svd::interface1::Online
Computes results of the SVD algorithm in the online processing mode.
Definition: svd_online.h:88
daal::algorithms::svd::interface1::Distributed< step2Master, algorithmFPType, method >::clone
services::SharedPtr< Distributed< step2Master, algorithmFPType, method > > clone() const
Definition: svd_distributed.h:299
daal::algorithms::svd::inputOfStep3FromStep1
Definition: svd_types.h:147
daal::services::ErrorNullPartialResult
Definition: error_indexes.h:105
daal::algorithms::svd::interface1::Distributed< step2Master, algorithmFPType, method >::setPartialResult
services::Status setPartialResult(const DistributedPartialResultPtr &partialRes)
Definition: svd_distributed.h:275
daal_defines.h
daal::algorithms::svd::interface1::Distributed< step3Local, algorithmFPType, method >
Runs the third step of the SVD algorithm in the distributed processing mode.
Definition: svd_distributed.h:349
daal::algorithms::svd::interface1::Distributed< step2Master, algorithmFPType, method >
Runs the second step of the SVD algorithm in the distributed processing mode.
Definition: svd_distributed.h:221
daal::algorithms::svd::interface1::Distributed< step2Master, algorithmFPType, method >::checkFinalizeComputeParams
services::Status checkFinalizeComputeParams() DAAL_C11_OVERRIDE
Definition: svd_distributed.h:287
daal::algorithms::svd::interface1::DistributedContainer
Provides methods to run implementations of the SVD algorithm.
Definition: svd_distributed.h:55
daal::algorithms::kmeans::init::interface2::Distributed
class DAAL_EXPORT Distributed
Computes initial clusters for the K-Means algorithm in the distributed processing mode...
Definition: kmeans_init_distributed.h:275
daal::distributed
Definition: daal_defines.h:111
daal::algorithms::svd::interface1::Distributed< step3Local, algorithmFPType, method >::input
InputType input
Definition: svd_distributed.h:358
daal::algorithms::svd::interface1::DistributedContainer< step1Local, algorithmFPType, method, cpu >::~DistributedContainer
virtual ~DistributedContainer()
Definition: svd_distributed.h:74
daal::algorithms::svd::interface1::Distributed< step2Master, algorithmFPType, method >::parameter
ParameterType parameter
Definition: svd_distributed.h:230
daal::algorithms::svd::interface1::Distributed< step3Local, algorithmFPType, method >::getPartialResult
DistributedPartialResultStep3Ptr getPartialResult()
Definition: svd_distributed.h:396
daal::algorithms::svd::finalResultFromStep2Master
Definition: svd_types.h:116
daal::algorithms::svd::interface1::DistributedContainer< step1Local, algorithmFPType, method, cpu >::DistributedContainer
DistributedContainer(daal::services::Environment::env *daalEnv)
Definition: svd_distributed.h:72
daal::algorithms::svd::interface1::Distributed< step2Master, algorithmFPType, method >::input
InputType input
Definition: svd_distributed.h:229
daal::algorithms::svd::interface1::Distributed< step2Master, algorithmFPType, method >::getResult
ResultPtr getResult()
Definition: svd_distributed.h:258
daal::algorithms::svd::interface1::Distributed< step3Local, algorithmFPType, method >::parameter
ParameterType parameter
Definition: svd_distributed.h:359
daal::algorithms::svd::interface1::Distributed< step3Local, algorithmFPType, method >::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: svd_distributed.h:381
daal::algorithms::svd::interface1::Distributed< step2Master, algorithmFPType, method >::getPartialResult
DistributedPartialResultPtr getPartialResult()
Definition: svd_distributed.h:267
daal::algorithms::svd::interface1::OnlineContainer
Provides methods to run implementations of the SVD algorithm in the online processing mode...
Definition: svd_online.h:53
daal::algorithms::svd::interface1::Distributed< step3Local, algorithmFPType, method >::setPartialResult
services::Status setPartialResult(const DistributedPartialResultStep3Ptr &partialRes)
Definition: svd_distributed.h:405
daal::algorithms::svd::interface1::Distributed< step3Local, algorithmFPType, method >::getResult
ResultPtr getResult()
Definition: svd_distributed.h:387
daal::algorithms::svd::interface1::Distributed< step3Local, algorithmFPType, method >::Distributed
Distributed(const Distributed< step3Local, algorithmFPType, method > &other)
Definition: svd_distributed.h:372
daal::algorithms::Analysis
Provides methods for execution of operations over data, such as computation of Summary Statistics est...
Definition: analysis.h:68
daal::algorithms::svd::interface1::Distributed< step1Local, algorithmFPType, method >::Distributed
Distributed(const Distributed< step1Local, algorithmFPType, method > &other)
Definition: svd_distributed.h:188
daal::algorithms::kmeans::interface1::DistributedContainer
class DAAL_EXPORT DistributedContainer
Provides methods to run implementations of the K-Means algorithm. This class is associated with the d...
Definition: kmeans_distributed.h:55
daal::step1Local
Definition: daal_defines.h:121
daal::algorithms::svd::finalResultFromStep3
Definition: svd_types.h:127
daal::algorithms::svd::interface1::Distributed< step2Master, algorithmFPType, method >::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: svd_distributed.h:252
daal::algorithms::svd::interface1::Distributed< step3Local, algorithmFPType, method >::checkFinalizeComputeParams
services::Status checkFinalizeComputeParams() DAAL_C11_OVERRIDE
Definition: svd_distributed.h:423
daal::step2Master
Definition: daal_defines.h:122
daal::algorithms::svd::interface1::Distributed< step2Master, algorithmFPType, method >::Distributed
Distributed(const Distributed< step2Master, algorithmFPType, method > &other)
Definition: svd_distributed.h:243
daal::step3Local
Definition: daal_defines.h:123
daal::algorithms::svd::interface1::Distributed
Computes results of the SVD algorithm in the distributed processing mode.
Definition: svd_distributed.h:156
daal::services::ErrorNullResult
Definition: error_indexes.h:96

For more complete information about compiler optimizations, see our Optimization Notice.