Closed jihoonseo closed 8 years ago
The latest master seems to work just fine.
However, the use of matrix multiply *
is really unnecessary. Note that *
is currently not handled by ParallelAccelerator, and matrix multiplication in Julia becomes a ccall
to native library such as MKL. Here what you had was not a matrix by matrix, but matrix by vector, which becomes serial code in Julia.
So I suggest instead the following program, and call it with 1-D array [0,1,0,1]
(instead of 2-D [0 1 0 1]
)
@acc function bi2de(binaryArray)
z = 2.^(0:1:length(binaryArray)-1);
return sum(binaryArray.*z)
end
This also works with ParallelAccelerator and has the benefit of parallelizing the .*
operator.
1)
After switching to the latest master, MethodError
does not appear.
2)
I was able to convert 2-D array [0 1 0 1]
to 1-D array [0, 1, 0, 1]
with reshape()
.
using ParallelAccelerator
@acc function bi2de(binaryArray)
binaryArray = reshape(binaryArray, length(binaryArray));
z = 2 .^ (0:1:length(binaryArray)-1);
return sum(binaryArray .* z)
end
result = bi2de([0 1 1 1])
println(result)
This code runs with no warnings and errors.
Thank you for your comment.
Hi I've been trying to apply ParallelAccelerator to my code, and some errors aroused. (I am not sure whether there will exist some performance gain with parallelization or not, and if someone points that there will not, then I will not use parallelization on this function.)
bi2de()
is a function that converts a binary array that LSB (least significant bit) is on the left to a decimal number.FYI: You may test
bi2de()
with[0 1 0 1]
, likebi2de([0 1 0 1])
->10
.When I call this function, an error occurs:
And I don't know which part causes an error..
I would appreciate your comments.