souffle  2.0.2-371-g6315b36
ParallelAggregate.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 ParallelAggregate.h
12  *
13  ***********************************************************************/
14 
15 #pragma once
16 
17 #include "AggregateOp.h"
18 #include "ram/AbstractAggregate.h"
19 #include "ram/AbstractParallel.h"
20 #include "ram/Aggregate.h"
21 #include "ram/Condition.h"
22 #include "ram/Expression.h"
23 #include "ram/Node.h"
24 #include "ram/Operation.h"
25 #include "ram/Relation.h"
26 #include "ram/RelationOperation.h"
27 #include "ram/utility/Utils.h"
30 #include <iosfwd>
31 #include <memory>
32 #include <ostream>
33 #include <string>
34 #include <utility>
35 
36 namespace souffle::ram {
37 
38 /**
39  * @class ParallelAggregate
40  * @brief Parallel Aggregation function applied on some relation
41  *
42  * For example:
43  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~
44  * PARALLEL t0.0 = COUNT FOR ALL t0 IN A
45  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~
46  * Applies the function PARALLEL COUNT to determine the number
47  * of elements in A.
48  */
49 class ParallelAggregate : public Aggregate, public AbstractParallel {
50 public:
51  ParallelAggregate(Own<Operation> nested, AggregateOp fun, std::string rel, Own<Expression> expression,
52  Own<Condition> condition, int ident)
53  : Aggregate(std::move(nested), fun, rel, std::move(expression), std::move(condition), ident) {}
54 
55  ParallelAggregate* clone() const override {
56  return new ParallelAggregate(souffle::clone(&getOperation()), function, relation,
58  }
59 
60 protected:
61  void print(std::ostream& os, int tabpos) const override {
62  os << times(" ", tabpos);
63  os << "PARALLEL t" << getTupleId() << ".0=";
64  AbstractAggregate::print(os, tabpos);
65  os << "FOR ALL t" << getTupleId() << " ∈ " << relation;
66  if (!isTrue(condition.get())) {
67  os << " WHERE " << getCondition();
68  }
69  os << std::endl;
70  RelationOperation::print(os, tabpos + 1);
71  }
72 };
73 
74 } // namespace souffle::ram
Aggregate.h
souffle::ram::ParallelAggregate::ParallelAggregate
ParallelAggregate(Own< Operation > nested, AggregateOp fun, std::string rel, Own< Expression > expression, Own< Condition > condition, int ident)
Definition: ParallelAggregate.h:55
AggregateOp.h
souffle::ram::AbstractAggregate::getCondition
const Condition & getCondition() const
Get condition.
Definition: AbstractAggregate.h:53
souffle::ram::ParallelAggregate::print
void print(std::ostream &os, int tabpos) const override
Pretty print with indentation.
Definition: ParallelAggregate.h:65
souffle::AggregateOp
AggregateOp
Types of aggregation functions.
Definition: AggregateOp.h:34
souffle::ram::NestedOperation::getOperation
Operation & getOperation() const
Get nested operation.
Definition: NestedOperation.h:62
MiscUtil.h
RelationOperation.h
souffle::ram::AbstractAggregate::print
void print(std::ostream &os, int) const
Definition: AbstractAggregate.h:74
souffle::ram
Definition: AstToRamTranslator.h:54
souffle::ram::ParallelAggregate::clone
ParallelAggregate * clone() const override
Create a clone (i.e.
Definition: ParallelAggregate.h:59
souffle::ram::RelationOperation::relation
const std::string relation
Search relation.
Definition: RelationOperation.h:60
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
Relation.h
souffle::ram::AbstractAggregate::expression
Own< Expression > expression
Aggregation expression.
Definition: AbstractAggregate.h:104
souffle::ram::Aggregate
Aggregation function applied on some relation.
Definition: Aggregate.h:53
Condition.h
souffle::ram::ParallelAggregate
Parallel Aggregation function applied on some relation.
Definition: ParallelAggregate.h:53
souffle::ram::TupleOperation::getTupleId
int getTupleId() const
Get identifier.
Definition: TupleOperation.h:43
Utils.h
souffle::ram::isTrue
bool isTrue(const Condition *cond)
Determines if a condition represents true.
Definition: Utils.h:45
AbstractParallel.h
souffle::ram::TupleOperation::identifier
int identifier
Identifier for the tuple, corresponding to its position in the loop nest.
Definition: TupleOperation.h:66
Node.h
std
Definition: Brie.h:3053
Operation.h
StreamUtil.h
AbstractAggregate.h
Expression.h
rel
void rel(size_t limit, bool showLimit=true)
Definition: Tui.h:1086
souffle::ram::NestedOperation::print
void print(std::ostream &os, int tabpos) const override
Pretty print with indentation.
Definition: NestedOperation.h:80
souffle::ram::AbstractAggregate::condition
Own< Condition > condition
Aggregation tuple condition.
Definition: AbstractAggregate.h:107