souffle  2.0.2-371-g6315b36
Public Member Functions | Protected Member Functions | Protected Attributes
souffle::ram::transform::ParallelTransformer Class Reference

Transforms Choice/IndexChoice/IndexScan/Scan into parallel versions. More...

#include <Parallel.h>

Inheritance diagram for souffle::ram::transform::ParallelTransformer:
Inheritance graph
Collaboration diagram for souffle::ram::transform::ParallelTransformer:
Collaboration graph

Public Member Functions

std::string getName () const override
 @Brief get name of the transformer More...
 
bool parallelizeOperations (Program &program)
 Parallelize operations. More...
 
- Public Member Functions inherited from souffle::ram::transform::Transformer
bool apply (TranslationUnit &translationUnit)
 @Brief apply the transformer to a translation unit @Param translationUnit that will be transformed. More...
 
virtual ~Transformer ()=default
 

Protected Member Functions

bool transform (TranslationUnit &translationUnit) override
 @Brief transform the translation unit / used by apply @Param translationUnit that will be transformed. More...
 

Protected Attributes

analysis::RelationAnalysisrelAnalysis {nullptr}
 

Detailed Description

Transforms Choice/IndexChoice/IndexScan/Scan into parallel versions.

For example ..

QUERY
FOR t0 in A
...

will be rewritten to

QUERY
PARALLEL FOR t0 in A
...

Definition at line 50 of file Parallel.h.

Member Function Documentation

◆ getName()

std::string souffle::ram::transform::ParallelTransformer::getName ( ) const
inlineoverridevirtual

@Brief get name of the transformer

Implements souffle::ram::transform::Transformer.

Definition at line 52 of file Parallel.h.

59  :
60  bool transform(TranslationUnit& translationUnit) override {

◆ parallelizeOperations()

bool souffle::ram::transform::ParallelTransformer::parallelizeOperations ( Program program)

Parallelize operations.

Parameters
programProgram that is transformed
Returns
Flag showing whether the program has been changed by the transformation

Definition at line 36 of file Parallel.cpp.

37  {
38  std::function<Own<Node>(Own<Node>)> parallelRewriter = [&](Own<Node> node) -> Own<Node> {
39  if (const Scan* scan = dynamic_cast<Scan*>(node.get())) {
40  const Relation& rel = relAnalysis->lookup(scan->getRelation());
41  if (scan->getTupleId() == 0 && rel.getArity() > 0) {
42  if (!isA<Project>(&scan->getOperation())) {
43  changed = true;
44  return mk<ParallelScan>(scan->getRelation(), scan->getTupleId(),
45  souffle::clone(&scan->getOperation()), scan->getProfileText());
46  }
47  }
48  } else if (const Choice* choice = dynamic_cast<Choice*>(node.get())) {
49  if (choice->getTupleId() == 0) {
50  changed = true;
51  return mk<ParallelChoice>(choice->getRelation(), choice->getTupleId(),
52  souffle::clone(&choice->getCondition()), souffle::clone(&choice->getOperation()),
53  choice->getProfileText());
54  }
55  } else if (const IndexScan* indexScan = dynamic_cast<IndexScan*>(node.get())) {
56  if (indexScan->getTupleId() == 0) {
57  changed = true;
58  RamPattern queryPattern = clone(indexScan->getRangePattern());
59  return mk<ParallelIndexScan>(indexScan->getRelation(), indexScan->getTupleId(),
60  std::move(queryPattern), souffle::clone(&indexScan->getOperation()),
61  indexScan->getProfileText());
62  }
63  } else if (const IndexChoice* indexChoice = dynamic_cast<IndexChoice*>(node.get())) {
64  if (indexChoice->getTupleId() == 0) {
65  changed = true;
66  RamPattern queryPattern = clone(indexChoice->getRangePattern());
67  return mk<ParallelIndexChoice>(indexChoice->getRelation(), indexChoice->getTupleId(),
68  souffle::clone(&indexChoice->getCondition()), std::move(queryPattern),
69  souffle::clone(&indexChoice->getOperation()), indexChoice->getProfileText());
70  }
71  } else if (const Aggregate* aggregate = dynamic_cast<Aggregate*>(node.get())) {
72  const Relation& rel = relAnalysis->lookup(aggregate->getRelation());
73  if (aggregate->getTupleId() == 0 && !rel.isNullary()) {
74  changed = true;
75  return mk<ParallelAggregate>(Own<Operation>(aggregate->getOperation().clone()),
76  aggregate->getFunction(), aggregate->getRelation(),
77  Own<Expression>(aggregate->getExpression().clone()),
78  Own<Condition>(aggregate->getCondition().clone()), aggregate->getTupleId());
79  }
80  } else if (const IndexAggregate* indexAggregate = dynamic_cast<IndexAggregate*>(node.get())) {
81  const Relation& rel = relAnalysis->lookup(indexAggregate->getRelation());
82  if (indexAggregate->getTupleId() == 0 && !rel.isNullary()) {
83  changed = true;
84  RamPattern queryPattern = clone(indexAggregate->getRangePattern());
85  return mk<ParallelIndexAggregate>(Own<Operation>(indexAggregate->getOperation().clone()),
86  indexAggregate->getFunction(), indexAggregate->getRelation(),
87  Own<Expression>(indexAggregate->getExpression().clone()),
88  Own<Condition>(indexAggregate->getCondition().clone()), std::move(queryPattern),
89  indexAggregate->getTupleId());
90  }
91  }
92  node->apply(makeLambdaRamMapper(parallelRewriter));
93  return node;
94  };
95  const_cast<Query*>(&query)->apply(makeLambdaRamMapper(parallelRewriter));
96  });
97  return changed;
98 }
99 
100 } // namespace souffle::ram::transform

References souffle::ram::transform::Transformer::apply(), souffle::clone(), souffle::ram::analysis::RelationAnalysis::lookup(), souffle::ram::makeLambdaRamMapper(), rel(), and relAnalysis.

Here is the call graph for this function:

◆ transform()

bool souffle::ram::transform::ParallelTransformer::transform ( TranslationUnit translationUnit)
inlineoverrideprotectedvirtual

@Brief transform the translation unit / used by apply @Param translationUnit that will be transformed.

@Return flag reporting whether the RAM program has changed

Implements souffle::ram::transform::Transformer.

Definition at line 64 of file Parallel.h.

64  {nullptr};
65 };
66 
67 } // namespace souffle::ram::transform

Field Documentation

◆ relAnalysis

analysis::RelationAnalysis* souffle::ram::transform::ParallelTransformer::relAnalysis {nullptr}
protected

Definition at line 68 of file Parallel.h.

Referenced by parallelizeOperations().


The documentation for this class was generated from the following files:
souffle::ram::transform::Transformer::apply
bool apply(TranslationUnit &translationUnit)
@Brief apply the transformer to a translation unit @Param translationUnit that will be transformed.
Definition: Transformer.cpp:39
souffle::clone
auto clone(const std::vector< A * > &xs)
Definition: ContainerUtil.h:172
souffle::ram::transform::ParallelTransformer::transform
bool transform(TranslationUnit &translationUnit) override
@Brief transform the translation unit / used by apply @Param translationUnit that will be transformed...
Definition: Parallel.h:64
souffle::ram::RamPattern
std::pair< RamBound, RamBound > RamPattern
Definition: IndexOperation.h:42
souffle::ram::transform::ParallelTransformer::relAnalysis
analysis::RelationAnalysis * relAnalysis
Definition: Parallel.h:68
souffle::ram::analysis::RelationAnalysis::lookup
const ram::Relation & lookup(const std::string &name) const
Definition: Relation.cpp:33
rel
void rel(size_t limit, bool showLimit=true)
Definition: Tui.h:1086
souffle::ram::makeLambdaRamMapper
LambdaNodeMapper< Lambda > makeLambdaRamMapper(const Lambda &lambda)
Creates a node mapper based on a corresponding lambda expression.
Definition: LambdaNodeMapper.h:67