p.Chaos.MinRangeBatchSize
p.Chaos.MinRangeBatchSize
#Overview
name: p.Chaos.MinRangeBatchSize
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
Set the min range batch size for parallel for
It is referenced in 4
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of p.Chaos.MinRangeBatchSize is to set the minimum range batch size for parallel processing in the Chaos physics system of Unreal Engine 5. This setting is used to control the granularity of parallel task distribution in physics simulations.
-
The Chaos physics subsystem within Unreal Engine 5 relies on this setting variable. It’s part of the experimental Chaos framework, which is responsible for physics simulations in the engine.
-
The value of this variable is set through a console variable (CVar) system. It’s initialized in the Chaos namespace and can be modified at runtime using the console command “p.Chaos.MinRangeBatchSize”.
-
This variable interacts closely with other batch size and worker-related variables in the Chaos system, such as InnerParallelForBatchSize, MaxNumWorkers, SmallBatchSize, and LargeBatchSize.
-
Developers must be aware that this variable affects the performance and parallelization of physics calculations. Setting it too low might lead to excessive overhead from task distribution, while setting it too high might result in underutilization of available processing power.
-
Best practices when using this variable include:
- Experimenting with different values to find the optimal balance between parallelization and overhead for your specific use case.
- Considering the capabilities of the target hardware when setting this value.
- Using it in conjunction with other batch size and worker count settings for fine-tuned performance optimization.
Regarding the associated variable MinRangeBatchSize:
- MinRangeBatchSize is the internal variable that stores the value set by p.Chaos.MinRangeBatchSize.
- It’s used directly in the PhysicsParallelForRange function to determine the actual batch size for parallel processing.
- The value of MinRangeBatchSize is compared against a provided minimum batch size (InMinBatchSize) to ensure that the batch size doesn’t fall below a certain threshold.
- Developers should be aware that changes to p.Chaos.MinRangeBatchSize will directly affect this internal variable and, consequently, the behavior of parallel physics calculations.
- Best practices include monitoring the impact of changes to this variable on physics performance and stability, especially in scenarios with varying numbers of physics objects or different types of physics interactions.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/Framework/Parallel.cpp:22
Scope (from outer to inner):
file
namespace Chaos
Source code excerpt:
FAutoConsoleVariableRef CVarDisableCollisionParallelFor(TEXT("p.Chaos.DisableCollisionParallelFor"), bDisableCollisionParallelFor, TEXT("Disable parallel execution for Chaos Collisions (also disabled by DisableParticleParallelFor)"));
FAutoConsoleVariableRef CVarInnerPhysicsBatchSize(TEXT("p.Chaos.InnerParallelForBatchSize"), InnerParallelForBatchSize, TEXT("Set the batch size threshold for inner parallel fors"));
FAutoConsoleVariableRef CVarMinRangeBatchSize(TEXT("p.Chaos.MinRangeBatchSize"), MinRangeBatchSize, TEXT("Set the min range batch size for parallel for"));
FAutoConsoleVariableRef CVarMaxRangeBatchWorkers(TEXT("p.Chaos.MaxNumWorkers"), MaxNumWorkers, TEXT("Set the max number of workers for physics"));
FAutoConsoleVariableRef CVarSmallBatchSize(TEXT("p.Chaos.SmallBatchSize"), SmallBatchSize, TEXT("Small batch size for chaos parallel loops"));
FAutoConsoleVariableRef CVarLargeBatchSize(TEXT("p.Chaos.LargeBatchSize"), LargeBatchSize, TEXT("Large batch size for chaos parallel loops"));
#endif
}
#Associated Variable and Callsites
This variable is associated with another variable named MinRangeBatchSize
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/Framework/Parallel.cpp:8
Scope (from outer to inner):
file
namespace Chaos
Source code excerpt:
CHAOS_API int32 GSingleThreadedPhysics = 0;
CHAOS_API int32 InnerParallelForBatchSize = 0;
CHAOS_API int32 MinRangeBatchSize = 0;
CHAOS_API int32 MaxNumWorkers = 100;
CHAOS_API int32 SmallBatchSize = 10;
CHAOS_API int32 LargeBatchSize = 100;
#if !UE_BUILD_SHIPPING
CHAOS_API bool bDisablePhysicsParallelFor = false;
#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/Framework/Parallel.cpp:22
Scope (from outer to inner):
file
namespace Chaos
Source code excerpt:
FAutoConsoleVariableRef CVarDisableCollisionParallelFor(TEXT("p.Chaos.DisableCollisionParallelFor"), bDisableCollisionParallelFor, TEXT("Disable parallel execution for Chaos Collisions (also disabled by DisableParticleParallelFor)"));
FAutoConsoleVariableRef CVarInnerPhysicsBatchSize(TEXT("p.Chaos.InnerParallelForBatchSize"), InnerParallelForBatchSize, TEXT("Set the batch size threshold for inner parallel fors"));
FAutoConsoleVariableRef CVarMinRangeBatchSize(TEXT("p.Chaos.MinRangeBatchSize"), MinRangeBatchSize, TEXT("Set the min range batch size for parallel for"));
FAutoConsoleVariableRef CVarMaxRangeBatchWorkers(TEXT("p.Chaos.MaxNumWorkers"), MaxNumWorkers, TEXT("Set the max number of workers for physics"));
FAutoConsoleVariableRef CVarSmallBatchSize(TEXT("p.Chaos.SmallBatchSize"), SmallBatchSize, TEXT("Small batch size for chaos parallel loops"));
FAutoConsoleVariableRef CVarLargeBatchSize(TEXT("p.Chaos.LargeBatchSize"), LargeBatchSize, TEXT("Large batch size for chaos parallel loops"));
#endif
}
#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/Framework/Parallel.cpp:106
Scope (from outer to inner):
file
function void Chaos::PhysicsParallelForRange
Source code excerpt:
check(NumWorkers > 0);
int32 BatchSize = FMath::DivideAndRoundUp<int32>(InNum, NumWorkers);
int32 MinBatchSize = FMath::Max(InMinBatchSize, MinRangeBatchSize);
// @todo(mlentine): Find a better batch size in this case
if (InNum < MinBatchSize)
{
NumWorkers = 1;
BatchSize = InNum;
}