11#include "CombBLAS/CombBLAS.h"
39 MPI_Comm_rank(MPI_COMM_WORLD,&myrank);
42 cout <<
"\n-------------- usage --------------\n";
43 cout <<
"Usage: ./awpm -input <filename>\n";
44 cout <<
"Optional parameters: -randPerm: randomly permute the matrix for load balance (default: no random permutation)\n";
45 cout <<
" -optsum: Optimize the sum of diagonal (default: Optimize the product of diagonal)\n";
46 cout <<
" -noWeightedCard: do not use weighted cardinality matching (default: use weighted cardinality matching)\n";
47 cout <<
" -output <output file>: output file name \n";
49 cout <<
" \n-------------- examples ----------\n";
50 cout <<
"Example: mpirun -np 4 ./awpm -input cage12.mtx \n" << endl;
51 cout <<
"(output matching is saved to cage12.mtx.awpm.txt)\n" << endl;
61int main(
int argc,
char* argv[])
66 MPI_Init_thread(&argc, &argv, MPI_THREAD_SERIALIZED, &provided);
67 if (provided < MPI_THREAD_SERIALIZED)
69 printf(
"ERROR: The MPI library does not have MPI_THREAD_SERIALIZED support\n");
70 MPI_Abort(MPI_COMM_WORLD, 1);
73 MPI_Comm_size(MPI_COMM_WORLD,&
nprocs);
74 MPI_Comm_rank(MPI_COMM_WORLD,&myrank);
83 bool optimizeProd =
true;
85 bool weightedCard =
true;
86 string ifilename =
"";
89 for(
int i = 1; i<argc; i++)
91 if (
string(argv[i]) ==
string(
"-input")) ifilename = argv[i+1];
92 if (
string(argv[i]) ==
string(
"-output"))
ofname = argv[i+1];
94 if (
string(argv[i]) ==
string(
"-optsum")) optimizeProd =
false;
95 if (
string(argv[i]) ==
string(
"-noWeightedCard")) weightedCard =
false;
96 if (
string(argv[i]) ==
string(
"-randPerm"))
randPerm =
true;
118 SpParHelper::Print(
"Rectangular matrix: Can not compute a perfect matching.\n");
124 tinfo <<
"Input file name: " << ifilename << endl;
125 tinfo <<
"Reading the input matrix in" << t02-t01 <<
" seconds" << endl;
126 SpParHelper::Print(tinfo.str());
128 SpParHelper::Print(
"Pruning explicit zero entries\n");
129 AWeighted->
Prune([](
double val){
return fabs(val)==0;},
true);
153 (*AWeighted)(randp,randp,
true);
155 SpParHelper::Print(
"Matrix is randomly permuted for load balance.\n");
157 s <<
"load-balance: before:" << oldbalance <<
" after:" << newbalance << endl;
158 SpParHelper::Print(s.str());
162 SpParHelper::Print(
"Rectangular matrix: Can not apply symmetric permutation.\n");
170 A.Reduce(degCol,
Column, plus<int64_t>(),
static_cast<int64_t>(0));
174 tinfo <<
"Maximum degree: " << maxdeg << endl;
175 SpParHelper::Print(tinfo.str());
177 SpParHelper::Print(
"Preprocessing is done.\n");
178 SpParHelper::Print(
"----------------------------------------\n");
183 double startT = MPI_Wtime();
184 AWPM(*AWeighted, mateRow2Col, mateCol2Row, optimizeProd, weightedCard);
185 double endT = MPI_Wtime();
194 double origWeight =
Trace(*AWeighted, diagnnz);
195 double mWeight =
MatchingWeight( *AWeighted, mateRow2Col, mateCol2Row) ;
197 tinfo <<
"Matching is computed " << endl;
198 tinfo <<
"Sum of Diagonal (with transformation)" << endl;
199 tinfo <<
" After matching: "<< mWeight << endl;
200 tinfo <<
" Before matching: " << origWeight << endl;
202 tinfo <<
"Time: " << endT - startT << endl;
203 tinfo <<
"----------------------------------------\n";
204 SpParHelper::Print(tinfo.str());
207 if(
randPerm==
true && randp.TotalLength() >0)
211 mateRow2Col = mateRow2Col(invRandp);
int main(int argc, char *argv[])
SpParMat< int64_t, bool, SpDCCols< int64_t, bool > > Par_DCSC_Bool
SpParMat< int64_t, double, SpCCols< int64_t, double > > Par_CSC_Double
SpParMat< int64_t, bool, SpCCols< int64_t, bool > > Par_CSC_Bool
SpParMat< int64_t, double, SpDCCols< int64_t, double > > Par_DCSC_Double
SpParMat< int64_t, int64_t, SpDCCols< int64_t, int64_t > > Par_DCSC_int64_t
NT Reduce(_BinaryOperation __binary_op, NT identity) const
void ParallelWrite(const std::string &filename, bool onebased, HANDLER handler, bool includeindices=true)
void iota(IT globalsize, NT first)
FullyDistVec< IT, IT > sort()
SpParMat< IT, NT, DER > Prune(_UnaryOperation __unary_op, bool inPlace=true)
float LoadImbalance() const
void ParallelReadMM(const std::string &filename, bool onebased, _BinaryOperation BinOp)
std::shared_ptr< CommGrid > getcommgrid() const
NT MatchingWeight(std::vector< NT > &RepMateWC2R, MPI_Comm RowWorld, NT &minw)
void TransformWeight(SpParMat< IT, NT, DER > &A, bool applylog)
NT Trace(SpParMat< IT, NT, DER > &A, IT &rettrnnz=0)
void AWPM(SpParMat< IT, NT, SpDCCols< IT, NT > > &A1, FullyDistVec< IT, IT > &mateRow2Col, FullyDistVec< IT, IT > &mateCol2Row, bool optimizeProd=true, bool weightedCard=true)
Compute the maximum of two values.