13 #ifndef THRILL_EXAMPLES_PAGE_RANK_PAGE_RANK_HEADER 14 #define THRILL_EXAMPLES_PAGE_RANK_PAGE_RANK_HEADER 38 static constexpr
bool debug =
false;
50 return os <<
'(' << a.
src <<
'>' << a.
tgt <<
')';
60 return os <<
'(' << a.
page <<
'|' << a.
rank <<
')';
70 template <
typename InStack>
72 size_t num_pages,
size_t iterations) {
75 double num_pages_d =
static_cast<double>(num_pages);
82 [num_pages_d](
size_t) {
return Rank(1.0) / num_pages_d; })
86 for (
size_t iter = 0; iter < iterations; ++iter) {
97 auto outs_rank = links.
Zip(
112 auto contribs = outs_rank.template FlatMap<PageRankPair>(
114 if (p.first.size() == 0)
117 Rank rank_contrib = p.second /
static_cast<double>(p.first.size());
118 for (
const PageId& tgt : p.first)
141 template <const
bool UseLocationDetection = false,
typename InStack>
146 double num_pages_d =
static_cast<double>(num_pages);
153 [num_pages_d](
size_t idx) {
154 return std::make_pair(idx,
Rank(1.0) / num_pages_d);
159 for (
size_t iter = 0; iter < iterations; ++iter) {
173 [](
const LinkedPage& lp) {
return lp.first; },
174 [](
const RankedPage& rp) {
return rp.first; },
176 return std::make_pair(lp.second, rp.second);
188 auto contribs = outs_rank.template FlatMap<PageRankStdPair>(
190 if (p.first.size() > 0) {
191 Rank rank_contrib = p.second /
static_cast<double>(p.first.size());
192 for (
const PageId& tgt : p.first)
193 emit(std::make_pair(tgt, rank_contrib));
203 [](
const Rank& p1,
const Rank& p2) {
207 return std::make_pair(
209 dampening * p.second + (1 - dampening) / num_pages_d);
221 #endif // !THRILL_EXAMPLES_PAGE_RANK_PAGE_RANK_HEADER DIA is the interface between the user and the Thrill framework.
auto Generate(Context &ctx, size_t size, const GenerateFunction &generate_function)
Generate is a Source-DOp, which creates a DIA of given size using a generator function.
auto ReducePair(const ReduceFunction &reduce_function, const ReduceConfig &reduce_config=ReduceConfig()) const
ReducePair is a DOp, which groups key-value-pairs in the input DIA by their key and reduces each key-...
auto ReduceToIndex(const KeyExtractor &key_extractor, const ReduceFunction &reduce_function, size_t size, const ValueType &neutral_element=ValueType(), const ReduceConfig &reduce_config=ReduceConfig()) const
ReduceToIndex is a DOp, which groups elements of the DIA with the key_extractor returning an unsigned...
Context & context() const
Return context_ of DIANode, e.g. for creating new LOps and DOps.
std::pair< PageId, Rank > RankedPage
auto InnerJoin(const LocationDetectionFlag< LocationDetectionValue > &, const FirstDIA &first_dia, const SecondDIA &second_dia, const KeyExtractor1 &key_extractor1, const KeyExtractor2 &key_extractor2, const JoinFunction &join_function, const HashFunction &hash_function=HashFunction())
Performs an inner join between this DIA and the DIA given in the first parameter. ...
The Context of a job is a unique instance per worker which holds references to all underlying parts o...
static by_string to_string(int val)
convert to string
struct examples::page_rank::PagePageLink TLX_ATTRIBUTE_PACKED
std::vector< PageId > OutgoingLinks
static constexpr double dampening
static constexpr bool debug
std::pair< PageId, Rank > PageRankStdPair
auto PageRank(const DIA< OutgoingLinks, InStack > &links, size_t num_pages, size_t iterations)
std::pair< PageId, OutgoingLinks > LinkedPage
A pair (page source, page target)
auto Zip(const SecondDIA &second_dia, const ZipFunction &zip_function) const
Zips two DIAs of equal size in style of functional programming by applying zip_function to the i-th e...
auto PageRankJoin(const DIA< LinkedPage, InStack > &links, size_t num_pages, size_t iterations)
std::string join(char glue, const std::vector< std::string > &parts)
Join a vector of strings by some glue character between each pair from the sequence.
tag structure for GroupByKey(), and InnerJoin()
std::pair< std::vector< PageId >, Rank > OutgoingLinksRank
std::ostream & operator<<(std::ostream &os, const DIABase &d)
make ostream-able.