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
44namespace combblas {
45
46template <class IT, class NT>
47class Dcsc
48{
49public:
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 SetDifference(const Dcsc<IT,NT> & rhs); //<! Aydin (June 2021): generalize this to any rhs NT type; as it isn't used anyway
69 void EWiseScale(NT ** scaler); //<! scale elements of "this" with the elements dense rhs matrix
70
71 template <typename IU, typename NU1, typename NU2>
72 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
73
74 template <typename IU, typename NU1, typename NU2>
75 friend Dcsc<IU, typename promote_trait<NU1,NU2>::T_promote> SetDifference(const Dcsc<IU,NU1> & A, const Dcsc<IU,NU2> * B); // Note that the second parameter is a POINTER
76
77 template <typename _UnaryOperation>
78 void Apply(_UnaryOperation __unary_op)
79 {
80 //transform(numx, numx+nz, numx, __unary_op);
81#ifdef _OPENMP
82#pragma omp parallel for
83#endif
84 for(IT i=0; i < nz; ++i)
85 numx[i] = __unary_op(numx[i]);
86
87 }
88
89 template <typename _UnaryOperation, typename GlobalIT>
90 Dcsc<IT,NT>* PruneI(_UnaryOperation __unary_op, bool inPlace, GlobalIT rowOffset, GlobalIT colOffset);
91 template <typename _UnaryOperation>
92 Dcsc<IT,NT>* Prune(_UnaryOperation __unary_op, bool inPlace);
93 template <typename _BinaryOperation>
94 Dcsc<IT,NT>* PruneColumn(NT* pvals, _BinaryOperation __binary_op, bool inPlace);
95 template <typename _BinaryOperation>
96 Dcsc<IT,NT>* PruneColumn(IT* pinds, NT* pvals, _BinaryOperation __binary_op, bool inPlace);
97
98 void PruneColumnByIndex(const std::vector<IT>& ci);
99
100 IT AuxIndex(const IT colind, bool & found, IT * aux, IT csize) const;
101
102 void RowSplit(int numsplits);
103 void ColSplit(std::vector< Dcsc<IT,NT>* > & parts, std::vector<IT> & cuts);
104 void ColConcatenate(std::vector< Dcsc<IT,NT>* > & parts, std::vector<IT> & offsets);
105
106 void Split(Dcsc<IT,NT> * & A, Dcsc<IT,NT> * & B, IT cut);
107 void Merge(const Dcsc<IT,NT> * Adcsc, const Dcsc<IT,NT> * B, IT cut);
108
109 IT ConstructAux(IT ndim, IT * & aux) const;
110 void Resize(IT nzcnew, IT nznew);
111
112 template<class VT>
113 void FillColInds(const VT * colnums, IT nind, std::vector< std::pair<IT,IT> > & colinds, IT * aux, IT csize) const;
114
115 Dcsc<IT,NT> & AddAndAssign (StackEntry<NT, std::pair<IT,IT> > * multstack, IT mdim, IT ndim, IT nnz);
116
117 template <typename _BinaryOperation>
118 void UpdateDense(NT ** array, _BinaryOperation __binary_op) const; // update dense 2D array's entries with __binary_op using elements of "this"
119
121 Dcsc (IT * _cp, IT * _jc, IT * _ir, NT * _numx, IT _nz, IT _nzc, bool _memowned = true)
122 : cp(_cp), jc(_jc), ir(_ir), numx(_numx), nz(_nz), nzc(_nzc), memowned(_memowned) {};
123
124 IT * cp;
125 IT * jc ;
126 IT * ir ;
128
132
133private:
134 void getindices (StackEntry<NT, std::pair<IT,IT> > * multstack, IT & rindex, IT & cindex, IT & j, IT nnz);
135};
136
137}
138
139#include "dcsc.cpp"
140
141#endif
int64_t IT
double NT
Definition: test.cpp:53
void EWiseScale(NT **scaler)
Definition: dcsc.cpp:945
void SetDifference(const Dcsc< IT, NT > &rhs)
Definition: dcsc.cpp:526
NT value_type
Definition: dcsc.h:50
Dcsc< IT, NT > * PruneI(_UnaryOperation __unary_op, bool inPlace, GlobalIT rowOffset, GlobalIT colOffset)
Definition: dcsc.cpp:536
void ColConcatenate(std::vector< Dcsc< IT, NT > * > &parts, std::vector< IT > &offsets)
Definition: dcsc.cpp:1239
void ColSplit(std::vector< Dcsc< IT, NT > * > &parts, std::vector< IT > &cuts)
Definition: dcsc.cpp:1141
Dcsc< IT, NT > * PruneColumn(NT *pvals, _BinaryOperation __binary_op, bool inPlace)
Definition: dcsc.cpp:699
Dcsc< IT, NT > & operator=(const Dcsc< IT, NT > &rhs)
Definition: dcsc.cpp:329
void EWiseMult(const Dcsc< IT, NT > &rhs, bool exclude)
Definition: dcsc.cpp:514
IT AuxIndex(const IT colind, bool &found, IT *aux, IT csize) const
Definition: dcsc.cpp:1084
IT * ir
row indices, size nz
Definition: dcsc.h:126
bool operator==(const Dcsc< IT, NT > &rhs)
Definition: dcsc.cpp:473
void PruneColumnByIndex(const std::vector< IT > &ci)
Definition: dcsc.cpp:780
void Merge(const Dcsc< IT, NT > *Adcsc, const Dcsc< IT, NT > *B, IT cut)
Definition: dcsc.cpp:1205
Dcsc< IT, NT > * Prune(_UnaryOperation __unary_op, bool inPlace)
Definition: dcsc.cpp:617
void Apply(_UnaryOperation __unary_op)
Definition: dcsc.h:78
Dcsc< IT, NT > & AddAndAssign(StackEntry< NT, std::pair< IT, IT > > *multstack, IT mdim, IT ndim, IT nnz)
Definition: dcsc.cpp:72
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:121
IT * cp
The master array, size nzc+1 (keeps column pointers)
Definition: dcsc.h:124
void Resize(IT nzcnew, IT nznew)
Definition: dcsc.cpp:1017
IT nzc
number of columns with at least one non-zero in them
Definition: dcsc.h:130
void Split(Dcsc< IT, NT > *&A, Dcsc< IT, NT > *&B, IT cut)
Definition: dcsc.cpp:1101
IT ConstructAux(IT ndim, IT *&aux) const
Definition: dcsc.cpp:983
NT * numx
generic values, size nz
Definition: dcsc.h:127
Dcsc< IT, NT > & operator+=(const Dcsc< IT, NT > &rhs)
Definition: dcsc.cpp:375
bool memowned
Definition: dcsc.h:131
void FillColInds(const VT *colnums, IT nind, std::vector< std::pair< IT, IT > > &colinds, IT *aux, IT csize) const
Definition: dcsc.cpp:1282
IT index_type
Definition: dcsc.h:51
void UpdateDense(NT **array, _BinaryOperation __binary_op) const
Definition: dcsc.cpp:964
IT * jc
col indices, size nzc
Definition: dcsc.h:125
void RowSplit(int numsplits)
Definition: CCGrid.h:4
double A