30 #ifndef _FULLY_DIST_SP_VEC_H_ 31 #define _FULLY_DIST_SP_VEC_H_ 46 template <
class IT,
class NT,
class DER>
52 template <
class IU,
class NU>
55 template <
class IU,
class NU>
72 template <
class IT,
class NT>
81 template <
typename _UnaryOperation>
85 FullyDistSpVec (std::shared_ptr<CommGrid> grid, IT globallen,
const std::vector<IT>& indvec,
const std::vector<NT> & numvec,
bool SumDuplicates =
false,
bool sorted=
false);
90 template <
typename _BinaryOperationIdx,
typename _BinaryOperationVal,
typename _BinaryOperationDuplicate>
91 FullyDistSpVec<IT,NT> Invert (IT globallen, _BinaryOperationIdx __binopIdx, _BinaryOperationVal __binopVal, _BinaryOperationDuplicate __binopDuplicate);
92 template <
typename _BinaryOperationIdx,
typename _BinaryOperationVal>
96 template <
typename NT1,
typename _UnaryOperation>
98 template <
typename _UnaryOperation>
100 template <
typename NT1>
106 template <
typename NT1,
typename _UnaryOperation,
typename _BinaryOperation>
119 #pragma omp parallel for 121 for(
size_t i=0; i < ind.size(); ++i)
131 NT
getNoNum(IT index) {
return static_cast<NT
>(1); }
133 template <
typename c,
typename t>
134 NT
read(std::basic_istream<c,t>& is, IT index)
141 template <
typename c,
typename t>
142 void save(std::basic_ostream<c,t>& os,
const NT& v, IT index)
148 template <
class HANDLER>
149 void ParallelWrite(
const std::string & filename,
bool onebased, HANDLER handler,
bool includeindices =
true,
bool includeheader =
false);
153 template <
typename _BinaryOperation>
154 void ParallelRead (
const std::string & filename,
bool onebased, _BinaryOperation BinOp);
158 template <
class HANDLER>
159 std::ifstream&
ReadDistribute (std::ifstream& infile,
int master, HANDLER handler);
162 template <
class HANDLER>
163 void SaveGathered(std::ofstream& outfile,
int master, HANDLER handler,
bool printProcSplits =
false);
170 CVT.ind = std::vector<IT>(ind.begin(), ind.end());
171 CVT.num = std::vector<NNT>(num.begin(), num.end());
183 void PrintInfo(std::string vecname)
const;
184 void iota(IT globalsize, NT first);
195 #if __cplusplus > 199711L 196 template <
typename _BinaryOperation = minimum<NT> >
199 template <
typename _BinaryOperation >
211 IT locnnz = ind.size();
212 MPI_Allreduce( &locnnz, &totnnz, 1, MPIType<IT>(), MPI_SUM, commGrid->GetWorld());
224 IT offset = LengthUntil();
225 IT spsize = ind.size();
227 #pragma omp parallel for 229 for(IT i=0; i< spsize; ++i)
230 num[i] = ind[i] + offset;
233 template <
typename _Predicate>
234 IT
Count(_Predicate pred)
const;
236 template <
typename _UnaryOperation>
237 void Apply(_UnaryOperation __unary_op)
240 IT spsize = num.size();
242 #pragma omp parallel for 244 for(IT i=0; i < spsize; ++i)
245 num[i] = __unary_op(num[i]);
248 template <
typename _BinaryOperation>
251 IT offset = LengthUntil();
252 IT spsize = ind.size();
254 #pragma omp parallel for 256 for(IT i=0; i < spsize; ++i)
257 num[i] = __binary_op(num[i], ind[i] + offset);
262 template <
typename _BinaryOperation>
263 NT
Reduce(_BinaryOperation __binary_op, NT
init)
const;
265 template <
typename OUT,
typename _BinaryOperation,
typename _UnaryOperation>
266 OUT
Reduce(_BinaryOperation __binary_op, OUT default_val, _UnaryOperation __unary_op)
const;
269 std::shared_ptr<CommGrid>
getcommgrid()
const {
return commGrid; }
273 void BulkSet(IT inds[],
int count);
274 std::vector<IT>
GetLocalInd (){std::vector<IT> rind = ind;
return rind;};
275 std::vector<NT>
GetLocalNum (){std::vector<NT> rnum = num;
return rnum;};
277 template <
typename _Predicate>
279 template <
typename _Predicate>
288 std::vector< IT > ind;
289 std::vector< NT > num;
293 template <
typename _BinaryOperation>
294 void SparseCommon(std::vector< std::vector < std::pair<IT,NT> > > & data, _BinaryOperation BinOp);
297 #if __cplusplus > 199711L 298 template <
typename _BinaryOperation = minimum<NT> >
299 FullyDistSpVec<IT, NT> UniqAll2All(_BinaryOperation __binary_op = _BinaryOperation(), MPI_Op mympiop = MPI_MIN);
301 template <
typename _BinaryOperation >
306 template <
class IU,
class NU>
309 template <
class IU,
class NU>
312 template <
class IU,
class NU,
class UDER>
315 template <
class IU,
class NU>
318 template <
typename SR,
typename IU,
typename NUM,
typename NUV,
typename UDER>
322 template <
typename SR,
typename IU,
typename NUM,
typename UDER>
326 template <
typename VT,
typename IU,
typename UDER>
329 template <
typename SR,
typename IVT,
typename OVT,
typename IU,
typename NUM,
typename UDER>
332 template <
typename SR,
typename IVT,
typename OVT,
typename IU,
typename NUM,
typename UDER>
333 friend void SpMV (
const SpParMat<IU,NUM,UDER> &
A,
const FullyDistSpVec<IU,IVT> & x,
FullyDistSpVec<IU,OVT> & y,
bool indexisvalue,
OptBuf<int32_t, OVT > & optbuf,
PreAllocatedSPA<OVT> & SPA);
335 template <
typename IU,
typename NU1,
typename NU2>
339 template <
typename RET,
typename IU,
typename NU1,
typename NU2,
typename _BinaryOperation,
typename _BinaryPredicate>
343 template <
typename RET,
typename IU,
typename NU1,
typename NU2,
typename _BinaryOperation,
typename _BinaryPredicate>
348 template <
typename RET,
typename IU,
typename NU1,
typename NU2,
typename _BinaryOperation,
typename _BinaryPredicate>
350 EWiseApply (
const FullyDistSpVec<IU,NU1> & V,
const FullyDistSpVec<IU,NU2> & W , _BinaryOperation _binary_op, _BinaryPredicate _doOp,
bool allowVNulls,
bool allowWNulls, NU1 Vzero, NU2 Wzero,
const bool allowIntersect,
const bool useExtendedBinOp);
352 template <
typename IU>
355 template <
typename IU>
363 template <
typename IU,
typename VT>
366 template<
typename IU,
typename NV>
369 template <
class IU,
class NU,
class DER,
typename _UnaryOperation>
void SetElement(IT indx, NT numx)
Indexing is performed 0-based.
void Setminus(const FullyDistSpVec< IT, NT1 > &other)
void stealFrom(FullyDistSpVec< IT, NT > &victim)
std::ifstream & ReadDistribute(std::ifstream &infile, int master)
friend FullyDistSpVec< IU, typename promote_trait< NUM, NUV >::T_promote > SpMV(const SpParMat< IU, NUM, UDER > &A, const FullyDistSpVec< IU, NUV > &x)
void nziota(NT first)
iota over existing nonzero entries
friend SpParMat< IU, bool, DER > PermMat1(const FullyDistSpVec< IU, NU > &ri, const IU ncol, _UnaryOperation __unop)
void FilterByVal(FullyDistSpVec< IT, IT > Selector, _UnaryOperation __unop, bool filterByIndex)
void ParallelRead(const std::string &filename, bool onebased, _BinaryOperation BinOp)
std::shared_ptr< CommGrid > getcommgrid() const
void SaveGathered(std::ofstream &outfile, int master)
NT GetLocalElement(IT indx)
FullyDistSpVec< IT, NT > & operator=(const FullyDistSpVec< IT, NT > &rhs)
friend void RenameVertices(DistEdgeList< IU > &DEL)
void Select(const FullyDistVec< IT, NT1 > &denseVec, _UnaryOperation unop)
void BulkSet(IT inds[], int count)
FullyDistSpVec< IT, NT > Invert(IT globallen)
IT NnzUntil() const
Returns the number of nonzeros until this processor.
FullyDistSpVec< IT, NT > InvertRMA(IT globallen, _BinaryOperationIdx __binopIdx, _BinaryOperationVal __binopVal)
void PrintInfo(std::string vecname) const
friend void RandPerm(FullyDistSpVec< IU, IU > &V)
NT Reduce(_BinaryOperation __binary_op, NT init) const
FullyDistVec< IT, IT > FindInds(_Predicate pred) const
friend FullyDistSpVec< IU, RET > EWiseApply_threaded(const FullyDistSpVec< IU, NU1 > &V, const FullyDistVec< IU, NU2 > &W, _BinaryOperation _binary_op, _BinaryPredicate _doOp, bool allowVNulls, NU1 Vzero, const bool useExtendedBinOp)
void SaveGathered(std::ofstream &outfile, int master, HANDLER handler, bool printProcSplits=false)
void SelectApply(const FullyDistVec< IT, NT1 > &denseVec, _UnaryOperation __unop, _BinaryOperation __binop)
FullyDistVec< IT, NT > operator()(const FullyDistVec< IT, IT > &ri) const
SpRef (expects ri to be 0-based)
friend FullyDistSpVec< IU, typename promote_trait< NU1, NU2 >::T_promote > EWiseMult(const FullyDistSpVec< IU, NU1 > &V, const FullyDistVec< IU, NU2 > &W, bool exclude, NU2 zero)
void iota(IT globalsize, NT first)
std::vector< NT > GetLocalNum()
NT read(std::basic_istream< c, t > &is, IT index)
FullyDistSpVec< IT, NT > & operator=(NT fixedval)
void save(std::basic_ostream< c, t > &os, const NT &v, IT index)
friend void TransposeVector(MPI_Comm &World, const FullyDistSpVec< IU, NV > &x, int32_t &trxlocnz, IU &lenuntil, int32_t *&trxinds, NV *&trxnums, bool indexisvalue)
void ApplyInd(_BinaryOperation __binary_op)
std::ifstream & ReadDistribute(std::ifstream &infile, int master, HANDLER handler)
Totally obsolete version that only accepts an ifstream object and ascii files.
FullyDistSpVec< IT, NT > Uniq(_BinaryOperation __binary_op, MPI_Op mympiop)
friend void MergeContributions(FullyDistSpVec< IU, VT > &y, int *&recvcnt, int *&rdispls, int32_t *&recvindbuf, VT *&recvnumbuf, int rowneighs)
Helper functions for sparse matrix X sparse vector.
void ParallelWrite(const std::string &filename, bool onebased, HANDLER handler, bool includeindices=true, bool includeheader=false)
FullyDistSpVec< IT, NT > & operator+=(const FullyDistSpVec< IT, NT > &rhs)
bool operator==(const FullyDistSpVec< IT, NT > &rhs) const
FullyDistVec< IT, NT > FindVals(_Predicate pred) const
FullyDistSpVec< IT, NT > & operator-=(const FullyDistSpVec< IT, NT > &rhs)
void ParallelWrite(const std::string &filename, bool onebased, bool includeindices=true)
void Apply(_UnaryOperation __unary_op)
std::vector< IT > GetLocalInd()
friend FullyDistSpVec< IU, RET > EWiseApply(const FullyDistSpVec< IU, NU1 > &V, const FullyDistVec< IU, NU2 > &W, _BinaryOperation _binary_op, _BinaryPredicate _doOp, bool allowVNulls, NU1 Vzero, const bool useExtendedBinOp)
FullyDistSpVec< IT, IT > sort()
sort the vector itself, return the permutation vector (0-based)
IT Count(_Predicate pred) const
Return the number of elements for which pred is true.