Thrill  0.1
print.hpp
Go to the documentation of this file.
1 /*******************************************************************************
2  * thrill/api/print.hpp
3  *
4  * Part of Project Thrill - http://project-thrill.org
5  *
6  * Copyright (C) 2016 Timo Bingmann <[email protected]>
7  *
8  * All rights reserved. Published under the BSD-2 license in the LICENSE file.
9  ******************************************************************************/
10 
11 #pragma once
12 #ifndef THRILL_API_PRINT_HEADER
13 #define THRILL_API_PRINT_HEADER
14 
15 #include <thrill/api/gather.hpp>
16 
17 #include <string>
18 #include <vector>
19 
20 namespace thrill {
21 namespace api {
22 
23 template <typename ValueType, typename Stack>
24 void DIA<ValueType, Stack>::Print(const std::string& name, std::ostream& os) const {
25  assert(IsValid());
26 
28 
29  std::vector<ValueType> output;
30 
31  auto node = tlx::make_counting<GatherNode>(*this, "Print", 0, &output);
32 
33  node->RunScope();
34 
35  if (node->context().my_rank() == 0)
36  {
37  if (!name.empty())
38  os << name << ' ';
39  os << "--- Begin DIA.Print() --- size=" << output.size() << '\n';
40  for (size_t i = 0; i < output.size(); ++i) {
41  os << name << '[' << i << "]: " << output[i] << '\n';
42  }
43  if (!name.empty())
44  os << name << ' ';
45  os << "--- End DIA.Print() --- size=" << output.size() << std::endl;
46  }
47 }
48 
49 template <typename ValueType, typename Stack>
50 void DIA<ValueType, Stack>::Print(const std::string& name) const {
51  return Print(name, std::cout);
52 }
53 
54 } // namespace api
55 } // namespace thrill
56 
57 #endif // !THRILL_API_PRINT_HEADER
58 
59 /******************************************************************************/
void Print(const std::string &name=std::string()) const
Print is an Action, which collects all data of the DIA at the worker 0 and prints using ostream seria...
Definition: print.hpp:50
std::basic_string< char, std::char_traits< char >, Allocator< char > > string
string with Manager tracking
Definition: allocator.hpp:220