4 #include "../CombBLAS.h" 11 template <
typename PARMAT>
16 MPI_Comm_size(MPI_COMM_WORLD,&nprocs);
17 MPI_Comm_rank(MPI_COMM_WORLD,&myrank);
26 A.
Reduce(*ColSums,
Column, std::plus<int64_t>(), static_cast<int64_t>(0));
27 A.Reduce(*RowSums,
Row, std::plus<int64_t>(), static_cast<int64_t>(0));
38 nonisoColV = ColSums->
FindInds(bind2nd(std::greater<int64_t>(), 0));
39 nonisoRowV = RowSums->
FindInds(bind2nd(std::greater<int64_t>(), 0));
50 int64_t nrows1=A.getnrow(), ncols1=A.getncol(), nnz1 = A.getnnz();
51 double avgDeg1 = (double) nnz1/(nrows1+ncols1);
54 A.operator()(nonisoRowV, nonisoColV,
true);
56 int64_t nrows2=A.getnrow(), ncols2=A.getncol(), nnz2 = A.getnnz();
57 double avgDeg2 = (double) nnz2/(nrows2+ncols2);
62 std::cout <<
"ncol nrows nedges deg \n";
63 std::cout << nrows1 <<
" " << ncols1 <<
" " << nnz1 <<
" " << avgDeg1 <<
" \n";
64 std::cout << nrows2 <<
" " << ncols2 <<
" " << nnz2 <<
" " << avgDeg2 <<
" \n";
67 MPI_Barrier(MPI_COMM_WORLD);
79 template <
class IT,
class NT>
84 MPI_Comm_rank(MPI_COMM_WORLD,&myrank);
85 for(
int i=0; i< mateRow2Col.glen ; i++)
87 int t = mateRow2Col[i];
89 if(t!=-1 && mateCol2Row[t]!=i)
92 std::cout <<
"Does not satisfy the matching constraints\n";
97 for(
int i=0; i< mateCol2Row.glen ; i++)
99 int t = mateCol2Row[i];
100 if(t!=-1 && mateRow2Col[t]!=i)
103 std::cout <<
"Does not satisfy the matching constraints\n";
117 MPI_Comm_rank(MPI_COMM_WORLD,&myrank);
118 int64_t nrow = mateRow2Col.TotalLength();
119 int64_t ncol = mateCol2Row.TotalLength();
128 if((mateCol2RowSparse == mateRow2ColInverted) && (mateRow2ColSparse == mateCol2RowInverted))
131 bool isPerfectMatching =
false;
132 if((mateRow2ColSparse.getnnz()==nrow) && (mateCol2RowSparse.getnnz() == ncol))
133 isPerfectMatching =
true;
138 std::cout <<
"-------------------------------" << std::endl;
142 std::cout <<
"| This is a matching |" << std::endl;
143 if(isPerfectMatching)
144 std::cout <<
"| This is a perfect matching |" << std::endl;
149 std::cout <<
"| This is not a matching |" << std::endl;
150 std::cout <<
"-------------------------------" << std::endl;
153 return isPerfectMatching;
159 template <
class IT,
class NT,
class DER>
164 int myrank=commGrid->GetRank();
165 MPI_Comm World = commGrid->GetWorld();
166 MPI_Comm ColWorld = commGrid->GetColWorld();
167 MPI_Comm RowWorld = commGrid->GetRowWorld();
168 int nprocs = commGrid->GetSize();
169 int pr = commGrid->GetGridRows();
170 int pc = commGrid->GetGridCols();
171 int rowrank = commGrid->GetRankInProcRow();
172 int colrank = commGrid->GetRankInProcCol();
173 int diagneigh = commGrid->GetComplementRank();
180 IT m_perproc = nrows / pr;
181 IT n_perproc = ncols / pc;
184 IT lnrow = spSeq->getnrow();
185 IT lncol = spSeq->getncol();
186 IT localRowStart = colrank * m_perproc;
187 IT localColStart = rowrank * n_perproc;
195 MPI_Sendrecv(&xsize, 1, MPI_INT, diagneigh,
TRX, &trxsize, 1, MPI_INT, diagneigh,
TRX, World, &status);
196 std::vector<IT> trxnums(trxsize);
197 MPI_Sendrecv(mateCol2Row.
GetLocArr(), xsize, MPIType<IT>(), diagneigh,
TRX, trxnums.data(), trxsize, MPIType<IT>(), diagneigh,
TRX, World, &status);
200 std::vector<int> colsize(pc);
201 colsize[colrank] = trxsize;
202 MPI_Allgather(MPI_IN_PLACE, 1, MPI_INT, colsize.data(), 1, MPI_INT, ColWorld);
203 std::vector<int> dpls(pc,0);
204 std::partial_sum(colsize.data(), colsize.data()+pc-1, dpls.data()+1);
205 int accsize = std::accumulate(colsize.data(), colsize.data()+pc, 0);
206 std::vector<IT> RepMateC2R(accsize);
207 MPI_Allgatherv(trxnums.data(), trxsize, MPIType<IT>(), RepMateC2R.data(), colsize.data(), dpls.data(), MPIType<IT>(), ColWorld);
218 for(
auto colit = spSeq->begcol(); colit != spSeq->endcol(); ++colit)
220 IT lj = colit.colid();
221 IT mj = RepMateC2R[lj];
222 if(mj >= localRowStart && mj < (localRowStart+lnrow) )
224 for(
auto nzit = spSeq->begnz(colit); nzit < spSeq->endnz(colit); ++nzit)
226 IT li = nzit.rowid();
227 IT i = li + localRowStart;
240 MPI_Allreduce(MPI_IN_PLACE, &w, 1, MPIType<NT>(), MPI_SUM, World);
253 template <
typename PARMAT>
std::shared_ptr< CommGrid > getcommgrid() const
FullyDistVec< IT, IT > FindInds(_Predicate pred) const
Return the indices where pred is true.
FullyDistSpVec< IT, NT > Invert(IT globallen)
NT MatchingWeight(std::vector< NT > &RepMateWC2R, MPI_Comm RowWorld, NT &minw)
bool isMatching(FullyDistVec< IT, NT > &mateCol2Row, FullyDistVec< IT, NT > &mateRow2Col)
bool CheckMatching(FullyDistVec< IT, IT > &mateRow2Col, FullyDistVec< IT, IT > &mateCol2Row)
NT Reduce(_BinaryOperation __binary_op, NT identity) const
void Symmetricize(PARMAT &A)
void removeIsolated(PARMAT &A)
const NT * GetLocArr() const