Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

Commit

Permalink
Copied pattern_match_reduce_sum from HPAT. If in distributed mode and…
Browse files Browse the repository at this point in the history
… depth = 1 then pattern match reductionFunc for sum and if present then add reduction(+:rdvar) to rdsclause. If in distributed mode and depth 1 and some rdsclause was present then add #pragma simd before the loop.
  • Loading branch information
DrTodd13 committed Dec 7, 2016
1 parent ebdbb2c commit 8d35d2f
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/cgen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1997,6 +1997,21 @@ end
# mode = 2 does all of the above
# mode = 3 in addition to 2, also uses host minimum (0) and Phi minimum (10)

function pattern_match_reduce_sum(reductionFunc::DelayedFunc,linfo)
reduce_box = reductionFunc.args[1][1].args[2]
@assert reduce_box.args[1]==GlobalRef(Core.Intrinsics,:box) "invalid reduction function"
if reduce_box.args[3].args[1].name==:add_float || reduce_box.args[3].args[1].name==:add_int
return true
end
return false
end

function pattern_match_reduce_sum(reductionFunc::GlobalRef,linfo)
if reductionFunc.name==:add_float || reductionFunc.name==:add_int
return true
end
return false
end

function from_parforstart(args, linfo)
global lstate
Expand Down Expand Up @@ -2106,6 +2121,11 @@ function from_parforstart(args, linfo)
rdsextra *= "$rdvtyp &shared_$(rdvar) = $(rdvar)_vec[omp_get_thread_num()];\n"
rdsextra *= "$rdvtyp $(rdvar) = shared_$(rdvar);\n"
else
if isDistributedMode() && lstate.ompdepth == 1
if pattern_match_reduce_sum(rd.reductionFunc, linfo)
rdsclause *= "reduction(+: $(rdvar)) "
end
end
# The init is now handled in pre-statements
#rdsprolog *= from_reductionVarInit(rd.reductionVarInit, rdv, linfo)
# parallel IR no longer produces reductionFunc as a symbol
Expand All @@ -2118,6 +2138,12 @@ function from_parforstart(args, linfo)
@dprintln(3, "rdsprolog = ", rdsprolog)
@dprintln(3, "rdsclause = ", rdsclause)

if isDistributedMode() && lstate.ompdepth == 1 && rdsclause != ""
s *= "$rdsprolog #pragma simd $rdsclause\n"
s *= loopheaders
return s
end

# Don't put openmp pragmas on nested parfors.
if USE_OMP==0 || lstate.ompdepth > 1
# Still need to prepend reduction variable initialization for non-openmp loops.
Expand Down

0 comments on commit 8d35d2f

Please sign in to comment.