planc
Parallel Lowrank Approximation with Non-negativity Constraints
ntfanlsbpp.hpp
Go to the documentation of this file.
1 /* Copyright Ramakrishnan Kannan 2018 */
2 
3 #ifndef NTF_NTFANLSBPP_HPP_
4 #define NTF_NTFANLSBPP_HPP_
5 
6 #include "nnls/bppnnls.hpp"
7 #include "ntf/auntf.hpp"
8 
9 namespace planc {
10 
11 #define ONE_THREAD_MATRIX_SIZE 2000
12 
13 class NTFANLSBPP : public AUNTF {
14  protected:
15  MAT update(const int mode) {
16  MAT othermat(this->m_ncp_factors.factor(mode).t());
17  unsigned int numThreads =
18  (this->ncp_mttkrp_t[mode].n_cols / ONE_THREAD_MATRIX_SIZE) + 1;
19 #pragma omp parallel for schedule(dynamic)
20  for (UINT i = 0; i < numThreads; i++) {
21  UINT spanStart = i * ONE_THREAD_MATRIX_SIZE;
22  UINT spanEnd = (i + 1) * ONE_THREAD_MATRIX_SIZE - 1;
23  if (spanEnd > this->ncp_mttkrp_t[mode].n_cols - 1) {
24  spanEnd = this->ncp_mttkrp_t[mode].n_cols - 1;
25  }
26  // if it is exactly divisible, the last iteration is unnecessary.
27  BPPNNLS<MAT, VEC> *subProblem;
28  if (spanStart <= spanEnd) {
29  if (spanStart == spanEnd) {
30  subProblem = new BPPNNLS<MAT, VEC>(
31  this->gram_without_one,
32  (VEC)this->ncp_mttkrp_t[mode].col(spanStart), true);
33  } else { // if (spanStart < spanEnd)
34  subProblem = new BPPNNLS<MAT, VEC>(
35  this->gram_without_one,
36  (MAT)this->ncp_mttkrp_t[mode].cols(spanStart, spanEnd), true);
37  }
38 #ifdef _VERBOSE
39  INFO << "Scheduling " << worh << " start=" << spanStart
40  << ", end=" << spanEnd << ", tid=" << omp_get_thread_num()
41  << std::endl;
42 #endif
43  // tic();
44  subProblem->solveNNLS();
45  // t2 = toc();
46 #ifdef _VERBOSE
47  INFO << "completed " << worh << " start=" << spanStart
48  << ", end=" << spanEnd << ", tid=" << omp_get_thread_num()
49  << " cpu=" << sched_getcpu() << " time taken=" << t2
50  << " num_iterations()=" << numIter << std::endl;
51 #endif
52  if (spanStart == spanEnd) {
53  VEC solVec = subProblem->getSolutionVector();
54  othermat.col(i) = solVec;
55  } else { // if (spanStart < spanEnd)
56  othermat.cols(spanStart, spanEnd) =
57  subProblem->getSolutionMatrix();
58  }
59  subProblem->clear();
60  delete subProblem;
61  }
62  }
63  return othermat;
64  }
65 
66  public:
67  NTFANLSBPP(const Tensor &i_tensor, const int i_k, algotype i_algo)
68  : AUNTF(i_tensor, i_k, i_algo) {}
69 }; // class NTFANLSBPP
70 
71 } // namespace planc
72 
73 #endif // NTF_NTFANLSBPP_HPP_
MATTYPE getSolutionMatrix()
Definition: nnls.hpp:79
Data is stored such that the unfolding is column major.
Definition: tensor.hpp:32
algotype
Definition: utils.h:10
#define ONE_THREAD_MATRIX_SIZE
Definition: ntfanlsbpp.hpp:11
#define INFO
Definition: utils.h:36
int solveNNLS()
Definition: bppnnls.hpp:30
VECTYPE getSolutionVector()
Definition: nnls.hpp:76
unsigned int UINT
Definition: utils.h:68
#define MAT
Definition: utils.h:52
void clear()
Definition: nnls.hpp:82
NTFANLSBPP(const Tensor &i_tensor, const int i_k, algotype i_algo)
Definition: ntfanlsbpp.hpp:67
ncp_factors contains the factors of the ncp every ith factor is of size n_i * k number of factors is ...
Definition: ncpfactors.hpp:20
#define VEC
Definition: utils.h:61