Macaulay2 Engine
Loading...
Searching...
No Matches
res-dep-graph.hpp
Go to the documentation of this file.
1#ifndef _res_dep_graph_hpp_
2#define _res_dep_graph_hpp_
3
47
48#include "m2tbb.hpp"
49
50#ifdef WITH_TBB
51
52#include <iostream>
53#include <vector>
54#include <memory>
55#include <mutex>
56#include <stack>
57
58using TBBNode = tbb::flow::continue_node<tbb::flow::continue_msg>;
59using TBBNodePtr = std::shared_ptr<TBBNode>;
60
61class SchreyerFrame;
62class F4Res;
63
64inline int getIndex(int lev, int sldeg, int nlevels, int nslanted_degrees)
65{
66 (void) nslanted_degrees;
67 return lev + (sldeg * nlevels);
68}
69
70// return value is (lev, sldeg)
71inline std::pair<int,int> getPair(int index, int nlevels, int nslanted_degrees)
72{
73 (void) nslanted_degrees;
74 return std::make_pair(index % nlevels, index / nlevels);
75}
76
77struct Node {
78 int mLevel;
79 int mSlantedDegree;
80 std::vector<int> mEdges;
81 TBBNodePtr mFillAndReduceNode;
82 TBBNodePtr mRankNode;
83 TBBNodePtr mMinimalBettiNode;
84};
85
86// perhaps better name: MinimalBettiGraph
87class DependencyGraph
88{
89private:
90 tbb::flow::graph mTBBGraph;
91 std::vector<Node> mVertices;
92 std::mutex mMutex;
93
94 SchreyerFrame* mFrame;
95
96 void topologicalSortWorker(int curVertex, std::vector<bool> &visited, std::stack<int> &result) const;
97
98 TBBNodePtr createFillAndReduceNode(int level, int slantedDegree);
99 TBBNodePtr createRankNode(int level, int slantedDegree);
100 TBBNodePtr createMinimalBettiNode(int level, int slantedDegree);
101
102public:
103
104 DependencyGraph() : mFrame(nullptr) {};
105 DependencyGraph(SchreyerFrame *framePtr) : mFrame(framePtr) {};
106
107 // return value is the index of the added vertex
108 int addVertex(int level, int slantedDegree);
109
110 const Node& getVertex(int index) const { return mVertices[index]; }
111
112 int numVertices() const { return mVertices.size(); }
113
114 void addFillMatrixEdge(int source, int target);
115 void addMinimalBettiEdge(int level, int slantedDegree, int nLevels, int nSlantedDegrees);
116
117 std::stack<int> topologicalSort() const;
118
119 void print() const;
120
121 // need to ensure that mVertices[0] will always be the 'top' of the dependency tree
122 void startComputation() { mVertices[0].mFillAndReduceNode->try_put(tbb::flow::continue_msg()); }
123
124 void waitForCompletion() { mTBBGraph.wait_for_all(); }
125};
126
127void makeDependencyGraph(DependencyGraph &G, int nlevels, int nslanted_degrees, bool doMinimalBetti);
128
129#endif // WITH_TBB
130
131#endif // file guard
F4-style engine that computes one (level, degree) slice of a free resolution into the host SchreyerFr...
Definition res-f4.hpp:84
State container for the in-progress free resolution built by the F4 resolution engine.
VALGRIND_MAKE_MEM_DEFINED & result(result)
Engine TBB shim — single point of inclusion for every parallel primitive.
tbb::flow::continue_node< tbb::flow::continue_msg > Node
void makeDependencyGraph(int nlevels, int nslanted_degrees)
tbb::flow::graph G