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

svd_distributed.h
1 /* file: svd_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 of the SVD algorithm in the distributed processing mode
45 //--
46 */
47 
48 #ifndef __SVD_DISTRIBUTED_H__
49 #define __SVD_DISTRIBUTED_H__
50 
51 #include "algorithms/algorithm.h"
52 #include "data_management/data/numeric_table.h"
53 #include "services/daal_defines.h"
54 #include "algorithms/svd/svd_types.h"
55 #include "algorithms/svd/svd_online.h"
56 
57 namespace daal
58 {
59 namespace algorithms
60 {
61 namespace svd
62 {
63 
64 namespace interface1
65 {
80 template<ComputeStep step, typename algorithmFPType, Method method, CpuType cpu>
81 class DAAL_EXPORT DistributedContainer
82 {};
83 
92 template<typename algorithmFPType, Method method, CpuType cpu>
93 class DAAL_EXPORT DistributedContainer<step1Local, algorithmFPType, method, cpu> : public
94  OnlineContainer<algorithmFPType, method, cpu>
95 {
96 public:
98  DistributedContainer(daal::services::Environment::env *daalEnv) : OnlineContainer<algorithmFPType, method, cpu>(daalEnv) {}
100  virtual ~DistributedContainer() {}
101 };
102 
111 template<typename algorithmFPType, Method method, CpuType cpu>
112 class DAAL_EXPORT DistributedContainer<step2Master, algorithmFPType, method, cpu> :
113  public daal::algorithms::AnalysisContainerIface<distributed>
114 {
115 public:
121  DistributedContainer(daal::services::Environment::env *daalEnv);
123  virtual ~DistributedContainer();
128  virtual services::Status compute() DAAL_C11_OVERRIDE;
133  virtual services::Status finalizeCompute() DAAL_C11_OVERRIDE;
134 };
135 
144 template<typename algorithmFPType, Method method, CpuType cpu>
145 class DAAL_EXPORT DistributedContainer<step3Local, algorithmFPType, method, cpu> :
146  public daal::algorithms::AnalysisContainerIface<distributed>
147 {
148 public:
154  DistributedContainer(daal::services::Environment::env *daalEnv);
156  virtual ~DistributedContainer();
161  virtual services::Status compute() DAAL_C11_OVERRIDE;
166  virtual services::Status finalizeCompute() DAAL_C11_OVERRIDE;
167 };
168 
181 template<ComputeStep step, typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = defaultDense>
182 class DAAL_EXPORT Distributed : public daal::algorithms::Analysis<distributed> {};
183 
195 template<typename algorithmFPType, Method method>
196 class DAAL_EXPORT Distributed<step1Local, algorithmFPType, method> : public Online<algorithmFPType, method>
197 {
198 public:
199  typedef Online<algorithmFPType, method> super;
200 
201  typedef typename super::InputType InputType;
202  typedef typename super::ParameterType ParameterType;
203  typedef typename super::ResultType ResultType;
204  typedef typename super::PartialResultType PartialResultType;
205 
206  Distributed() : Online<algorithmFPType, method>() {}
207 
214  Distributed(const Distributed<step1Local, algorithmFPType, method> &other) :
215  Online<algorithmFPType, method>(other)
216  {}
217 
223  services::SharedPtr<Distributed<step1Local, algorithmFPType, method> > clone() const
224  {
225  return services::SharedPtr<Distributed<step1Local, algorithmFPType, method> >(cloneImpl());
226  }
227 
228 protected:
229  virtual Distributed<step1Local, algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
230  {
231  return new Distributed<step1Local, algorithmFPType, method>(*this);
232  }
233 };
234 
246 template<typename algorithmFPType, Method method>
247 class DAAL_EXPORT Distributed<step2Master, algorithmFPType, method> : public daal::algorithms::Analysis<distributed>
248 {
249 public:
250  typedef algorithms::svd::DistributedStep2Input InputType;
251  typedef algorithms::svd::Parameter ParameterType;
252  typedef algorithms::svd::Result ResultType;
253  typedef algorithms::svd::DistributedPartialResult PartialResultType;
254 
255  InputType input;
256  ParameterType parameter;
258  Distributed()
259  {
260  initialize();
261  }
262 
269  Distributed(const Distributed<step2Master, algorithmFPType, method> &other) : input(other.input), parameter(other.parameter)
270  {
271  initialize();
272  }
273 
278  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int)method; }
279 
284  ResultPtr getResult()
285  {
286  return _partialResult->get(finalResultFromStep2Master);
287  }
288 
293  DistributedPartialResultPtr getPartialResult()
294  {
295  return _partialResult;
296  }
297 
301  services::Status setPartialResult(const DistributedPartialResultPtr& partialRes)
302  {
303  DAAL_CHECK(partialRes, services::ErrorNullPartialResult);
304  DAAL_CHECK(partialRes->get(finalResultFromStep2Master), services::ErrorNullResult)
305  _partialResult = partialRes;
306  _pres = _partialResult.get();
307  return services::Status();
308  }
309 
313  services::Status checkFinalizeComputeParams() DAAL_C11_OVERRIDE
314  {
315  if(!_partialResult)
316  return services::Status(services::ErrorNullResult);
317  return _partialResult->check(_par, method);
318  }
319 
325  services::SharedPtr<Distributed<step2Master, algorithmFPType, method> > clone() const
326  {
327  return services::SharedPtr<Distributed<step2Master, algorithmFPType, method> >(cloneImpl());
328  }
329 
330 protected:
331  virtual Distributed<step2Master, algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
332  {
333  return new Distributed<step2Master, algorithmFPType, method>(*this);
334  }
335 
336  virtual services::Status allocateResult() DAAL_C11_OVERRIDE{ return services::Status(); }
337 
338  virtual services::Status allocatePartialResult() DAAL_C11_OVERRIDE
339  {
340  _partialResult.reset(new PartialResultType());
341  services::Status s = _partialResult->allocate<algorithmFPType>(_in, 0, 0);
342  _pres = _partialResult.get();
343  return s;
344  }
345 
346  virtual services::Status initializePartialResult() DAAL_C11_OVERRIDE
347  {
348  _pres = _partialResult.get();
349  return services::Status();
350  }
351 
352  void initialize()
353  {
354  Analysis<distributed>::_ac = new __DAAL_ALGORITHM_CONTAINER(distributed, DistributedContainer, step2Master, algorithmFPType, method)(&_env);
355  _in = &input;
356  _par = &parameter;
357  }
358 
359 private:
360  DistributedPartialResultPtr _partialResult;
361 };
362 
374 template<typename algorithmFPType, Method method>
375 class DAAL_EXPORT Distributed<step3Local, algorithmFPType, method> : public
376  daal::algorithms::Analysis<distributed>
377 {
378 public:
379  typedef algorithms::svd::DistributedStep3Input InputType;
380  typedef algorithms::svd::Parameter ParameterType;
381  typedef algorithms::svd::Result ResultType;
382  typedef algorithms::svd::DistributedPartialResultStep3 PartialResultType;
383 
384  InputType input;
385  ParameterType parameter;
387  Distributed()
388  {
389  initialize();
390  }
391 
398  Distributed(const Distributed<step3Local, algorithmFPType, method> &other) : input(other.input), parameter(other.parameter)
399  {
400  initialize();
401  }
402 
407  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int)method; }
408 
413  ResultPtr getResult()
414  {
415  return _partialResult->get(finalResultFromStep3);
416  }
417 
422  DistributedPartialResultStep3Ptr getPartialResult()
423  {
424  return _partialResult;
425  }
426 
431  services::Status setPartialResult(const DistributedPartialResultStep3Ptr& partialRes)
432  {
433  DAAL_CHECK(partialRes, services::ErrorNullPartialResult);
434  DAAL_CHECK(partialRes->get(finalResultFromStep3), services::ErrorNullResult)
435  _partialResult = partialRes;
436  _pres = _partialResult.get();
437  return services::Status();
438  }
439 
444  services::Status setResult(const ResultPtr& res) { return services::Status(); }
445 
449  services::Status checkFinalizeComputeParams() DAAL_C11_OVERRIDE
450  {
451  if(!_partialResult)
452  return services::Status(services::ErrorNullResult);
453  return _partialResult->check(_par, method);
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)
478  return s;
479 
480  data_management::DataCollectionPtr qCollection = input.get(inputOfStep3FromStep1);
481 
482  s = _partialResult->setPartialResultStorage<algorithmFPType>(qCollection.get());
483 
484  _pres = _partialResult.get();
485  return s;
486  }
487 
488  virtual services::Status allocateResult() DAAL_C11_OVERRIDE{ return services::Status(); }
489 
490  virtual services::Status initializePartialResult() DAAL_C11_OVERRIDE{ return services::Status(); }
491 
492  void initialize()
493  {
494  Analysis<distributed>::_ac = new __DAAL_ALGORITHM_CONTAINER(distributed, DistributedContainer, step3Local, algorithmFPType, method)(&_env);
495  _in = &input;
496  _par = &parameter;
497  }
498 
499 private:
500  DistributedPartialResultStep3Ptr _partialResult;
501 };
503 } // namespace interface1
504 using interface1::DistributedContainer;
505 using interface1::Distributed;
506 
507 } // namespace daal::algorithms::svd
508 } // namespace daal::algorithms
509 } // namespace daal
510 #endif
daal::algorithms::svd::interface1::Distributed< step3Local, algorithmFPType, method >::setResult
services::Status setResult(const ResultPtr &res)
Definition: svd_distributed.h:444
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:196
daal::algorithms::svd::interface1::Parameter
Parameters for the computation method of the SVD algorithm.
Definition: svd_types.h:187
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::svd::interface1::Online
Computes results of the SVD algorithm in the online processing mode.
Definition: svd_online.h:114
daal::algorithms::svd::interface1::DistributedStep3Input::get
data_management::DataCollectionPtr get(FinalizeOnLocalInputId id) const
daal::algorithms::svd::inputOfStep3FromStep1
Definition: svd_types.h:173
daal::services::ErrorNullPartialResult
Definition: error_indexes.h:131
daal::algorithms::svd::interface1::DistributedStep2Input
Input objects for the second step of the SVD algorithm in the distributed processing mode ...
Definition: svd_types.h:249
daal::algorithms::svd::interface1::Result
Provides methods to access final results obtained with the compute() method of the SVD algorithm in t...
Definition: svd_types.h:425
daal::algorithms::svd::interface1::Distributed< step2Master, algorithmFPType, method >::setPartialResult
services::Status setPartialResult(const DistributedPartialResultPtr &partialRes)
Definition: svd_distributed.h:301
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:375
daal::algorithms::svd::interface1::DistributedPartialResultStep3
Provides methods to access partial results obtained with the compute() method of the SVD algorithm in...
Definition: svd_types.h:609
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:247
daal::algorithms::svd::interface1::Distributed< step1Local, algorithmFPType, method >::clone
services::SharedPtr< Distributed< step1Local, algorithmFPType, method > > clone() const
Definition: svd_distributed.h:223
daal::algorithms::svd::interface1::Distributed< step2Master, algorithmFPType, method >::checkFinalizeComputeParams
services::Status checkFinalizeComputeParams() DAAL_C11_OVERRIDE
Definition: svd_distributed.h:313
daal::algorithms::svd::interface1::DistributedContainer
Provides methods to run implementations of the SVD algorithm.
Definition: svd_distributed.h:81
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::svd::interface1::Distributed< step3Local, algorithmFPType, method >::input
InputType input
Definition: svd_distributed.h:384
daal::algorithms::svd::interface1::Input
Input objects for the SVD algorithm in the batch processing and online processing modes...
Definition: svd_types.h:207
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::algorithms::svd::interface1::DistributedContainer< step1Local, algorithmFPType, method, cpu >::~DistributedContainer
virtual ~DistributedContainer()
Definition: svd_distributed.h:100
daal::algorithms::svd::interface1::Distributed< step2Master, algorithmFPType, method >::clone
services::SharedPtr< Distributed< step2Master, algorithmFPType, method > > clone() const
Definition: svd_distributed.h:325
daal::algorithms::svd::interface1::Distributed< step2Master, algorithmFPType, method >::parameter
ParameterType parameter
Definition: svd_distributed.h:256
daal::services::interface1::SharedPtr::get
T * get() const
Definition: daal_shared_ptr.h:332
daal::algorithms::svd::interface1::Distributed< step3Local, algorithmFPType, method >::getPartialResult
DistributedPartialResultStep3Ptr getPartialResult()
Definition: svd_distributed.h:422
daal::algorithms::svd::finalResultFromStep2Master
Definition: svd_types.h:142
daal::algorithms::svd::interface1::DistributedContainer< step1Local, algorithmFPType, method, cpu >::DistributedContainer
DistributedContainer(daal::services::Environment::env *daalEnv)
Definition: svd_distributed.h:98
daal::algorithms::svd::interface1::Distributed< step2Master, algorithmFPType, method >::input
InputType input
Definition: svd_distributed.h:255
daal::algorithms::svd::interface1::Distributed< step2Master, algorithmFPType, method >::getResult
ResultPtr getResult()
Definition: svd_distributed.h:284
daal::algorithms::svd::interface1::Distributed< step3Local, algorithmFPType, method >::parameter
ParameterType parameter
Definition: svd_distributed.h:385
daal::algorithms::svd::interface1::Distributed< step3Local, algorithmFPType, method >::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: svd_distributed.h:407
daal::algorithms::svd::interface1::Distributed< step2Master, algorithmFPType, method >::getPartialResult
DistributedPartialResultPtr getPartialResult()
Definition: svd_distributed.h:293
daal::algorithms::svd::interface1::OnlineContainer
Provides methods to run implementations of the SVD algorithm in the online processing mode...
Definition: svd_online.h:79
daal::algorithms::svd::interface1::Distributed< step3Local, algorithmFPType, method >::clone
services::SharedPtr< Distributed< step3Local, algorithmFPType, method > > clone() const
Definition: svd_distributed.h:461
daal::algorithms::svd::interface1::Distributed< step3Local, algorithmFPType, method >::setPartialResult
services::Status setPartialResult(const DistributedPartialResultStep3Ptr &partialRes)
Definition: svd_distributed.h:431
daal::algorithms::svd::interface1::DistributedStep3Input
Input objects for the third step of the SVD algorithm in the distributed processing mode ...
Definition: svd_types.h:302
daal::algorithms::svd::interface1::Distributed< step3Local, algorithmFPType, method >::getResult
ResultPtr getResult()
Definition: svd_distributed.h:413
daal::algorithms::svd::interface1::Distributed< step3Local, algorithmFPType, method >::Distributed
Distributed(const Distributed< step3Local, algorithmFPType, method > &other)
Definition: svd_distributed.h:398
daal::algorithms::Analysis
Provides methods for execution of operations over data, such as computation of Summary Statistics est...
Definition: analysis.h:94
daal::algorithms::svd::interface1::Distributed< step1Local, algorithmFPType, method >::Distributed
Distributed(const Distributed< step1Local, algorithmFPType, method > &other)
Definition: svd_distributed.h:214
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::algorithms::svd::finalResultFromStep3
Definition: svd_types.h:153
daal::algorithms::svd::interface1::Distributed< step2Master, algorithmFPType, method >::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: svd_distributed.h:278
daal::algorithms::svd::interface1::Distributed< step3Local, algorithmFPType, method >::checkFinalizeComputeParams
services::Status checkFinalizeComputeParams() DAAL_C11_OVERRIDE
Definition: svd_distributed.h:449
daal::step2Master
Definition: daal_defines.h:144
daal::algorithms::svd::interface1::OnlinePartialResult
Provides methods to access partial results obtained with the compute() method of the SVD algorithm in...
Definition: svd_types.h:342
daal::algorithms::svd::interface1::Distributed< step2Master, algorithmFPType, method >::Distributed
Distributed(const Distributed< step2Master, algorithmFPType, method > &other)
Definition: svd_distributed.h:269
daal::step3Local
Definition: daal_defines.h:145
daal::algorithms::svd::interface1::DistributedPartialResult
Provides methods to access partial results obtained with the compute() method of the SVD algorithm in...
Definition: svd_types.h:510
daal::algorithms::svd::interface1::Distributed
Computes results of the SVD algorithm in the distributed processing mode.
Definition: svd_distributed.h:182
daal::services::ErrorNullResult
Definition: error_indexes.h:122

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