45 template <
class IT,
class NT>
49 template <
class IT,
class NT>
54 template <
class IT,
class NT>
56 :m(nRow), n(nCol), nnz(size), splits(0)
64 template <
class IT,
class NT>
73 for(
int i=0; i<splits; ++i)
87 template <
class IT,
class NT>
89 : m(rhs.m), n(rhs.n), nnz(rhs.nnz), splits(rhs.splits)
93 for(
int i=0; i<splits; ++i)
108 template <
class IT,
class NT>
110 : m(rhs.m), n(rhs.n), nnz(rhs.nnz), splits(0)
115 if(transpose) std::swap(m,n);
124 std::vector< std::pair<IT,NT> > tosort (nnz);
125 std::vector<IT> work(n+1, (IT) 0 );
126 for (IT k = 0 ; k < nnz ; ++k)
133 std::partial_sum(work.begin(), work.end(), work.begin());
134 std::copy(work.begin(), work.end(),
csc->jc);
136 for (IT k = 0 ; k < nnz ; ++k)
141 #pragma omp parallel for 143 for(
int i=0; i< n; ++i)
145 sort(tosort.begin() +
csc->jc[i], tosort.begin() +
csc->jc[i+1]);
148 typename std::vector<std::pair<IT,NT> >::iterator itr;
149 for(itr = tosort.begin() +
csc->jc[i], ind =
csc->jc[i]; itr != tosort.begin() +
csc->jc[i+1]; ++itr, ++ind)
151 csc->ir[ind] = itr->first;
152 csc->num[ind] = itr->second;
160 std::vector< std::pair<IT,NT> > tosort (nnz);
161 std::vector<IT> work(n+1, (IT) 0 );
162 for (IT k = 0 ; k < nnz ; ++k)
169 std::partial_sum(work.begin(), work.end(), work.begin());
170 std::copy(work.begin(), work.end(),
csc->jc);
172 for (IT k = 0 ; k < nnz ; ++k)
177 #pragma omp parallel for 179 for(
int i=0; i< n; ++i)
181 sort(tosort.begin() +
csc->jc[i], tosort.begin() +
csc->jc[i+1]);
184 typename std::vector<std::pair<IT,NT> >::iterator itr;
185 for(itr = tosort.begin() +
csc->jc[i], ind =
csc->jc[i]; itr != tosort.begin() +
csc->jc[i+1]; ++itr, ++ind)
187 csc->ir[ind] = itr->first;
188 csc->num[ind] = itr->second;
205 template <
class IT,
class NT>
212 if(
csc != NULL && nnz > 0)
235 template <
class IT,
class NT>
239 IT perpiece = m / splits;
240 std::vector<IT> nnzs(splits, 0);
241 std::vector < std::vector < std::tuple<IT,IT,NT> > > colrowpairs(splits);
242 std::vector< std::vector<IT> > colcnts(splits);
243 for(
int i=0; i< splits; ++i)
244 colcnts[i].resize(n, 0);
246 if(nnz > 0 &&
csc != NULL)
248 for(IT i=0; i<
csc->n; ++i)
250 for(IT j =
csc->jc[i]; j< csc->jc[i+1]; ++j)
252 IT rowid =
csc->ir[j];
253 IT owner = std::min(rowid / perpiece, static_cast<IT>(splits-1));
254 colrowpairs[owner].push_back(std::make_tuple(i, rowid - owner*perpiece,
csc->num[i]));
256 ++(colcnts[owner][i]);
265 #pragma omp parallel for 267 for(
int i=0; i< splits; ++i)
270 sort(colrowpairs[i].begin(), colrowpairs[i].end());
272 std::partial_sum(colcnts[i].begin(), colcnts[i].end(),
cscarr[i]->jc+1);
273 std::copy(
cscarr[i]->jc,
cscarr[i]->jc+n, colcnts[i].begin());
276 for(IT k=0; k<nnzs[i]; ++k)
278 IT cindex = std::get<0>(colrowpairs[i][k]);
279 IT rindex = std::get<1>(colrowpairs[i][k]);
280 NT value = std::get<2>(colrowpairs[i][k]);
282 IT curcptr = (colcnts[i][cindex])++;
283 cscarr[i]->ir[curcptr] = rindex;
284 cscarr[i]->num[curcptr] = value;
290 template<
class IT,
class NT>
293 std::cout <<
"m: " << m ;
294 std::cout <<
", n: " << n ;
295 std::cout <<
", nnz: "<< nnz ;
299 std::cout <<
", local splits: " << splits << std::endl;
301 if(omp_get_thread_num() == 0)
309 std::cout << std::endl;
322 template <
class IT,
class NT>
326 std::cout <<
"Printing for thread " << omp_get_thread_num() << std::endl;
330 NT **
A = SpHelper::allocate2D<NT>(m,n);
331 for(IT i=0; i< m; ++i)
332 for(IT j=0; j<n; ++j)
336 for(IT i=0; i< n; ++i)
338 for(IT j = mycsc->
jc[i]; j< mycsc->jc[i+1]; ++j)
340 IT rowid = mycsc->
ir[j];
341 A[rowid][i] = mycsc->
num[j];
345 for(IT i=0; i< m; ++i)
347 for(IT j=0; j<n; ++j)
349 std::cout << std::setiosflags(std::ios::fixed) << std::setprecision(2) << A[i][j];
352 std::cout << std::endl;
359 template <
class IT,
class NT>
SpCCols< IT, NT > & operator=(const SpCCols< IT, NT > &rhs)
void RowSplit(int numsplits)
static void deallocate2D(T **array, I m)