Thrill  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
sleep.cpp
Go to the documentation of this file.
1 /*******************************************************************************
2  * examples/sleep/sleep.cpp
3  *
4  * A sleep or Hello World program to measure framework startup time.
5  *
6  * Part of Project Thrill - http://project-thrill.org
7  *
8  * Copyright (C) 2016 Timo Bingmann <[email protected]>
9  *
10  * All rights reserved. Published under the BSD-2 license in the LICENSE file.
11  ******************************************************************************/
12 
13 #include <thrill/api/generate.hpp>
14 #include <thrill/api/size.hpp>
15 #include <thrill/common/logger.hpp>
16 #include <tlx/cmdline_parser.hpp>
17 
18 #include <string>
19 
20 using namespace thrill; // NOLINT
21 
22 int main(int argc, char* argv[]) {
23 
25 
26  unsigned seconds;
27  clp.add_param_unsigned("seconds", seconds, "seconds to sleep");
28 
29  if (!clp.process(argc, argv))
30  return -1;
31 
32  return api::Run(
33  [seconds](api::Context& ctx) {
34  Generate(ctx, ctx.num_workers())
35  .Map([seconds](size_t i) {
36  std::this_thread::sleep_for(std::chrono::seconds(seconds));
37  return i;
38  })
39  .Size();
40  });
41 }
42 
43 /******************************************************************************/
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
Command line parser which automatically fills variables and prints nice usage messages.
size_t num_workers() const
Global number of workers in the system.
Definition: context.hpp:248
void add_param_unsigned(const std::string &name, unsigned int &dest, const std::string &desc)
add unsigned integer parameter [name] with description and store to dest
bool process(int argc, const char *const *argv, std::ostream &os)
int main(int argc, char *argv[])
Definition: sleep.cpp:22