news 2026/11/2 14:54:20

Sogou【同构】可对标taskflow的并行计算,网络请求并串发库

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
Sogou【同构】可对标taskflow的并行计算,网络请求并串发库

GitHub - sogou/workflow: C++ Parallel Computing and Asynchronous Networking Framework

示例代码:

#include <stdio.h>
#include "workflow/WFHttpServer.h"

#include <mutex>
#include <condition_variable>
#include <chrono>
#include "workflow/WFAlgoTaskFactory.h"

#include <atomic>
#include "workflow/WFTaskFactory.h"
#include "workflow/WFFacilities.h"

#pragma comment(lib, "ws2_32.lib")
#pragma comment(lib, "libssl.lib")
#pragma comment(lib, "libcrypto.lib")
#pragma comment(lib, "Mswsock.lib")

static void __arr_init(int* arr, int n)
{
srand(time(NULL));
for (int i = 0; i < n; i++)
arr[i] = rand() % 65536;
}


void parallelSort() {
static constexpr int n = 100000;
int* arr = new int[n];
__arr_init(arr, n);

std::mutex mutex;
std::condition_variable cond;
bool done = false;
auto* task = WFAlgoTaskFactory::create_psort_task("psort", arr, arr + n, [&mutex, &cond, &done](WFSortTask<int>* task) {
int* first = task->get_input()->first;
int* last = task->get_input()->last;
mutex.lock();
done = true;
mutex.unlock();
cond.notify_one();
});

task->start();

std::unique_lock<std::mutex> lock(mutex);
while (!done)
cond.wait(lock);

lock.unlock();

delete[]arr;
}

static SubTask* create_task(int& target)
{
static std::atomic<int> generator;
return WFTaskFactory::create_timer_task(0, [&](WFTimerTask*)
{
target = generator++;
});
}


void graphTask() {
WFFacilities::WaitGroup wait_group(1);

auto graph = WFTaskFactory::create_graph_task([&wait_group](WFGraphTask*) { wait_group.done(); });

constexpr int N = 4096 - 1;

auto target = new int[N];
auto node = new WFGraphNode * [N];

for (int i = 0; i < N; i++)
node[i] = &graph->create_graph_node(create_task(target[i]));

for (int i = 1; i < N; i++)
node[i]->precede(*node[(i - 1) / 2]);

graph->start();
wait_group.wait();

delete[] target;
delete[] node;
}


int test()
{
parallelSort();
graphTask();
WFHttpServer server([](WFHttpTask* task) {
task->get_resp()->append_output_body("<html>Hello World!</html>

});

if (server.start(8888) == 0) { // start server on port 8888
getchar(); // press "Enter" to end.
server.stop();
}

return 0;
}

GitHub - NVIDIA/thrust: [ARCHIVED] The C++ parallel algorithms library. See https://github.com/NVIDIA/cccl


创作不易,小小的支持一下吧!

版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/11/2 14:54:11

面试谈薪实战指南:一个被拒过、也被抢过的人,写给你的真心话

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

作者头像 李华
网站建设 2026/11/2 14:53:35

【Inpho精品教程】任务二:Inpho创建工程(创建项目、新建相机参数、导入照片、导入POS、生成航条、保存项目)

《无人机航空摄影测量精品教程》合集目录(Pix4d、CC、EPS、PhotoScan、Inpho) 在任务一中,我们做了Inpho创建工程前的数据预处理工作,获取了未畸变的图像、相机参数、Inpho支持的POS等数据,本文在此基础之上,创建Inpho工程,主要步骤有:创建项目、新建相机参数、导入照片…

作者头像 李华
网站建设 2026/11/2 14:53:08

轻量级服务监控系统设计:从探针采集到告警闭环

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

作者头像 李华
网站建设 2026/11/2 14:51:47

工业SPI隔离设计:MAX14431BAEE+与STM32F303RC实战指南

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

作者头像 李华
网站建设 2026/11/2 14:51:29

工业SPI隔离设计:地环路问题与数字隔离器实战

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

作者头像 李华
网站建设 2026/11/2 14:50:26

工业级SPI隔离通信设计:MAX14431BAEE+与PIC18F86K90实战方案

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

作者头像 李华