Thrill  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
select_run.cpp
Go to the documentation of this file.
1 /*******************************************************************************
2  * examples/select/select_run.cpp
3  *
4  * Part of Project Thrill - http://project-thrill.org
5  *
6  * Copyright (C) 2016 Lorenz Hübschle-Schneider <[email protected]>
7  *
8  * All rights reserved. Published under the BSD-2 license in the LICENSE file.
9  ******************************************************************************/
10 
12 
13 #include <thrill/api/cache.hpp>
14 #include <thrill/api/context.hpp>
15 #include <thrill/api/generate.hpp>
16 #include <thrill/common/logger.hpp>
17 #include <tlx/cmdline_parser.hpp>
18 
19 using namespace thrill; // NOLINT
20 using namespace examples::select; // NOLINT
21 
22 static auto RunSelect(api::Context& ctx, size_t num_elems, size_t rank, bool max) {
23  auto data = Generate(ctx, num_elems).Cache();
24  if (max) {
25  auto result = Select(data, rank,
26  [](const auto& a, const auto& b) -> bool
27  { return a > b; });
28 
29  LOG << "Result: " << result;
30  return result;
31  }
32  else {
33  auto result = Select(data, rank);
34 
35  LOG << "Result: " << result;
36  return result;
37  }
38 }
39 
40 int main(int argc, char* argv[]) {
42  clp.set_verbose_process(false);
43 
44  size_t num_elems = 1024 * 1024, rank = 10;
45  bool max;
46  clp.add_size_t('n', "num_elemes", num_elems, "Number of elements, default: 2^10");
47  clp.add_size_t('k', "rank", rank, "Rank to select, default: 10");
48  clp.add_bool('m', "max", max, "Select maximum, default off");
49 
50  if (!clp.process(argc, argv)) {
51  return -1;
52  }
53  clp.print_result();
54 
55  return api::Run(
56  [&](api::Context& ctx) {
57  RunSelect(ctx, num_elems, rank, max);
58  });
59 }
60 
61 /******************************************************************************/
static uint_pair max()
return an uint_pair instance containing the largest value possible
Definition: uint_types.hpp:226
void add_size_t(char key, const std::string &longkey, const std::string &keytype, size_t &dest, const std::string &desc)
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.
Definition: generate.hpp:85
int Run(const std::function< void(Context &)> &job_startpoint)
Runs the given job startpoint with a Context instance.
Definition: context.cpp:863
The Context of a job is a unique instance per worker which holds references to all underlying parts o...
Definition: context.hpp:218
void print_result(std::ostream &os)
print nicely formatted result of processing
Command line parser which automatically fills variables and prints nice usage messages.
static auto RunSelect(api::Context &ctx, size_t num_elems, size_t rank, bool max)
Definition: select_run.cpp:22
void set_verbose_process(bool verbose_process)
Set verbose processing of command line arguments.
int main(int argc, char *argv[])
Definition: select_run.cpp:40
ValueType Select(const DIA< ValueType, InStack > &data, size_t rank, const Compare &compare=Compare())
Definition: select.hpp:91
void add_bool(char key, const std::string &longkey, const std::string &keytype, bool &dest, const std::string &desc)
#define LOG
Default logging method: output if the local debug variable is true.
Definition: logger.hpp:141
bool process(int argc, const char *const *argv, std::ostream &os)