基于演员模型的基于时间的模拟 [英] time-based simulation with actors model

查看:135
本文介绍了基于演员模型的基于时间的模拟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个单线程应用程序,它可以模拟随着时间的推移,共享内存模型与成千上万个对象的交互作用。显然,它不能在多CPU硬件上扩展。



在阅读了一些关于基于代理的建模和函数式编程/ actor模型之后,我正在考虑用消息传递范式重写。



这个想法非常简单 - 每个对象都是一个actor,他们的交互作用将成为消息,以便模拟可以并行发生。给定一个特定时间的对象配置 - 它的未来结果可以很容易计算出来。问题是如何建模时间:

例如让我们假设对象X的行为依赖于A和B,因为不能保证actor和消息的计算顺序,它可能是当计算X时A已经将消息发送给X但是B没有。
如何确保计算正确发生?



我希望这个问题是清楚

在此先感谢。

解决方案

使用消息传递并行化(离散事件?)模拟的方法是众所周知的,不需要函数式本身(当然,这并不妨碍你这样实现)。



你描述的基本问题wrt到事件的时间也被称为本地因果约束(例如,参见这本教科书)。基本上,您需要使用同步协议来确保每个对象(或代理)以正确的顺序处理其消息。在并行离散事件模拟领域,这些对象称为逻辑进程,它们通过事件(即时间标记的消息)进行通信。



为这些事件正确实施同步协议是很有挑战性的,协议的正确选择是高度针对特定应用的 。例如,一个重要因素是每个事件所需的平均计算量:如果所需的计算量很少,通信成本就会占据总体执行时间,并且难以调整模拟。

因此,我建议您在从零开始开始之前,在您打算使用的actors框架之上寻找现有解决方案/库


we have a single threaded application that simulates the interaction of a hundred of thousands of objects over time with the shared memory model.
obviously, it suffers from its inability to scale over multi CPU hardware.

after reading a little about agent based modeling and functional programming/actor model I was considering a rewrite with the message-passing paradigm.

the idea is very simple - each object will be an actor and their interactions will be messages so that the simulation could happen in parallel. given a configuration of objects at a certain time - its future consequences can be easily computed.

the question is how to model the time:
for example let's assume the the behavior of object X depends on A and B, as the actors and the messages calculations order is not guaranteed it could be that when X is to be computed A has already sent its message to X but B didn't. how to make sure the computation happens correctly?

I hope the question is clear
thanks in advance.

解决方案

Your approach of using message passing to parallelize a (discrete-event?) simulation is well-known and does not require a functional style per se (although, of course, this does not prevent you to implement it like that).

The basic problem you describe w.r.t. to the timing of events is also known as the local causality constraint (see, for example, this textbook). Basically, you need to use a synchronization protocol to ensure that each object (or agent) processes its messages in the right order. In the domain of parallel discrete-event simulation, such objects are called logical processes, and they communicate via events (i.e. time-stamped messages).

Correctly implementing a synchronization protocol for these events is challenging and the right choice of protocol is highly application-specific. For example, one important factor is the average amount of computation required per event: if there is little computation required, the communication costs dominate the overall execution time and it will be hard to scale the simulation.

I would therefore recommend to look for existing solutions/libraries on top of the actors framework you intend to use before starting from scratch.

这篇关于基于演员模型的基于时间的模拟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆