Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions fannkuchredux/fannkuchredux-fast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# https://salsa.debian.org/benchmarksgame-team/benchmarksgame/

# based on Oleg Mazurov's Java Implementation and Jeremy Zerfas' C implementation
# transliterated by Hamza Yusuf Çakır
# transliterated and modified by Hamza Yusuf Çakır

global const preferred_num_blocks = 24

Expand Down Expand Up @@ -42,7 +42,7 @@ Base.@propagate_inbounds @inline function first_permutation(perm::Perm, idx)
pp = perm.pp

for i = 2:length(p)
p[i] = i - 1
p[i] = (i - 1) % Int8
end

for i = length(p):-1:2
Expand Down Expand Up @@ -102,7 +102,7 @@ Base.@propagate_inbounds @inline function count_flips(perm::Perm)
while true
flips += one(flips)
new_first = pp[first]
pp[first] = first - 1
pp[first] = (first - 1) % Int8

if first > 3
lo = 2; hi = first - 1
Expand Down Expand Up @@ -134,7 +134,7 @@ Base.@propagate_inbounds function run_task(f::Fannkuch, perm::Perm, idxmin, idxm
while true
if perm.p[1] != 0
flips = count_flips(perm)
maxflips = max(maxflips, flips)
(flips > maxflips) && (maxflips = flips)
chksum += iseven(i) ? flips : -flips
end
i != idxmax || break
Expand All @@ -143,7 +143,7 @@ Base.@propagate_inbounds function run_task(f::Fannkuch, perm::Perm, idxmin, idxm
end

id = Threads.threadid()
f.maxflips[id] = max(f.maxflips[id], maxflips)
(maxflips > f.maxflips[id]) && (f.maxflips[id] = maxflips)
f.chksums[id] += chksum
nothing
end
Expand Down Expand Up @@ -172,4 +172,4 @@ function fannkuchredux(n)
end

n = parse(Int, ARGS[1])
fannkuchredux(n)
fannkuchredux(n)