30 #ifndef _SP_PAR_MAT_H_ 31 #define _SP_PAR_MAT_H_ 67 template <
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>
107 template <
typename _BinaryOperation>
110 template <
typename _BinaryOperation,
typename _UnaryOperation >
113 template <
typename _BinaryOperation>
116 template <
typename VT,
typename GIT,
typename _BinaryOperation,
typename _UnaryOperation >
119 template <
typename VT,
typename GIT,
typename _BinaryOperation>
122 template <
typename VT,
typename GIT>
124 template <
typename VT,
typename GIT>
127 template <
typename VT,
typename GIT,
typename _UnaryOperation>
129 template <
typename VT,
typename GIT,
typename _UnaryOperation>
131 template <
typename VT,
typename GIT>
133 template <
typename VT,
typename GIT>
139 template <
typename VT,
typename GIT,
typename _BinaryOperation>
141 template <
typename VT,
typename GIT,
typename _BinaryOperation,
typename _UnaryOperation >
144 template <
typename _UnaryOperation>
145 void Apply(_UnaryOperation __unary_op)
147 spSeq->Apply(__unary_op);
151 void AddLoops(NT loopval,
bool replaceExisting=
false);
154 template <
typename LIT,
typename OT>
158 template <
typename _UnaryOperation>
162 GetPlaceInGlobalGrid(grow, gcol);
165 spSeq->PruneI(__unary_op, inPlace, grow, gcol);
174 template <
typename _UnaryOperation>
179 spSeq->Prune(__unary_op, inPlace);
188 template <
typename _BinaryOperation>
191 template <
typename _BinaryOperation>
194 template <
typename _BinaryOperation>
197 void Dump(std::string filename)
const;
207 template <
typename LIT>
208 int Owner(IT total_m, IT total_n, IT grow, IT gcol, LIT & lrow, LIT & lcol)
const;
213 template <
typename SelectFirstSR,
typename SelectSecondSR>
228 NT
getNoNum(IT row, IT col) {
return static_cast<NT
>(1); }
231 if (fread(&row,
sizeof(IT), 1,rFile) != 1)
232 std::cout <<
"binaryfill(): error reading row index" << std::endl;
233 if (fread(&col,
sizeof(IT), 1,rFile) != 1)
234 std::cout <<
"binaryfill(): error reading col index" << std::endl;
235 if (fread(&val,
sizeof(NT), 1,rFile) != 1)
236 std::cout <<
"binaryfill(): error reading value" << std::endl;
241 template <
typename c,
typename t>
242 NT
read(std::basic_istream<c,t>& is, IT row, IT col)
249 template <
typename c,
typename t>
250 void save(std::basic_ostream<c,t>& os,
const NT& v, IT row, IT col)
256 template <
typename _BinaryOperation>
257 void ParallelReadMM (
const std::string & filename,
bool onebased, _BinaryOperation BinOp);
259 template <
typename _BinaryOperation>
262 template <
class HANDLER>
263 void ReadDistribute (
const std::string & filename,
int master,
bool nonum, HANDLER handler,
bool transpose =
false,
bool pario =
false);
264 void ReadDistribute (
const std::string & filename,
int master,
bool nonum=
false,
bool pario =
false)
266 ReadDistribute(filename, master, nonum, ScalarReadSaveHandler(),
false, pario);
269 template <
class HANDLER>
270 void SaveGathered(std::string filename, HANDLER handler,
bool transpose =
false)
const;
273 std::ofstream&
put(std::ofstream& outfile)
const;
275 std::shared_ptr<CommGrid>
getcommgrid()
const {
return commGrid; }
276 typename DER::LocalIT
getlocalrows()
const {
return spSeq->getnrow(); }
278 typename DER::LocalIT
getlocalnnz()
const {
return spSeq->getnnz(); }
279 DER &
seq() {
return (*spSeq); }
282 template <
typename _BinaryOperation,
typename LIT>
283 void SparseCommon(std::vector< std::vector < std::tuple<LIT,LIT,NT> > > & data, LIT locsize, IT total_m, IT total_n, _BinaryOperation BinOp);
286 template <
typename SR,
typename NUO,
typename UDERO,
typename IU,
typename NU1,
typename NU2,
typename UDER1,
typename UDER2>
290 template <
typename SR,
typename NUO,
typename UDERO,
typename IU,
typename NU1,
typename NU2,
typename UDER1,
typename UDER2>
294 template <
typename IU,
typename NU1,
typename NU2,
typename UDERA,
typename UDERB>
297 template <
typename SR,
typename IU,
typename NU1,
typename NU2,
typename UDER1,
typename UDER2>
301 template <
typename SR,
typename IU,
typename NU1,
typename NU2,
typename UDER1,
typename UDER2>
305 template <
typename SR,
typename IU,
typename NU1,
typename NU2,
typename UDER1,
typename UDER2>
309 template <
typename SR,
typename NUO,
typename UDERO,
typename IU,
typename NU1,
typename NU2,
typename UDERA,
typename UDERB>
311 int phases, NUO hardThreshold, IU selectNum, IU recoverNum, NUO recoverPct,
int kselectVersion,
int64_t perProcessMem);
313 template <
typename SR,
typename IU,
typename NUM,
typename NUV,
typename UDER>
317 template <
typename SR,
typename IU,
typename NUM,
typename NUV,
typename UDER>
321 template <
typename SR,
typename IU,
typename NUM,
typename UDER>
326 template <
typename SR,
typename IVT,
typename OVT,
typename IU,
typename NUM,
typename UDER>
329 template <
typename SR,
typename IVT,
typename OVT,
typename IU,
typename NUM,
typename UDER>
332 template <
typename IU,
typename NU1,
typename NU2,
typename UDER1,
typename UDER2>
336 template <
typename RETT,
typename RETDER,
typename IU,
typename NU1,
typename NU2,
typename UDERA,
typename UDERB,
typename _BinaryOperation>
340 template <
typename RETT,
typename RETDER,
typename IU,
typename NU1,
typename NU2,
typename UDERA,
typename UDERB,
typename _BinaryOperation,
typename _BinaryPredicate>
342 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);
344 template<
typename SR,
typename IVT,
typename OVT,
typename IU,
typename NUM,
typename UDER>
346 int32_t * & sendindbuf, OVT * & sendnumbuf,
int * & sdispls,
int * sendcnt,
int accnz,
bool indexisvalue,
PreAllocatedSPA<OVT> & SPA);
348 template<
typename VT,
typename IU,
typename UDER>
352 typedef std::array<char, MAXVERTNAME> STRASARRAY;
353 typedef std::pair< STRASARRAY, uint64_t> TYPE2SEND;
355 class CharArraySaveHandler
359 template <
typename c,
typename t>
360 void save(std::basic_ostream<c,t>& os, STRASARRAY & chararray,
int64_t index)
362 auto locnull = std::find(chararray.begin(), chararray.end(),
'\0');
363 std::string strtmp(chararray.begin(), locnull);
368 MPI_File TupleRead1stPassNExchange (
const std::string & filename, TYPE2SEND * & senddata, IT & totsend,
FullyDistVec<IT,STRASARRAY> & distmapper, uint64_t & totallength);
370 template <
typename VT,
typename GIT,
typename _BinaryOperation,
typename _UnaryOperation >
374 template <
typename VT,
typename GIT>
375 void TopKGather(std::vector<NT> & all_medians, std::vector<IT> & nnz_per_col,
int & thischunk,
int & chunksize,
376 const std::vector<NT> & medians,
const std::vector<IT> & nnzperc,
int itersuntil, std::vector< std::vector<NT> > & localmat,
377 const std::vector<IT> & actcolsmap, std::vector<IT> & klimits, std::vector<IT> & toretain, std::vector<std::vector<std::pair<IT,NT>>> & tmppair,
380 void GetPlaceInGlobalGrid(IT& rowOffset, IT& colOffset)
const;
382 void HorizontalSend(IT * & rows, IT * & cols, NT * & vals, IT * & temprows, IT * & tempcols, NT * & tempvals, std::vector < std::tuple <IT,IT,NT> > & localtuples,
383 int * rcurptrs,
int * rdispls, IT buffperrowneigh,
int rowneighs,
int recvcount, IT m_perproc, IT n_perproc,
int rankinrow);
385 template <
class HANDLER>
386 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,
387 IT m_perproc, IT n_perproc,
int rowneighs,
int colneighs, IT buffperrowneigh, IT buffpercolneigh, IT entriestoread, HANDLER handler,
int rankinrow,
bool transpose);
389 void VerticalSend(IT * & rows, IT * & cols, NT * & vals, std::vector< std::tuple<IT,IT,NT> > & localtuples,
int * rcurptrs,
int * ccurptrs,
int * rdispls,
int * cdispls,
390 IT m_perproc, IT n_perproc,
int rowneighs,
int colneighs, IT buffperrowneigh, IT buffpercolneigh,
int rankinrow);
392 void AllocateSetBuffers(IT * & rows, IT * & cols, NT * & vals,
int * & rcurptrs,
int * & ccurptrs,
int rowneighs,
int colneighs, IT buffpercolneigh);
393 void BcastEssentials(MPI_Comm & world, IT & total_m, IT & total_n, IT & total_nnz,
int master);
395 std::shared_ptr<CommGrid> commGrid;
398 template <
class IU,
class NU>
401 template <
typename IU,
typename NU,
typename UDER>
402 friend std::ofstream& operator<< (std::ofstream& outfile, const SpParMat<IU,NU,UDER> & s);
405 template <
typename SR,
typename NUO,
typename UDERO,
typename IU,
typename NU1,
typename NU2,
typename UDER1,
typename UDER2>
406 void PSpGEMM(
SpParMat<IU,NU1,UDER1> &
A,
SpParMat<IU,NU2,UDER2> &
B,
SpParMat<IU,NUO,UDERO> & out,
bool clearA =
false,
bool clearB =
false)
408 out = Mult_AnXBn_Synch<SR, NUO, UDERO> (
A,
B, clearA, clearB );
411 template <
typename SR,
typename IU,
typename NU1,
typename NU2,
typename UDER1,
typename UDER2>
417 return Mult_AnXBn_Synch<SR, N_promote, DER_promote> (
A,
B, clearA, clearB );
FullyDistVec< IT, NT > Reduce(Dim dim, _BinaryOperation __binary_op, NT id, _UnaryOperation __unary_op) const
std::shared_ptr< CommGrid > getcommgrid() const
void ActivateThreading(int numsplits)
void PSpGEMM(SpParMat< IU, NU1, UDER1 > &A, SpParMat< IU, NU2, UDER2 > &B, SpParMat< IU, NUO, UDERO > &out, bool clearA=false, bool clearB=false)
FullyDistVec< IT, std::array< char, MAXVERTNAME > > ReadGeneralizedTuples(const std::string &, _BinaryOperation)
void SpAsgn(const FullyDistVec< IT, IT > &ri, const FullyDistVec< IT, IT > &ci, SpParMat< IT, NT, DER > &B)
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)
void SparseCommon(std::vector< std::vector< std::tuple< LIT, LIT, NT > > > &data, LIT locsize, IT total_m, IT total_n, _BinaryOperation BinOp)
SpParMat< IT, NT, DER > & operator=(const SpParMat< IT, NT, DER > &rhs)
void Apply(_UnaryOperation __unary_op)
DER::LocalIT getlocalrows() const
void save(std::basic_ostream< c, t > &os, const NT &v, IT row, IT col)
SpParMat< IT, NT, DER > SubsRef_SR(const FullyDistVec< IT, IT > &ri, const FullyDistVec< IT, IT > &ci, bool inplace=false)
General indexing with serial semantics.
friend SpParMat< IU, NUO, UDERO > Mult_AnXBn_Synch(SpParMat< IU, NU1, UDER1 > &A, SpParMat< IU, NU2, UDER2 > &B, bool clearA, bool clearB)
bool Kselect(FullyDistVec< GIT, VT > &rvec, IT k_limit, int kselectVersion) const
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)
void binaryfill(FILE *rFile, IT &row, IT &col, NT &val)
float LoadImbalance() const
void SaveGathered(std::string filename, HANDLER handler, bool transpose=false) const
bool operator==(const SpParMat< IT, NT, DER > &rhs) const
void DimApply(Dim dim, const FullyDistVec< IT, NT > &v, _BinaryOperation __binary_op)
DER::LocalIT getlocalcols() const
void OptimizeForGraph500(OptBuf< LIT, OT > &optbuf)
void AddLoops(NT loopval, bool replaceExisting=false)
void ReadDistribute(const std::string &filename, int master, bool nonum, HANDLER handler, bool transpose=false, bool pario=false)
void Dump(std::string filename) const
std::ofstream & put(std::ofstream &outfile) const
SpParMat< IT, NT, DER > PruneI(_UnaryOperation __unary_op, bool inPlace=true)
NT getNoNum(IT row, IT col)
bool Kselect1(FullyDistVec< GIT, VT > &rvec, IT k_limit, _UnaryOperation __unary_op) const
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)
void SaveGathered(std::string filename) const
friend int64_t EstPerProcessNnzSUMMA(SpParMat< IU, NU1, UDERA > &A, SpParMat< IU, NU2, UDERB > &B)
int Owner(IT total_m, IT total_n, IT grow, IT gcol, LIT &lrow, LIT &lcol) const
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, int64_t perProcessMem)
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, RETT, RETDER > EWiseApply(const SpParMat< IU, NU1, UDERA > &A, const SpParMat< IU, NU2, UDERB > &B, _BinaryOperation __binary_op, bool notB, const NU2 &defaultBVal)
friend FullyDistSpVec< IU, typename promote_trait< NUM, NUV >::T_promote > SpMV(const SpParMat< IU, NUM, UDER > &A, const FullyDistSpVec< IU, NUV > &x)
void MaskedReduce(FullyDistVec< GIT, VT > &rvec, FullyDistSpVec< GIT, VT > &mask, Dim dim, _BinaryOperation __binary_op, VT id, bool exclude=false) const
DER::LocalIT getlocalnnz() const
void UpdateDense(DenseParMat< IT, NT > &rhs, _BinaryOperation __binary_op) const
SpParMat()
Deprecated. Don't call the default constructor.
void ReadDistribute(const std::string &filename, int master, bool nonum=false, bool pario=false)
SpParMat< IT, NT, DER > & operator+=(const SpParMat< IT, NT, DER > &rhs)
SpParMat< IT, NT, DER > SubsRefCol(const std::vector< IT > &ci) const
Column indexing with special parallel semantics.
friend SpParMat< IU, NUO, UDERO > Mult_AnXBn_DoubleBuff(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)
bool Kselect2(FullyDistVec< GIT, VT > &rvec, IT k_limit) const
NT read(std::basic_istream< c, t > &is, IT row, IT col)
void Find(FullyDistVec< IT, IT > &, FullyDistVec< IT, IT > &, FullyDistVec< IT, NT > &) const
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)
void EWiseMult(const SpParMat< IT, NT, DER > &rhs, bool exclude)
SpParMat< IT, NT, DER > Prune(_UnaryOperation __unary_op, bool inPlace=true)
void ParallelReadMM(const std::string &filename, bool onebased, _BinaryOperation BinOp)
void EWiseScale(const DenseParMat< IT, NT > &rhs)