C++ API Reference for Intel® Data Analytics Acceleration Library 2020 Update 1

qr_distributed.h
1 /* file: qr_distributed.h */
2 /*******************************************************************************
3 * Copyright 2014-2020 Intel Corporation
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *******************************************************************************/
17 
18 /*
19 //++
20 // Implementation of the interface for the QR decomposition algorithm in the
21 // distributed processing mode
22 //--
23 */
24 
25 #ifndef __QR_DISTRIBUTED_H__
26 #define __QR_DISTRIBUTED_H__
27 
28 #include "algorithms/algorithm.h"
29 #include "data_management/data/numeric_table.h"
30 #include "services/daal_defines.h"
31 #include "algorithms/qr/qr_types.h"
32 #include "algorithms/qr/qr_online.h"
33 
34 namespace daal
35 {
36 namespace algorithms
37 {
38 namespace qr
39 {
40 
41 namespace interface1
42 {
57 template<ComputeStep step, typename algorithmFPType, Method method, CpuType cpu>
58 class DistributedContainer
59 {};
60 
69 template<typename algorithmFPType, Method method, CpuType cpu>
70 class DistributedContainer<step2Master, algorithmFPType, method, cpu> :
71  public daal::algorithms::AnalysisContainerIface<distributed>
72 {
73 public:
79  DistributedContainer(daal::services::Environment::env *daalEnv);
81  virtual ~DistributedContainer();
86  virtual services::Status compute() DAAL_C11_OVERRIDE;
91  virtual services::Status finalizeCompute() DAAL_C11_OVERRIDE;
92 };
93 
102 template<typename algorithmFPType, Method method, CpuType cpu>
103 class DistributedContainer<step3Local, algorithmFPType, method, cpu> :
104  public daal::algorithms::AnalysisContainerIface<distributed>
105 {
106 public:
112  DistributedContainer(daal::services::Environment::env *daalEnv);
114  virtual ~DistributedContainer();
119  virtual services::Status compute() DAAL_C11_OVERRIDE;
124  virtual services::Status finalizeCompute() DAAL_C11_OVERRIDE;
125 };
126 
139 template<ComputeStep step, typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = defaultDense>
140 class DAAL_EXPORT Distributed : public daal::algorithms::Analysis<distributed> {};
141 
153 template<typename algorithmFPType, Method method>
154 class DAAL_EXPORT Distributed<step1Local, algorithmFPType, method> : public Online<algorithmFPType, method>
155 {
156 public:
157  typedef Online<algorithmFPType, method> super;
158 
159  typedef typename super::InputType InputType;
160  typedef typename super::ParameterType ParameterType;
161  typedef typename super::ResultType ResultType;
162  typedef typename super::PartialResultType PartialResultType;
163 
164  Distributed() : Online<algorithmFPType, method>() {}
165 
172  Distributed(const Distributed<step1Local, algorithmFPType, method> &other) :
173  Online<algorithmFPType, method>(other)
174  {}
175 
181  services::SharedPtr<Distributed<step1Local, algorithmFPType, method> > clone() const
182  {
183  return services::SharedPtr<Distributed<step1Local, algorithmFPType, method> >(cloneImpl());
184  }
185 
186 protected:
187  virtual Distributed<step1Local, algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
188  {
189  return new Distributed<step1Local, algorithmFPType, method>(*this);
190  }
191 };
192 
204 template<typename algorithmFPType, Method method>
205 class DAAL_EXPORT Distributed<step2Master, algorithmFPType, method> : public daal::algorithms::Analysis<distributed>
206 {
207 public:
208  typedef DistributedStep2Input Input;
209 
210  typedef algorithms::qr::DistributedStep2Input InputType;
211  typedef algorithms::qr::Parameter ParameterType;
212  typedef algorithms::qr::Result ResultType;
213  typedef algorithms::qr::DistributedPartialResult PartialResultType;
214 
215  InputType input;
216  ParameterType parameter;
218  Distributed()
219  {
220  initialize();
221  }
222 
229  Distributed(const Distributed<step2Master, algorithmFPType, method> &other) : input(other.input), parameter(other.parameter)
230  {
231  initialize();
232  }
233 
238  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int)method; }
239 
244  ResultPtr getResult()
245  {
246  return _partialResult->get(finalResultFromStep2Master);
247  }
248 
253  DistributedPartialResultPtr getPartialResult()
254  {
255  return _partialResult;
256  }
257 
262  services::Status setPartialResult(const DistributedPartialResultPtr& partialRes)
263  {
264  DAAL_CHECK(partialRes, services::ErrorNullPartialResult);
265  DAAL_CHECK(partialRes->get(finalResultFromStep2Master), services::ErrorNullResult)
266  _partialResult = partialRes;
267  _pres = _partialResult.get();
268  return services::Status();
269  }
270 
274  services::Status checkFinalizeComputeParams() DAAL_C11_OVERRIDE
275  {
276  if(_partialResult)
277  {
278  return _partialResult->check(_par, method);
279  }
280  else
281  {
282  return services::Status(services::ErrorNullResult);
283  }
284  return services::Status();
285  }
286 
292  services::SharedPtr<Distributed<step2Master, algorithmFPType, method> > clone() const
293  {
294  return services::SharedPtr<Distributed<step2Master, algorithmFPType, method> >(cloneImpl());
295  }
296 
297 protected:
298  virtual Distributed<step2Master, algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
299  {
300  return new Distributed<step2Master, algorithmFPType, method>(*this);
301  }
302 
303  virtual services::Status allocateResult() DAAL_C11_OVERRIDE { return services::Status(); }
304 
305  virtual services::Status allocatePartialResult() DAAL_C11_OVERRIDE
306  {
307  _partialResult.reset(new PartialResultType());
308  services::Status s = _partialResult->allocate<algorithmFPType>(_in, 0, 0);
309  _pres = _partialResult.get();
310  return s;
311  }
312 
313  virtual services::Status initializePartialResult() DAAL_C11_OVERRIDE
314  {
315  _pres = _partialResult.get();
316  return services::Status();
317  }
318 
319  void initialize()
320  {
321  Analysis<distributed>::_ac = new __DAAL_ALGORITHM_CONTAINER(distributed, DistributedContainer, step2Master, algorithmFPType, method)(&_env);
322  _in = &input;
323  _par = &parameter;
324  }
325 
326 private:
327  DistributedPartialResultPtr _partialResult;
328 };
329 
341 template<typename algorithmFPType, Method method>
342 class DAAL_EXPORT Distributed<step3Local, algorithmFPType, method> : public
343  daal::algorithms::Analysis<distributed>
344 {
345 public:
346  typedef DistributedStep3Input Input;
347 
348  typedef algorithms::qr::DistributedStep3Input InputType;
349  typedef algorithms::qr::Parameter ParameterType;
350  typedef algorithms::qr::Result ResultType;
351  typedef algorithms::qr::DistributedPartialResultStep3 PartialResultType;
352 
353  InputType input;
354  ParameterType parameter;
357  Distributed()
358  {
359  initialize();
360  }
361 
368  Distributed(const Distributed<step3Local, algorithmFPType, method> &other) : input(other.input), parameter(other.parameter)
369  {
370  initialize();
371  }
372 
377  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int)method; }
378 
383  ResultPtr getResult()
384  {
385  return _partialResult->get(finalResultFromStep3);
386  }
387 
392  DistributedPartialResultStep3Ptr getPartialResult()
393  {
394  return _partialResult;
395  }
396 
401  services::Status setPartialResult(const DistributedPartialResultStep3Ptr& partialRes)
402  {
403  DAAL_CHECK(partialRes, services::ErrorNullPartialResult);
404  DAAL_CHECK(partialRes->get(finalResultFromStep3), services::ErrorNullResult)
405  _partialResult = partialRes;
406  _pres = _partialResult.get();
407  return services::Status();
408  }
409 
414  services::Status setResult(const ResultPtr& res) { return services::Status();}
415 
419  services::Status checkFinalizeComputeParams() DAAL_C11_OVERRIDE
420  {
421  if(_partialResult)
422  {
423  return _partialResult->check(_par, method);
424  }
425  else
426  {
427  return services::Status(services::ErrorNullResult);
428  }
429  return services::Status();
430  }
431 
437  services::SharedPtr<Distributed<step3Local, algorithmFPType, method> > clone() const
438  {
439  return services::SharedPtr<Distributed<step3Local, algorithmFPType, method> >(cloneImpl());
440  }
441 
442 protected:
443  virtual Distributed<step3Local, algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
444  {
445  return new Distributed<step3Local, algorithmFPType, method>(*this);
446  }
447 
448  virtual services::Status allocatePartialResult() DAAL_C11_OVERRIDE
449  {
450  _partialResult.reset(new PartialResultType());
451 
452  services::Status s = _partialResult->allocate<algorithmFPType>(_in, 0, 0);
453  if(!s) { return s; }
454 
455  data_management::DataCollectionPtr qCollection = input.get(inputOfStep3FromStep1);
456 
457  s = _partialResult->setPartialResultStorage<algorithmFPType>(qCollection.get());
458 
459  _pres = _partialResult.get();
460  return s;
461  }
462 
463  virtual services::Status allocateResult() DAAL_C11_OVERRIDE { return services::Status(); }
464 
465  virtual services::Status initializePartialResult() DAAL_C11_OVERRIDE { return services::Status(); }
466 
467  void initialize()
468  {
469  Analysis<distributed>::_ac = new __DAAL_ALGORITHM_CONTAINER(distributed, DistributedContainer, step3Local, algorithmFPType, method)(&_env);
470  _in = &input;
471  _par = &parameter;
472  }
473 
474 private:
475  DistributedPartialResultStep3Ptr _partialResult;
476 };
478 } // namespace interface1
479 using interface1::DistributedContainer;
480 using interface1::Distributed;
481 
482 } // namespace daal::algorithms::qr
483 } // namespace daal::algorithms
484 } // namespace daal
485 #endif
daal::algorithms::qr::interface1::Distributed< step2Master, algorithmFPType, method >::parameter
ParameterType parameter
Definition: qr_distributed.h:216
daal::algorithms::qr::interface1::Distributed< step3Local, algorithmFPType, method >::setPartialResult
services::Status setPartialResult(const DistributedPartialResultStep3Ptr &partialRes)
Definition: qr_distributed.h:401
daal::step1Local
Definition: daal_defines.h:123
daal::algorithms::qr::interface1::Distributed
Computes the results of the QR decomposition algorithm in the distributed processing mode...
Definition: qr_distributed.h:140
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:342
daal::algorithms::qr::interface1::Distributed< step2Master, algorithmFPType, method >::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: qr_distributed.h:238
daal::algorithms::qr::finalResultFromStep3
Definition: qr_types.h:124
daal::algorithms::qr::interface1::Distributed< step3Local, algorithmFPType, method >::parameter
ParameterType parameter
Definition: qr_distributed.h:354
daal::algorithms::qr::interface1::Distributed< step2Master, algorithmFPType, method >::clone
services::SharedPtr< Distributed< step2Master, algorithmFPType, method > > clone() const
Definition: qr_distributed.h:292
daal::step2Master
Definition: daal_defines.h:124
daal::algorithms::qr::interface1::Distributed< step2Master, algorithmFPType, method >::setPartialResult
services::Status setPartialResult(const DistributedPartialResultPtr &partialRes)
Definition: qr_distributed.h:262
daal::algorithms::qr::interface1::DistributedContainer
Provides methods to run implementations of the QR decomposition algorithm.
Definition: qr_distributed.h:58
daal::algorithms::qr::interface1::Distributed< step2Master, algorithmFPType, method >::input
InputType input
Definition: qr_distributed.h:215
daal::algorithms::qr::interface1::Distributed< step2Master, algorithmFPType, method >::getResult
ResultPtr getResult()
Definition: qr_distributed.h:244
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:204
daal::algorithms::qr::interface1::Distributed< step3Local, algorithmFPType, method >::setResult
services::Status setResult(const ResultPtr &res)
Definition: qr_distributed.h:414
daal::step3Local
Definition: daal_defines.h:125
daal::services::ErrorNullResult
Definition: error_indexes.h:98
daal::algorithms::AnalysisContainerIface
Abstract interface class that provides virtual methods to access and run implementations of the analy...
Definition: analysis.h:55
daal::algorithms::qr::interface1::Distributed< step2Master, algorithmFPType, method >::checkFinalizeComputeParams
services::Status checkFinalizeComputeParams() DAAL_C11_OVERRIDE
Definition: qr_distributed.h:274
daal::algorithms::kmeans::init::interface2::Distributed
class DAAL_EXPORT Distributed
Computes initial clusters for K-Means algorithm in the distributed processing mode.
Definition: kmeans_init_distributed.h:277
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:259
daal_defines.h
daal::algorithms::qr::interface1::Distributed< step3Local, algorithmFPType, method >::clone
services::SharedPtr< Distributed< step3Local, algorithmFPType, method > > clone() const
Definition: qr_distributed.h:437
daal::algorithms::qr::interface1::Distributed< step3Local, algorithmFPType, method >::Distributed
Distributed()
Definition: qr_distributed.h:357
daal::algorithms::qr::interface1::Distributed< step3Local, algorithmFPType, method >::checkFinalizeComputeParams
services::Status checkFinalizeComputeParams() DAAL_C11_OVERRIDE
Definition: qr_distributed.h:419
daal::algorithms::qr::interface1::Online
Computes the results of the QR decomposition algorithm in the online processing mode.
Definition: qr_online.h:89
daal::algorithms::qr::finalResultFromStep2Master
Definition: qr_types.h:114
daal::algorithms::qr::interface1::Distributed< step3Local, algorithmFPType, method >::getPartialResult
DistributedPartialResultStep3Ptr getPartialResult()
Definition: qr_distributed.h:392
daal::algorithms::qr::interface1::Distributed< step1Local, algorithmFPType, method >::clone
services::SharedPtr< Distributed< step1Local, algorithmFPType, method > > clone() const
Definition: qr_distributed.h:181
daal::algorithms::qr::interface1::Distributed< step3Local, algorithmFPType, method >::getResult
ResultPtr getResult()
Definition: qr_distributed.h:383
daal::algorithms::qr::interface1::Distributed< step3Local, algorithmFPType, method >::Distributed
Distributed(const Distributed< step3Local, algorithmFPType, method > &other)
Definition: qr_distributed.h:368
daal::algorithms::qr::interface1::Distributed< step2Master, algorithmFPType, method >::getPartialResult
DistributedPartialResultPtr getPartialResult()
Definition: qr_distributed.h:253
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:154
daal::algorithms::qr::interface1::Distributed< step2Master, algorithmFPType, method >::Distributed
Distributed(const Distributed< step2Master, algorithmFPType, method > &other)
Definition: qr_distributed.h:229
daal::algorithms::qr::interface1::Distributed< step1Local, algorithmFPType, method >::Distributed
Distributed(const Distributed< step1Local, algorithmFPType, method > &other)
Definition: qr_distributed.h:172
daal::algorithms::Analysis
Provides methods for execution of operations over data, such as computation of Summary Statistics est...
Definition: analysis.h:70
daal::services::ErrorNullPartialResult
Definition: error_indexes.h:107
daal::distributed
Definition: daal_defines.h:113
daal::algorithms::qr::inputOfStep3FromStep1
Definition: qr_types.h:145
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:205
daal::algorithms::qr::interface1::Distributed< step3Local, algorithmFPType, method >::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: qr_distributed.h:377
daal::algorithms::qr::interface1::Distributed< step3Local, algorithmFPType, method >::input
InputType input
Definition: qr_distributed.h:353

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