# How to best parallelize custom decision tree / forest?

**URL:** <https://discourse.julialang.org/t/how-to-best-parallelize-custom-decision-tree-forest/98328>\
**Category:** Machine Learning\
**Tags:** question\
**Created:** [May 4, 2023, 3:39pm UTC](https://discourse.julialang.org/t/how-to-best-parallelize-custom-decision-tree-forest/98328 "2023-05-04T15:39:45Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![MiquellaXMalenia](https://avatars.discourse-cdn.com/v4/letter/m/90ced4/32.png) [@MiquellaXMalenia](https://discourse.julialang.org/u/MiquellaXMalenia)\
**Post date:** [May 4, 2023, 3:39pm UTC](https://discourse.julialang.org/t/how-to-best-parallelize-custom-decision-tree-forest/98328/1 "2023-05-04T15:39:45Z")

</div>

Hello,

Could anyone give me advice on the best way to parallelize a custom decision tree or forest algorithm on CPU / GPU?  
I am currently building my own from scratch to experiment with some of my ideas for multi-class / output scenarios .  
Available decision tree packages aren’t exactly aligned to what I want, so the need to do it from scratch. The code I wrote is unparallelized and uses for - loops for building the tree ( since I am not familiar with recursion) and data is saved in a julia dictionary which is causing me problems when I try parallelizing it.

Note: I have only been using Julia for 2 months, and have only ever used python.

Any help would be appreciated  
Thanks

Example Code

mutable struct Tree  
name   
max\_depth  
min\_samples  
data  
end

function build\_tree(tree::Tree,X,y)

```
for depth in 0:tree.max_depth
	# parallelize creating nodes per depth
	# Choices
	# Threads.@threads
	# Threads.@spawn
	# Distributed.@distributed
	# CUDA.jl ?
	for node in 1:2^depth
		# create nodes
	end
end

```

end
