1#ifndef BP_MAXIMAL_MATCHING_H
2#define BP_MAXIMAL_MATCHING_H
4#include "CombBLAS/CombBLAS.h"
23template <
typename Par_DCSC_Bool,
typename IT>
30 MPI_Comm_size(MPI_COMM_WORLD,&
nprocs);
31 MPI_Comm_rank(MPI_COMM_WORLD,&myrank);
36 nthreads = omp_get_num_threads();
51 unmatchedCol = EWiseApply<VertexType>(unmatchedCol, degCol,
62 IT curUnmatchedCol = unmatchedCol.
getnnz();
63 IT curUnmatchedRow = unmatchedRow.getnnz();
66 double tStart = MPI_Wtime();
67 std::vector<std::vector<double> > timing;
72 cout <<
"=======================================================\n";
73 cout <<
"@@@@@@ Number of processes: " <<
nprocs << endl;
74 cout <<
"=======================================================\n";
75 cout <<
"It | UMRow | UMCol | newlyMatched | Time "<< endl;
76 cout <<
"=======================================================\n";
79 MPI_Barrier(MPI_COMM_WORLD);
82 while(curUnmatchedCol !=0 && curUnmatchedRow!=0 && newlyMatched != 0 )
87 unmatchedCol = EWiseApply<VertexType>(unmatchedCol, degCol,
98 std::vector<double> times;
99 double t1 = MPI_Wtime();
102 SpMV<Select2ndMinSR<bool, VertexType>>(
A, unmatchedCol, fringeRow,
false);
106 SpMV<Select2ndMinSR<bool, VertexType>>(
A, unmatchedCol, fringeRow,
false);
110 deg1Col = EWiseApply<VertexType>(unmatchedCol, degCol,
118 SpMV<Select2ndMinSR<bool, VertexType>>(
A, unmatchedCol, fringeRow,
false);
121 fringeRow = EWiseApply<VertexType>(fringeRow, mateRow2Col,
126 if(myrank == 0){times.push_back(MPI_Wtime()-t1); t1 = MPI_Wtime();}
132 fringeRow2 = EWiseApply<IT>(fringeRow, mateRow2Col,
139 mateCol2Row.
Set(newMatchedCols);
140 mateRow2Col.
Set(newMatchedRows);
141 if(myrank == 0){times.push_back(MPI_Wtime()-t1); t1 = MPI_Wtime();}
146 unmatchedRow.Select(mateRow2Col, [](
IT mate){
return mate==-1;});
147 unmatchedCol.
Select(mateCol2Row, [](
IT mate){
return mate==-1;});
152 newMatchedRows.
Apply([](
IT val){
return 1;});
153 SpMV< SelectPlusSR<bool, IT>>(AT, newMatchedRows, degColSG,
false);
156 [](
IT old_deg,
IT new_deg){
return old_deg-new_deg;},
157 [](
IT old_deg,
IT new_deg){
return true;},
158 false,
static_cast<IT>(0));
160 unmatchedCol = EWiseApply<VertexType>(unmatchedCol, degCol,
165 if(myrank == 0){times.push_back(MPI_Wtime()-t1); t1 = MPI_Wtime();}
170 newlyMatched = newMatchedCols.getnnz();
171 times.push_back(std::accumulate(times.begin(), times.end(), 0.0));
172 timing.push_back(times);
176 printf(
"%3d %10lld %10lld %10lld %18lf\n", iteration , curUnmatchedRow, curUnmatchedCol, newlyMatched, times.back());
179 curUnmatchedCol = unmatchedCol.
getnnz();
180 curUnmatchedRow = unmatchedRow.getnnz();
181 MPI_Barrier(MPI_COMM_WORLD);
185 IT cardinality = mateRow2Col.
Count([](
IT mate){
return mate!=-1;});
186 std::vector<double> totalTimes(timing[0].
size(),0);
187 for(
int i=0; i<timing.size(); i++)
189 for(
int j=0; j<timing[i].size(); j++)
191 totalTimes[j] += timing[i][j];
199 cout <<
"==========================================================\n";
200 cout <<
"\n================individual timings =======================\n";
201 cout <<
" SpMV Update-Match Update-UMC Total "<< endl;
202 cout <<
"==========================================================\n";
203 for(
int i=0; i<timing.size(); i++)
205 for(
int j=0; j<timing[i].size(); j++)
207 printf(
"%12.5lf ", timing[i][j]);
212 cout <<
"-------------------------------------------------------\n";
213 for(
int i=0; i<totalTimes.size(); i++)
214 printf(
"%12.5lf ", totalTimes[i]);
217 std::cout <<
"****** maximal matching runtime ********\n";
218 std::cout <<
"nprocesses nthreads ncores algorithm Unmatched-Rows Cardinality Total Time***\n";
219 std::cout <<
nprocs <<
" " << nthreads <<
" " <<
nprocs * nthreads <<
" ";
220 if(type ==
DMD) std::cout <<
"DMD";
221 else if(type ==
GREEDY) std::cout <<
"Greedy";
222 else if(type ==
KARP_SIPSER) std::cout <<
"Karp-Sipser";
225 printf(
"%lld %lld %lf\n", curUnmatchedRow, cardinality, totalTimes.back());
226 std::cout <<
"-------------------------------------------------------\n\n";
238template <
typename Par_MAT_Double,
typename IT>
248 nthreads = omp_get_num_threads();
253 MPI_Comm_size(MPI_COMM_WORLD,&
nprocs);
254 MPI_Comm_rank(MPI_COMM_WORLD,&myrank);
264 unmatchedCol = EWiseApply<VertexType>(unmatchedCol, degCol,
274 IT curUnmatchedCol = unmatchedCol.
getnnz();
275 IT curUnmatchedRow = unmatchedRow.getnnz();
279 std::vector<std::vector<double> > timing;
284 cout <<
"=======================================================\n";
285 cout <<
"@@@@@@ Number of processes: " <<
nprocs << endl;
286 cout <<
"=======================================================\n";
287 cout <<
"It | UMRow | UMCol | newlyMatched | Time "<< endl;
288 cout <<
"=======================================================\n";
291 MPI_Barrier(MPI_COMM_WORLD);
294 while(curUnmatchedCol !=0 && curUnmatchedRow!=0 && newlyMatched != 0 )
301 std::vector<double> times;
302 double t1 = MPI_Wtime();
304 SpMV<WeightMaxMLSR<double, VertexType>>(
A, unmatchedCol, fringeRow,
false, SPA);
307 fringeRow = EWiseApply<VertexType>(fringeRow, mateRow2Col,
312 if(myrank == 0){times.push_back(MPI_Wtime()-t1); t1 = MPI_Wtime();}
318 fringeRow2 = EWiseApply<IT>(fringeRow, mateRow2Col,
325 mateCol2Row.
Set(newMatchedCols);
326 mateRow2Col.
Set(newMatchedRows);
327 if(myrank == 0){times.push_back(MPI_Wtime()-t1); t1 = MPI_Wtime();}
333 unmatchedRow.Select(mateRow2Col, [](
IT mate){
return mate==-1;});
334 unmatchedCol.Select(mateCol2Row, [](
IT mate){
return mate==-1;});
335 if(myrank == 0){times.push_back(MPI_Wtime()-t1); t1 = MPI_Wtime();}
340 newlyMatched = newMatchedCols.getnnz();
341 times.push_back(std::accumulate(times.begin(), times.end(), 0.0));
342 timing.push_back(times);
346 printf(
"%3d %10lld %10lld %10lld %18lf\n", iteration , curUnmatchedRow, curUnmatchedCol, newlyMatched, times.back());
349 curUnmatchedCol = unmatchedCol.getnnz();
350 curUnmatchedRow = unmatchedRow.getnnz();
351 MPI_Barrier(MPI_COMM_WORLD);
355 IT cardinality = mateRow2Col.
Count([](
IT mate){
return mate!=-1;});
356 std::vector<double> totalTimes(timing[0].
size(),0);
357 for(
int i=0; i<timing.size(); i++)
359 for(
int j=0; j<timing[i].size(); j++)
361 totalTimes[j] += timing[i][j];
369 cout <<
"==========================================================\n";
370 cout <<
"\n================individual timings =======================\n";
371 cout <<
" SpMV Update-Match Update-UMC Total "<< endl;
372 cout <<
"==========================================================\n";
373 for(
int i=0; i<timing.size(); i++)
375 for(
int j=0; j<timing[i].size(); j++)
377 printf(
"%12.5lf ", timing[i][j]);
382 cout <<
"-------------------------------------------------------\n";
383 for(
int i=0; i<totalTimes.size(); i++)
384 printf(
"%12.5lf ", totalTimes[i]);
388 std::cout <<
"****** maximal matching runtime ********\n";
389 std::cout <<
"Unmatched-Rows Cardinality Total Time***\n";
390 printf(
"%lld %lld %lf\n", curUnmatchedRow, cardinality, totalTimes.back());
391 std::cout <<
"-------------------------------------------------------\n\n";
400template <
class Par_DCSC_Bool,
class IT,
class NT>
405 MPI_Comm_rank(MPI_COMM_WORLD,&myrank);
411 unmatchedCol.setNumToInd();
414 SpMV<Select2ndMinSR<bool, VertexType>>(
A, unmatchedCol, fringeRow,
false);
415 fringeRow =
EWiseMult(fringeRow, mateRow2Col,
true, (
IT) -1);
416 if(fringeRow.
getnnz() != 0)
419 std::cout <<
"Not maximal matching!!\n";
425 SpMV<Select2ndMinSR<bool, VertexType>>(tA, unmatchedRow, fringeCol,
false);
426 fringeCol =
EWiseMult(fringeCol, mateCol2Row,
true, (
IT) -1);
427 if(fringeCol.
getnnz() != 0)
430 std::cout <<
"Not maximal matching**!!\n";
SpParMat< int64_t, bool, SpDCCols< int64_t, bool > > Par_DCSC_Bool
void Select(const FullyDistVec< IT, NT1 > &denseVec, _UnaryOperation unop)
void Apply(_UnaryOperation __unary_op)
FullyDistSpVec< IT, NT > Invert(IT globallen)
void ApplyInd(_BinaryOperation __binary_op)
void EWiseApply(const FullyDistVec< IT, NT2 > &other, _BinaryOperation __binary_op, _BinaryPredicate _do_op, const bool useExtendedBinOp)
void Set(const FullyDistSpVec< IT, NT > &rhs)
IT Count(_Predicate pred) const
Return the number of elements for which pred is true.
void MaximalMatching(Par_DCSC_Bool &A, Par_DCSC_Bool &AT, FullyDistVec< IT, IT > &mateRow2Col, FullyDistVec< IT, IT > &mateCol2Row, FullyDistVec< IT, IT > °ColRecv, int type, bool rand=true)
bool isMaximalmatching(Par_DCSC_Bool &A, FullyDistVec< IT, NT > &mateRow2Col, FullyDistVec< IT, NT > &mateCol2Row)
FullyDistSpVec< IT, VT > SpMV(const SpParMat< IT, bool, UDER > &A, const FullyDistSpVec< IT, VT > &x, OptBuf< int32_t, VT > &optbuf)
void WeightedGreedy(Par_MAT_Double &A, FullyDistVec< IT, IT > &mateRow2Col, FullyDistVec< IT, IT > &mateCol2Row, FullyDistVec< IT, IT > °Col)
Dcsc< IU, typename promote_trait< NU1, NU2 >::T_promote > EWiseMult(const Dcsc< IU, NU1 > &A, const Dcsc< IU, NU2 > *B, bool exclude)