Back

TaskScheduler

sofa::simulation::TaskScheduler
Doc (from source)

Base class for a task scheduler The API allows to: - initialize the scheduler with a number of dedicated threads - add a task to the scheduler - wait until all tasks are done etc.

Abstract (AI generated)

The `TaskScheduler` manages computational tasks in SOFA simulations, enabling efficient parallel execution by providing an interface to initialize with threads, add tasks, stop the scheduler, and wait for task completion.

Metadata
module
Sofa.framework.Simulation.Core
namespace
sofa::simulation
include
sofa/simulation/task/TaskScheduler.h
description

The TaskScheduler is a base class in the SOFA framework designed to manage and schedule computational tasks for parallel execution within simulations. It does not directly implement or contribute to any specific mathematical or physical operators, such as mass matrix $M$, stiffness matrix $K$, internal force $f_{int}$, residual $R$, or constitutive laws like strain measures, stress tensors, hyperelastic potentials, damping models, constraint Jacobians, etc. Instead, its role is to provide the infrastructure necessary for efficient parallel computation and task management, which indirectly supports the numerical methods and discretization choices encoded in other components of the simulation pipeline.

Role in the Global FEM Pipeline

The TaskScheduler plays a critical role in managing the computational tasks involved in various stages of the FEM pipeline:
- Assembly Phase: It can be used to parallelize the assembly of global matrices and vectors, such as mass and stiffness matrices.
- Time Integration: Tasks for time integration steps (e.g., implicit Euler) can be scheduled for parallel execution.
- Nonlinear Resolution: Newton-Raphson iterations or other nonlinear solvers can benefit from task-based parallelism to solve large systems of equations more efficiently.
- Linear Resolution: Iterative linear solvers, such as Krylov subspace methods (e.g., Conjugate Gradient), can leverage the TaskScheduler for parallel matrix-vector operations and preconditioning steps.
- Update Phase: State updates and velocity reconstructions can be managed in parallel to ensure timely progress through simulation timesteps.

Numerical Methods and Discretization Choices

The TaskScheduler itself does not encode any numerical methods or discretization choices. However, it is designed to support the efficient execution of tasks that may involve such methods, including:
- Implicit Time Integration: The scheduler can manage tasks for implicit Euler or Newmark-type schemes.
- Iterative Solvers: It supports parallelism in iterative linear solvers like Conjugate Gradient and Krylov subspace methods.
- Matrix-Free Operations: Matrix-free tangent stiffness evaluation, enabled by automatic differentiation, can be scheduled as computational tasks.

Mathematical Content

As a base class for task scheduling, the TaskScheduler does not contribute any direct mathematical content. Its primary function is to manage and distribute computational tasks across multiple threads or processes, thereby optimizing performance and scalability of FEM simulations.

In summary, while the TaskScheduler itself does not implement physical laws or numerical operators directly, it provides a crucial infrastructure for efficient parallel computation that underpins various stages of the finite element simulation pipeline.

Methods
unsigned int GetHardwareThreadsCount ()
void init (const unsigned int nbThread) virtual
void stop () virtual
unsigned int getThreadCount () virtual
const char * getCurrentThreadName () virtual
int getCurrentThreadType () virtual
bool addTask (Task * task) virtual
bool addTask (Task::Status & status, const int & task) virtual
void workUntilDone (Task::Status * status) virtual
Task::Allocator * getTaskAllocator () virtual
{
  "name": "TaskScheduler",
  "namespace": "sofa::simulation",
  "module": "Sofa.framework.Simulation.Core",
  "include": "sofa/simulation/task/TaskScheduler.h",
  "doc": "Base class for a task scheduler\nThe API allows to:\n- initialize the scheduler with a number of dedicated threads\n- add a task to the scheduler\n- wait until all tasks are done etc.",
  "inherits": [],
  "templates": [],
  "data_fields": [],
  "links": [],
  "methods": [
    {
      "name": "GetHardwareThreadsCount",
      "return_type": "unsigned int",
      "params": [],
      "is_virtual": false,
      "is_pure_virtual": false,
      "is_static": true,
      "access": "public"
    },
    {
      "name": "init",
      "return_type": "void",
      "params": [
        {
          "name": "nbThread",
          "type": "const unsigned int"
        }
      ],
      "is_virtual": true,
      "is_pure_virtual": true,
      "is_static": false,
      "access": "public"
    },
    {
      "name": "stop",
      "return_type": "void",
      "params": [],
      "is_virtual": true,
      "is_pure_virtual": true,
      "is_static": false,
      "access": "public"
    },
    {
      "name": "getThreadCount",
      "return_type": "unsigned int",
      "params": [],
      "is_virtual": true,
      "is_pure_virtual": true,
      "is_static": false,
      "access": "public"
    },
    {
      "name": "getCurrentThreadName",
      "return_type": "const char *",
      "params": [],
      "is_virtual": true,
      "is_pure_virtual": true,
      "is_static": false,
      "access": "public"
    },
    {
      "name": "getCurrentThreadType",
      "return_type": "int",
      "params": [],
      "is_virtual": true,
      "is_pure_virtual": true,
      "is_static": false,
      "access": "public"
    },
    {
      "name": "addTask",
      "return_type": "bool",
      "params": [
        {
          "name": "task",
          "type": "Task *"
        }
      ],
      "is_virtual": true,
      "is_pure_virtual": true,
      "is_static": false,
      "access": "public"
    },
    {
      "name": "addTask",
      "return_type": "bool",
      "params": [
        {
          "name": "status",
          "type": "Task::Status &"
        },
        {
          "name": "task",
          "type": "const int &"
        }
      ],
      "is_virtual": true,
      "is_pure_virtual": false,
      "is_static": false,
      "access": "public"
    },
    {
      "name": "workUntilDone",
      "return_type": "void",
      "params": [
        {
          "name": "status",
          "type": "Task::Status *"
        }
      ],
      "is_virtual": true,
      "is_pure_virtual": true,
      "is_static": false,
      "access": "public"
    },
    {
      "name": "getTaskAllocator",
      "return_type": "Task::Allocator *",
      "params": [],
      "is_virtual": true,
      "is_pure_virtual": true,
      "is_static": false,
      "access": "public"
    }
  ],
  "description": "The `TaskScheduler` is a base class in the SOFA framework designed to manage and schedule computational tasks, enabling efficient parallel execution within simulations. It provides an interface for initializing with a specified number of threads, adding tasks to the scheduler, stopping the scheduler, and waiting until all tasks are completed. The component interacts closely with other components that require task-based processing or parallelization, such as solvers, collision detection, and haptics devices. \n\nThe `TaskScheduler` API includes methods for initializing (`init`), adding tasks (`addTask`), stopping the scheduler (`stop`), getting thread counts (`getThreadCount`, `getCurrentThreadName`, `getCurrentThreadType`), and working until all tasks are done (`workUntilDone`). The component also provides a method to get hardware thread count (`GetHardwareThreadsCount`) and retrieve task allocator (`getTaskAllocator`).\n\nPractical usage involves initializing the scheduler with an appropriate number of threads based on system capabilities, adding computational tasks that need parallel execution, and ensuring all tasks are completed before proceeding. This helps in achieving optimal performance by leveraging multi-threading for computationally intensive operations within SOFA simulations.",
  "maths": "The `TaskScheduler` is a base class in the SOFA framework designed to manage and schedule computational tasks for parallel execution within simulations. It does not directly implement or contribute to any specific mathematical or physical operators, such as mass matrix \\(M\\), stiffness matrix \\(K\\), internal force \\(f_{int}\\), residual \\(R\\), or constitutive laws like strain measures, stress tensors, hyperelastic potentials, damping models, constraint Jacobians, etc. Instead, its role is to provide the infrastructure necessary for efficient parallel computation and task management, which indirectly supports the numerical methods and discretization choices encoded in other components of the simulation pipeline.\n\n### Role in the Global FEM Pipeline\nThe `TaskScheduler` plays a critical role in managing the computational tasks involved in various stages of the FEM pipeline:\n- **Assembly Phase**: It can be used to parallelize the assembly of global matrices and vectors, such as mass and stiffness matrices.\n- **Time Integration**: Tasks for time integration steps (e.g., implicit Euler) can be scheduled for parallel execution.\n- **Nonlinear Resolution**: Newton-Raphson iterations or other nonlinear solvers can benefit from task-based parallelism to solve large systems of equations more efficiently.\n- **Linear Resolution**: Iterative linear solvers, such as Krylov subspace methods (e.g., Conjugate Gradient), can leverage the `TaskScheduler` for parallel matrix-vector operations and preconditioning steps.\n- **Update Phase**: State updates and velocity reconstructions can be managed in parallel to ensure timely progress through simulation timesteps.\n\n### Numerical Methods and Discretization Choices\nThe `TaskScheduler` itself does not encode any numerical methods or discretization choices. However, it is designed to support the efficient execution of tasks that may involve such methods, including:\n- **Implicit Time Integration**: The scheduler can manage tasks for implicit Euler or Newmark-type schemes.\n- **Iterative Solvers**: It supports parallelism in iterative linear solvers like Conjugate Gradient and Krylov subspace methods.\n- **Matrix-Free Operations**: Matrix-free tangent stiffness evaluation, enabled by automatic differentiation, can be scheduled as computational tasks.\n\n### Mathematical Content\nAs a base class for task scheduling, the `TaskScheduler` does not contribute any direct mathematical content. Its primary function is to manage and distribute computational tasks across multiple threads or processes, thereby optimizing performance and scalability of FEM simulations.\n\nIn summary, while the `TaskScheduler` itself does not implement physical laws or numerical operators directly, it provides a crucial infrastructure for efficient parallel computation that underpins various stages of the finite element simulation pipeline.",
  "abstract": "The `TaskScheduler` manages computational tasks in SOFA simulations, enabling efficient parallel execution by providing an interface to initialize with threads, add tasks, stop the scheduler, and wait for task completion.",
  "sheet": "# TaskScheduler\n\n## Overview\nThe `TaskScheduler` is a base class in the SOFA framework designed to manage and schedule computational tasks for parallel execution within simulations. It provides methods for initializing the scheduler with a specified number of threads (`init`), adding tasks (`addTask`), stopping the scheduler (`stop`), and waiting until all tasks are completed (`workUntilDone`). This component is crucial for optimizing performance in computationally intensive operations such as assembly, time integration, nonlinear resolution, linear resolution, and state updates.\n\n## Dependencies and Connections\nThe `TaskScheduler` interacts closely with other components that require task-based processing or parallelization. These include solvers (e.g., iterative Krylov subspace methods), collision detection systems, haptics devices, and any component involved in the assembly of global matrices and vectors, time integration steps, Newton-Raphson iterations, matrix-free tangent stiffness evaluation, and state updates."
}