COMBINATORIAL_BLAS  1.6
dcsc.h
Go to the documentation of this file.
1 /****************************************************************/
2 /* Parallel Combinatorial BLAS Library (for Graph Computations) */
3 /* version 1.6 -------------------------------------------------*/
4 /* date: 6/15/2017 ---------------------------------------------*/
5 /* authors: Ariful Azad, Aydin Buluc --------------------------*/
6 /****************************************************************/
7 /*
8  Copyright (c) 2010-2017, The Regents of the University of California
9 
10 
11  Permission is hereby granted, free of charge, to any person obtaining a copy
12  of this software and associated documentation files (the "Software"), to deal
13  in the Software without restriction, including without limitation the rights
14  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15  copies of the Software, and to permit persons to whom the Software is
16  furnished to do so, subject to the following conditions:
17 
18  The above copyright notice and this permission notice shall be included in
19  all copies or substantial portions of the Software.
20 
21  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27  THE SOFTWARE.
28  */
29 
30 
31 #ifndef _DCSC_H
32 #define _DCSC_H
33 
34 #include <cstdlib>
35 #include <vector>
36 #include <limits>
37 #include <cassert>
38 #include "SpDefs.h"
39 #include "SpHelper.h"
40 #include "StackEntry.h"
41 #include "MemoryPool.h"
42 #include "promote.h"
43 
44 namespace combblas {
45 
46 template <class IT, class NT>
47 class Dcsc
48 {
49 public:
50  typedef NT value_type;
51  typedef IT index_type;
52  Dcsc ();
53  Dcsc (IT nnz, IT nzcol);
54 
55  Dcsc (IT nnz, const std::vector<IT> & indices, bool isRow);
56  Dcsc (StackEntry<NT, std::pair<IT,IT> > * multstack, IT mdim, IT ndim, IT nnz);
57 
58  Dcsc (const Dcsc<IT,NT> & rhs); // copy constructor
59  Dcsc<IT,NT> & operator=(const Dcsc<IT,NT> & rhs); // assignment operator
60  Dcsc<IT,NT> & operator+=(const Dcsc<IT,NT> & rhs); // add and assign operator
61  ~Dcsc();
62 
63  bool operator==(const Dcsc<IT,NT> & rhs);
64  template <typename NNT> operator Dcsc<IT,NNT>() const; //<! numeric type conversion
65  template <typename NIT, typename NNT> operator Dcsc<NIT,NNT>() const; //<! index+numeric type conversion
66 
67  void EWiseMult(const Dcsc<IT,NT> & rhs, bool exclude);
68  void EWiseScale(NT ** scaler); //<! scale elements of "this" with the elements dense rhs matrix
69 
70  template <typename IU, typename NU1, typename NU2>
71  friend Dcsc<IU, typename promote_trait<NU1,NU2>::T_promote> EWiseMult(const Dcsc<IU,NU1> & A, const Dcsc<IU,NU2> * B, bool exclude); // Note that the second parameter is a POINTER
72 
73  template <typename _UnaryOperation>
74  void Apply(_UnaryOperation __unary_op)
75  {
76  //transform(numx, numx+nz, numx, __unary_op);
77 #ifdef _OPENMP
78 #pragma omp parallel for
79 #endif
80  for(IT i=0; i < nz; ++i)
81  numx[i] = __unary_op(numx[i]);
82 
83  }
84 
85  template <typename _UnaryOperation, typename GlobalIT>
86  Dcsc<IT,NT>* PruneI(_UnaryOperation __unary_op, bool inPlace, GlobalIT rowOffset, GlobalIT colOffset);
87  template <typename _UnaryOperation>
88  Dcsc<IT,NT>* Prune(_UnaryOperation __unary_op, bool inPlace);
89  template <typename _BinaryOperation>
90  Dcsc<IT,NT>* PruneColumn(NT* pvals, _BinaryOperation __binary_op, bool inPlace);
91  template <typename _BinaryOperation>
92  Dcsc<IT,NT>* PruneColumn(IT* pinds, NT* pvals, _BinaryOperation __binary_op, bool inPlace);
93 
94 
95  IT AuxIndex(const IT colind, bool & found, IT * aux, IT csize) const;
96 
97  void RowSplit(int numsplits);
98  void ColSplit(std::vector< Dcsc<IT,NT>* > & parts, std::vector<IT> & cuts);
99  void ColConcatenate(std::vector< Dcsc<IT,NT>* > & parts, std::vector<IT> & offsets);
100 
101  void Split(Dcsc<IT,NT> * & A, Dcsc<IT,NT> * & B, IT cut);
102  void Merge(const Dcsc<IT,NT> * Adcsc, const Dcsc<IT,NT> * B, IT cut);
103 
104  IT ConstructAux(IT ndim, IT * & aux) const;
105  void Resize(IT nzcnew, IT nznew);
106 
107  template<class VT>
108  void FillColInds(const VT * colnums, IT nind, std::vector< std::pair<IT,IT> > & colinds, IT * aux, IT csize) const;
109 
110  Dcsc<IT,NT> & AddAndAssign (StackEntry<NT, std::pair<IT,IT> > * multstack, IT mdim, IT ndim, IT nnz);
111 
112  template <typename _BinaryOperation>
113  void UpdateDense(NT ** array, _BinaryOperation __binary_op) const; // update dense 2D array's entries with __binary_op using elements of "this"
114 
116  Dcsc (IT * _cp, IT * _jc, IT * _ir, NT * _numx, IT _nz, IT _nzc, bool _memowned = true)
117  : cp(_cp), jc(_jc), ir(_ir), numx(_numx), nz(_nz), nzc(_nzc), memowned(_memowned) {};
118 
119  IT * cp;
120  IT * jc ;
121  IT * ir ;
122  NT * numx;
123 
124  IT nz;
125  IT nzc;
126  bool memowned;
127 
128 private:
129  void getindices (StackEntry<NT, std::pair<IT,IT> > * multstack, IT & rindex, IT & cindex, IT & j, IT nnz);
130 };
131 
132 }
133 
134 #include "dcsc.cpp"
135 
136 #endif
double B
void RowSplit(int numsplits)
void EWiseScale(NT **scaler)
Definition: dcsc.cpp:874
bool memowned
Definition: dcsc.h:126
Dcsc< IT, NT > * PruneColumn(NT *pvals, _BinaryOperation __binary_op, bool inPlace)
Definition: dcsc.cpp:686
void Apply(_UnaryOperation __unary_op)
Definition: dcsc.h:74
Definition: StackEntry.h:9
Dcsc(IT *_cp, IT *_jc, IT *_ir, NT *_numx, IT _nz, IT _nzc, bool _memowned=true)
wrap object around pre-allocated arrays (possibly RDMA registered)
Definition: dcsc.h:116
void Resize(IT nzcnew, IT nznew)
Definition: dcsc.cpp:946
IT * ir
row indices, size nz
Definition: dcsc.h:121
void EWiseMult(const Dcsc< IT, NT > &rhs, bool exclude)
Definition: dcsc.cpp:513
IT * cp
The master array, size nzc+1 (keeps column pointers)
Definition: dcsc.h:117
void Merge(const Dcsc< IT, NT > *Adcsc, const Dcsc< IT, NT > *B, IT cut)
Definition: dcsc.cpp:1134
void FillColInds(const VT *colnums, IT nind, std::vector< std::pair< IT, IT > > &colinds, IT *aux, IT csize) const
Definition: dcsc.cpp:1211
double A
Dcsc< IT, NT > * Prune(_UnaryOperation __unary_op, bool inPlace)
Definition: dcsc.cpp:604
void ColSplit(std::vector< Dcsc< IT, NT > * > &parts, std::vector< IT > &cuts)
Definition: dcsc.cpp:1070
bool operator==(const Dcsc< IT, NT > &rhs)
Definition: dcsc.cpp:472
IT AuxIndex(const IT colind, bool &found, IT *aux, IT csize) const
Definition: dcsc.cpp:1013
void ColConcatenate(std::vector< Dcsc< IT, NT > * > &parts, std::vector< IT > &offsets)
Definition: dcsc.cpp:1168
void UpdateDense(NT **array, _BinaryOperation __binary_op) const
Definition: dcsc.cpp:893
Dcsc< IT, NT > & operator+=(const Dcsc< IT, NT > &rhs)
Definition: dcsc.cpp:374
NT * numx
generic values, size nz
Definition: dcsc.h:122
IT nzc
number of columns with at least one non-zero in them
Definition: dcsc.h:125
NT value_type
Definition: dcsc.h:50
IT ConstructAux(IT ndim, IT *&aux) const
Definition: dcsc.cpp:912
Dcsc< IT, NT > * PruneI(_UnaryOperation __unary_op, bool inPlace, GlobalIT rowOffset, GlobalIT colOffset)
Definition: dcsc.cpp:523
Definition: CCGrid.h:4
IT index_type
Definition: dcsc.h:51
IT * jc
col indices, size nzc
Definition: dcsc.h:120
Dcsc< IT, NT > & operator=(const Dcsc< IT, NT > &rhs)
Definition: dcsc.cpp:328
Dcsc< IT, NT > & AddAndAssign(StackEntry< NT, std::pair< IT, IT > > *multstack, IT mdim, IT ndim, IT nnz)
Definition: dcsc.cpp:71
void Split(Dcsc< IT, NT > *&A, Dcsc< IT, NT > *&B, IT cut)
Definition: dcsc.cpp:1030