p.Chaos.InnerParallelForBatchSize
p.Chaos.InnerParallelForBatchSize
#Overview
name: p.Chaos.InnerParallelForBatchSize
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
Set the batch size threshold for inner parallel fors
It is referenced in 5
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of p.Chaos.InnerParallelForBatchSize is to set the batch size threshold for inner parallel operations in the Chaos physics system of Unreal Engine 5. This setting is used to control the parallelization of physics computations, specifically for determining when to use parallel processing for certain operations.
This setting variable is primarily used in the Chaos physics subsystem, which is part of Unreal Engine’s experimental physics framework. It’s referenced in the Chaos namespace within the Parallel.cpp file, indicating its importance in managing parallel processing for physics calculations.
The value of this variable is set through a console variable system, as evidenced by the FAutoConsoleVariableRef declaration. This allows developers to adjust the value at runtime or through configuration files.
The p.Chaos.InnerParallelForBatchSize interacts closely with the InnerParallelForBatchSize variable. They share the same value, with the console variable providing a way to modify the internal variable.
Developers should be aware that this variable affects the performance and behavior of physics calculations in the Chaos system. It determines the threshold at which parallel processing is used for inner loops in physics computations. If the batch size exceeds this threshold, the system may switch to single-threaded processing depending on other conditions.
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.
- Monitoring performance metrics when adjusting this value to ensure it’s improving, not degrading, physics simulation performance.
- Considering the hardware capabilities of target platforms when setting this value, as optimal batch sizes may vary across different systems.
Regarding the associated variable InnerParallelForBatchSize:
The purpose of InnerParallelForBatchSize is to store the actual value used by the Chaos physics system for determining the batch size threshold for inner parallel operations. It’s the internal representation of the p.Chaos.InnerParallelForBatchSize console variable.
This variable is used directly in the physics code to make decisions about parallelization. It’s referenced in functions like InnerPhysicsParallelFor and InnerPhysicsParallelForRange to determine whether to use parallel or single-threaded processing based on the calculated batch size.
The value of InnerParallelForBatchSize is set through the console variable system, allowing for runtime adjustments.
Developers should be aware that changes to this variable will directly affect the parallelization behavior of the Chaos physics system. It’s crucial to test thoroughly after making adjustments to ensure optimal performance across different scenarios and hardware configurations.
Best practices for using InnerParallelForBatchSize include:
- Coordinating any changes with the p.Chaos.InnerParallelForBatchSize console variable, as they should always have the same value.
- Profiling the physics performance with different values to find the optimal setting for your specific game or application.
- Documenting any custom values used in your project to maintain consistency across development and ensure proper configuration in different environments.
#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:21
Scope (from outer to inner):
file
namespace Chaos
Source code excerpt:
FAutoConsoleVariableRef CVarDisableParticleParallelFor(TEXT("p.Chaos.DisableParticleParallelFor"), bDisableParticleParallelFor, TEXT("Disable parallel execution for Chaos Particles (Collisions, "));
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 InnerParallelForBatchSize
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/Framework/Parallel.cpp:7
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
#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/Framework/Parallel.cpp:21
Scope (from outer to inner):
file
namespace Chaos
Source code excerpt:
FAutoConsoleVariableRef CVarDisableParticleParallelFor(TEXT("p.Chaos.DisableParticleParallelFor"), bDisableParticleParallelFor, TEXT("Disable parallel execution for Chaos Particles (Collisions, "));
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:37
Scope (from outer to inner):
file
function void Chaos::InnerPhysicsParallelFor
Source code excerpt:
}
int32 BatchSize = FMath::DivideAndRoundUp<int32>(Num, NumWorkers);
PhysicsParallelFor(Num, InCallable, (BatchSize > InnerParallelForBatchSize) ? bForceSingleThreaded : true);
}
void Chaos::InnerPhysicsParallelForRange(int32 InNum, TFunctionRef<void(int32, int32)> InCallable, const int32 InMinBatchSize, bool bForceSingleThreaded)
{
int32 NumWorkers = int32(LowLevelTasks::FScheduler::Get().GetNumWorkers());
if (NumWorkers == 0)
#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/Framework/Parallel.cpp:48
Scope (from outer to inner):
file
function void Chaos::InnerPhysicsParallelForRange
Source code excerpt:
}
int32 BatchSize = FMath::DivideAndRoundUp<int32>(InNum, NumWorkers);
PhysicsParallelForRange(InNum, InCallable, InMinBatchSize, (BatchSize > InnerParallelForBatchSize) ? bForceSingleThreaded : true);
}
void Chaos::PhysicsParallelFor(int32 InNum, TFunctionRef<void(int32)> InCallable, bool bForceSingleThreaded)
{
TRACE_CPUPROFILER_EVENT_SCOPE(Chaos_PhysicsParallelFor);
using namespace Chaos;