11 #include "../CombBLAS.h"
49 MPI_Comm_rank(MPI_COMM_WORLD,&myrank);
52 cout <<
"\n-------------- usage --------------\n";
53 cout <<
"Usage: ./awpm -input <filename>\n";
54 cout <<
"Optional parameters: -randPerm: randomly permute the matrix for load balance (default: no random permutation)\n";
55 cout <<
" -optsum: Optimize the sum of diagonal (default: Optimize the product of diagonal)\n";
56 cout <<
" -noWeightedCard: do not use weighted cardinality matching (default: use weighted cardinality matching)\n";
57 cout <<
" -output <output file>: output file name (if not provided: inputfile.awpm.txt)\n";
58 cout <<
" \n-------------- examples ----------\n";
59 cout <<
"Example: mpirun -np 4 ./awpm -input cage12.mtx \n" << endl;
60 cout <<
"(output matching is saved to cage12.mtx.awpm.txt)\n" << endl;
70 int main(
int argc,
char* argv[])
75 MPI_Init_thread(&argc, &argv, MPI_THREAD_SERIALIZED, &provided);
76 if (provided < MPI_THREAD_SERIALIZED)
78 printf(
"ERROR: The MPI library does not have MPI_THREAD_SERIALIZED support\n");
79 MPI_Abort(MPI_COMM_WORLD, 1);
82 MPI_Comm_size(MPI_COMM_WORLD,&nprocs);
83 MPI_Comm_rank(MPI_COMM_WORLD,&myrank);
100 bool optimizeProd =
true;
102 bool weightedCard =
true;
103 string ifilename =
"";
105 for(
int i = 1; i<argc; i++)
107 if (
string(argv[i]) ==
string(
"-input")) ifilename = argv[i+1];
108 if (
string(argv[i]) ==
string(
"-output"))
ofname = argv[i+1];
109 if (
string(argv[i]) ==
string(
"-optsum")) optimizeProd =
false;
110 if (
string(argv[i]) ==
string(
"-noWeightedCard")) weightedCard =
false;
111 if (
string(argv[i]) ==
string(
"-randPerm"))
randPerm =
true;
134 SpParHelper::Print(
"Rectangular matrix: Can not compute a perfect matching.\n");
140 tinfo <<
"Reading input matrix in" << t02-t01 <<
" seconds" << endl;
141 SpParHelper::Print(tinfo.str());
143 SpParHelper::Print(
"Pruning explicit zero entries....\n");
144 AWeighted->
Prune([](
double val){
return fabs(val)==0;},
true);
167 (*AWeighted)(randp,randp,
true);
168 SpParHelper::Print(
"Matrix is randomly permuted for load balance.\n");
172 SpParHelper::Print(
"Rectangular matrix: Can not apply symmetric permutation.\n");
180 A.Reduce(degCol,
Column, plus<int64_t>(),
static_cast<int64_t>(0));
195 double origWeight =
Trace(*AWeighted, diagnnz);
196 bool isOriginalPerfect = diagnnz==
A.getnrow();
211 double ts = MPI_Wtime();
216 double tmcl = MPI_Wtime() - ts;
218 double mclWeight =
MatchingWeight( *AWeighted, mateRow2Col, mateCol2Row);
219 SpParHelper::Print(
"After Greedy sanity check\n");
222 if(isOriginalPerfect && mclWeight<=origWeight)
224 SpParHelper::Print(
"Maximal is not better that the natural ordering. Hence, keeping the natural ordering.\n");
225 mateRow2Col.
iota(
A.getnrow(), 0);
226 mateCol2Row.
iota(
A.getncol(), 0);
227 mclWeight = origWeight;
234 double mcmWeight = mclWeight;
239 maximumMatching(AWeightedCSC, mateRow2Col, mateCol2Row,
true,
false,
true);
241 maximumMatching(AWeightedCSC, mateRow2Col, mateCol2Row,
true,
false,
false);
242 tmcm = MPI_Wtime() - ts;
243 mcmWeight =
MatchingWeight( *AWeighted, mateRow2Col, mateCol2Row) ;
244 SpParHelper::Print(
"After MCM sanity check\n");
252 double tawpm = MPI_Wtime() - ts;
254 double awpmWeight =
MatchingWeight( *AWeighted, mateRow2Col, mateCol2Row) ;
255 SpParHelper::Print(
"After AWPM sanity check\n");
257 if(isOriginalPerfect && awpmWeight<origWeight)
259 SpParHelper::Print(
"AWPM is not better that the natural ordering. Hence, keeping the natural ordering.\n");
260 mateRow2Col.
iota(
A.getnrow(), 0);
261 mateCol2Row.
iota(
A.getncol(), 0);
262 awpmWeight = origWeight;
270 nthreads = omp_get_num_threads();
275 tinfo <<
"Weight: [ Original Greedy MCM AWPM] " << origWeight <<
" " << mclWeight <<
" "<< mcmWeight <<
" " << awpmWeight << endl;
277 SpParHelper::Print(tinfo.str());
280 if(
randPerm==
true && randp.TotalLength() >0)
284 mateRow2Col = mateRow2Col(invRandp);