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

svd_distributed.h
1 /* file: svd_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 of the SVD algorithm in the distributed processing mode
21 //--
22 */
23 
24 #ifndef __SVD_DISTRIBUTED_H__
25 #define __SVD_DISTRIBUTED_H__
26 
27 #include "algorithms/algorithm.h"
28 #include "data_management/data/numeric_table.h"
29 #include "services/daal_defines.h"
30 #include "algorithms/svd/svd_types.h"
31 #include "algorithms/svd/svd_online.h"
32 
33 namespace daal
34 {
35 namespace algorithms
36 {
37 namespace svd
38 {
39 
40 namespace interface1
41 {
56 template<ComputeStep step, typename algorithmFPType, Method method, CpuType cpu>
57 class DistributedContainer
58 {};
59 
68 template<typename algorithmFPType, Method method, CpuType cpu>
69 class DistributedContainer<step1Local, algorithmFPType, method, cpu> : public
70  OnlineContainer<algorithmFPType, method, cpu>
71 {
72 public:
74  DistributedContainer(daal::services::Environment::env *daalEnv) : OnlineContainer<algorithmFPType, method, cpu>(daalEnv) {}
76  virtual ~DistributedContainer() {}
77 };
78 
87 template<typename algorithmFPType, Method method, CpuType cpu>
88 class DistributedContainer<step2Master, algorithmFPType, method, cpu> :
89  public daal::algorithms::AnalysisContainerIface<distributed>
90 {
91 public:
97  DistributedContainer(daal::services::Environment::env *daalEnv);
99  virtual ~DistributedContainer();
104  virtual services::Status compute() DAAL_C11_OVERRIDE;
109  virtual services::Status finalizeCompute() DAAL_C11_OVERRIDE;
110 };
111 
120 template<typename algorithmFPType, Method method, CpuType cpu>
121 class DistributedContainer<step3Local, algorithmFPType, method, cpu> :
122  public daal::algorithms::AnalysisContainerIface<distributed>
123 {
124 public:
130  DistributedContainer(daal::services::Environment::env *daalEnv);
132  virtual ~DistributedContainer();
137  virtual services::Status compute() DAAL_C11_OVERRIDE;
142  virtual services::Status finalizeCompute() DAAL_C11_OVERRIDE;
143 };
144 
157 template<ComputeStep step, typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = defaultDense>
158 class DAAL_EXPORT Distributed : public daal::algorithms::Analysis<distributed> {};
159 
171 template<typename algorithmFPType, Method method>
172 class DAAL_EXPORT Distributed<step1Local, algorithmFPType, method> : public Online<algorithmFPType, method>
173 {
174 public:
175  typedef Online<algorithmFPType, method> super;
176 
177  typedef typename super::InputType InputType;
178  typedef typename super::ParameterType ParameterType;
179  typedef typename super::ResultType ResultType;
180  typedef typename super::PartialResultType PartialResultType;
181 
182  Distributed() : Online<algorithmFPType, method>() {}
183 
190  Distributed(const Distributed<step1Local, algorithmFPType, method> &other) :
191  Online<algorithmFPType, method>(other)
192  {}
193 
199  services::SharedPtr<Distributed<step1Local, algorithmFPType, method> > clone() const
200  {
201  return services::SharedPtr<Distributed<step1Local, algorithmFPType, method> >(cloneImpl());
202  }
203 
204 protected:
205  virtual Distributed<step1Local, algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
206  {
207  return new Distributed<step1Local, algorithmFPType, method>(*this);
208  }
209 };
210 
222 template<typename algorithmFPType, Method method>
223 class DAAL_EXPORT Distributed<step2Master, algorithmFPType, method> : public daal::algorithms::Analysis<distributed>
224 {
225 public:
226  typedef algorithms::svd::DistributedStep2Input InputType;
227  typedef algorithms::svd::Parameter ParameterType;
228  typedef algorithms::svd::Result ResultType;
229  typedef algorithms::svd::DistributedPartialResult PartialResultType;
230 
231  InputType input;
232  ParameterType parameter;
234  Distributed()
235  {
236  initialize();
237  }
238 
245  Distributed(const Distributed<step2Master, algorithmFPType, method> &other) : input(other.input), parameter(other.parameter)
246  {
247  initialize();
248  }
249 
254  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int)method; }
255 
260  ResultPtr getResult()
261  {
262  return _partialResult->get(finalResultFromStep2Master);
263  }
264 
269  DistributedPartialResultPtr getPartialResult()
270  {
271  return _partialResult;
272  }
273 
277  services::Status setPartialResult(const DistributedPartialResultPtr& partialRes)
278  {
279  DAAL_CHECK(partialRes, services::ErrorNullPartialResult);
280  DAAL_CHECK(partialRes->get(finalResultFromStep2Master), services::ErrorNullResult)
281  _partialResult = partialRes;
282  _pres = _partialResult.get();
283  return services::Status();
284  }
285 
289  services::Status checkFinalizeComputeParams() DAAL_C11_OVERRIDE
290  {
291  if(!_partialResult)
292  return services::Status(services::ErrorNullResult);
293  return _partialResult->check(_par, method);
294  }
295 
301  services::SharedPtr<Distributed<step2Master, algorithmFPType, method> > clone() const
302  {
303  return services::SharedPtr<Distributed<step2Master, algorithmFPType, method> >(cloneImpl());
304  }
305 
306 protected:
307  virtual Distributed<step2Master, algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
308  {
309  return new Distributed<step2Master, algorithmFPType, method>(*this);
310  }
311 
312  virtual services::Status allocateResult() DAAL_C11_OVERRIDE{ return services::Status(); }
313 
314  virtual services::Status allocatePartialResult() DAAL_C11_OVERRIDE
315  {
316  _partialResult.reset(new PartialResultType());
317  services::Status s = _partialResult->allocate<algorithmFPType>(_in, 0, 0);
318  _pres = _partialResult.get();
319  return s;
320  }
321 
322  virtual services::Status initializePartialResult() DAAL_C11_OVERRIDE
323  {
324  _pres = _partialResult.get();
325  return services::Status();
326  }
327 
328  void initialize()
329  {
330  Analysis<distributed>::_ac = new __DAAL_ALGORITHM_CONTAINER(distributed, DistributedContainer, step2Master, algorithmFPType, method)(&_env);
331  _in = &input;
332  _par = &parameter;
333  }
334 
335 private:
336  DistributedPartialResultPtr _partialResult;
337 };
338 
350 template<typename algorithmFPType, Method method>
351 class DAAL_EXPORT Distributed<step3Local, algorithmFPType, method> : public
352  daal::algorithms::Analysis<distributed>
353 {
354 public:
355  typedef algorithms::svd::DistributedStep3Input InputType;
356  typedef algorithms::svd::Parameter ParameterType;
357  typedef algorithms::svd::Result ResultType;
358  typedef algorithms::svd::DistributedPartialResultStep3 PartialResultType;
359 
360  InputType input;
361  ParameterType parameter;
363  Distributed()
364  {
365  initialize();
366  }
367 
374  Distributed(const Distributed<step3Local, algorithmFPType, method> &other) : input(other.input), parameter(other.parameter)
375  {
376  initialize();
377  }
378 
383  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int)method; }
384 
389  ResultPtr getResult()
390  {
391  return _partialResult->get(finalResultFromStep3);
392  }
393 
398  DistributedPartialResultStep3Ptr getPartialResult()
399  {
400  return _partialResult;
401  }
402 
407  services::Status setPartialResult(const DistributedPartialResultStep3Ptr& partialRes)
408  {
409  DAAL_CHECK(partialRes, services::ErrorNullPartialResult);
410  DAAL_CHECK(partialRes->get(finalResultFromStep3), services::ErrorNullResult)
411  _partialResult = partialRes;
412  _pres = _partialResult.get();
413  return services::Status();
414  }
415 
420  services::Status setResult(const ResultPtr& res) { return services::Status(); }
421 
425  services::Status checkFinalizeComputeParams() DAAL_C11_OVERRIDE
426  {
427  if(!_partialResult)
428  return services::Status(services::ErrorNullResult);
429  return _partialResult->check(_par, method);
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)
454  return s;
455 
456  data_management::DataCollectionPtr qCollection = input.get(inputOfStep3FromStep1);
457 
458  s = _partialResult->setPartialResultStorage<algorithmFPType>(qCollection.get());
459 
460  _pres = _partialResult.get();
461  return s;
462  }
463 
464  virtual services::Status allocateResult() DAAL_C11_OVERRIDE{ return services::Status(); }
465 
466  virtual services::Status initializePartialResult() DAAL_C11_OVERRIDE{ return services::Status(); }
467 
468  void initialize()
469  {
470  Analysis<distributed>::_ac = new __DAAL_ALGORITHM_CONTAINER(distributed, DistributedContainer, step3Local, algorithmFPType, method)(&_env);
471  _in = &input;
472  _par = &parameter;
473  }
474 
475 private:
476  DistributedPartialResultStep3Ptr _partialResult;
477 };
479 } // namespace interface1
480 using interface1::DistributedContainer;
481 using interface1::Distributed;
482 
483 } // namespace daal::algorithms::svd
484 } // namespace daal::algorithms
485 } // namespace daal
486 #endif
daal::algorithms::svd::interface1::Distributed< step3Local, algorithmFPType, method >::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: svd_distributed.h:383
daal::step1Local
Definition: daal_defines.h:123
daal::algorithms::svd::interface1::Distributed< step2Master, algorithmFPType, method >::checkFinalizeComputeParams
services::Status checkFinalizeComputeParams() DAAL_C11_OVERRIDE
Definition: svd_distributed.h:289
daal::algorithms::svd::interface1::Distributed< step3Local, algorithmFPType, method >::input
InputType input
Definition: svd_distributed.h:360
daal::algorithms::svd::interface1::DistributedContainer< step1Local, algorithmFPType, method, cpu >::DistributedContainer
DistributedContainer(daal::services::Environment::env *daalEnv)
Definition: svd_distributed.h:74
daal::algorithms::svd::interface1::Distributed< step2Master, algorithmFPType, method >::getPartialResult
DistributedPartialResultPtr getPartialResult()
Definition: svd_distributed.h:269
daal::algorithms::svd::interface1::Distributed< step3Local, algorithmFPType, method >::parameter
ParameterType parameter
Definition: svd_distributed.h:361
daal::algorithms::svd::interface1::DistributedContainer
Provides methods to run implementations of the SVD algorithm.
Definition: svd_distributed.h:57
daal::algorithms::svd::interface1::DistributedContainer< step1Local, algorithmFPType, method, cpu >::~DistributedContainer
virtual ~DistributedContainer()
Definition: svd_distributed.h:76
daal::algorithms::svd::interface1::Distributed< step2Master, algorithmFPType, method >::getResult
ResultPtr getResult()
Definition: svd_distributed.h:260
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:351
daal::algorithms::svd::inputOfStep3FromStep1
Definition: svd_types.h:149
daal::algorithms::svd::finalResultFromStep3
Definition: svd_types.h:129
daal::algorithms::svd::interface1::OnlineContainer
Provides methods to run implementations of the SVD algorithm in the online processing mode...
Definition: svd_online.h:55
daal::step2Master
Definition: daal_defines.h:124
daal::algorithms::svd::finalResultFromStep2Master
Definition: svd_types.h:118
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::svd::interface1::Distributed< step3Local, algorithmFPType, method >::setResult
services::Status setResult(const ResultPtr &res)
Definition: svd_distributed.h:420
daal::algorithms::svd::interface1::Distributed< step3Local, algorithmFPType, method >::clone
services::SharedPtr< Distributed< step3Local, algorithmFPType, method > > clone() const
Definition: svd_distributed.h:437
daal::algorithms::svd::interface1::Distributed< step2Master, algorithmFPType, method >::parameter
ParameterType parameter
Definition: svd_distributed.h:232
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_defines.h
daal::algorithms::svd::interface1::Distributed< step3Local, algorithmFPType, method >::checkFinalizeComputeParams
services::Status checkFinalizeComputeParams() DAAL_C11_OVERRIDE
Definition: svd_distributed.h:425
daal::algorithms::svd::interface1::Distributed< step2Master, algorithmFPType, method >::input
InputType input
Definition: svd_distributed.h:231
daal::algorithms::svd::interface1::Distributed< step1Local, algorithmFPType, method >::clone
services::SharedPtr< Distributed< step1Local, algorithmFPType, method > > clone() const
Definition: svd_distributed.h:199
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:172
daal::algorithms::svd::interface1::Distributed< step3Local, algorithmFPType, method >::getPartialResult
DistributedPartialResultStep3Ptr getPartialResult()
Definition: svd_distributed.h:398
daal::algorithms::svd::interface1::Distributed< step2Master, algorithmFPType, method >::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: svd_distributed.h:254
daal::algorithms::svd::interface1::Distributed< step3Local, algorithmFPType, method >::getResult
ResultPtr getResult()
Definition: svd_distributed.h:389
daal::algorithms::svd::interface1::Distributed< step3Local, algorithmFPType, method >::Distributed
Distributed(const Distributed< step3Local, algorithmFPType, method > &other)
Definition: svd_distributed.h:374
daal::algorithms::svd::interface1::Distributed< step2Master, algorithmFPType, method >::setPartialResult
services::Status setPartialResult(const DistributedPartialResultPtr &partialRes)
Definition: svd_distributed.h:277
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:223
daal::algorithms::svd::interface1::Distributed< step2Master, algorithmFPType, method >::Distributed
Distributed(const Distributed< step2Master, algorithmFPType, method > &other)
Definition: svd_distributed.h:245
daal::algorithms::Analysis
Provides methods for execution of operations over data, such as computation of Summary Statistics est...
Definition: analysis.h:70
daal::algorithms::svd::interface1::Distributed< step2Master, algorithmFPType, method >::clone
services::SharedPtr< Distributed< step2Master, algorithmFPType, method > > clone() const
Definition: svd_distributed.h:301
daal::services::ErrorNullPartialResult
Definition: error_indexes.h:107
daal::algorithms::svd::interface1::Distributed< step1Local, algorithmFPType, method >::Distributed
Distributed(const Distributed< step1Local, algorithmFPType, method > &other)
Definition: svd_distributed.h:190
daal::distributed
Definition: daal_defines.h:113
daal::algorithms::svd::interface1::Online
Computes results of the SVD algorithm in the online processing mode.
Definition: svd_online.h:90
daal::algorithms::svd::interface1::Distributed< step3Local, algorithmFPType, method >::setPartialResult
services::Status setPartialResult(const DistributedPartialResultStep3Ptr &partialRes)
Definition: svd_distributed.h:407
daal::algorithms::svd::interface1::Distributed
Computes results of the SVD algorithm in the distributed processing mode.
Definition: svd_distributed.h:158

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