souffle  2.0.2-371-g6315b36
Parallel.h
Go to the documentation of this file.
1 /*
2  * Souffle - A Datalog Compiler
3  * Copyright (c) 2018, The Souffle Developers. All rights reserved
4  * Licensed under the Universal Permissive License v 1.0 as shown at:
5  * - https://opensource.org/licenses/UPL
6  * - <souffle root>/licenses/SOUFFLE-UPL.txt
7  */
8 
9 /************************************************************************
10  *
11  * @file Parallel.h
12  *
13  ***********************************************************************/
14 
15 #pragma once
16 
17 #include "ram/ListStatement.h"
18 #include "ram/Statement.h"
21 #include <memory>
22 #include <ostream>
23 #include <utility>
24 #include <vector>
25 
26 namespace souffle::ram {
27 
28 /**
29  * @class Parallel
30  * @brief Parallel block of statements
31  *
32  * Execute statements in parallel and wait until all statements have
33  * completed their execution before completing the execution of the
34  * parallel block.
35  *
36  * For example:
37  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~
38  * PARALLEL
39  * BEGIN DEBUG...
40  * QUERY
41  * ...
42  * END PARALLEL
43  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~
44  */
45 class Parallel : public ListStatement {
46 public:
47  Parallel(VecOwn<Statement> statements) : ListStatement(std::move(statements)) {}
48  Parallel() : ListStatement() {}
49  template <typename... Stmts>
50  Parallel(Own<Statement> first, Own<Stmts>... rest)
51  : ListStatement(std::move(first), std::move(rest)...) {}
52 
53  Parallel* clone() const override {
54  auto* res = new Parallel();
55  for (auto& cur : statements) {
56  res->statements.push_back(souffle::clone(cur));
57  }
58  return res;
59  }
60 
61 protected:
62  void print(std::ostream& os, int tabpos) const override {
63  os << times(" ", tabpos) << "PARALLEL" << std::endl;
64  for (auto const& stmt : statements) {
65  Statement::print(stmt.get(), os, tabpos + 1);
66  }
67  os << times(" ", tabpos) << "END PARALLEL" << std::endl;
68  }
69 };
70 
71 } // namespace souffle::ram
souffle::ram::Parallel::Parallel
Parallel()
Definition: Parallel.h:52
souffle::ram::Parallel
Parallel block of statements.
Definition: Parallel.h:49
souffle::Own
std::unique_ptr< A > Own
Definition: ContainerUtil.h:42
souffle::ram::ListStatement::ListStatement
ListStatement()=default
ListStatement.h
MiscUtil.h
souffle::ram::Parallel::print
void print(std::ostream &os, int tabpos) const override
Pretty print with indentation.
Definition: Parallel.h:66
souffle::ram
Definition: AstToRamTranslator.h:54
souffle::ram::ListStatement::statements
VecOwn< Statement > statements
Ordered list of RAM statements.
Definition: ListStatement.h:77
souffle::clone
auto clone(const std::vector< A * > &xs)
Definition: ContainerUtil.h:172
souffle::times
detail::multiplying_printer< T > times(const T &value, unsigned num)
A utility printing a given value multiple times.
Definition: StreamUtil.h:322
souffle::ram::Parallel::Parallel
Parallel(Own< Statement > first, Own< Stmts >... rest)
Definition: Parallel.h:54
souffle::ram::Statement::print
void print(std::ostream &os) const override
Print RAM node.
Definition: Statement.h:42
souffle::ram::Parallel::clone
Parallel * clone() const override
Create a clone (i.e.
Definition: Parallel.h:57
std
Definition: Brie.h:3053
StreamUtil.h
Statement.h
souffle::ram::ListStatement
Abstract class for a list of RAM statements.
Definition: ListStatement.h:36