【问题标题】:Multi threading for reading CSV Files in Julia用于在 Julia 中读取 CSV 文件的多线程
【发布时间】:2021-01-18 17:42:44
【问题描述】:

有没有办法在 Julia 的 CSV.read 上实现多线程? Parallelism for reading a large file in Julia 中提供了一个读取大文件的好例子。 但由于我必须经常更改我的数据集,这些方法可能不适用。

using CSV
file = ("C:\\Users\\User\\Desktop\\Datasets\\X_train_sat4.csv")
@time df = CSV.read(file, DataFrame)

Output:
69.469112 seconds (6.29 M allocations: 9.767 GiB, 0.76% gc time)
29723 rows × 2456 columns

我已经使用了Speed up loading and compilation time 此处推荐的步骤,但这些步骤只改善了第一次加载时间。

提前致谢!

【问题讨论】:

    标签: multithreading csv julia


    【解决方案1】:

    CSV.jl 支持多线程。您可以使用 tasks 关键字参数选择要使用的线程数。您不能使用超过启动 Julia 进程的线程数。

    以下是读取具有 10^8 行和 10 列的文件的示例时序:

    julia> @time CSV.read("test.csv", DataFrame, tasks=1); # one thread
     75.190387 seconds (23.24 M allocations: 9.253 GiB, 1.24% gc time)
    
    julia> @time CSV.read("test.csv", DataFrame, tasks=2); # two threads
     43.078513 seconds (4.34 M allocations: 8.044 GiB, 2.30% gc time)
    

    默认使用的任务数设置为Threads.nthreads()

    【讨论】:

      猜你喜欢
      • 2021-04-16
      • 2013-03-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-05
      相关资源
      最近更新 更多