33 #ifndef __STDC_CONSTANT_MACROS 34 #define __STDC_CONSTANT_MACROS 36 #ifndef __STDC_LIMIT_MACROS 37 #define __STDC_LIMIT_MACROS 56 template <
typename T1,
typename T2>
60 static T_promote
id(){
return std::numeric_limits<T_promote>::max(); };
62 static MPI_Op
mpi_op() {
return MPI_MIN; };
64 static T_promote
add(
const T_promote & arg1,
const T_promote & arg2)
66 return std::min(arg1, arg2);
69 static T_promote
multiply(
const T1 & arg1,
const T2 & arg2)
71 return static_cast<T_promote
> (arg2);
74 static void axpy(
const T1 a,
const T2 & x, T_promote & y)
82 template <
typename IT,
typename NT,
typename DER>
94 [](IT pv, IT gpv) ->
short {
return static_cast<short>(pv == gpv); },
101 [](
short isStar, IT gf){
return gf;},
102 [](
short isStar, IT gf){
return true;},
103 false,
static_cast<short>(0));
111 star.EWiseApply(gfNonstar, [](
short isStar, IT x){
return static_cast<short>(0);},
112 false,
static_cast<IT
>(0));
116 star.EWiseApply(starFather, std::multiplies<short>());
130 template <
typename IT,
typename NT,
typename DER>
136 minNeighborFather = SpMV<Select2ndMinSR<NT, IT>>(
A, father);
139 hooks = EWiseApply<std::pair<IT, IT>>(hooks, stars,
140 [](std::pair<IT, IT> x,
short isStar){
return std::make_pair(0,0);},
141 [](std::pair<IT, IT> x,
short isStar){
return isStar==1;},
147 hooks = EWiseApply<std::pair<IT, IT>>(hooks, father,
148 [](std::pair<IT, IT> x, IT f){
return std::make_pair(f,0);},
149 [](std::pair<IT, IT> x, IT f){
return true;},
153 hooks = EWiseApply<std::pair<IT, IT>>(hooks, minNeighborFather,
154 [](std::pair<IT, IT> x, IT mnf){
return std::make_pair(std::get<0>(x), mnf);},
155 [](std::pair<IT, IT> x, IT mnf){
return std::get<0>(x) > mnf;},
159 [](std::pair<IT, IT> val, IT ind){
return std::get<0>(val);},
160 [](std::pair<IT, IT> val, IT ind){
return std::make_pair(ind, std::get<1>(val));},
161 [](std::pair<IT, IT> val1, std::pair<IT, IT> val2){
return val2;} );
168 [](std::pair<IT, IT> x, IT f){
return std::get<1>(x);},
169 [](std::pair<IT, IT> x, IT f){
return true;},
171 father.Set(finalhooks);
174 template <
typename IT,
typename NT,
typename DER>
180 minNeighborFather = SpMV<Select2ndMinSR<NT, IT>>(
A, father);
184 hooks = EWiseApply<std::pair<IT, IT>>(hooks, stars,
185 [](std::pair<IT, IT> x,
short isStar){
return std::make_pair(0,0);},
186 [](std::pair<IT, IT> x,
short isStar){
return isStar==1;},
192 hooks = EWiseApply<std::pair<IT, IT>>(hooks, father,
193 [](std::pair<IT, IT> x, IT f){
return std::make_pair(f,0);},
194 [](std::pair<IT, IT> x, IT f){
return true;},
198 hooks = EWiseApply<std::pair<IT, IT>>(hooks, minNeighborFather,
199 [](std::pair<IT, IT> x, IT mnf){
return std::make_pair(std::get<0>(x), mnf);},
200 [](std::pair<IT, IT> x, IT mnf){
return std::get<0>(x) != mnf;},
204 [](std::pair<IT, IT> val, IT ind){
return std::get<0>(val);},
205 [](std::pair<IT, IT> val, IT ind){
return std::make_pair(ind, std::get<1>(val));},
206 [](std::pair<IT, IT> val1, std::pair<IT, IT> val2){
return val1;} );
211 [](std::pair<IT, IT> x, IT f){
return std::get<1>(x);},
212 [](std::pair<IT, IT> x, IT f){
return true;},
214 father.Set(finalhooks);
217 template <
typename IT>
221 father = grandfather;
224 template <
typename IT,
typename NT,
typename DER>
228 minNeighborCCLabel = SpMV<Select2ndMinSR<NT, IT>>(
A, cclabel);
229 return minNeighborCCLabel==cclabel;
234 template <
typename IT,
typename NT,
typename DER>
239 for(
auto colit = spSeq->begcol(); colit != spSeq->endcol(); ++colit)
241 IT j = colit.colid();
242 for(
auto nzit = spSeq->begnz(colit); nzit < spSeq->endnz(colit); ++nzit)
245 if( cclabel[i] != cclabel[j])
247 std::cout << i <<
" (" << father[i] <<
", "<< cclabel[i] <<
") & "<< j <<
"("<< father[j] <<
", " << cclabel[j] <<
")\n";
261 template <
typename IT>
265 cclabel.
ApplyInd([](IT val, IT ind){
return val==ind ? -1 : val;});
269 cclabel = cclabel(father);
275 template <
typename IT,
typename NT,
typename DER>
283 std::ostringstream outs;
287 double t1 = MPI_Wtime();
293 nonstars = stars.
Reduce(std::plus<IT>(), static_cast<IT>(0), [](
short isStar){
return static_cast<IT
>(isStar==0);});
301 double t2 = MPI_Wtime();
304 outs <<
"Iteration: " << iteration <<
" Non stars: " << nonstars;
305 outs <<
" Time: " << t2 - t1;
322 template <
typename IT>
325 for(IT i=0; i< nCC; i++)
333 template <
typename IT>
341 std::ostringstream outs;
344 outs <<
"Size of the first component: " << cc1.
getnnz() << std::endl;
345 outs <<
"Size of the second component: " << cc2.
getnnz() << std::endl;
346 outs <<
"Size of the third component: " << cc3.
getnnz() << std::endl;
347 outs <<
"Size of the fourth component: " << cc4.
getnnz() << std::endl;
351 template <
typename IT>
355 for(IT i=0; i< nCC; i++)
358 ccSizes.SetElement(i, ith.
getnnz());
361 IT largestCCSise = ccSizes.Reduce(
maximum<IT>(), static_cast<IT>(0));
364 const IT * locCCSizes = ccSizes.GetLocArr();
366 std::vector<IT> localHist(numBins,0);
367 for(IT i=0; i< ccSizes.LocArrSize(); i++)
369 IT bin = (locCCSizes[i]*(numBins-1))/largestCCSise;
373 std::vector<IT> globalHist(numBins,0);
375 MPI_Reduce(localHist.data(), globalHist.data(), numBins, MPIType<IT>(), MPI_SUM, 0, world);
379 MPI_Comm_rank(world,&myrank);
382 std::cout <<
"The largest component size: " << largestCCSise << std::endl;
383 std::ofstream output;
384 output.open(
"hist.txt", std::ios_base::app );
385 std::copy(globalHist.begin(), globalHist.end(), std::ostream_iterator<IT> (output,
" "));
void EWiseOut(const FullyDistVec< IT, NT > &rhs, _BinaryOperation __binary_op, FullyDistVec< IT, OUT > &result)
std::shared_ptr< CommGrid > getcommgrid() const
Compute the maximum of two values.
static void axpy(const T1 a, const T2 &x, T_promote &y)
IT LabelCC(FullyDistVec< IT, IT > &father, FullyDistVec< IT, IT > &cclabel)
void Set(const FullyDistSpVec< IT, NT > &rhs)
FullyDistVec< IT, IT > FindInds(_Predicate pred) const
Return the indices where pred is true.
promote_trait< T1, T2 >::T_promote T_promote
void nziota(NT first)
iota over existing nonzero entries
static bool returnedSAID()
FullyDistSpVec< IT, NT > Find(_Predicate pred) const
Return the elements for which pred is true.
std::shared_ptr< CommGrid > getcommgrid() const
static T_promote add(const T_promote &arg1, const T_promote &arg2)
static T_promote multiply(const T1 &arg1, const T2 &arg2)
void ConditionalHook(const SpParMat< IT, NT, DER > &A, FullyDistVec< IT, IT > &father)
FullyDistVec< IT, IT > CC(SpParMat< IT, NT, DER > &A, IT &nCC)
void AddLoops(NT loopval, bool replaceExisting=false)
FullyDistSpVec< IT, NT > Invert(IT globallen)
bool neigborsInSameCC(const SpParMat< IT, NT, DER > &A, FullyDistVec< IT, IT > &cclabel)
void HistCC(FullyDistVec< IT, IT > CC, IT nCC)
void Correctness(const SpParMat< IT, NT, DER > &A, FullyDistVec< IT, IT > &cclabel, IT nCC, FullyDistVec< IT, IT > father)
static void Print(const std::string &s)
void UnconditionalHook(const SpParMat< IT, NT, DER > &A, FullyDistVec< IT, IT > &father)
void iota(IT globalsize, NT first)
void PrintCC(FullyDistVec< IT, IT > CC, IT nCC)
void First4Clust(FullyDistVec< IT, IT > &cc)
void Shortcut(FullyDistVec< IT, IT > &father)
static T2 add(const T2 &arg1, const T2 &arg2)
static T2 multiply(const T1 &arg1, const T2 &arg2)
void ApplyInd(_BinaryOperation __binary_op)
NT Reduce(_BinaryOperation __binary_op, NT identity) const
FullyDistVec< IT, short > StarCheck(const SpParMat< IT, NT, DER > &A, FullyDistVec< IT, IT > &father)