Hi, Just wondering, I have the following doube loop:

for site in 1:nsites
        votes[1] = votes[2] = votes[3] = votes[4] = votes[5] = 0
        for seq in 1:neqs
            nuc = mat[seq, site]
            votes[1] += iscompatible(nuc, DNA_A)
            votes[2] += iscompatible(nuc, DNA_C)
            votes[3] += iscompatible(nuc, DNA_G)
            votes[4] += iscompatible(nuc, DNA_T)
            votes[5] += iscompatible(nuc, DNA_Gap)
        end
    end

Say I add an @inbounds macro to the outer loop to eliminate bounds checks, 
will it's effects extend to setmatrix statements in the inner loop. 
Inspecting the expanded macro I believe it is the case, as an @inbounds is 
set to true, and then after the inner loop is popped. But I'm not 100% sure 
if I am correct that is indeed how it works:

*quote  # REPL[63], line 2:*

*    begin *

*        $(Expr(:inbounds, true))*

*        for site = 1:nsites # REPL[63], line 3:*

*            votes[1] = (votes[2] = (votes[3] = (votes[4] = (votes[5] = 
0)))) # REPL[63], line 4:*

*            for seq = 1:neqs # REPL[63], line 5:*

*                nuc = mat[seq,site] # REPL[63], line 6:*

*                votes[1] += iscompatible(nuc,DNA_A) # REPL[63], line 7:*

*                votes[2] += iscompatible(nuc,DNA_C) # REPL[63], line 8:*

*                votes[3] += iscompatible(nuc,DNA_G) # REPL[63], line 9:*

*                votes[4] += iscompatible(nuc,DNA_T) # REPL[63], line 10:*

*                votes[5] += iscompatible(nuc,DNA_Gap)*

*            end*

*        end*

*        $(Expr(:inbounds, :pop))*

*    end*

*end*

I'd also like someone's opinion. Will I benefit from @simd on the inner 
loop?

The function `iscompatible` is annotated with @inline, and has no branching:

@inline function iscompatible{T<:Nucleotide}(x::T, y::T)
    return compatbits(x) & compatbits(y) != 0
end

# Return the compatibility bits of `nt`.
@inline function compatbits(nt::Nucleotide)
    return reinterpret(UInt8, nt)
end

As per the assumptions of an simd loop I read in the docs, each iteration 
is independent, order does not matter.
I'd just like some advice as if I'm right this will be the first time I use 
a simd loop to speed up my loops. 

Thanks,
Ben.

Reply via email to