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;
113 if(ofname==
"") ofname = ifilename +
".awpm.txt";
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");
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");
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);
int main(int argc, char *argv[])
FullyDistVec< IT, NT > Reduce(Dim dim, _BinaryOperation __binary_op, NT id, _UnaryOperation __unary_op) const
SpParMat< int64_t, int64_t, SpDCCols< int64_t, int64_t > > Par_DCSC_int64_t
std::shared_ptr< CommGrid > getcommgrid() const
Compute the maximum of two values.
NT Trace(SpParMat< IT, NT, DER > &A, IT &rettrnnz=0)
SpParMat< int64_t, bool, SpCCols< int64_t, bool > > Par_CSC_Bool
SpParMat< int64_t, bool, SpDCCols< int64_t, bool > > Par_DCSC_Bool
SpParMat< int64_t, double, SpCCols< int64_t, double > > Par_CSC_Double
void iota(IT globalsize, NT first)
void maximumMatching(PSpMat_s32p64 &Aeff, FullyDistVec< int64_t, int64_t > &mateRow2Col, FullyDistVec< int64_t, int64_t > &mateCol2Row)
void TransformWeight(SpParMat< IT, NT, DER > &A, bool applylog)
NT MatchingWeight(std::vector< NT > &RepMateWC2R, MPI_Comm RowWorld, NT &minw)
void ParallelWrite(const std::string &filename, bool onebased, HANDLER handler, bool includeindices=true)
FullyDistVec< IT, IT > sort()
void TwoThirdApprox(SpParMat< IT, NT, DER > &A, FullyDistVec< IT, IT > &mateRow2Col, FullyDistVec< IT, IT > &mateCol2Row)
bool CheckMatching(FullyDistVec< IT, IT > &mateRow2Col, FullyDistVec< IT, IT > &mateCol2Row)
void WeightedGreedy(Par_MAT_Double &A, FullyDistVec< IT, IT > &mateRow2Col, FullyDistVec< IT, IT > &mateCol2Row, FullyDistVec< IT, IT > °Col)
SpParMat< IT, NT, DER > Prune(_UnaryOperation __unary_op, bool inPlace=true)
SpParMat< int64_t, double, SpDCCols< int64_t, double > > Par_DCSC_Double
void ParallelReadMM(const std::string &filename, bool onebased, _BinaryOperation BinOp)