> Hi everyone!
Welcome to CAF! 🙂
> I'm experimenting on building a scientific compute backend with the actor model. In short a calculator :) .
> My goal is to provide the user the mathematical functions, blocks and operations and at runtime (through a UI or a parser) let them build the operations and pass the input data for compute.
> For example: c = cos(A) + log(B)
> _______ ___ _______ _____
> | cos(A) |---->| + |----->| log(B) | ---->| C |
> |_______| |___| |_______| |____|
>
> The goal is that every mathematical block or operation is an independent module that the application can call and compose.
Message passing isn’t terribly expensive, but it does have its price. If you send a message to have an actor compute cos(A), it’s probably cheaper to do the work in-place. Just pointing it out here. As long as cos/log were just some examples and your actual buildings blocks are more heavyweight then it’s probably going to be worth it.
> Before meeting CAF and the actor model, traditionally I would have gone for a directed acyclic graph with OOP... but where I'm blocked in the design now is how do I pass the user's data to CAF. So I've copied the typed_calculator example and like most examples they pass through a tester which is spawned in the caf_main function with a testee.
>
> • Can we pass arguments directly while spawning the actor without passing through a function?
> i.e system.spawn(typed_actor_addClass(A, B);
If you have implement your actor as a function: sys.spawn(my_fun, 1, 2, 3). If you have implemented your actor as a class: sys.spawn<my_class>(1, 2, 3). See
https://actor-framework.readthedocs.io/en/0.17.4/Actors.html#spawning-actors.
> • Can each block or operation have it's own system and CAF_MAIN function or it is better the integrate them into one that manages all the actor of the user session? Would there be a drawback in performance?
It’s better to integrate them. Running multiple actor-systems in the same OS process can have some undesired side effects and running multiple OS processes usually only makes sense if you need a strong (i.e. segfault-safe) separation of some actors. Besides, spawning actors is the natural way actor applications scale. An actor has a couple hundred Bytes overhead (as opposed to several kB for a thread) and CAF allocates a thread pool for you that makes sure your actors use as many cores as possible.
> • Can an event_based_actor Class have custom members and methods?
> i.e
> class Node : public event_based_actor {
> public:
> Node(actor_config& cfg, const string node_label) : event_based_actor(cfg),
> label_(node_label) {}
> void setLabel(string newLabel){
> label_ = newLabel;
> }
>
> string label() -> string { return label_; }
>
> protected:
>
>
> behavior make_behavior() override {
> }
>
> private:
> string label_;
> };
Sure. But keep in mind that Node communicates to other actors via messages only. No calling of those member functions outside of the actor itself.
> Sorry for the very basic questions and thanks in advance!
No worries. Good luck with the project!
Dominik