// Copyright Sebastian Jeckel 2014. // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) #pragma once #include #include #include #include #include "BenchmarkBase.h" #include "react/common/Types.h" #include "react/Domain.h" #include "react/Signal.h" using namespace react; /////////////////////////////////////////////////////////////////////////////////////////////////// /// DiamondGraphGenerator /////////////////////////////////////////////////////////////////////////////////////////////////// template < typename D, typename TValue > class RandomGraphGenerator { public: typedef typename D::template SignalT MyHandle; typedef typename D::template VarSignalT MyInputHandle; typedef std::vector HandleVect; typedef std::vector InputHandleVect; InputHandleVect InputSignals; HandleVect OutputSignals; std::function SlowDelayFunc; std::function FastDelayFunc; typedef std::function Func1T; typedef std::function Func2T; typedef std::function Func3T; typedef std::function Func4T; Func1T Function1; Func2T Function2; Func3T Function3; Func4T Function4; int Width = 1; int Height = 1; int SelectSlowCount = 0; int SelectEdgeCount = 0; int EdgeSeed; int SlowSeed; void Generate() { assert(InputSignals.size() == Width); Func1T f1Slow = [this] (TValue a1) { SlowDelayFunc(); return Function1(a1); }; Func2T f2Slow = [this] (TValue a1, TValue a2) { SlowDelayFunc(); return Function2(a1,a2); }; Func3T f3Slow = [this] (TValue a1, TValue a2, TValue a3) { SlowDelayFunc(); return Function3(a1,a2,a3); }; Func4T f4Slow = [this] (TValue a1, TValue a2, TValue a3, TValue a4) { SlowDelayFunc(); return Function4(a1,a2,a3,a4); }; Func1T f1Fast = [this] (TValue a1) { FastDelayFunc(); return Function1(a1); }; Func2T f2Fast = [this] (TValue a1, TValue a2) { FastDelayFunc(); return Function2(a1,a2); }; Func3T f3Fast = [this] (TValue a1, TValue a2, TValue a3) { FastDelayFunc(); return Function3(a1,a2,a3); }; Func4T f4Fast = [this] (TValue a1, TValue a2, TValue a3, TValue a4) { FastDelayFunc(); return Function4(a1,a2,a3,a4); }; int nodeCount = Width * Height; std::mt19937 edgeGen(EdgeSeed); const auto edgeNodes = GetUniqueRandomNumbers(edgeGen, Width, nodeCount - 1, SelectEdgeCount); std::mt19937 slowGen(SlowSeed); const auto slowNodes = GetUniqueRandomNumbers(slowGen, Width, nodeCount - 1, SelectSlowCount); std::mt19937 edgeCountGen(EdgeSeed); std::geometric_distribution edgeCountDist(0.5); auto edgeNodeIt = edgeNodes.begin(); auto slowNodeIt = slowNodes.begin(); auto cur = 0; HandleVect nodes(nodeCount); for (int w=0; w nodeDist(0, Width*h - 1); for (int w=0; w 4); int kNode0 = cur-Width; int rNode1 = nodeDist(edgeGen); while (rNode1 == kNode0) rNode1 = nodeDist(edgeGen); int rNode2 = nodeDist(edgeGen); while (rNode2 == kNode0 || rNode2 == rNode1) rNode2 = nodeDist(edgeGen); int rNode3 = nodeDist(edgeGen); while (rNode3 == kNode0 || rNode3 == rNode2 || rNode3 == rNode1) rNode3 = nodeDist(edgeGen); if (edgeCount == 2) { nodes[cur] = (nodes[kNode0], nodes[rNode1]) ->* f2; } else if (edgeCount == 3) { nodes[cur] = (nodes[kNode0], nodes[rNode1], nodes[rNode2]) ->* f3; } else { nodes[cur] = (nodes[kNode0], nodes[rNode1], nodes[rNode2], nodes[rNode3]) ->* f4; } } else { nodes[cur] = nodes[cur-Width] ->* f1; } cur++; } } OutputSignals.clear(); for (int i=Width*(Height-1); i