COMBINATORIAL_BLAS 1.6
 
Loading...
Searching...
No Matches
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
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>
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>
91 template <typename _UnaryOperation>
93 template <typename _BinaryOperation>
95 template <typename _BinaryOperation>
97
98 void PruneColumnByIndex(const std::vector<IT>& ci);
99
100 IT AuxIndex(const IT colind, bool & found, IT * aux, IT csize) const;
101
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
107 void Merge(const Dcsc<IT,NT> * Adcsc, const Dcsc<IT,NT> * B, IT cut);
108
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 ;
127 NT * numx;
128
129 IT nz;
130 IT nzc;
131 bool memowned;
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)
void SetDifference(const Dcsc< IT, NT > &rhs)
NT value_type
Definition dcsc.h:50
Dcsc< IT, NT > * PruneI(_UnaryOperation __unary_op, bool inPlace, GlobalIT rowOffset, GlobalIT colOffset)
void ColConcatenate(std::vector< Dcsc< IT, NT > * > &parts, std::vector< IT > &offsets)
void ColSplit(std::vector< Dcsc< IT, NT > * > &parts, std::vector< IT > &cuts)
Dcsc< IT, NT > * PruneColumn(NT *pvals, _BinaryOperation __binary_op, bool inPlace)
Dcsc< IT, NT > & operator=(const Dcsc< IT, NT > &rhs)
void EWiseMult(const Dcsc< IT, NT > &rhs, bool exclude)
IT AuxIndex(const IT colind, bool &found, IT *aux, IT csize) const
IT * ir
row indices, size nz
Definition dcsc.h:126
Dcsc(IT nnz, const std::vector< IT > &indices, bool isRow)
Create a logical matrix from (row/column) indices vector.
Dcsc(const Dcsc< IT, NT > &rhs)
bool operator==(const Dcsc< IT, NT > &rhs)
void PruneColumnByIndex(const std::vector< IT > &ci)
void Merge(const Dcsc< IT, NT > *Adcsc, const Dcsc< IT, NT > *B, IT cut)
Dcsc(StackEntry< NT, std::pair< IT, IT > > *multstack, IT mdim, IT ndim, IT nnz)
Dcsc< IT, NT > * Prune(_UnaryOperation __unary_op, bool inPlace)
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)
friend Dcsc< IU, typename promote_trait< NU1, NU2 >::T_promote > SetDifference(const Dcsc< IU, NU1 > &A, const Dcsc< IU, NU2 > *B)
Definition Friends.h:748
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
Dcsc< IT, NT > * PruneColumn(IT *pinds, NT *pvals, _BinaryOperation __binary_op, bool inPlace)
void Resize(IT nzcnew, IT nznew)
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)
IT ConstructAux(IT ndim, IT *&aux) const
NT * numx
generic values, size nz
Definition dcsc.h:127
Dcsc(IT nnz, IT nzcol)
Dcsc< IT, NT > & operator+=(const Dcsc< IT, NT > &rhs)
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
IT index_type
Definition dcsc.h:51
void UpdateDense(NT **array, _BinaryOperation __binary_op) const
IT * jc
col indices, size nzc
Definition dcsc.h:125
void RowSplit(int numsplits)
friend Dcsc< IU, typename promote_trait< NU1, NU2 >::T_promote > EWiseMult(const Dcsc< IU, NU1 > &A, const Dcsc< IU, NU2 > *B, bool exclude)
Definition Friends.h:834
double A