Actor model vs tasked based parallizm.
举例子:计算pi
actor model
概念:一般有n个actor(task),和一个调度线程(本身也是一个actor)
调度线程负责向每个task发送命令执行计算,以及接收每个task的结果并归并到一起
接口一般定义为:
addTask( new Task{ onReceive(msg,from)..., send(to,xxx)} )
tasked based parallizm
概念:可以定义task和io,io用来计算task的依赖关系。系统自动根据依赖关系执行所有task
使用流程:
创建子task,子task无依赖
创建汇总task,依赖所有的子task
最后启动所有task,等待完成即可
接口一般定义为:
addTask(new task(in, out, callbackfun))
如何用actor model实现tasked based parallizm?
MyTask
{
MyTask(in,out) //记录下io即可
onReceive(msg)
{
if msg.id in my dependencies
mark this dependency is done
if all dependencies are done
do the callbackfun
send msg to all out tasks
}
}
boost:;future实现任务并行化
for i in N
future_i =start subtask
ins.append(future_i)
start merge task(ins as input)
wait all task done
Actor model
c++ CAF
http://actor-framework.org/pdf/cshw-nassp-13.pdf
https://github.com/actor-framework/actor-framework
QP/C++
Akka
https://github.com/Neverlord/libcppa
http://www.theron-library.com/
- 上一篇 Redis资料
- 下一篇 标 题 re 总感觉it没我大山东啥事?.