p.Chaos.Solver.IslandGroups.MinBodiesPerWorker

p.Chaos.Solver.IslandGroups.MinBodiesPerWorker

#Overview

name: p.Chaos.Solver.IslandGroups.MinBodiesPerWorker

This variable is created as a Console Variable (cvar).

It is referenced in 3 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of p.Chaos.Solver.IslandGroups.MinBodiesPerWorker is to set the minimum number of bodies that should be processed by each worker thread in the Chaos physics solver’s island system. This setting is part of the performance optimization mechanism for the Chaos physics engine in Unreal Engine 5.

This setting variable is primarily used by the Chaos physics subsystem, specifically within the island grouping functionality. The island system is a technique used in physics simulations to group interacting objects together for more efficient processing.

The value of this variable is set through the Unreal Engine’s console variable system. It’s initialized with a default value of 50 but can be changed at runtime using console commands or through configuration files.

The associated variable GIslandGroupsMinBodiesPerWorker directly interacts with this setting. They share the same value, with GIslandGroupsMinBodiesPerWorker being the actual variable used in the code, while p.Chaos.Solver.IslandGroups.MinBodiesPerWorker is the console-accessible name.

Developers should be aware that this variable affects the distribution of work among threads in the physics simulation. Setting it too low might result in too many small tasks, which could increase overhead on many-core systems. Setting it too high might lead to uneven work distribution and potentially reduced parallelism.

Best practices when using this variable include:

  1. Profiling the physics performance with different values to find the optimal setting for your specific game and target hardware.
  2. Considering the typical number of physics bodies in your scenes when adjusting this value.
  3. Balancing this setting with other related physics settings for optimal performance.

Regarding the associated variable GIslandGroupsMinBodiesPerWorker:

#References in C++ code

#Callsites

This variable is referenced in the following C++ source code:

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/Island/IslandGroupManager.cpp:48

Scope (from outer to inner):

file
namespace    Chaos
namespace    CVars

Source code excerpt:

		// We want a minimum number of bodies to gather on each thread. This prevents us running too many tiny tasks on a many-core machine
		int32 GIslandGroupsMinBodiesPerWorker = 50;
		FAutoConsoleVariableRef GCVarIslandGroupsMinBodiesPerWorker(TEXT("p.Chaos.Solver.IslandGroups.MinBodiesPerWorker"), GIslandGroupsMinBodiesPerWorker, TEXT("The minimum number of bodies we want per worker thread"));

	}

	namespace Private
	{

#Associated Variable and Callsites

This variable is associated with another variable named GIslandGroupsMinBodiesPerWorker. They share the same value. See the following C++ source code.

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/Island/IslandGroupManager.cpp:47

Scope (from outer to inner):

file
namespace    Chaos
namespace    CVars

Source code excerpt:


		// We want a minimum number of bodies to gather on each thread. This prevents us running too many tiny tasks on a many-core machine
		int32 GIslandGroupsMinBodiesPerWorker = 50;
		FAutoConsoleVariableRef GCVarIslandGroupsMinBodiesPerWorker(TEXT("p.Chaos.Solver.IslandGroups.MinBodiesPerWorker"), GIslandGroupsMinBodiesPerWorker, TEXT("The minimum number of bodies we want per worker thread"));

	}

	namespace Private
	{

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/Island/IslandGroupManager.cpp:162

Scope (from outer to inner):

file
namespace    Chaos
namespace    Private
function     int32 FPBDIslandGroupManager::BuildGroups

Source code excerpt:

			// @todo(chaos): we may want to consider separating the gather task count from the number of island groups by adding a second multiplier.
			TargetNumConstraintsPerTask = FMath::Max(TargetNumConstraintsPerTask, CVars::GIslandGroupsMinConstraintsPerWorker);
			TargetNumBodiesPerTask = FMath::Max(TargetNumConstraintsPerTask, CVars::GIslandGroupsMinBodiesPerWorker);

			// Reset all the groups
			for (TUniquePtr<FPBDIslandConstraintGroupSolver>& IslandGroup : IslandGroups)
			{
				IslandGroup->Reset();
			}