Last active
June 23, 2022 16:11
-
-
Save sa-/8f2f05c7ec3950ce03f5420984964671 to your computer and use it in GitHub Desktop.
Parallel broadcast in julia
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function divide_range_into_max_n_chunks(r::UnitRange{Int64}, n::Int64) | |
range_length = r.stop - r.start | |
chunk_size = Int64(ceil(range_length / n)) | |
return [i:min(i + chunk_size - 1, r.stop) for i in r.start:chunk_size:r.stop] | |
end | |
macro parallel_broadcast(col_a, broadcasted_operator, col_b) | |
return (:macrocall, Symbol("@threads"), :(#= none:1 =#), (:for, (:(=), :subrange, (:call, :divide_range_into_n_chunks, (:call, :(:), 1, :df_length), (:call, :nthreads))), (:block, | |
:(#= none:2 =#), | |
(:(=), (:ref, :result_col, :subrange), (:call, broadcasted_operator, (:call, :view, col_a, :subrange), (:call, :view, col_b, :subrange))) | |
))) | |
end | |
#df_length = nrow(df) | |
#concatenated_col = Vector(undef, df_length) | |
#@threads for subrange in divide_range_into_max_n_chunks(1:df_length, nthreads()) | |
# concatenated_col[subrange] = view(df.input, subrange) .* view(df.target, subrange) | |
#end | |
@parallel_broadcast df.input .* df.target |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment