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

qr_distributed.h
1 /* file: qr_distributed.h */
2 /*******************************************************************************
3 * Copyright 2014-2018 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 for the QR decomposition algorithm in the
19 // distributed processing mode
20 //--
21 */
22 
23 #ifndef __QR_DISTRIBUTED_H__
24 #define __QR_DISTRIBUTED_H__
25 
26 #include "algorithms/algorithm.h"
27 #include "data_management/data/numeric_table.h"
28 #include "services/daal_defines.h"
29 #include "algorithms/qr/qr_types.h"
30 #include "algorithms/qr/qr_online.h"
31 
32 namespace daal
33 {
34 namespace algorithms
35 {
36 namespace qr
37 {
38 
39 namespace interface1
40 {
55 template<ComputeStep step, typename algorithmFPType, Method method, CpuType cpu>
56 class DAAL_EXPORT DistributedContainer
57 {};
58 
67 template<typename algorithmFPType, Method method, CpuType cpu>
68 class DAAL_EXPORT DistributedContainer<step2Master, algorithmFPType, method, cpu> :
69  public daal::algorithms::AnalysisContainerIface<distributed>
70 {
71 public:
77  DistributedContainer(daal::services::Environment::env *daalEnv);
79  virtual ~DistributedContainer();
84  virtual services::Status compute() DAAL_C11_OVERRIDE;
89  virtual services::Status finalizeCompute() DAAL_C11_OVERRIDE;
90 };
91 
100 template<typename algorithmFPType, Method method, CpuType cpu>
101 class DAAL_EXPORT DistributedContainer<step3Local, algorithmFPType, method, cpu> :
102  public daal::algorithms::AnalysisContainerIface<distributed>
103 {
104 public:
110  DistributedContainer(daal::services::Environment::env *daalEnv);
112  virtual ~DistributedContainer();
117  virtual services::Status compute() DAAL_C11_OVERRIDE;
122  virtual services::Status finalizeCompute() DAAL_C11_OVERRIDE;
123 };
124 
137 template<ComputeStep step, typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = defaultDense>
138 class DAAL_EXPORT Distributed : public daal::algorithms::Analysis<distributed> {};
139 
151 template<typename algorithmFPType, Method method>
152 class DAAL_EXPORT Distributed<step1Local, algorithmFPType, method> : public Online<algorithmFPType, method>
153 {
154 public:
155  typedef Online<algorithmFPType, method> super;
156 
157  typedef typename super::InputType InputType;
158  typedef typename super::ParameterType ParameterType;
159  typedef typename super::ResultType ResultType;
160  typedef typename super::PartialResultType PartialResultType;
161 
162  Distributed() : Online<algorithmFPType, method>() {}
163 
170  Distributed(const Distributed<step1Local, algorithmFPType, method> &other) :
171  Online<algorithmFPType, method>(other)
172  {}
173 
179  services::SharedPtr<Distributed<step1Local, algorithmFPType, method> > clone() const
180  {
181  return services::SharedPtr<Distributed<step1Local, algorithmFPType, method> >(cloneImpl());
182  }
183 
184 protected:
185  virtual Distributed<step1Local, algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
186  {
187  return new Distributed<step1Local, algorithmFPType, method>(*this);
188  }
189 };
190 
202 template<typename algorithmFPType, Method method>
203 class DAAL_EXPORT Distributed<step2Master, algorithmFPType, method> : public daal::algorithms::Analysis<distributed>
204 {
205 public:
206  typedef DistributedStep2Input Input;
207 
208  typedef algorithms::qr::DistributedStep2Input InputType;
209  typedef algorithms::qr::Parameter ParameterType;
210  typedef algorithms::qr::Result ResultType;
211  typedef algorithms::qr::DistributedPartialResult PartialResultType;
212 
213  InputType input;
214  ParameterType parameter;
216  Distributed()
217  {
218  initialize();
219  }
220 
227  Distributed(const Distributed<step2Master, algorithmFPType, method> &other) : input(other.input), parameter(other.parameter)
228  {
229  initialize();
230  }
231 
236  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int)method; }
237 
242  ResultPtr getResult()
243  {
244  return _partialResult->get(finalResultFromStep2Master);
245  }
246 
251  DistributedPartialResultPtr getPartialResult()
252  {
253  return _partialResult;
254  }
255 
260  services::Status setPartialResult(const DistributedPartialResultPtr& partialRes)
261  {
262  DAAL_CHECK(partialRes, services::ErrorNullPartialResult);
263  DAAL_CHECK(partialRes->get(finalResultFromStep2Master), services::ErrorNullResult)
264  _partialResult = partialRes;
265  _pres = _partialResult.get();
266  return services::Status();
267  }
268 
272  services::Status checkFinalizeComputeParams() DAAL_C11_OVERRIDE
273  {
274  if(_partialResult)
275  {
276  return _partialResult->check(_par, method);
277  }
278  else
279  {
280  return services::Status(services::ErrorNullResult);
281  }
282  return services::Status();
283  }
284 
290  services::SharedPtr<Distributed<step2Master, algorithmFPType, method> > clone() const
291  {
292  return services::SharedPtr<Distributed<step2Master, algorithmFPType, method> >(cloneImpl());
293  }
294 
295 protected:
296  virtual Distributed<step2Master, algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
297  {
298  return new Distributed<step2Master, algorithmFPType, method>(*this);
299  }
300 
301  virtual services::Status allocateResult() DAAL_C11_OVERRIDE { return services::Status(); }
302 
303  virtual services::Status allocatePartialResult() DAAL_C11_OVERRIDE
304  {
305  _partialResult.reset(new PartialResultType());
306  services::Status s = _partialResult->allocate<algorithmFPType>(_in, 0, 0);
307  _pres = _partialResult.get();
308  return s;
309  }
310 
311  virtual services::Status initializePartialResult() DAAL_C11_OVERRIDE
312  {
313  _pres = _partialResult.get();
314  return services::Status();
315  }
316 
317  void initialize()
318  {
319  Analysis<distributed>::_ac = new __DAAL_ALGORITHM_CONTAINER(distributed, DistributedContainer, step2Master, algorithmFPType, method)(&_env);
320  _in = &input;
321  _par = &parameter;
322  }
323 
324 private:
325  DistributedPartialResultPtr _partialResult;
326 };
327 
339 template<typename algorithmFPType, Method method>
340 class DAAL_EXPORT Distributed<step3Local, algorithmFPType, method> : public
341  daal::algorithms::Analysis<distributed>
342 {
343 public:
344  typedef DistributedStep3Input Input;
345 
346  typedef algorithms::qr::DistributedStep3Input InputType;
347  typedef algorithms::qr::Parameter ParameterType;
348  typedef algorithms::qr::Result ResultType;
349  typedef algorithms::qr::DistributedPartialResultStep3 PartialResultType;
350 
351  InputType input;
352  ParameterType parameter;
355  Distributed()
356  {
357  initialize();
358  }
359 
366  Distributed(const Distributed<step3Local, algorithmFPType, method> &other) : input(other.input), parameter(other.parameter)
367  {
368  initialize();
369  }
370 
375  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int)method; }
376 
381  ResultPtr getResult()
382  {
383  return _partialResult->get(finalResultFromStep3);
384  }
385 
390  DistributedPartialResultStep3Ptr getPartialResult()
391  {
392  return _partialResult;
393  }
394 
399  services::Status setPartialResult(const DistributedPartialResultStep3Ptr& partialRes)
400  {
401  DAAL_CHECK(partialRes, services::ErrorNullPartialResult);
402  DAAL_CHECK(partialRes->get(finalResultFromStep3), services::ErrorNullResult)
403  _partialResult = partialRes;
404  _pres = _partialResult.get();
405  return services::Status();
406  }
407 
412  services::Status setResult(const ResultPtr& res) { return services::Status();}
413 
417  services::Status checkFinalizeComputeParams() DAAL_C11_OVERRIDE
418  {
419  if(_partialResult)
420  {
421  return _partialResult->check(_par, method);
422  }
423  else
424  {
425  return services::Status(services::ErrorNullResult);
426  }
427  return services::Status();
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) { return s; }
452 
453  data_management::DataCollectionPtr qCollection = input.get(inputOfStep3FromStep1);
454 
455  s = _partialResult->setPartialResultStorage<algorithmFPType>(qCollection.get());
456 
457  _pres = _partialResult.get();
458  return s;
459  }
460 
461  virtual services::Status allocateResult() DAAL_C11_OVERRIDE { return services::Status(); }
462 
463  virtual services::Status initializePartialResult() DAAL_C11_OVERRIDE { return services::Status(); }
464 
465  void initialize()
466  {
467  Analysis<distributed>::_ac = new __DAAL_ALGORITHM_CONTAINER(distributed, DistributedContainer, step3Local, algorithmFPType, method)(&_env);
468  _in = &input;
469  _par = &parameter;
470  }
471 
472 private:
473  DistributedPartialResultStep3Ptr _partialResult;
474 };
476 } // namespace interface1
477 using interface1::DistributedContainer;
478 using interface1::Distributed;
479 
480 } // namespace daal::algorithms::qr
481 } // namespace daal::algorithms
482 } // namespace daal
483 #endif
daal::algorithms::qr::interface1::Distributed< step2Master, algorithmFPType, method >::setPartialResult
services::Status setPartialResult(const DistributedPartialResultPtr &partialRes)
Definition: qr_distributed.h:260
daal::algorithms::qr::interface1::Distributed< step3Local, algorithmFPType, method >::input
InputType input
Definition: qr_distributed.h:351
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::qr::interface1::Distributed< step3Local, algorithmFPType, method >::getPartialResult
DistributedPartialResultStep3Ptr getPartialResult()
Definition: qr_distributed.h:390
daal::algorithms::qr::interface1::Distributed< step2Master, algorithmFPType, method >::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: qr_distributed.h:236
daal::algorithms::qr::finalResultFromStep2Master
Definition: qr_types.h:112
daal::services::ErrorNullPartialResult
Definition: error_indexes.h:105
daal::algorithms::qr::interface1::Distributed< step3Local, algorithmFPType, method >::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: qr_distributed.h:375
daal::algorithms::qr::interface1::Distributed< step1Local, algorithmFPType, method >
Computes the result of the first step of the QR decomposition algorithm in the distributed processing...
Definition: qr_distributed.h:152
daal::algorithms::qr::interface1::DistributedStep3Input
Input objects for the third step of the QR decomposition algorithm in the distributed processing mode...
Definition: qr_types.h:257
daal::algorithms::qr::interface1::Distributed< step2Master, algorithmFPType, method >::input
InputType input
Definition: qr_distributed.h:213
daal::algorithms::qr::inputOfStep3FromStep1
Definition: qr_types.h:143
daal::algorithms::qr::interface1::Distributed
Computes the results of the QR decomposition algorithm in the distributed processing mode...
Definition: qr_distributed.h:138
daal::algorithms::qr::interface1::Distributed< step3Local, algorithmFPType, method >::clone
services::SharedPtr< Distributed< step3Local, algorithmFPType, method > > clone() const
Definition: qr_distributed.h:435
daal::algorithms::qr::interface1::Distributed< step3Local, algorithmFPType, method >::Distributed
Distributed(const Distributed< step3Local, algorithmFPType, method > &other)
Definition: qr_distributed.h:366
daal::algorithms::qr::interface1::Online
Computes the results of the QR decomposition algorithm in the online processing mode.
Definition: qr_online.h:87
daal_defines.h
daal::algorithms::qr::interface1::Distributed< step3Local, algorithmFPType, method >::setPartialResult
services::Status setPartialResult(const DistributedPartialResultStep3Ptr &partialRes)
Definition: qr_distributed.h:399
daal::algorithms::qr::interface1::Distributed< step2Master, algorithmFPType, method >::getPartialResult
DistributedPartialResultPtr getPartialResult()
Definition: qr_distributed.h:251
daal::algorithms::qr::interface1::Distributed< step2Master, algorithmFPType, method >::parameter
ParameterType parameter
Definition: qr_distributed.h:214
daal::algorithms::kmeans::init::interface1::Distributed
class DAAL_EXPORT Distributed
Computes initial clusters for the K-Means algorithm in the distributed processing mode...
Definition: kmeans_init_distributed.h:255
daal::distributed
Definition: daal_defines.h:107
daal::algorithms::qr::interface1::DistributedContainer
Provides methods to run implementations of the QR decomposition algorithm.
Definition: qr_distributed.h:56
daal::algorithms::qr::interface1::Distributed< step2Master, algorithmFPType, method >::clone
services::SharedPtr< Distributed< step2Master, algorithmFPType, method > > clone() const
Definition: qr_distributed.h:290
daal::algorithms::qr::interface1::Distributed< step2Master, algorithmFPType, method >::checkFinalizeComputeParams
services::Status checkFinalizeComputeParams() DAAL_C11_OVERRIDE
Definition: qr_distributed.h:272
daal::algorithms::qr::interface1::Distributed< step1Local, algorithmFPType, method >::clone
services::SharedPtr< Distributed< step1Local, algorithmFPType, method > > clone() const
Definition: qr_distributed.h:179
daal::algorithms::qr::interface1::Distributed< step3Local, algorithmFPType, method >
Computes the results of the QR decomposition algorithm on the third step in the distributed processin...
Definition: qr_distributed.h:340
daal::algorithms::qr::interface1::Distributed< step3Local, algorithmFPType, method >::getResult
ResultPtr getResult()
Definition: qr_distributed.h:381
daal::algorithms::qr::interface1::Distributed< step2Master, algorithmFPType, method >::Distributed
Distributed(const Distributed< step2Master, algorithmFPType, method > &other)
Definition: qr_distributed.h:227
daal::algorithms::qr::interface1::Distributed< step1Local, algorithmFPType, method >::Distributed
Distributed(const Distributed< step1Local, algorithmFPType, method > &other)
Definition: qr_distributed.h:170
daal::algorithms::qr::interface1::Distributed< step3Local, algorithmFPType, method >::setResult
services::Status setResult(const ResultPtr &res)
Definition: qr_distributed.h:412
daal::algorithms::Analysis
Provides methods for execution of operations over data, such as computation of Summary Statistics est...
Definition: analysis.h:68
daal::algorithms::qr::interface1::Distributed< step3Local, algorithmFPType, method >::checkFinalizeComputeParams
services::Status checkFinalizeComputeParams() DAAL_C11_OVERRIDE
Definition: qr_distributed.h:417
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:117
daal::step2Master
Definition: daal_defines.h:118
daal::algorithms::qr::interface1::Distributed< step2Master, algorithmFPType, method >
Computes the results of the QR decomposition algorithm on the second step in the distributed processi...
Definition: qr_distributed.h:203
daal::algorithms::qr::interface1::Distributed< step3Local, algorithmFPType, method >::Distributed
Distributed()
Definition: qr_distributed.h:355
daal::algorithms::qr::interface1::DistributedStep2Input
Input objects for the second step of the QR decomposition algorithm in the distributed processing mod...
Definition: qr_types.h:202
daal::algorithms::qr::interface1::Distributed< step2Master, algorithmFPType, method >::getResult
ResultPtr getResult()
Definition: qr_distributed.h:242
daal::algorithms::qr::finalResultFromStep3
Definition: qr_types.h:122
daal::step3Local
Definition: daal_defines.h:119
daal::services::ErrorNullResult
Definition: error_indexes.h:96
daal::algorithms::qr::interface1::Distributed< step3Local, algorithmFPType, method >::parameter
ParameterType parameter
Definition: qr_distributed.h:352

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