Blender V4.3
blender::threading Namespace Reference

Namespaces

namespace  detail
 
namespace  enumerable_thread_specific_utils
 

Classes

class  EnumerableThreadSpecific
 
class  TaskSizeHints
 

Functions

template<typename Range , typename Function >
void parallel_for_each (Range &&range, const Function &function)
 
template<typename Function >
void parallel_for (const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))
 
IndexRange align_sub_range (const IndexRange unaligned_range, const int64_t alignment, const IndexRange global_range)
 
template<typename Function >
void parallel_for_aligned (const IndexRange range, const int64_t grain_size, const int64_t alignment, const Function &function)
 
template<typename Value , typename Function , typename Reduction >
Value parallel_reduce (IndexRange range, int64_t grain_size, const Value &identity, const Function &function, const Reduction &reduction)
 
template<typename Value , typename Function , typename Reduction >
Value parallel_reduce_aligned (const IndexRange range, const int64_t grain_size, const int64_t alignment, const Value &identity, const Function &function, const Reduction &reduction)
 
template<typename... Functions>
void parallel_invoke (Functions &&...functions)
 
template<typename... Functions>
void parallel_invoke (const bool use_threading, Functions &&...functions)
 
template<typename Function >
void isolate_task (const Function &function)
 
template<typename Function >
void memory_bandwidth_bound_task (const int64_t approximate_bytes_touched, const Function &function)
 
bool use_single_thread (const TaskSizeHints &size_hints, const IndexRange range, const int64_t threshold)
 
template<typename Fn >
auto individual_task_sizes (Fn &&fn, const std::optional< int64_t > full_size=std::nullopt)
 
template<typename Fn >
auto accumulated_task_sizes (Fn &&fn)
 

Function Documentation

◆ accumulated_task_sizes()

template<typename Fn >
auto blender::threading::accumulated_task_sizes ( Fn && fn)
inline

Very similar to individual_task_sizes, but should be used if one can very efficiently compute the accumulated task size (in O(1) time). This is often the case when e.g. working with #OffsetIndices.

Parameters
fnA function that returns the accumulated size for a range of tasks: (IndexRange indices) -> int64_t.

Definition at line 178 of file BLI_task_size_hints.hh.

◆ align_sub_range()

IndexRange blender::threading::align_sub_range ( const IndexRange unaligned_range,
const int64_t alignment,
const IndexRange global_range )
inline

Move the sub-range boundaries down to the next aligned index. The "global" begin and end remain fixed though.

Definition at line 115 of file BLI_task.hh.

References blender::IndexRange::from_begin_end(), blender::IndexRange::one_after_last(), and blender::IndexRange::start().

Referenced by parallel_for_aligned(), and parallel_reduce_aligned().

◆ individual_task_sizes()

template<typename Fn >
auto blender::threading::individual_task_sizes ( Fn && fn,
const std::optional< int64_t > full_size = std::nullopt )
inline

Specify how large the task at each index is with a callback. This is especially useful if the size of each individual task can be very different. Specifying the size allows the scheduler to distribute the work across threads more equally.

Parameters
fnA function that returns the size for a single task: (int64_t index) -> int64_t.
full_sizeThe (approximate) accumulated size of all tasks. This is optional and should only be passed in if it is trivially accessible already.

Definition at line 158 of file BLI_task_size_hints.hh.

References range.

Referenced by blender::nodes::node_geo_proximity_cc::ProximityFunction::init_for_mesh(), blender::nodes::node_geo_proximity_cc::ProximityFunction::init_for_pointcloud(), and blender::nodes::node_geo_sample_nearest_surface_cc::SampleNearestSurfaceFunction::SampleNearestSurfaceFunction().

◆ isolate_task()

template<typename Function >
void blender::threading::isolate_task ( const Function & function)
inline

◆ memory_bandwidth_bound_task()

template<typename Function >
void blender::threading::memory_bandwidth_bound_task ( const int64_t approximate_bytes_touched,
const Function & function )
inline

Should surround parallel code that is highly bandwidth intensive, e.g. it just fills a buffer with no or just few additional operations. If the buffers are large, it's beneficial to limit the number of threads doing the work because that just creates more overhead on the hardware level and doesn't provide a notable performance benefit beyond a certain point.

Definition at line 243 of file BLI_task.hh.

References blender::threading::detail::memory_bandwidth_bound_task_impl().

Referenced by blender::geometry::calculate_uvs(), blender::geometry::create_line_mesh(), blender::draw::extract_orco(), blender::draw::extract_positions_mesh(), blender::draw::extract_uv_maps(), blender::offset_indices::fill_constant_group_size(), blender::draw::fill_loose_lines_ibo(), and GPU_indexbuf_build_in_place_from_memory().

◆ parallel_for()

template<typename Function >
void blender::threading::parallel_for ( const IndexRange range,
const int64_t grain_size,
const Function & function,
const TaskSizeHints & size_hints = detail::TaskSizeHints_Static(1) )
inline

Executes the given function for sub-ranges of the given range, potentially in parallel. This is the main primitive for parallelizing code.

Parameters
rangeThe indices that should be iterated over in parallel.
grain_sizeThe approximate amount of work that should be scheduled at once. For example of the range is [0 - 1000] and the grain size is 200, then the function will be called 5 times with [0 - 200], [201 - 400], ... (approximately). The size_hints parameter can be used to adjust how the work is split up if the tasks have different sizes.
functionA callback that actually does the work in parallel. It should have one #IndexRange parameter.
size_hintsCan be used to specify the size of the tasks relative to each other and the grain size. If all tasks have approximately the same size, this can be ignored. Otherwise, one can use threading::individual_task_sizes(...) or threading::accumulated_task_sizes(...). If the grain size is e.g. 200 and each task has the size 100, then only two tasks will be scheduled at once.

Definition at line 95 of file BLI_task.hh.

References blender::threading::detail::parallel_for_impl(), and use_single_thread().

Referenced by blender::bke::adapt_curve_domain_point_to_curve_impl(), blender::bke::adapt_mesh_domain_corner_to_edge_impl(), blender::bke::adapt_mesh_domain_corner_to_point_impl(), blender::bke::adapt_mesh_domain_edge_to_corner_impl(), blender::bke::adapt_mesh_domain_edge_to_point_impl(), blender::bke::adapt_mesh_domain_face_to_corner_impl(), blender::bke::adapt_mesh_domain_face_to_edge_impl(), blender::bke::adapt_mesh_domain_face_to_point_impl(), blender::nodes::node_geo_string_to_curves_cc::add_instances_from_handles(), blender::ed::greasepencil::apply_mask_as_segment_selection(), blender::AtomicDisjointSet::AtomicDisjointSet(), blender::ed::greasepencil::bake_grease_pencil_animation_exec(), BKE_mesh_merge_customdata_for_apply_modifier(), blur_isolate_highlights(), blender::compositor::blur_pass(), blender::bm_to_mesh_verts(), blender::nodes::node_geo_blur_attribute_cc::build_edge_to_edge_by_vert_map(), blender::bke::pbvh::build_mesh_leaf_nodes(), blender::nodes::node_geo_blur_attribute_cc::build_vert_to_vert_by_edge_map(), blender::realtime_compositor::CachedMask::CachedMask(), blender::realtime_compositor::CachedTexture::CachedTexture(), blender::bke::pbvh::calc_boundary_face_normals(), blender::bke::pbvh::calc_boundary_vert_normals(), blender::io::usd::calc_curve_offsets(), blender::nodes::node_geo_dual_mesh_cc::calc_dual_mesh(), blender::ed::sculpt_paint::filter::calc_limit_surface_positions(), blender::draw::pbvh::calc_material_indices(), blender::AtomicDisjointSet::calc_reduced_ids(), blender::ed::sculpt_paint::islands::calc_topology_islands_grids(), blender::draw::pbvh::calc_use_flat_layout(), blender::geometry::calc_vert_ranges_per_old_vert(), blender::bke::curves::bezier::calculate_auto_handles(), blender::bke::CurvesGeometry::calculate_bezier_auto_handles(), blender::bke::curves::bezier::calculate_evaluated_positions(), blender::geometry::calculate_fillet_positions(), blender::nodes::node_geo_curve_spline_parameter_cc::calculate_point_lengths(), colorBalance_apply(), composite_shadow(), blender::compositor::DoubleEdgeMaskOperation::compute_boundary(), blender::compositor::DoubleEdgeMaskOperation::compute_gradient(), blender::compositor::InpaintSimpleOperation::compute_inpainting_boundary(), blender::compositor::InpaintSimpleOperation::compute_inpainting_region(), blender::compositor::compute_max_tile_velocity(), blender::nodes::node_geo_distribute_points_on_faces_cc::compute_normal_outputs(), blender::realtime_compositor::compute_preview_from_result(), blender::nodes::node_geo_distribute_points_on_faces_cc::compute_rotation_output(), blender::ed::greasepencil::compute_topology_change(), blender::nodes::node_geo_input_mesh_face_neighbors_cc::construct_neighbor_count_varray(), blender::draw::convert_normals_impl(), blender::array_utils::copy(), blender::array_utils::copy(), blender::array_utils::copy(), blender::array_utils::copy(), blender::geometry::copy_transformed_positions(), blender::nodes::node_geo_extrude_mesh_cc::copy_with_mixing(), blender::bke::mesh::corner_tris_calc_impl(), blender::array_utils::count_indices(), blender::bke::curve_normal_point_domain(), blender::geometry::curve_simplify(), blender::nodes::node_geo_input_tangent_cc::curve_tangent_point_domain(), blender::ed::sculpt_paint::greasepencil::EraseOperationExecutor::curves_intersections_and_points_sides(), blender::ed::greasepencil::curves_merge_by_distance(), blender::nodes::node_geo_deform_curves_on_surface_cc::deform_curves(), blender::deform_drawing(), blender::bke::calc_edges::deselect_known_edges(), detect_holes(), blender::realtime_compositor::DistortionGrid::DistortionGrid(), do_gaussian_blur_effect(), do_glow_effect_byte(), do_solid_color(), do_wipe_effect(), draw_text_outline(), draw_text_shadow(), blender::draw::DRW_subdivide_loose_geom(), blender::nodes::node_geo_edge_paths_to_selection_cc::edge_paths_to_selection(), blender::bke::CurvesGeometry::ensure_evaluated_lengths(), blender::fn::evaluate_fields(), blender::index_mask::evaluate_short_unknown_segments_exactly(), blender::bke::CurvesGeometry::evaluated_normals(), blender::bke::CurvesGeometry::evaluated_tangents(), blender::nodes::node_composite_glare_cc::GlareOperation::execute_fog_glow(), blender::ed::greasepencil::execute_trim_on_drawing(), blender::geometry::extend_curves(), blender::draw::extract_data_mesh_mapped_corner(), blender::draw::extract_edge_factor_bm(), blender::draw::extract_edit_data_mesh(), blender::draw::extract_edituv_data_bm(), blender::draw::extract_face_dot_normals_mesh(), blender::draw::extract_face_dot_positions_mesh(), blender::draw::extract_face_dots_edituv_data(), blender::draw::extract_face_dots_uv_mesh(), blender::draw::extract_lines_paint_mask(), blender::draw::extract_mesh_loose_edge_data(), blender::draw::extract_orco(), blender::draw::extract_positions_bm(), blender::draw::extract_sculpt_data(), blender::draw::extract_tris_mesh(), blender::draw::extract_vert_index_mesh(), blender::draw::extract_vert_normals_bm(), blender::draw::extract_weights_mesh(), blender::nodes::node_geo_curve_fill_cc::fill_curve_vert_indices(), blender::compositor::InpaintSimpleOperation::fill_inpainting_region(), blender::ed::transform::curves::fill_map(), blender::draw::fill_points_position_time_vbo(), blender::nodes::node_geo_curve_to_points_cc::fill_rotation_attribute(), blender::bke::pbvh::pixels::Rows::find_copy_source(), blender::geometry::find_curve_neighbors(), blender::bke::find_nearest_tris_parallel(), blender::bke::find_nearest_verts(), blender::nodes::node_geo_interpolate_curves_cc::find_neighbor_guides(), blender::compositor::float4_to_float3_image(), blender::realtime_compositor::FogGlowKernel::FogGlowKernel(), blender::ed::sculpt_paint::greasepencil::GreasePencilStrokeOperationCommon::foreach_editable_drawing(), blender::index_mask::IndexMask::foreach_index(), blender::index_mask::IndexMask::foreach_index_optimized(), blender::index_mask::IndexMask::foreach_segment(), blender::index_mask::IndexMask::foreach_segment_optimized(), blender::io::grease_pencil::GreasePencilExporter::foreach_stroke_in_layer(), blender::bke::pbvh::Tree::from_bmesh(), blender::index_mask::IndexMask::from_indices(), blender::array_utils::gather(), blender::geometry::gaussian_blur_1D(), blender::generate_curves(), blender::compositor::GlareFogGlowOperation::generate_glare(), blender::io::alembic::get_loop_normals(), blender::index_mask::get_static_index_mask_for_min_size(), blender::ed::greasepencil::get_stroke_colors(), blender::nodes::node_geo_curve_endpoint_selection_cc::EndpointFieldInput::get_varray_for_context(), blender::nodes::node_geo_index_of_nearest_cc::IndexOfNearestFieldInput::get_varray_for_context(), blender::nodes::node_geo_input_mesh_island_cc::IslandFieldInput::get_varray_for_context(), blender::nodes::node_geo_mesh_face_group_boundaries_cc::BoundaryFieldInput::get_varray_for_context(), blender::nodes::node_geo_volume_cube_cc::Grid3DFieldContext::get_varray_for_input(), glow_blur_bitmap(), blender::draw::grease_pencil_cache_add_nurbs(), grease_pencil_do_layer_adjustments(), blender::draw::grease_pencil_edit_batch_ensure(), blender::draw::grease_pencil_weight_batch_ensure(), blender::draw::grease_pencil_wire_batch_ensure(), blender::nodes::node_geo_points_to_curves_cc::grouped_sort(), blender::nodes::node_geo_sort_elements_cc::grouped_sort(), image_exr_from_rgb_to_bw(), image_exr_opaque_alpha_buffer(), blender::ed::image_trace::image_to_bitmap(), IMB_transform(), blender::compositor::inflate_input(), blender::nodes::node_composite_file_output_cc::FileOutputOperation::inflate_result(), blender::ed::sculpt_paint::auto_mask::init_face_sets_masking(), blender::nodes::node_geo_proximity_cc::ProximityFunction::init_for_mesh(), blender::nodes::node_geo_proximity_cc::ProximityFunction::init_for_pointcloud(), blender::ed::sculpt_paint::greasepencil::WeightPaintOperation::init_weight_data_for_drawings(), initialize_shadow_alpha(), blender::geometry::interpolate_from_neighbor_curves(), blender::bke::curves::bezier::interpolate_to_evaluated(), blender::bke::curves::catmull_rom::interpolate_to_evaluated(), blender::bke::curves::nurbs::interpolate_to_evaluated(), blender::bke::CurvesGeometry::interpolate_to_evaluated(), blender::compositor::jump_flooding_pass(), jump_flooding_pass(), blender::bke::greasepencil::convert::legacy_gpencil_frame_to_grease_pencil_drawing(), blender::ed::seq::make_sep_waveform_view_from_ibuf(), blender::ed::seq::make_waveform_view_from_ibuf(), blender::ed::seq::make_zebra_view_from_ibuf(), blender::bke::VArrayImpl_For_VertexWeights::materialize(), blender::geometry::merge_layers(), blender::bke::mesh_edge_hide_from_vert(), blender::geometry::mix_with_indices(), blender::compositor::motion_blur(), multiply_ibuf(), blender::nodes::node_shader_tex_sky_cc::node_shader_gpu_tex_sky(), blender::bke::mesh::normals_calc_corners(), blender::bke::mesh::normals_calc_faces(), blender::io::obj::obj_parallel_chunked_output(), blender::ed::sculpt_paint::greasepencil::CloneOperation::on_stroke_begin(), blender::ed::sculpt_paint::SelectionPaintOperationExecutor::paint_point_selection_projected(), blender::ed::sculpt_paint::SelectionPaintOperationExecutor::paint_point_selection_spherical(), parallel_for_aligned(), parallel_nodes_loop_with_mirror_check(), blender::ed::curves::convert_from_particle_system::particles_to_curves(), blender::geometry::point_merge_by_distance(), blender::draw::pointcloud_extract_indices(), precompute_weight_values(), blender::draw::process_ibo_verts_mesh(), blender::ed::greasepencil::DrawingPlacement::project(), blender::ed::sculpt_paint::hide::propagate_vertex_visibility(), blender::string_search::StringSearchBase::query_impl(), remake_graph_transdata(), blender::ed::greasepencil::remap_material_indices(), blender::bke::Instances::remove_unused_references(), blender::geometry::reorder_and_flip_attributes_group_to_group(), blender::geometry::reorder_attributes_group_to_group(), blender::ed::greasepencil::DrawingPlacement::reproject(), blender::ed::sculpt_paint::undo::restore_position_mesh(), blender::nodes::node_geo_scale_elements_cc::reverse_indices_in_groups(), blender::length_parameterize::sample_at_lengths(), blender::ed::sculpt_paint::greasepencil::sample_curve_2d(), blender::geometry::ReverseUVSampler::sample_many(), blender::length_parameterize::sample_uniform(), blender::length_parameterize::sample_uniform_reverse(), blender::nodes::node_geo_sample_nearest_surface_cc::SampleNearestSurfaceFunction::SampleNearestSurfaceFunction(), blender::array_utils::scatter(), blender::bke::greasepencil::select_from_group(), blender::ed::sculpt_paint::select_grow::select_grow_invoke_per_curve(), blender::bke::VArrayImpl_For_VertexWeights::set_all(), blender::nodes::node_geo_input_shortest_edge_paths_cc::shortest_paths(), blender::ed::sculpt_paint::SlideOperationExecutor::slide(), blender::bke::mesh::sort_small_groups(), blender::geometry::sort_tris_into_rows(), blender::ed::sculpt_paint::expand::spherical_falloff_create(), blender::nodes::node_geo_split_to_instances_cc::split_mesh_groups(), blender::ed::curves::undo::step_encode(), blender::ed::greasepencil::undo::step_encode(), blender::bke::pbvh::store_bounds_orig(), blender::ed::greasepencil::stroke_simplify(), blender::geometry::subdivide_attribute_linear(), blender::subdivide_drawing(), blender::fftw::tbb_parallel_loop_for_fftw(), blender::bke::greasepencil::Drawing::texture_matrices(), blender::nodes::node_geo_duplicate_elements_cc::threaded_id_offset_copy(), tonemapmodifier_apply(), blender::bke::transform_normals(), blender::bke::transform_positions(), blender::ed::object::transform_positions(), transform_positions(), blender::bke::translate_positions(), blender::geometry::translate_positions(), blender::bke::try_capture_fields_on_geometry(), blender::bke::calc_edges::update_edge_indices_in_face_loops(), blender::bke::node_tree_runtime::update_logically_linked_sockets(), blender::compositor::SMAAOperation::update_memory_buffer(), blender::compositor::SummedAreaTableOperation::update_memory_buffer(), blender::bke::pbvh::pixels::update_pixels(), blender::compositor::upsample(), visible_strips_ordered_get(), blender::io::obj::write_mesh_objects(), blender::write_weights_for_drawing(), and blender::fn::lazy_function::Executor::~Executor().

◆ parallel_for_aligned()

template<typename Function >
void blender::threading::parallel_for_aligned ( const IndexRange range,
const int64_t grain_size,
const int64_t alignment,
const Function & function )
inline

Same as parallel_for but tries to make the sub-range sizes multiples of the given alignment. This can improve performance when the range is processed using vectorized and/or unrolled loops, because the fallback loop that processes remaining values is used less often. A disadvantage of using this instead of parallel_for is that the size differences between sub-ranges can be larger, which means that work is distributed less evenly.

Definition at line 141 of file BLI_task.hh.

References align_sub_range(), and parallel_for().

Referenced by blender::fn::multi_function::MultiFunction::call_auto(), and blender::ed::sculpt_paint::expand::enabled_state_to_bitmap().

◆ parallel_for_each()

template<typename Range , typename Function >
void blender::threading::parallel_for_each ( Range && range,
const Function & function )
inline

Definition at line 58 of file BLI_task.hh.

References range.

Referenced by blender::bke::calc_edges::add_existing_edges_to_hash_maps(), blender::bke::calc_edges::add_face_edges_to_hash_maps(), blender::nodes::node_geo_interpolate_curves_cc::build_kdtrees_for_root_positions(), blender::bke::calc_edges::clear_hash_tables(), blender::ed::sculpt_paint::greasepencil::GreasePencilStrokeOperationCommon::foreach_editable_drawing(), blender::ed::sculpt_paint::greasepencil::GrabOperation::foreach_grabbed_drawing(), blender::nodes::node_geo_scale_elements_cc::from_indices_large_groups(), gizmo_3d_foreach_selected(), grease_pencil_do_layer_adjustments(), blender::ed::greasepencil::grease_pencil_stroke_smooth_exec(), blender::ed::greasepencil::grease_pencil_vertex_paint_brightness_contrast_exec(), blender::ed::greasepencil::grease_pencil_vertex_paint_hsv_exec(), blender::ed::greasepencil::grease_pencil_vertex_paint_invert_exec(), blender::ed::greasepencil::grease_pencil_vertex_paint_levels_exec(), blender::ed::greasepencil::grease_pencil_vertex_paint_reset_exec(), blender::ed::greasepencil::grease_pencil_vertex_paint_set_exec(), blender::bke::pbvh::pixels::Rows::mark_pixels_effected_by_brush(), blender::modify_geometry_set(), blender::modify_geometry_set(), blender::bke::GeometrySet::modify_geometry_sets(), blender::ed::sculpt_paint::greasepencil::GrabOperation::on_stroke_begin(), blender::ed::sculpt_paint::greasepencil::TintOperation::on_stroke_begin(), blender::ed::sculpt_paint::greasepencil::AverageWeightPaintOperation::on_stroke_extended(), blender::ed::sculpt_paint::greasepencil::BlurWeightPaintOperation::on_stroke_extended(), blender::ed::sculpt_paint::greasepencil::DrawWeightPaintOperation::on_stroke_extended(), blender::ed::sculpt_paint::greasepencil::SmearWeightPaintOperation::on_stroke_extended(), blender::bke::calc_edges::reserve_hash_maps(), and blender::bke::calc_edges::serialize_and_initialize_deduplicated_edges().

◆ parallel_invoke() [1/2]

template<typename... Functions>
void blender::threading::parallel_invoke ( const bool use_threading,
Functions &&... functions )
inline

Same parallel_invoke, but allows disabling threading dynamically. This is useful because when the individual functions do very little work, there is a lot of overhead from starting parallel tasks.

Definition at line 214 of file BLI_task.hh.

References parallel_invoke(), and blender::lazy_threading::send_hint().

◆ parallel_invoke() [2/2]

◆ parallel_reduce()

◆ parallel_reduce_aligned()

template<typename Value , typename Function , typename Reduction >
Value blender::threading::parallel_reduce_aligned ( const IndexRange range,
const int64_t grain_size,
const int64_t alignment,
const Value & identity,
const Function & function,
const Reduction & reduction )
inline

Definition at line 177 of file BLI_task.hh.

References align_sub_range(), and parallel_reduce().

◆ use_single_thread()