Multiple Loops in Julia

HI, I’m writing a code that need multiples loops inside each other and i want to make parallelization it.

Loop1{
Loop2{
Loop3{
Loop4{

}
}
}
}

Can recommended some techique ? o maybe something to read o implemented

Take a look into the Base.Cartesian standard library:

1 Like

While Base.Cartesian has some nifty macros, I haven’t ever had much need for it specifically. In most cases I’ve been able to instead simply loop over CartesianIndices to perform the multiple loops as I disassemble the resulting CartesianIndex at each iteration to get what I need for each dimension.

Check out this blog post for some examples.

2 Likes

Same here. I tend to use CartesianIndices.

The macros in Base.Cartesian can be useful to unroll loops manually (e.g., performance).

2 Likes

Thanks for you suggestions, but How can I do when I work with CUDA Julia and need the loops?

CUDA isn’t a straightforward way to generally parallelize heavily nested loops, it really depends on what you’re doing in those loops.

1 Like

Thanks, let me explain more.
The three inner loops is for a 3D Matrix to calculate field values and the external loop is for other iteration in this calculate.

Can I paralyze this loops with CUDA?

You can probably parallelize the inner triple loop, either with array programming or with kernel programming