IntelLabs / ParallelAccelerator.jl

The ParallelAccelerator package, part of the High Performance Scripting project at Intel Labs
BSD 2-Clause "Simplified" License
294 stars 32 forks source link

Comprehensions Error #114

Open Wajihulhassan opened 8 years ago

Wajihulhassan commented 8 years ago

I am trying out following example of Comprehensions with ParallelAccelerator but it is throwing error.

julia> @acc f(a,b)=[ x for x in a ]
f (generic function with 1 method)

julia> f([1,2,3],2)
OptFramework failed to optimize function ##f#11563 in optimization pass ParallelAccelerator.Driver.toDomainIR with error from_expr: unknown Expr head :static_typeof
ERROR: MethodError: `step` has no method matching step(::Array{Int64,1})
 in anonymous at /home/whassan/.julia/v0.4/ParallelAccelerator/src/comprehension.jl:76
 in cartesianarray at /home/whassan/.julia/v0.4/ParallelAccelerator/src/api.jl:174
 [inlined code] from /home/whassan/.julia/v0.4/ParallelAccelerator/src/comprehension.jl:73
 in ##f#11563 at none:1
 in f at /home/whassan/.julia/v0.4/CompilerTools/src/OptFramework.jl:577

I also added type annotation like in black-scholes example but it didn't work either.

ninegua commented 8 years ago

Unfortunately I realized that our macro translation for comprehension does not yet support syntax such as [... for x in a] when a is an array. ParallelAccelerator only works when a is a range. I'm not even sure there is a simple fix to this, unless we move to using generators as in Julia's own implementation. But generators are sequential by nature, and hard to parallelize.

So I would suggest instead using map for situations like this. For example, map(x -> x, a) would be equivalent.

I also tried map(x -> x ? 1 : 0, (a .== b)), as you raised the question of converting bitarray to array of int in the other thread. This had a problem with Julia 0.4, and is now fixed by commit bbd8796a36e6db0bd24040190b040f5d732349a8. However, Julia 0.5 itself (not ParallelAccelerator) has trouble dealing with this expression. So the conversion is still best handed by multiplying Bool with Int.