1 /*******************************************************************************
2  * thrill/api/print.hpp
3  *
4  * Part of Project Thrill - http://project-thrill.org
5  *
6  * Copyright (C) 2016 Timo Bingmann <tb@panthema.net>
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>
Print(const std::string & name,std::ostream & os) const24 void DIA<ValueType, Stack>::Print(const std::string& name, std::ostream& os) const {
25     assert(IsValid());
26 
27     using GatherNode = api::GatherNode<ValueType>;
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>
Print(const std::string & name) const50 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 /******************************************************************************/
60