英特尔 TBB 计算图:如何指定节点的输入队列容量
Intel TBB computational graph: how to specify input queue capacity of the node
我正在寻找C++.NET TPL数据流库的模拟。
在TPL数据流中,您可以指定并行性和块的容量选项。如果块的输入队列的大小达到其容量,则相应块的生产者的执行将暂停:
var buffer = new BufferBlock<int>(new DataflowBlockOptions() { BoundedCapacity = 10 });
var producer = new Task(() => {
for (int i = 0; i < 1000; i++) {
buffer.Post(i);
}
});
var fstAction = new TransformBlock<int, int>(async (i) => {
return i*i;
}, MaxDegreeOfParallelism = 4, BoundedCapacity = 10);
var sndAction = new ActionBlock<int>(async (i) => {
Thread.Sleep(5000);
Console.WriteLine(i);
}, MaxDegreeOfParallelism = 4, BoundedCapacity = 10);
buffer.LinkTo(fstAction, new DataflowLinkOptions() { PropagateCompletion = true });
fstAction.LinkTo(sndAction, new DataflowLinkOptions() { PropagateCompletion = true });
sndAction.Completition.Wait();
我在C++中需要类似的功能。TBB 似乎是一个很好的选择,但我找不到如何在function_node
/buffer_node
上指定容量。下面是一个示例:
std::size_t exportConcurrency = 16;
std::size_t uploadConcurrency = 16;
flow::graph graph;
std::size_t count = 1000;
std::size_t idx = 0;
flow::source_node<std::vector<std::string>> producerNode(graph, [&count, &idx](auto& out) {
out = { "0"s };
return ++idx != count;
});
flow::function_node<std::vector<std::string>, std::string> exportNode(graph, exportConcurrency, [](auto& ids) {
return "0"s;
});
flow::function_node<std::string, std::string> uploadNode(graph, uploadConcurrency, [](auto& chunk) {
std::this_thread::sleep_for(5s);
return "0"s;
});
flow::make_edge(producerNode, exportNode);
flow::make_edge(exportNode, uploadNode);
graph.wait_for_all();
可以在官方文档中找到,有三种推荐的方法可以限制资源消耗,其中一种是使用limiter_node
:
限制资源消耗的一种方法是使用
limiter_node
来限制可以流经图形中给定点的消息数。
这不是你想要的确切东西,但仍然应该调查。我还能够找到并发队列类部分,这些部分可以通过set_capacity
方法与有限容量一起使用。也许你可以这样管理它。希望这有帮助。
相关文章:
- 反向给定链表中的K节点
- 在C++程序中输入的文本文件将不起作用,除非文本被复制和粘贴
- 2D数组来自文本输入,中间有空格
- 如何使用 < 和 > 命令获取 c++ 中的输入和输出?
- 检查输入是否不是整数或数字
- 正在尝试了解输入验证循环
- 如果我只是不访问queue_front节点的子节点,而是将它们推到队列中呢?还是BFS吗
- 读取文件并输入到矢量中
- C++如何通过用户输入删除列表元素
- 用c++从输入文件中读取另一行
- 读取文件的最后一行并输入到链接列表时出错
- 创建一个函数以在输入为负数或零时输出字符串.第一次执行用户定义的函数
- 如何使用用户输入在C++中正确填充2D数组
- 修改链表主函数代码,用户将在其中输入节点的索引和数据以及正确的消息
- 检查节点的输入验证的整数
- 英特尔 TBB 计算图:如何指定节点的输入队列容量
- TensorFlow模型:如何从原始爱好文件中识别输入/输出节点名称
- 来自TBB节点的异步输入/输出和不均匀输出
- 指定输入/输出节点以在加载C API的模型上在Tensorflow 1.0 中运行推理
- 将输入数据发送到节点.js中的子进程