Blender V5.3
lazy_function_graph_executor_generic.hh File Reference

Go to the source code of this file.

Classes

struct  blender::fn::lazy_function::generic_graph_executor::InputState
struct  blender::fn::lazy_function::generic_graph_executor::OutputState
struct  blender::fn::lazy_function::generic_graph_executor::NodeState
struct  blender::fn::lazy_function::generic_graph_executor::LockedNode
struct  blender::fn::lazy_function::generic_graph_executor::ScheduledNodes
struct  blender::fn::lazy_function::generic_graph_executor::CurrentTask
class  blender::fn::lazy_function::generic_graph_executor::GenericGraphExecutor
class  blender::fn::lazy_function::generic_graph_executor::GraphExecutorLFParams

Namespaces

namespace  blender
 BMesh Iterators.
namespace  blender::fn
namespace  blender::fn::lazy_function
namespace  blender::fn::lazy_function::generic_graph_executor

Enumerations

enum class  blender::fn::lazy_function::generic_graph_executor::NodeScheduleState : uint8_t { blender::fn::lazy_function::generic_graph_executor::NotScheduled , blender::fn::lazy_function::generic_graph_executor::Scheduled , blender::fn::lazy_function::generic_graph_executor::Running , blender::fn::lazy_function::generic_graph_executor::RunningAndRescheduled }

Detailed Description

This file implements the evaluation of a lazy-function graph. It's main objectives are:

  • Only compute values that are actually used.
  • Stay single threaded when nodes are executed quickly.
  • Allow spreading the work over an arbitrary number of threads efficiently.

This executor makes use of FN_lazy_threading.hh to enable multi-threading only when it seems beneficial. It operates in two modes: single- and multi-threaded. The use of a task pool and locks is avoided in single-threaded mode. Once multi-threading is enabled the executor starts using both. It is not possible to switch back from multi-threaded to single-threaded mode.

The multi-threading design implemented in this executor requires no main thread that coordinates everything. Instead, one thread will trigger some initial work and then many threads coordinate themselves in a distributed fashion. In an ideal situation, every thread ends up processing a separate part of the graph which results in less communication overhead. The way TBB schedules tasks helps with that: a thread will next process the task that it added to a task pool just before.

Communication between threads is synchronized by using a mutex in every node. When a thread wants to access the state of a node, its mutex has to be locked first (with some documented exceptions). The assumption here is that most nodes are only ever touched by a single thread and therefore the lock contention is reduced the more nodes there are.

Similar to how a #LazyFunction can be thought of as a state machine (see FN_lazy_function.hh), each node can also be thought of as a state machine. The state of a node contains the evaluation state of its inputs and outputs. Every time a node is executed, it has to advance its state in some way (e.g. it requests a new input or computes a new output).

When a node is executed it may send notifications to other nodes which may in turn schedule those nodes. For example, when the current node has computed one of its outputs, then the computed value is forwarded to all linked inputs, changing their node states in the process. If this input was the last missing required input, the node will be scheduled that it is executed next.

When all tasks are completed, the executor gives back control to the caller which may later provide new inputs to the graph which in turn leads to new nodes being scheduled and the process starts again.

Definition in file lazy_function_graph_executor_generic.hh.