COMBINATORIAL_BLAS 1.6
 
Loading...
Searching...
No Matches
SpCCols.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 Permission is hereby granted, free of charge, to any person obtaining a copy
11 of this software and associated documentation files (the "Software"), to deal
12 in the Software without restriction, including without limitation the rights
13 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 copies of the Software, and to permit persons to whom the Software is
15 furnished to do so, subject to the following conditions:
16
17 The above copyright notice and this permission notice shall be included in
18 all copies or substantial portions of the Software.
19
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26 THE SOFTWARE.
27 */
28
29
30#ifndef _SP_CCOLS_H_
31#define _SP_CCOLS_H_
32
33#include <cmath>
34#include "SpMat.h" // Best to include the base class first
35#include "SpHelper.h"
36#include "csc.h"
37
38namespace combblas {
39
40template <class IT, class NT>
41class SpCCols: public SpMat<IT, NT, SpCCols<IT, NT> >
42{
43public:
44 typedef IT LocalIT;
45 typedef NT LocalNT;
46
47 // Constructors :
48 SpCCols ();
50 SpCCols (const SpTuples<IT,NT> & rhs, bool transpose);
51 SpCCols (const SpDCCols<IT,NT> & rhs):nnz(0), n(0), m(0), splits(0), csc(NULL)
52 {
53 SpTuples<IT,NT> tuples(rhs);
54 SpCCols<IT,NT> object(tuples, false);
55 *this = object; // its members are already initialized by the initializer list
56 }
57
58 SpCCols (const SpCCols<IT,NT> & rhs); // Actual copy constructor
59 ~SpCCols();
60
61 // Member Functions and Operators:
64
65 void RowSplit(int numsplits);
66 void ColSplit(int parts, std::vector< SpCCols<IT,NT> > & matrices);
67
68 void CreateImpl(const std::vector<IT> & essentials);
69 void CreateImpl(IT size, IT nRow, IT nCol, std::tuple<IT, IT, NT> * mytuples);
70
71 Arr<IT,NT> GetArrays() const;
72 std::vector<IT> GetEssentials() const;
73 const static IT esscount;
74
75 IT getnrow() const { return m; }
76 IT getncol() const { return n; }
77 IT getnnz() const { return nnz; }
78 int getnsplit() const { return splits; }
79
80
81 auto GetInternal() const { return GetCSC(); }
82 auto GetInternal(int i) const { return GetCSC(i); }
83
84
85 class SpColIter
86 {
87 public:
88 class NzIter
89 {
90 public:
91 NzIter(IT * ir = NULL, NT * num = NULL) : rid(ir), val(num) {}
92
93 bool operator==(const NzIter & other)
94 {
95 return(rid == other.rid); // compare pointers
96 }
97 bool operator!=(const NzIter & other)
98 {
99 return(rid != other.rid);
100 }
101 NzIter & operator++() // prefix operator
102 {
103 ++rid;
104 ++val;
105 return(*this);
106 }
107 NzIter operator++(int) // postfix operator
108 {
109 NzIter tmp(*this);
110 ++(*this);
111 return(tmp);
112 }
114 {
115 return (*rid);
116 }
118 {
119 return (*val);
120 }
121 private:
122 IT * rid;
123 NT * val;
124
125 };
126
127 SpColIter(IT * jc = NULL) : begcptr(jc), curcptr(jc) {}
128 bool operator==(const SpColIter& other)
129 {
130 return(curcptr == other.curcptr); // compare pointers
131 }
132 bool operator!=(const SpColIter& other)
133 {
134 return(curcptr != other.curcptr);
135 }
136 SpColIter& operator++() // prefix operator (different across derived classes)
137 {
138 ++curcptr;
139 return(*this);
140 }
142 {
143 return (curcptr-begcptr);
144 }
145 IT colptr() const // only needed internally by ::begnz() below
146 {
147 return (*curcptr);
148 }
149 IT colptrnext() const // only needed internally by ::begnz() below
150 {
151 return (*(curcptr+1));
152 }
153 IT nnz() const
154 {
155 return (colptrnext() - colptr());
156 }
157 private:
158 IT * begcptr;
159 IT * curcptr;
160 };
161
162 SpColIter begcol() // serial version
163 {
164 if( nnz > 0 )
165 return SpColIter(csc->jc);
166 else
167 return SpColIter(NULL);
168 }
169 SpColIter endcol() //serial version
170 {
171 if( nnz > 0 )
172 return SpColIter(csc->jc + n); // (csc->jc+n) should never execute because SpColIter::colptrnext() would point invalid
173 else
174 return SpColIter(NULL);
175 }
176
177 SpColIter begcol(int i) // multithreaded version
178 {
179 if( cscarr[i] )
180 return SpColIter(cscarr[i]->jc);
181 else
182 return SpColIter(NULL);
183 }
184 SpColIter endcol(int i) //multithreaded version
185 {
186 if( cscarr[i] )
187 return SpColIter(cscarr[i]->jc + n); // (csc->jc+n) should never execute because SpColIter::colptrnext() would point invalid
188 else
189 return SpColIter(NULL);
190 }
191
192
194 {
195 return typename SpColIter::NzIter( csc->ir + ccol.colptr(), csc->num + ccol.colptr() );
196 }
197
199 {
200 return typename SpColIter::NzIter( csc->ir + ccol.colptrnext(), NULL );
201 }
202
203 typename SpColIter::NzIter begnz(const SpColIter & ccol, int i)
204 {
205 return typename SpColIter::NzIter( cscarr[i]->ir + ccol.colptr(), cscarr[i]->num + ccol.colptr() );
206 }
207
208 typename SpColIter::NzIter endnz(const SpColIter & ccol, int i)
209 {
210 return typename SpColIter::NzIter( cscarr[i]->ir + ccol.colptrnext(), NULL );
211 }
212
213 void PrintInfo() const;
214
215
216 template <typename UnaryOperation,
217 typename GlobalIT>
220 GlobalIT rowOffset, GlobalIT colOffset);
221
222
224 GetCSC() const // only for single threaded matrices
225 {
226 return csc;
227 }
228
229
231 GetCSC(int i) const // only for split (multithreaded) matrices
232 {
233 return cscarr[i];
234 }
235
236
237 bool
238 isZero() const
239 {
240 return (nnz == 0);
241 }
242
243
244 // Transpose members
245 void Transpose();
248
249 void
251
252 void
254
255 std::ofstream &
256 put (std::ofstream &outfile) const;
257
258
259
260private:
261
263
264 void SubPrintInfo(Csc<IT,NT> * mycsc) const;
265
266 // Anonymous union
267 union {
270 };
271
272 IT m;
273 IT n;
274 IT nnz;
275
276 int splits; // for multithreading
277
278 template <class IU, class NU>
279 friend class SpTuples;
280
281 void CopyCsc(Csc<IT,NT> * source);
282
283 template <typename SR, typename IU, typename NU, typename RHS, typename LHS>
284 friend void csc_gespmv_dense (const SpCCols<IU, NU> & A, const RHS * x, LHS * y);
285
286 //<! sparse vector version
287 template <typename SR, typename IU, typename NUM, typename DER, typename IVT, typename OVT>
288 friend int generic_gespmv_threaded (const SpMat<IU,NUM,DER> & A, const int32_t * indx, const IVT * numx, int32_t nnzx,
289 int32_t * & sendindbuf, OVT * & sendnumbuf, int * & sdispls, int p_c, PreAllocatedSPA<OVT> & SPA);
290};
291
292
293// At this point, complete type of of SpCCols is known, safe to declare these specialization (but macros won't work as they are preprocessed)
294// General case #1: When both NT is the same
295template <class IT, class NT> struct promote_trait< SpCCols<IT,NT> , SpCCols<IT,NT> >
296{
298};
299// General case #2: First is boolean the second is anything except boolean (to prevent ambiguity)
300template <class IT, class NT> struct promote_trait< SpCCols<IT,bool> , SpCCols<IT,NT>, typename combblas::disable_if< combblas::is_boolean<NT>::value >::type >
301{
303};
304// General case #3: Second is boolean the first is anything except boolean (to prevent ambiguity)
305template <class IT, class NT> struct promote_trait< SpCCols<IT,NT> , SpCCols<IT,bool>, typename combblas::disable_if< combblas::is_boolean<NT>::value >::type >
306{
308};
309template <class IT> struct promote_trait< SpCCols<IT,int> , SpCCols<IT,float> >
310{
312};
313
314template <class IT> struct promote_trait< SpCCols<IT,float> , SpCCols<IT,int> >
315{
317};
318template <class IT> struct promote_trait< SpCCols<IT,int> , SpCCols<IT,double> >
319{
321};
322template <class IT> struct promote_trait< SpCCols<IT,double> , SpCCols<IT,int> >
323{
325};
326
327
328// Capture everything of the form SpCCols<OIT, ONT>
329// it may come as a surprise that the partial specializations can
330// involve more template parameters than the primary template
331template <class NIT, class NNT, class OIT, class ONT>
336
337}
338
339#include "SpCCols.cpp"
340
341#endif
int64_t IT
double NT
Iterate over the nonzeros of the sparse column.
Definition SpCCols.h:89
bool operator==(const NzIter &other)
Definition SpCCols.h:93
IT rowid() const
< Return the "local" rowid of the current nonzero entry.
Definition SpCCols.h:113
NzIter(IT *ir=NULL, NT *num=NULL)
Definition SpCCols.h:91
bool operator!=(const NzIter &other)
Definition SpCCols.h:97
Iterate over (sparse) columns of the sparse matrix.
Definition SpCCols.h:86
IT colid() const
< Return the "local" colid of the current column.
Definition SpCCols.h:141
bool operator!=(const SpColIter &other)
Definition SpCCols.h:132
bool operator==(const SpColIter &other)
Definition SpCCols.h:128
void CreateImpl(const std::vector< IT > &essentials)
Definition SpCCols.cpp:383
SpColIter::NzIter endnz(const SpColIter &ccol, int i)
Definition SpCCols.h:208
Csc< IT, NT > * GetCSC(int i) const
Definition SpCCols.h:231
friend int generic_gespmv_threaded(const SpMat< IU, NUM, DER > &A, const int32_t *indx, const IVT *numx, int32_t nnzx, int32_t *&sendindbuf, OVT *&sendnumbuf, int *&sdispls, int p_c, PreAllocatedSPA< OVT > &SPA)
Definition Friends.h:182
SpColIter begcol(int i)
Definition SpCCols.h:177
SpCCols< IT, NT > & operator+=(const SpCCols< IT, NT > &rhs)
Csc< IT, NT > ** cscarr
Definition SpCCols.h:269
void RowSplit(int numsplits)
Definition SpCCols.cpp:236
Csc< IT, NT > * GetCSC() const
Definition SpCCols.h:224
IT getncol() const
Definition SpCCols.h:76
friend void csc_gespmv_dense(const SpCCols< IU, NU > &A, const RHS *x, LHS *y)
dense vector (not implemented)
void Split(SpCCols< IT, NT > &partA, SpCCols< IT, NT > &partB)
Definition SpCCols.cpp:480
SpCCols< IT, NT > TransposeConst() const
Definition SpCCols.cpp:456
SpCCols< IT, NT > * TransposeConstPtr() const
Definition SpCCols.cpp:468
SpCCols< IT, NT > * PruneI(UnaryOperation unary_op, bool inPlace, GlobalIT rowOffset, GlobalIT colOffset)
Definition SpCCols.cpp:318
static const IT esscount
Definition SpCCols.h:73
void ColSplit(int parts, std::vector< SpCCols< IT, NT > > &matrices)
SpColIter begcol()
Definition SpCCols.h:162
Arr< IT, NT > GetArrays() const
Definition SpCCols.cpp:416
auto GetInternal() const
Definition SpCCols.h:81
IT getnrow() const
Definition SpCCols.h:75
void PrintInfo() const
Definition SpCCols.cpp:291
std::ofstream & put(std::ofstream &outfile) const
Definition SpCCols.cpp:549
auto GetInternal(int i) const
Definition SpCCols.h:82
SpColIter endcol(int i)
Definition SpCCols.h:184
SpColIter endcol()
Definition SpCCols.h:169
SpCCols(const SpDCCols< IT, NT > &rhs)
Definition SpCCols.h:51
int getnsplit() const
Definition SpCCols.h:78
SpCCols< IT, NT > & operator=(const SpCCols< IT, NT > &rhs)
Definition SpCCols.cpp:206
void Merge(SpCCols< IT, NT > &partA, SpCCols< IT, NT > &partB)
Definition SpCCols.cpp:507
std::vector< IT > GetEssentials() const
Definition SpCCols.cpp:370
SpColIter::NzIter begnz(const SpColIter &ccol, int i)
Definition SpCCols.h:203
SpColIter::NzIter begnz(const SpColIter &ccol)
Definition SpCCols.h:193
bool isZero() const
Definition SpCCols.h:238
Csc< IT, NT > * csc
Definition SpCCols.h:268
SpColIter::NzIter endnz(const SpColIter &ccol)
Definition SpCCols.h:198
IT getnnz() const
Definition SpCCols.h:77
int size
Definition common.h:20
double A
signed int int32_t
Definition stdint.h:77