67template <
class IT,
class NT,
class DER>
79 SpParMat (std::shared_ptr<CommGrid> grid);
80 SpParMat (DER * myseq, std::shared_ptr<CommGrid> grid);
82 SpParMat (std::ifstream & input, MPI_Comm & world);
83 SpParMat (DER * myseq, MPI_Comm & world);
85 template <
class DELIT>
96 template <
typename SR>
110 template <
typename _BinaryOperation>
113 template <
typename _BinaryOperation,
typename _UnaryOperation >
116 template <
typename _BinaryOperation>
119 template <
typename VT,
typename GIT,
typename _BinaryOperation,
typename _UnaryOperation >
122 template <
typename VT,
typename GIT,
typename _BinaryOperation>
125 template <
typename VT,
typename GIT>
127 template <
typename VT,
typename GIT>
130 template <
typename VT,
typename GIT,
typename _UnaryOperation>
132 template <
typename VT,
typename GIT,
typename _UnaryOperation>
134 template <
typename VT,
typename GIT>
136 template <
typename VT,
typename GIT>
142 template <
typename VT,
typename GIT,
typename _BinaryOperation>
144 template <
typename VT,
typename GIT,
typename _BinaryOperation,
typename _UnaryOperation >
147 template <
typename _UnaryOperation>
148 void Apply(_UnaryOperation __unary_op)
150 spSeq->Apply(__unary_op);
154 void AddLoops(
NT loopval,
bool replaceExisting=
false);
157 template <
typename LIT,
typename OT>
161 template <
typename _UnaryOperation>
165 GetPlaceInGlobalGrid(grow, gcol);
168 spSeq->PruneI(__unary_op, inPlace, grow, gcol);
177 template <
typename _UnaryOperation>
182 spSeq->Prune(__unary_op, inPlace);
191 template <
typename _BinaryOperation>
194 template <
typename _BinaryOperation>
197 template <
typename IRRELEVANT_NT>
200 template <
typename _BinaryOperation>
203 void Dump(std::string filename)
const;
213 template <
typename LIT>
214 int Owner(
IT total_m,
IT total_n,
IT grow,
IT gcol, LIT & lrow, LIT & lcol)
const;
219 template <
typename SelectFirstSR,
typename SelectSecondSR>
223 template<
typename SelectFirstSR,
224 typename SelectSecondSR>
236 return SubsRef_SR<BoolCopy1stSRing<NT>,
252 if (fread(&row,
sizeof(
IT), 1,rFile) != 1)
253 std::cout <<
"binaryfill(): error reading row index" << std::endl;
254 if (fread(&col,
sizeof(
IT), 1,rFile) != 1)
255 std::cout <<
"binaryfill(): error reading col index" << std::endl;
256 if (fread(&val,
sizeof(
NT), 1,rFile) != 1)
257 std::cout <<
"binaryfill(): error reading value" << std::endl;
262 template <
typename c,
typename t>
270 template <
typename c,
typename t>
271 void save(std::basic_ostream<c,t>& os,
const NT& v,
IT row,
IT col)
277 template <
typename _BinaryOperation>
278 void ParallelReadMM (
const std::string & filename,
bool onebased, _BinaryOperation BinOp);
280 template <
class HANDLER>
281 void ParallelWriteMM(
const std::string & filename,
bool onebased, HANDLER handler);
286 template <
typename _BinaryOperation>
289 template <
class HANDLER>
290 void ReadDistribute (
const std::string & filename,
int master,
bool nonum, HANDLER handler,
bool transpose =
false,
bool pario =
false);
291 void ReadDistribute (
const std::string & filename,
int master,
bool nonum=
false,
bool pario =
false)
296 template <
class HANDLER>
297 void SaveGathered(std::string filename, HANDLER handler,
bool transpose =
false)
const;
300 std::ofstream&
put(std::ofstream& outfile)
const;
302 std::shared_ptr<CommGrid>
getcommgrid()
const {
return commGrid; }
303 typename DER::LocalIT
getlocalrows()
const {
return spSeq->getnrow(); }
305 typename DER::LocalIT
getlocalnnz()
const {
return spSeq->getnnz(); }
306 DER &
seq()
const {
return (*spSeq); }
309 template <
typename _BinaryOperation,
typename LIT>
310 void SparseCommon(std::vector< std::vector < std::tuple<LIT,LIT,NT> > > & data, LIT locsize,
IT total_m,
IT total_n, _BinaryOperation BinOp);
314 std::vector<std::vector<SpParMat<IT, NT, DER>>>
319 template <
typename SR,
typename IU,
typename NU1,
typename NU2,
typename UDER1,
typename UDER2>
323 template <
typename SR,
typename NUO,
typename UDERO,
typename IU,
typename NU1,
typename NU2,
typename UDER1,
typename UDER2>
327 template <
typename SR,
typename NUO,
typename UDERO,
typename IU,
typename NU1,
typename NU2,
typename UDER1,
typename UDER2>
331 template <
typename SR,
typename NUO,
typename UDERO,
typename IU,
typename NU1,
typename NU2,
typename UDER1,
typename UDER2>
335 template <
typename IU,
typename NU1,
typename NU2,
typename UDERA,
typename UDERB>
338 template <
typename SR,
typename IU,
typename NU1,
typename NU2,
typename UDER1,
typename UDER2>
342 template <
typename SR,
typename IU,
typename NU1,
typename NU2,
typename UDER1,
typename UDER2>
346 template <
typename SR,
typename IU,
typename NU1,
typename NU2,
typename UDER1,
typename UDER2>
350 template <
typename SR,
typename NUO,
typename UDERO,
typename IU,
typename NU1,
typename NU2,
typename UDER1,
typename UDER2>
354 template <
typename SR,
typename NUO,
typename UDERO,
typename IU,
typename NU1,
typename NU2,
typename UDERA,
typename UDERB>
356 int phases, NUO hardThreshold, IU selectNum, IU recoverNum, NUO recoverPct,
int kselectVersion,
int computationKernel,
int64_t perProcessMem);
358 template <
typename SR,
typename NUO,
typename UDERO,
typename IU,
typename NU1,
typename NU2,
typename UDERA,
typename UDERB>
360 NUO hardThreshold, IU selectNum, IU recoverNum, NUO recoverPct,
int kselectVersion,
int64_t perProcessMem);
362 template <
typename SR,
typename IU,
typename NUM,
typename NUV,
typename UDER>
366 template <
typename SR,
typename IU,
typename NUM,
typename NUV,
typename UDER>
370 template <
typename SR,
typename IU,
typename NUM,
typename UDER>
375 template <
typename SR,
typename IVT,
typename OVT,
typename IU,
typename NUM,
typename UDER>
378 template <
typename SR,
typename IVT,
typename OVT,
typename IU,
typename NUM,
typename UDER>
381 template <
typename IU,
typename NU1,
typename NU2,
typename UDER1,
typename UDER2>
385 template <
typename RETT,
typename RETDER,
typename IU,
typename NU1,
typename NU2,
typename UDERA,
typename UDERB,
typename _BinaryOperation>
389 template <
typename RETT,
typename RETDER,
typename IU,
typename NU1,
typename NU2,
typename UDERA,
typename UDERB,
typename _BinaryOperation,
typename _BinaryPredicate>
391 EWiseApply (
const SpParMat<IU,NU1,UDERA> &
A,
const SpParMat<IU,NU2,UDERB> &
B, _BinaryOperation __binary_op, _BinaryPredicate do_op,
bool allowANulls,
bool allowBNulls,
const NU1& ANullVal,
const NU2& BNullVal,
const bool allowIntersect,
const bool useExtendedBinOp);
393 template<
typename SR,
typename IVT,
typename OVT,
typename IU,
typename NUM,
typename UDER>
395 int32_t * & sendindbuf, OVT * & sendnumbuf,
int * & sdispls,
int * sendcnt,
int accnz,
bool indexisvalue,
PreAllocatedSPA<OVT> & SPA);
397 template<
typename VT,
typename IU,
typename UDER>
401 typedef std::array<char, MAXVERTNAME> STRASARRAY;
402 typedef std::pair< STRASARRAY, uint64_t> TYPE2SEND;
404 class CharArraySaveHandler
408 template <
typename c,
typename t>
409 void save(std::basic_ostream<c,t>& os, STRASARRAY & chararray,
int64_t index)
411 auto locnull = std::find(chararray.begin(), chararray.end(),
'\0');
412 std::string strtmp(chararray.begin(), locnull);
417 MPI_File TupleRead1stPassNExchange (
const std::string & filename, TYPE2SEND * & senddata,
IT & totsend, FullyDistVec<IT,STRASARRAY> & distmapper,
uint64_t & totallength);
419 template <
typename VT,
typename GIT,
typename _BinaryOperation,
typename _UnaryOperation >
420 void Reduce(FullyDistVec<GIT,VT> & rvec,
Dim dim, _BinaryOperation __binary_op, VT
id, _UnaryOperation __unary_op, MPI_Op mympiop)
const;
423 template <
typename VT,
typename GIT>
424 void TopKGather(std::vector<NT> & all_medians, std::vector<IT> & nnz_per_col,
int & thischunk,
int & chunksize,
425 const std::vector<NT> & medians,
const std::vector<IT> & nnzperc,
int itersuntil, std::vector< std::vector<NT> > & localmat,
426 const std::vector<IT> & actcolsmap, std::vector<IT> & klimits, std::vector<IT> & toretain, std::vector<std::vector<std::pair<IT,NT>>> & tmppair,
427 IT coffset,
const FullyDistVec<GIT,VT> & rvec)
const;
429 void GetPlaceInGlobalGrid(
IT& rowOffset,
IT& colOffset)
const;
431 void HorizontalSend(
IT * & rows,
IT * & cols,
NT * & vals,
IT * & temprows,
IT * & tempcols,
NT * & tempvals, std::vector < std::tuple <IT,IT,NT> > & localtuples,
432 int * rcurptrs,
int * rdispls,
IT buffperrowneigh,
int rowneighs,
int recvcount,
IT m_perproc,
IT n_perproc,
int rankinrow);
434 template <
class HANDLER>
435 void ReadAllMine(FILE * binfile,
IT * & rows,
IT * & cols,
NT * & vals, std::vector< std::tuple<IT,IT,NT> > & localtuples,
int * rcurptrs,
int * ccurptrs,
int * rdispls,
int * cdispls,
436 IT m_perproc,
IT n_perproc,
int rowneighs,
int colneighs,
IT buffperrowneigh,
IT buffpercolneigh,
IT entriestoread, HANDLER handler,
int rankinrow,
bool transpose);
438 void VerticalSend(
IT * & rows,
IT * & cols,
NT * & vals, std::vector< std::tuple<IT,IT,NT> > & localtuples,
int * rcurptrs,
int * ccurptrs,
int * rdispls,
int * cdispls,
439 IT m_perproc,
IT n_perproc,
int rowneighs,
int colneighs,
IT buffperrowneigh,
IT buffpercolneigh,
int rankinrow);
441 void AllocateSetBuffers(
IT * & rows,
IT * & cols,
NT * & vals,
int * & rcurptrs,
int * & ccurptrs,
int rowneighs,
int colneighs,
IT buffpercolneigh);
442 void BcastEssentials(MPI_Comm & world,
IT & total_m,
IT & total_n,
IT & total_nnz,
int master);
444 std::shared_ptr<CommGrid> commGrid;
447 template <
class IU,
class NU>
450 template <
typename IU,
typename NU,
typename UDER>
454template <
typename SR,
typename NUO,
typename UDERO,
typename IU,
typename NU1,
typename NU2,
typename UDER1,
typename UDER2>
455void PSpGEMM(
SpParMat<IU,NU1,UDER1> &
A,
SpParMat<IU,NU2,UDER2> &
B,
SpParMat<IU,NUO,UDERO> & out,
bool clearA =
false,
bool clearB =
false)
457 out = Mult_AnXBn_Synch<SR, NUO, UDERO> (
A,
B, clearA, clearB );
460template <
typename SR,
typename IU,
typename NU1,
typename NU2,
typename UDER1,
typename UDER2>
466 return Mult_AnXBn_Synch<SR, N_promote, DER_promote> (
A,
B, clearA, clearB );
NT read(std::basic_istream< c, t > &is, IT row, IT col)
NT getNoNum(IT row, IT col)
void save(std::basic_ostream< c, t > &os, const NT &v, IT row, IT col)
void binaryfill(FILE *rFile, IT &row, IT &col, NT &val)
void PruneFull(const FullyDistVec< IT, IT > &ri, const FullyDistVec< IT, IT > &ci)
prune all entries whose row indices are in ri OR column indices are in ci
friend SpParMat< IU, NUO, UDERO > Mult_AnXBn_Overlap(SpParMat< IU, NU1, UDER1 > &A, SpParMat< IU, NU2, UDER2 > &B, bool clearA, bool clearB)
bool Kselect2(FullyDistVec< GIT, VT > &rvec, IT k_limit) const
void EWiseScale(const DenseParMat< IT, NT > &rhs)
void ReadDistribute(const std::string &filename, int master, bool nonum=false, bool pario=false)
friend SpParMat< IU, typename promote_trait< NU1, NU2 >::T_promote, typename promote_trait< UDER1, UDER2 >::T_promote > Mult_AnXBn_Fence(const SpParMat< IU, NU1, UDER1 > &A, const SpParMat< IU, NU2, UDER2 > &B)
FullyDistVec< IT, std::array< char, MAXVERTNAME > > ReadGeneralizedTuples(const std::string &, _BinaryOperation)
void SaveGathered(std::string filename) const
void DimApply(Dim dim, const FullyDistVec< IT, NT > &v, _BinaryOperation __binary_op)
FullyDistVec< IT, NT > Reduce(Dim dim, _BinaryOperation __binary_op, NT id, _UnaryOperation __unary_op) const
friend std::ofstream & operator<<(std::ofstream &outfile, const SpParMat< IU, NU, UDER > &s)
SpParMat< IT, NT, DER > PruneI(_UnaryOperation __unary_op, bool inPlace=true)
friend void LocalSpMV(const SpParMat< IU, NUM, UDER > &A, int rowneighs, OptBuf< int32_t, OVT > &optbuf, int32_t *&indacc, IVT *&numacc, int32_t *&sendindbuf, OVT *&sendnumbuf, int *&sdispls, int *sendcnt, int accnz, bool indexisvalue, PreAllocatedSPA< OVT > &SPA)
friend int64_t EstPerProcessNnzSUMMA(SpParMat< IU, NU1, UDERA > &A, SpParMat< IU, NU2, UDERB > &B, bool hashEstimate)
SpParMat< IT, NT, DER > SubsRefCol(const std::vector< IT > &ci) const
Column indexing with special parallel semantics.
bool operator==(const SpParMat< IT, NT, DER > &rhs) const
friend FullyDistSpVec< IU, typename promote_trait< NUM, NUV >::T_promote > SpMV(const SpParMat< IU, NUM, UDER > &A, const FullyDistSpVec< IU, NUV > &x)
friend void LocalSpMV(const SpParMat< IU, bool, UDER > &A, int rowneighs, OptBuf< int32_t, VT > &optbuf, int32_t *&indacc, VT *&numacc, int *sendcnt, int accnz)
friend SpParMat< IU, typename promote_trait< NU1, NU2 >::T_promote, typename promote_trait< UDER1, UDER2 >::T_promote > Mult_AnXBn_PassiveTarget(const SpParMat< IU, NU1, UDER1 > &A, const SpParMat< IU, NU2, UDER2 > &B)
std::vector< std::vector< SpParMat< IT, NT, DER > > > BlockSplit(int br, int bc)
void ReadDistribute(const std::string &filename, int master, bool nonum, HANDLER handler, bool transpose=false, bool pario=false)
bool Kselect(FullyDistVec< GIT, VT > &rvec, IT k_limit, int kselectVersion) const
void MaskedReduce(FullyDistVec< GIT, VT > &rvec, FullyDistSpVec< GIT, VT > &mask, Dim dim, _BinaryOperation __binary_op, VT id, bool exclude=false) const
void EWiseMult(const SpParMat< IT, NT, DER > &rhs, bool exclude)
DER::LocalIT getlocalcols() const
bool Kselect1(FullyDistVec< GIT, VT > &rvec, IT k_limit) const
SpParMat< IT, NT, DER > Prune(_UnaryOperation __unary_op, bool inPlace=true)
void ActivateThreading(int numsplits)
void Find(FullyDistVec< IT, IT > &, FullyDistVec< IT, IT > &, FullyDistVec< IT, NT > &) const
float LoadImbalance() const
friend SpParMat< IU, NUO, UDERO > Mult_AnXBn_DoubleBuff(SpParMat< IU, NU1, UDER1 > &A, SpParMat< IU, NU2, UDER2 > &B, bool clearA, bool clearB)
void SetDifference(const SpParMat< IT, NT, DER > &rhs)
SpParMat< IT, NT, DER > SubsRef_SR(const FullyDistVec< IT, IT > &ri, const FullyDistVec< IT, IT > &ci, bool inplace=false)
General indexing with serial semantics.
void SpAsgn(const FullyDistVec< IT, IT > &ri, const FullyDistVec< IT, IT > &ci, SpParMat< IT, NT, DER > &B)
SpParMat< IT, NT, DER > & operator+=(const SpParMat< IT, NT, DER > &rhs)
void Dump(std::string filename) const
void UpdateDense(DenseParMat< IT, NT > &rhs, _BinaryOperation __binary_op) const
void Apply(_UnaryOperation __unary_op)
friend SpParMat< IU, RETT, RETDER > EWiseApply(const SpParMat< IU, NU1, UDERA > &A, const SpParMat< IU, NU2, UDERB > &B, _BinaryOperation __binary_op, bool notB, const NU2 &defaultBVal)
friend SpParMat< IU, typename promote_trait< NU1, NU2 >::T_promote, typename promote_trait< UDER1, UDER2 >::T_promote > EWiseMult(const SpParMat< IU, NU1, UDER1 > &A, const SpParMat< IU, NU2, UDER2 > &B, bool exclude)
void AddLoops(NT loopval, bool replaceExisting=false)
void SaveGathered(std::string filename, HANDLER handler, bool transpose=false) const
SpParMat< IT, NT, DER > & operator=(const SpParMat< IT, NT, DER > &rhs)
void ParallelReadMM(const std::string &filename, bool onebased, _BinaryOperation BinOp)
DER::LocalIT getlocalrows() const
DER::LocalIT getlocalnnz() const
void ParallelBinaryWrite(std::string filename) const
friend int CalculateNumberOfPhases(SpParMat< IU, NU1, UDERA > &A, SpParMat< IU, NU2, UDERB > &B, NUO hardThreshold, IU selectNum, IU recoverNum, NUO recoverPct, int kselectVersion, int64_t perProcessMem)
bool Kselect1(FullyDistVec< GIT, VT > &rvec, IT k_limit, _UnaryOperation __unary_op) const
void OptimizeForGraph500(OptBuf< LIT, OT > &optbuf)
friend SpParMat< IU, typename promote_trait< NU1, NU2 >::T_promote, typename promote_trait< UDER1, UDER2 >::T_promote > Mult_AnXBn_ActiveTarget(const SpParMat< IU, NU1, UDER1 > &A, const SpParMat< IU, NU2, UDER2 > &B)
std::ofstream & put(std::ofstream &outfile) const
void ParallelWriteMM(const std::string &filename, bool onebased, HANDLER handler)
SpParMat()
Deprecated. Don't call the default constructor.
DER InducedSubgraphs2Procs(const FullyDistVec< IT, IT > &Assignments, std::vector< IT > &LocalIdxs) const
int Owner(IT total_m, IT total_n, IT grow, IT gcol, LIT &lrow, LIT &lcol) const
friend SpParMat< IU, NUO, UDERO > Mult_AnXBn_SUMMA(SpParMat< IU, NU1, UDER1 > &A, SpParMat< IU, NU2, UDER2 > &B, bool clearA, bool clearB)
void PruneColumnByIndex(const FullyDistSpVec< IT, IRRELEVANT_NT > &ci)
SpParMat< IT, NT, DER > PruneColumn(const FullyDistVec< IT, NT > &pvals, _BinaryOperation __binary_op, bool inPlace=true)
Prune every column of a sparse matrix based on pvals.
friend SpParMat< IU, NUO, UDERO > MemEfficientSpGEMM(SpParMat< IU, NU1, UDERA > &A, SpParMat< IU, NU2, UDERB > &B, int phases, NUO hardThreshold, IU selectNum, IU recoverNum, NUO recoverPct, int kselectVersion, int computationKernel, int64_t perProcessMem)
std::shared_ptr< CommGrid > getcommgrid() const
friend IU EstimateFLOP(SpParMat< IU, NU1, UDER1 > &A, SpParMat< IU, NU2, UDER2 > &B, bool clearA, bool clearB)
Friend declarations.
SpParMat< IT, NT, DER > operator()(const FullyDistVec< IT, IT > &ri, const FullyDistVec< IT, IT > &ci, bool inplace=false)
void ParallelWriteMM(const std::string &filename, bool onebased)
void SparseCommon(std::vector< std::vector< std::tuple< LIT, LIT, NT > > > &data, LIT locsize, IT total_m, IT total_n, _BinaryOperation BinOp)
friend SpParMat< IU, NUO, UDERO > Mult_AnXBn_Synch(SpParMat< IU, NU1, UDER1 > &A, SpParMat< IU, NU2, UDER2 > &B, bool clearA, bool clearB)
void PSpGEMM(SpParMat< IU, NU1, UDER1 > &A, SpParMat< IU, NU2, UDER2 > &B, SpParMat< IU, NUO, UDERO > &out, bool clearA=false, bool clearB=false)
unsigned __int64 uint64_t