1 #ifndef _PARTITIONER_HPP 2 #define _PARTITIONER_HPP 11 #include <lattice/Grid.hpp> 13 #include <debug/Warning.hpp> 14 #include <math/Partition.hpp> 15 #include <metaprogramming/UniversalReferences.hpp> 67 if(volIsSet()
and volume!=v)
84 if(sidesAreSet()
and sides!=s)
150 static_cast<
bool>(volume);
158 static_cast<
bool>(sides);
162 template <
typename G>
173 bool actualGridHasSetVolume=
176 actualGrid.forAllDims([&](
int mu)
178 actualGridHasSetVolume&=
179 (actualGrid.side(mu)!=0);
182 if(actualGridHasSetVolume)
187 const auto actualVolume=
220 enum{FATHER,CHILD1,CHILD2,NO_RELATIVE};
250 for(
int iRel=0;iRel<3;iRel++)
251 if(relatives[iRel]->volIsSet())
313 instructions.emplace_back(fw,bw);
329 RUNLOG<<
"Instruction "<<i;
339 if(instructions[i].second())
341 RUNLOG<<
"Success, moving to next instruction";
345 if(i==instructions.size())
347 RUNLOG<<
"Arrived to the end of the program, rewinding";
357 RUNLOG<<
"Failed, reverting move backward";
365 RUNLOG<<
"Moving backward";
369 if(instructions[i].first())
371 RUNLOG<<
"Success, reverting move forward";
378 RUNLOG<<
"Failed, moving to previous instruction";
389 template <
int NDims=4,
415 template <
typename G>
421 std::find_if(grids.begin(),grids.end(),[&actualGrid](
const SGrid& grid){
return grid.actualGrid==&actualGrid;});
464 template <
typename G>
473 template <
typename GF,
493 CRASH<<
"Father not found";
496 CRASH<<
"Child1 not found";
499 CRASH<<
"Child2 not found";
633 template <
typename F>
661 template <
typename F>
694 Vector<EnforceableRel> list;
696 for(
auto& p : partitionRelations)
698 const int iDeducible=
701 if(iDeducible!=PartRel::NO_RELATIVE)
702 list.emplace_back(&p,iDeducible);
716 for(
auto& p: partitionRelations)
717 for(
int j=1;j<=2;j++)
718 if(p.relatives[j]==grid)
719 res.push_back(p.relatives[PartRel::FATHER]);
730 Vector<std::pair<
const SGrid*,
const SGrid*>> res;
732 for(
auto& p : partitionRelations)
733 if(p.relatives[PartRel::FATHER]==grid)
734 res.push_back({p.relatives[PartRel::CHILD1],p.relatives[PartRel::CHILD2]});
745 Vector<
const SGrid*> list;
747 for(
auto& grid : grids)
748 if(grid.volIsSet()==f)
749 list.push_back(&grid);
776 std::map<
const SGrid*,
int> iChild;
778 for(
auto& g : partitionRelations)
784 RUNLOG<<g.father->name()<<
" -> "<<g.father->name()<<i;
786 for(
auto& child : {g.child1,g.child2})
787 RUNLOG<<g.father->name()<<i<<
" -> "<<child->name();
802 greatestCommonDivisor(gcd,f->getVol());
817 leastCommonMultiple(lcm,c->getVol());
824 template <
typename C,
839 template <
typename Fun>
846 enfRel.first->relatives;
852 RUNLOG<<
"Could enforce connection between "<<r[0]->name<<
" and its children "<<r[1]->name<<
" and "<<r[2]->name<<
" to element "<<w;
854 pretendToSetVol(r[w],cleanup);
858 getGridChecker(r[w]);
861 auto nextInstruction=
862 getConditionalExecuter(checker,compile(fun,cleanup));
866 getFatherVolDeducer(r[0],r[1],r[2],nextInstruction);
869 getChildVolDeducer(r[w],r[0],r[3-w],nextInstruction);
987 WARNING<<
"The program cannot be run";
992 CRASH<<
"Trying to execute an ill-formed program";
Vector< const SGrid * > getAllFathersOf(const SGrid *grid) const
Gets all fathers of a given grid.
std::set< PartRel > partitionRelations
List of relation to be satisfied between all the grid to be partitioned.
bool setSides(const Sides &s) const
Set the sides to s.
const SGrid *& father
Pointer to the grid to be partitioned.
Instruction compile(const Instruction &fun)
Compile the partitioner.
A program made of a set of pair of instructions.
static Vol leastCommonMultipleOfVolumes(const Vector< const SGrid * > &list)
Return the least common multiple of all the volumes.
PartitioningRelation(const SGrid *father, const SGrid *child1, const SGrid *child2)
Constructor.
Vector< const SGrid * > getAllGridsWithUnfixedVol() const
List all grids of the partitioning with unfixed volume.
const std::function< void(const Sides &)> setSidesOfActualGrid
Function to invocate setting the sides of the actual grid.
const SGrid *& child1
Pointer to the dividing grid.
static Vol greatestDivisorOfVolumes(const Vector< const SGrid * > &list)
Return the greatest divisor of all the volumes.
bool sidesAreSet() const
Check if the sides are set.
Vector< std::pair< const SGrid *, const SGrid * > > getAllChildrenOf(const SGrid *grid) const
Gets all children of a given grid.
void add(Action &&fw, Action &&bw)
Adds an instruction into the program.
#define CRASH
Initialize the crasher.
ShadowGrid(G &&actualGrid, const char *name)
Constructor taking the grid and type-erasing it.
const Side & getSide(int mu) const
Get a given side.
const SGrid * findShadowOfGrid(G &&actualGrid) const
Find the shadow of an actual grid.
auto listAllEnforceableRelations() const
Returns a list of all enforceable relations.
Instruction getConditionalExecuter(C &&checker, F &&fun)
Return a conditional executer.
Vector< const SGrid * > getAllGridsWithFixedVol() const
List all grids of the partitioning with fixed volume.
Instruction getRelationEnforcer(const EnforceableRel &enfRel, Vector< ScopeDoer< Instruction >> &cleanup, Fun fun)
Returns a function that enforce a given relation.
std::set< SGrid > grids
List of grids to be partitioned.
const Vol getVolFromSides() const
Get the volume from sides.
void printDot() const
Print the partition relation in a Dot format.
ScopeIndenter(Logger &logger)
Create and increase indent level.
#define RUNLOG
Create the line.
BACK_FORW
Enumerate the possibity to loop backward or forward.
bool operator<(const PartitioningRelation &oth) const
Comparison operator.
void divWithMod(Vector< TOut > "ient, Vector< TOut > &remainder, const Vector &divisor) const
Returns the result and remainder of the division.
Logger runLog("/dev/stdout")
Global logger.
const void * actualGrid
Reference to the actual grid.
Vector< Move > instructions
List of instrcutions to be executed.
bool operator<(const ShadowGrid &oth) const
Comparison operator.
#define PROVIDE_COORDS_TYPES
Provide the type needed to deal with grids.
const Vol & getVol() const
Get the volume.
bool volIsSet() const
Check if the volume is set.
Vector< const SGrid * > getAllGridsWithFixedOrUnfixedVol(const bool f) const
List all grids of the partitioning with fixed or unfixed volume, according to the parameter...
#define SCOPE_INDENT(VAR)
Mark the stream to be more indented.
const char * name
Name for debug purpose.
#define WARNING
Starts a new line in bold brown.
const Sides & getSides() const
Get the sides.
void pretendToSetVol(const SGrid *grid, Vector< ScopeDoer< Instruction >> &cleanup)
Pretend to set a volume for a grid.
void unSetVol() const
Unset the volume.
bool setVol(const Vol &v) const
Set the volume to v.
void exec()
Runs the program.
const SGrid *& child2
Pointer to the divisor grid.
Instruction getVolumeLooper(const SGrid *g, const Instruction &fun, Vector< ScopeDoer< Instruction >> &cleanup)
Returns a function which loops on all possible volume of g.
void unSetSides() const
Unset the sides.
Vector< int > data
Data used for loops.