Parallelizing if loops

How could I parallelize the following for loop including if condition?
I’d like to use a different thread for each A,B,C and D.

for i=1:N
    if x[i]>0 && y[i]>0
        do A
    elseif x[i]>0 && y[i]<0
        do B
    elseif x[i]<0 && y[i]>0
        do C
    else
        do D
    end
end

But only of them is going to run, so isn’t this always single threaded?

A, B, C and D are independent.

I mean I want to use 1 thread for each condition, so maybe for loop is not appropriate. If that’s the case, I am looking for an alternative way to solve this.

Sure they can be independant, but if you write

if cond1
    A()
elseif cond2
    B()
else
    C()
end

only one of those blocks of code actually runs, determined by the condition.

julia> if true
           println("A")
       elseif true
           println("B")
       else
           println("C")
       end
A

julia> if false
           println("A")
       elseif true
           println("B")
       else
           println("C")
       end
B

julia> if false
           println("A")
       elseif false
           println("B")
       else
           println("C")
       end
C

There’s no notion of parallelizing an if statement, because multiple things aren’t being run

Threads.@threads for i=1:N

does the job for me.

Ohh, if the OP is trying to multithread the loop, then yes you can do that. I think I just misunderstood what they were asking for originally, sorry for the noise @iangilan.