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

svd_distributed.h
1 /* file: svd_distributed.h */
2 /*******************************************************************************
3 * Copyright 2014-2017 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  Distributed() : Online<algorithmFPType, method>() {}
200 
207  Distributed(const Distributed<step1Local, algorithmFPType, method> &other) :
208  Online<algorithmFPType, method>(other)
209  {}
210 
216  services::SharedPtr<Distributed<step1Local, algorithmFPType, method> > clone() const
217  {
218  return services::SharedPtr<Distributed<step1Local, algorithmFPType, method> >(cloneImpl());
219  }
220 
221 protected:
222  virtual Distributed<step1Local, algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
223  {
224  return new Distributed<step1Local, algorithmFPType, method>(*this);
225  }
226 };
227 
239 template<typename algorithmFPType, Method method>
240 class DAAL_EXPORT Distributed<step2Master, algorithmFPType, method> : public daal::algorithms::Analysis<distributed>
241 {
242 public:
243  DistributedStep2Input input;
244  Parameter parameter;
246  Distributed()
247  {
248  initialize();
249  }
250 
257  Distributed(const Distributed<step2Master, algorithmFPType, method> &other) : input(other.input), parameter(other.parameter)
258  {
259  initialize();
260  }
261 
266  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int)method; }
267 
272  ResultPtr getResult()
273  {
274  return _partialResult->get(finalResultFromStep2Master);
275  }
276 
281  DistributedPartialResultPtr getPartialResult()
282  {
283  return _partialResult;
284  }
285 
289  services::Status setPartialResult(const DistributedPartialResultPtr& partialRes)
290  {
291  DAAL_CHECK(partialRes, services::ErrorNullPartialResult);
292  DAAL_CHECK(partialRes->get(finalResultFromStep2Master), services::ErrorNullResult)
293  _partialResult = partialRes;
294  _pres = _partialResult.get();
295  return services::Status();
296  }
297 
301  services::Status checkFinalizeComputeParams() DAAL_C11_OVERRIDE
302  {
303  if(!_partialResult)
304  return services::Status(services::ErrorNullResult);
305  return _partialResult->check(_par, method);
306  }
307 
313  services::SharedPtr<Distributed<step2Master, algorithmFPType, method> > clone() const
314  {
315  return services::SharedPtr<Distributed<step2Master, algorithmFPType, method> >(cloneImpl());
316  }
317 
318 protected:
319  virtual Distributed<step2Master, algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
320  {
321  return new Distributed<step2Master, algorithmFPType, method>(*this);
322  }
323 
324  virtual services::Status allocateResult() DAAL_C11_OVERRIDE{ return services::Status(); }
325 
326  virtual services::Status allocatePartialResult() DAAL_C11_OVERRIDE
327  {
328  _partialResult.reset(new DistributedPartialResult());
329  services::Status s = _partialResult->allocate<algorithmFPType>(_in, 0, 0);
330  _pres = _partialResult.get();
331  return s;
332  }
333 
334  virtual services::Status initializePartialResult() DAAL_C11_OVERRIDE
335  {
336  _pres = _partialResult.get();
337  return services::Status();
338  }
339 
340  void initialize()
341  {
342  Analysis<distributed>::_ac = new __DAAL_ALGORITHM_CONTAINER(distributed, DistributedContainer, step2Master, algorithmFPType, method)(&_env);
343  _in = &input;
344  _par = &parameter;
345  }
346 
347 private:
348  DistributedPartialResultPtr _partialResult;
349 };
350 
362 template<typename algorithmFPType, Method method>
363 class DAAL_EXPORT Distributed<step3Local, algorithmFPType, method> : public
364  daal::algorithms::Analysis<distributed>
365 {
366 public:
367  DistributedStep3Input input;
368  Parameter parameter;
370  Distributed()
371  {
372  initialize();
373  }
374 
381  Distributed(const Distributed<step3Local, algorithmFPType, method> &other) : input(other.input), parameter(other.parameter)
382  {
383  initialize();
384  }
385 
390  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int)method; }
391 
396  ResultPtr getResult()
397  {
398  return _partialResult->get(finalResultFromStep3);
399  }
400 
405  DistributedPartialResultStep3Ptr getPartialResult()
406  {
407  return _partialResult;
408  }
409 
414  services::Status setPartialResult(const DistributedPartialResultStep3Ptr& partialRes)
415  {
416  DAAL_CHECK(partialRes, services::ErrorNullPartialResult);
417  DAAL_CHECK(partialRes->get(finalResultFromStep3), services::ErrorNullResult)
418  _partialResult = partialRes;
419  _pres = _partialResult.get();
420  return services::Status();
421  }
422 
427  services::Status setResult(const ResultPtr& res) { return services::Status(); }
428 
432  services::Status checkFinalizeComputeParams() DAAL_C11_OVERRIDE
433  {
434  if(!_partialResult)
435  return services::Status(services::ErrorNullResult);
436  return _partialResult->check(_par, method);
437  }
438 
444  services::SharedPtr<Distributed<step3Local, algorithmFPType, method> > clone() const
445  {
446  return services::SharedPtr<Distributed<step3Local, algorithmFPType, method> >(cloneImpl());
447  }
448 
449 protected:
450  virtual Distributed<step3Local, algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
451  {
452  return new Distributed<step3Local, algorithmFPType, method>(*this);
453  }
454 
455  virtual services::Status allocatePartialResult() DAAL_C11_OVERRIDE
456  {
457  _partialResult.reset(new DistributedPartialResultStep3());
458 
459  services::Status s = _partialResult->allocate<algorithmFPType>(_in, 0, 0);
460  if(!s)
461  return s;
462 
463  data_management::DataCollectionPtr qCollection = input.get(inputOfStep3FromStep1);
464 
465  s = _partialResult->setPartialResultStorage<algorithmFPType>(qCollection.get());
466 
467  _pres = _partialResult.get();
468  return s;
469  }
470 
471  virtual services::Status allocateResult() DAAL_C11_OVERRIDE{ return services::Status(); }
472 
473  virtual services::Status initializePartialResult() DAAL_C11_OVERRIDE{ return services::Status(); }
474 
475  void initialize()
476  {
477  Analysis<distributed>::_ac = new __DAAL_ALGORITHM_CONTAINER(distributed, DistributedContainer, step3Local, algorithmFPType, method)(&_env);
478  _in = &input;
479  _par = &parameter;
480  }
481 
482 private:
483  DistributedPartialResultStep3Ptr _partialResult;
484 };
486 } // namespace interface1
487 using interface1::DistributedContainer;
488 using interface1::Distributed;
489 
490 } // namespace daal::algorithms::svd
491 } // namespace daal::algorithms
492 } // namespace daal
493 #endif
daal::algorithms::svd::interface1::Distributed< step1Local, algorithmFPType, method >::clone
services::SharedPtr< Distributed< step1Local, algorithmFPType, method > > clone() const
Definition: svd_distributed.h:216
daal::algorithms::svd::interface1::Distributed< step3Local, algorithmFPType, method >::parameter
Parameter parameter
Definition: svd_distributed.h:368
daal::algorithms::svd::interface1::Distributed< step3Local, algorithmFPType, method >::setResult
services::Status setResult(const ResultPtr &res)
Definition: svd_distributed.h:427
daal::algorithms::svd::interface1::Distributed< step3Local, algorithmFPType, method >::clone
services::SharedPtr< Distributed< step3Local, algorithmFPType, method > > clone() const
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
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::Distributed< step2Master, algorithmFPType, method >::clone
services::SharedPtr< Distributed< step2Master, algorithmFPType, method > > clone() const
Definition: svd_distributed.h:313
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::Distributed< step2Master, algorithmFPType, method >::setPartialResult
services::Status setPartialResult(const DistributedPartialResultPtr &partialRes)
Definition: svd_distributed.h:289
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:363
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:240
daal::algorithms::svd::interface1::Distributed< step2Master, algorithmFPType, method >::checkFinalizeComputeParams
services::Status checkFinalizeComputeParams() DAAL_C11_OVERRIDE
Definition: svd_distributed.h:301
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:132
daal::algorithms::svd::interface1::Distributed< step2Master, algorithmFPType, method >::input
DistributedStep2Input input
Definition: svd_distributed.h:243
daal::algorithms::svd::interface1::DistributedContainer< step1Local, algorithmFPType, method, cpu >::~DistributedContainer
virtual ~DistributedContainer()
Definition: svd_distributed.h:100
daal::algorithms::svd::interface1::Distributed< step3Local, algorithmFPType, method >::getPartialResult
DistributedPartialResultStep3Ptr getPartialResult()
Definition: svd_distributed.h:405
daal::algorithms::svd::interface1::Distributed< step3Local, algorithmFPType, method >::input
DistributedStep3Input input
Definition: svd_distributed.h:367
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 >::getResult
ResultPtr getResult()
Definition: svd_distributed.h:272
daal::algorithms::svd::interface1::Distributed< step3Local, algorithmFPType, method >::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: svd_distributed.h:390
daal::algorithms::svd::interface1::Distributed< step2Master, algorithmFPType, method >::getPartialResult
DistributedPartialResultPtr getPartialResult()
Definition: svd_distributed.h:281
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 >::setPartialResult
services::Status setPartialResult(const DistributedPartialResultStep3Ptr &partialRes)
Definition: svd_distributed.h:414
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:396
daal::algorithms::svd::interface1::Distributed< step3Local, algorithmFPType, method >::Distributed
Distributed(const Distributed< step3Local, algorithmFPType, method > &other)
Definition: svd_distributed.h:381
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:207
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::algorithms::svd::interface1::Distributed< step2Master, algorithmFPType, method >::parameter
Parameter parameter
Definition: svd_distributed.h:244
daal::step1Local
Definition: daal_defines.h:142
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:266
daal::algorithms::svd::interface1::Distributed< step3Local, algorithmFPType, method >::checkFinalizeComputeParams
services::Status checkFinalizeComputeParams() DAAL_C11_OVERRIDE
Definition: svd_distributed.h:432
daal::step2Master
Definition: daal_defines.h:143
daal::algorithms::svd::interface1::Distributed< step2Master, algorithmFPType, method >::Distributed
Distributed(const Distributed< step2Master, algorithmFPType, method > &other)
Definition: svd_distributed.h:257
daal::step3Local
Definition: daal_defines.h:144
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.