C++ API Reference for Intel® Data Analytics Acceleration Library 2018 Update 2

qr_distributed.h
1 /* file: qr_distributed.h */
2 /*******************************************************************************
3 * Copyright 2014-2018 Intel Corporation
4 * All Rights Reserved.
5 *
6 * If this software was obtained under the Intel Simplified Software License,
7 * the following terms apply:
8 *
9 * The source code, information and material ("Material") contained herein is
10 * owned by Intel Corporation or its suppliers or licensors, and title to such
11 * Material remains with Intel Corporation or its suppliers or licensors. The
12 * Material contains proprietary information of Intel or its suppliers and
13 * licensors. The Material is protected by worldwide copyright laws and treaty
14 * provisions. No part of the Material may be used, copied, reproduced,
15 * modified, published, uploaded, posted, transmitted, distributed or disclosed
16 * in any way without Intel's prior express written permission. No license under
17 * any patent, copyright or other intellectual property rights in the Material
18 * is granted to or conferred upon you, either expressly, by implication,
19 * inducement, estoppel or otherwise. Any license under such intellectual
20 * property rights must be express and approved by Intel in writing.
21 *
22 * Unless otherwise agreed by Intel in writing, you may not remove or alter this
23 * notice or any other notice embedded in Materials by Intel or Intel's
24 * suppliers or licensors in any way.
25 *
26 *
27 * If this software was obtained under the Apache License, Version 2.0 (the
28 * "License"), the following terms apply:
29 *
30 * You may not use this file except in compliance with the License. You may
31 * obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
32 *
33 *
34 * Unless required by applicable law or agreed to in writing, software
35 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
36 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
37 *
38 * See the License for the specific language governing permissions and
39 * limitations under the License.
40 *******************************************************************************/
41 
42 /*
43 //++
44 // Implementation of the interface for the QR decomposition algorithm in the
45 // distributed processing mode
46 //--
47 */
48 
49 #ifndef __QR_DISTRIBUTED_H__
50 #define __QR_DISTRIBUTED_H__
51 
52 #include "algorithms/algorithm.h"
53 #include "data_management/data/numeric_table.h"
54 #include "services/daal_defines.h"
55 #include "algorithms/qr/qr_types.h"
56 #include "algorithms/qr/qr_online.h"
57 
58 namespace daal
59 {
60 namespace algorithms
61 {
62 namespace qr
63 {
64 
65 namespace interface1
66 {
81 template<ComputeStep step, typename algorithmFPType, Method method, CpuType cpu>
82 class DAAL_EXPORT DistributedContainer
83 {};
84 
93 template<typename algorithmFPType, Method method, CpuType cpu>
94 class DAAL_EXPORT DistributedContainer<step2Master, algorithmFPType, method, cpu> :
95  public daal::algorithms::AnalysisContainerIface<distributed>
96 {
97 public:
103  DistributedContainer(daal::services::Environment::env *daalEnv);
105  virtual ~DistributedContainer();
110  virtual services::Status compute() DAAL_C11_OVERRIDE;
115  virtual services::Status finalizeCompute() DAAL_C11_OVERRIDE;
116 };
117 
126 template<typename algorithmFPType, Method method, CpuType cpu>
127 class DAAL_EXPORT DistributedContainer<step3Local, algorithmFPType, method, cpu> :
128  public daal::algorithms::AnalysisContainerIface<distributed>
129 {
130 public:
136  DistributedContainer(daal::services::Environment::env *daalEnv);
138  virtual ~DistributedContainer();
143  virtual services::Status compute() DAAL_C11_OVERRIDE;
148  virtual services::Status finalizeCompute() DAAL_C11_OVERRIDE;
149 };
150 
163 template<ComputeStep step, typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = defaultDense>
164 class DAAL_EXPORT Distributed : public daal::algorithms::Analysis<distributed> {};
165 
177 template<typename algorithmFPType, Method method>
178 class DAAL_EXPORT Distributed<step1Local, algorithmFPType, method> : public Online<algorithmFPType, method>
179 {
180 public:
181  typedef Online<algorithmFPType, method> super;
182 
183  typedef typename super::InputType InputType;
184  typedef typename super::ParameterType ParameterType;
185  typedef typename super::ResultType ResultType;
186  typedef typename super::PartialResultType PartialResultType;
187 
188  Distributed() : Online<algorithmFPType, method>() {}
189 
196  Distributed(const Distributed<step1Local, algorithmFPType, method> &other) :
197  Online<algorithmFPType, method>(other)
198  {}
199 
205  services::SharedPtr<Distributed<step1Local, algorithmFPType, method> > clone() const
206  {
207  return services::SharedPtr<Distributed<step1Local, algorithmFPType, method> >(cloneImpl());
208  }
209 
210 protected:
211  virtual Distributed<step1Local, algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
212  {
213  return new Distributed<step1Local, algorithmFPType, method>(*this);
214  }
215 };
216 
228 template<typename algorithmFPType, Method method>
229 class DAAL_EXPORT Distributed<step2Master, algorithmFPType, method> : public daal::algorithms::Analysis<distributed>
230 {
231 public:
232  typedef DistributedStep2Input Input;
233 
234  typedef algorithms::qr::DistributedStep2Input InputType;
235  typedef algorithms::qr::Parameter ParameterType;
236  typedef algorithms::qr::Result ResultType;
237  typedef algorithms::qr::DistributedPartialResult PartialResultType;
238 
239  InputType input;
240  ParameterType parameter;
242  Distributed()
243  {
244  initialize();
245  }
246 
253  Distributed(const Distributed<step2Master, algorithmFPType, method> &other) : input(other.input), parameter(other.parameter)
254  {
255  initialize();
256  }
257 
262  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int)method; }
263 
268  ResultPtr getResult()
269  {
270  return _partialResult->get(finalResultFromStep2Master);
271  }
272 
277  DistributedPartialResultPtr getPartialResult()
278  {
279  return _partialResult;
280  }
281 
286  services::Status setPartialResult(const DistributedPartialResultPtr& partialRes)
287  {
288  DAAL_CHECK(partialRes, services::ErrorNullPartialResult);
289  DAAL_CHECK(partialRes->get(finalResultFromStep2Master), services::ErrorNullResult)
290  _partialResult = partialRes;
291  _pres = _partialResult.get();
292  return services::Status();
293  }
294 
298  services::Status checkFinalizeComputeParams() DAAL_C11_OVERRIDE
299  {
300  if(_partialResult)
301  {
302  return _partialResult->check(_par, method);
303  }
304  else
305  {
306  return services::Status(services::ErrorNullResult);
307  }
308  return services::Status();
309  }
310 
316  services::SharedPtr<Distributed<step2Master, algorithmFPType, method> > clone() const
317  {
318  return services::SharedPtr<Distributed<step2Master, algorithmFPType, method> >(cloneImpl());
319  }
320 
321 protected:
322  virtual Distributed<step2Master, algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
323  {
324  return new Distributed<step2Master, algorithmFPType, method>(*this);
325  }
326 
327  virtual services::Status allocateResult() DAAL_C11_OVERRIDE { return services::Status(); }
328 
329  virtual services::Status allocatePartialResult() DAAL_C11_OVERRIDE
330  {
331  _partialResult.reset(new PartialResultType());
332  services::Status s = _partialResult->allocate<algorithmFPType>(_in, 0, 0);
333  _pres = _partialResult.get();
334  return s;
335  }
336 
337  virtual services::Status initializePartialResult() DAAL_C11_OVERRIDE
338  {
339  _pres = _partialResult.get();
340  return services::Status();
341  }
342 
343  void initialize()
344  {
345  Analysis<distributed>::_ac = new __DAAL_ALGORITHM_CONTAINER(distributed, DistributedContainer, step2Master, algorithmFPType, method)(&_env);
346  _in = &input;
347  _par = &parameter;
348  }
349 
350 private:
351  DistributedPartialResultPtr _partialResult;
352 };
353 
365 template<typename algorithmFPType, Method method>
366 class DAAL_EXPORT Distributed<step3Local, algorithmFPType, method> : public
367  daal::algorithms::Analysis<distributed>
368 {
369 public:
370  typedef DistributedStep3Input Input;
371 
372  typedef algorithms::qr::DistributedStep3Input InputType;
373  typedef algorithms::qr::Parameter ParameterType;
374  typedef algorithms::qr::Result ResultType;
375  typedef algorithms::qr::DistributedPartialResultStep3 PartialResultType;
376 
377  InputType input;
378  ParameterType parameter;
381  Distributed()
382  {
383  initialize();
384  }
385 
392  Distributed(const Distributed<step3Local, algorithmFPType, method> &other) : input(other.input), parameter(other.parameter)
393  {
394  initialize();
395  }
396 
401  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int)method; }
402 
407  ResultPtr getResult()
408  {
409  return _partialResult->get(finalResultFromStep3);
410  }
411 
416  DistributedPartialResultStep3Ptr getPartialResult()
417  {
418  return _partialResult;
419  }
420 
425  services::Status setPartialResult(const DistributedPartialResultStep3Ptr& partialRes)
426  {
427  DAAL_CHECK(partialRes, services::ErrorNullPartialResult);
428  DAAL_CHECK(partialRes->get(finalResultFromStep3), services::ErrorNullResult)
429  _partialResult = partialRes;
430  _pres = _partialResult.get();
431  return services::Status();
432  }
433 
438  services::Status setResult(const ResultPtr& res) { return services::Status();}
439 
443  services::Status checkFinalizeComputeParams() DAAL_C11_OVERRIDE
444  {
445  if(_partialResult)
446  {
447  return _partialResult->check(_par, method);
448  }
449  else
450  {
451  return services::Status(services::ErrorNullResult);
452  }
453  return services::Status();
454  }
455 
461  services::SharedPtr<Distributed<step3Local, algorithmFPType, method> > clone() const
462  {
463  return services::SharedPtr<Distributed<step3Local, algorithmFPType, method> >(cloneImpl());
464  }
465 
466 protected:
467  virtual Distributed<step3Local, algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
468  {
469  return new Distributed<step3Local, algorithmFPType, method>(*this);
470  }
471 
472  virtual services::Status allocatePartialResult() DAAL_C11_OVERRIDE
473  {
474  _partialResult.reset(new PartialResultType());
475 
476  services::Status s = _partialResult->allocate<algorithmFPType>(_in, 0, 0);
477  if(!s) { return s; }
478 
479  data_management::DataCollectionPtr qCollection = input.get(inputOfStep3FromStep1);
480 
481  s = _partialResult->setPartialResultStorage<algorithmFPType>(qCollection.get());
482 
483  _pres = _partialResult.get();
484  return s;
485  }
486 
487  virtual services::Status allocateResult() DAAL_C11_OVERRIDE { return services::Status(); }
488 
489  virtual services::Status initializePartialResult() DAAL_C11_OVERRIDE { return services::Status(); }
490 
491  void initialize()
492  {
493  Analysis<distributed>::_ac = new __DAAL_ALGORITHM_CONTAINER(distributed, DistributedContainer, step3Local, algorithmFPType, method)(&_env);
494  _in = &input;
495  _par = &parameter;
496  }
497 
498 private:
499  DistributedPartialResultStep3Ptr _partialResult;
500 };
502 } // namespace interface1
503 using interface1::DistributedContainer;
504 using interface1::Distributed;
505 
506 } // namespace daal::algorithms::qr
507 } // namespace daal::algorithms
508 } // namespace daal
509 #endif
daal::algorithms::qr::interface1::Distributed< step2Master, algorithmFPType, method >::clone
services::SharedPtr< Distributed< step2Master, algorithmFPType, method > > clone() const
Definition: qr_distributed.h:316
daal::algorithms::qr::interface1::Distributed< step2Master, algorithmFPType, method >::setPartialResult
services::Status setPartialResult(const DistributedPartialResultPtr &partialRes)
Definition: qr_distributed.h:286
daal::algorithms::qr::interface1::Distributed< step3Local, algorithmFPType, method >::input
InputType input
Definition: qr_distributed.h:377
daal::algorithms::qr::interface1::OnlinePartialResult
Provides methods to access partial results obtained with the compute() method of the QR decomposition...
Definition: qr_types.h:321
daal::services::interface1::Environment::_envStruct
The environment structure.
Definition: env_detect.h:95
daal::services::interface1::Status
Class that holds the results of API calls. In case of API routine failure it contains the list of err...
Definition: error_handling.h:491
daal
Definition: algorithm_base_common.h:57
daal::algorithms::AnalysisContainerIface
Abstract interface class that provides virtual methods to access and run implementations of the analy...
Definition: analysis.h:79
daal::algorithms::qr::interface1::Distributed< step3Local, algorithmFPType, method >::getPartialResult
DistributedPartialResultStep3Ptr getPartialResult()
Definition: qr_distributed.h:416
daal::algorithms::qr::interface1::Parameter
Parameters for the QR decomposition compute method.
Definition: qr_types.h:662
daal::algorithms::qr::interface1::Result
Provides methods to access final results obtained with the compute() method of the QR decomposition a...
Definition: qr_types.h:418
daal::algorithms::qr::interface1::Distributed< step2Master, algorithmFPType, method >::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: qr_distributed.h:262
daal::algorithms::qr::finalResultFromStep2Master
Definition: qr_types.h:138
daal::services::ErrorNullPartialResult
Definition: error_indexes.h:131
daal::algorithms::qr::interface1::Distributed< step3Local, algorithmFPType, method >::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: qr_distributed.h:401
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:178
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:283
daal::algorithms::qr::interface1::Input
Input objects for the QR decomposition algorithm in the batch and online processing modes and for the...
Definition: qr_types.h:186
daal::algorithms::qr::interface1::Distributed< step2Master, algorithmFPType, method >::input
InputType input
Definition: qr_distributed.h:239
daal::algorithms::qr::inputOfStep3FromStep1
Definition: qr_types.h:169
daal::algorithms::qr::interface1::Distributed
Computes the results of the QR decomposition algorithm in the distributed processing mode...
Definition: qr_distributed.h:164
daal::algorithms::qr::interface1::Distributed< step3Local, algorithmFPType, method >::Distributed
Distributed(const Distributed< step3Local, algorithmFPType, method > &other)
Definition: qr_distributed.h:392
daal::algorithms::qr::interface1::Online
Computes the results of the QR decomposition algorithm in the online processing mode.
Definition: qr_online.h:113
daal_defines.h
daal::algorithms::qr::interface1::Distributed< step3Local, algorithmFPType, method >::setPartialResult
services::Status setPartialResult(const DistributedPartialResultStep3Ptr &partialRes)
Definition: qr_distributed.h:425
daal::algorithms::qr::interface1::Distributed< step2Master, algorithmFPType, method >::getPartialResult
DistributedPartialResultPtr getPartialResult()
Definition: qr_distributed.h:277
daal::algorithms::qr::interface1::Distributed< step2Master, algorithmFPType, method >::parameter
ParameterType parameter
Definition: qr_distributed.h:240
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:281
daal::distributed
Definition: daal_defines.h:133
daal::algorithms::qr::interface1::DistributedStep3Input::get
data_management::DataCollectionPtr get(FinalizeOnLocalInputId id) const
daal::algorithms::qr::interface1::DistributedContainer
Provides methods to run implementations of the QR decomposition algorithm.
Definition: qr_distributed.h:82
daal::services::interface1::SharedPtr
Shared pointer that retains shared ownership of an object through a pointer. Several SharedPtr object...
Definition: daal_shared_ptr.h:187
daal::services::interface1::SharedPtr::get
T * get() const
Definition: daal_shared_ptr.h:332
daal::algorithms::qr::interface1::Distributed< step2Master, algorithmFPType, method >::checkFinalizeComputeParams
services::Status checkFinalizeComputeParams() DAAL_C11_OVERRIDE
Definition: qr_distributed.h:298
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:366
daal::algorithms::qr::interface1::Distributed< step3Local, algorithmFPType, method >::getResult
ResultPtr getResult()
Definition: qr_distributed.h:407
daal::algorithms::qr::interface1::DistributedPartialResult
Provides methods to access partial results obtained with the compute() method of the second step of t...
Definition: qr_types.h:499
daal::algorithms::qr::interface1::Distributed< step2Master, algorithmFPType, method >::Distributed
Distributed(const Distributed< step2Master, algorithmFPType, method > &other)
Definition: qr_distributed.h:253
daal::algorithms::qr::interface1::Distributed< step1Local, algorithmFPType, method >::Distributed
Distributed(const Distributed< step1Local, algorithmFPType, method > &other)
Definition: qr_distributed.h:196
daal::algorithms::qr::interface1::Distributed< step3Local, algorithmFPType, method >::setResult
services::Status setResult(const ResultPtr &res)
Definition: qr_distributed.h:438
daal::algorithms::Analysis
Provides methods for execution of operations over data, such as computation of Summary Statistics est...
Definition: analysis.h:94
daal::algorithms::qr::interface1::Distributed< step3Local, algorithmFPType, method >::checkFinalizeComputeParams
services::Status checkFinalizeComputeParams() DAAL_C11_OVERRIDE
Definition: qr_distributed.h:443
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:81
daal::step1Local
Definition: daal_defines.h:143
daal::step2Master
Definition: daal_defines.h:144
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:229
daal::algorithms::qr::interface1::Distributed< step3Local, algorithmFPType, method >::Distributed
Distributed()
Definition: qr_distributed.h:381
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:228
daal::algorithms::qr::interface1::Distributed< step2Master, algorithmFPType, method >::getResult
ResultPtr getResult()
Definition: qr_distributed.h:268
daal::algorithms::qr::finalResultFromStep3
Definition: qr_types.h:148
daal::step3Local
Definition: daal_defines.h:145
daal::algorithms::qr::interface1::DistributedPartialResultStep3
Provides methods to access partial results obtained with the compute() method of the third step of th...
Definition: qr_types.h:591
daal::algorithms::qr::interface1::Distributed< step3Local, algorithmFPType, method >::clone
services::SharedPtr< Distributed< step3Local, algorithmFPType, method > > clone() const
Definition: qr_distributed.h:461
daal::algorithms::qr::interface1::Distributed< step1Local, algorithmFPType, method >::clone
services::SharedPtr< Distributed< step1Local, algorithmFPType, method > > clone() const
Definition: qr_distributed.h:205
daal::services::ErrorNullResult
Definition: error_indexes.h:122
daal::algorithms::qr::interface1::Distributed< step3Local, algorithmFPType, method >::parameter
ParameterType parameter
Definition: qr_distributed.h:378

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