问题描述
当元素数量增加到相当大的大小时(大约 50 万个元素需要大约 1 秒,500 万个需要 10 秒),我在将一些带有位置数据的元素写入 netcdf 格式的文件时遇到了一些问题。用于与netcdf文件交互的库是sdsLite,编程语言是F#,但sdslite最初是用C#开发的。
//defining DataSet this happens once in the code...
type Writer = {
Ds : DataSet
First : bool
} with
static member New fp = {
Ds = DataSet ($"{fp}?openMode=create")
First = true
}
//this is called multiple times
let writetodisk (wr : Writer) (arr1 : int [,]) (arr2 : int [,]) (arr3 : int[,]) (arr4 : int[,]) =
if wr.First then
wr.Ds.Add("x",arr1,[| "time"; "element"|])
wr.Ds.Add("y",arr2,[| "time"; "element"|])
wr.Ds.Add("z",arr3,[| "time"; "element"|])
wr.Ds.Add("spawned_by",arr4,[| "time"; "element"|])
else
wr.Ds.Append("x",xAx) |> ignore
wr.Ds.Append("y",yAx) |> ignore
wr.Ds.Append("z",zAx) |> ignore
wr.Ds.Append("spawned_by",sb) |> ignore
wr.Ds.Commit ()
let run () =
let writer = Writer.New "file.nc"
let elements .. //initing 1000000 elements
for i in 0..4800 do
//doing work on elements...
writetodisk writer elements.X elements.Y elements.Z elements.SpawnedBy
在每个输入数组中使用 1M 元素运行 writetodisk 函数时,每次写入大约需要 9 秒。由于我必须为程序的单次运行编写大约 4800 次,因此这显然会很糟糕。
我想我可以尝试并行运行它,但似乎 sdslite 不允许这样做,因为此代码:
[|
async {
if wr.First then
wr.Ds.Add("x",[|"time"; "particle";|]) |> ignore
else
wr.Ds.Append("x",arr1) |> ignore
}
async {
if wr.First then
wr.Ds.Add("y",[|"time"; "particle";|]) |> ignore
else
wr.Ds.Append("y",arr2) |> ignore
}
async {
if wr.First then
wr.Ds.Add("z",[|"time"; "particle";|]) |> ignore
else
wr.Ds.Append("z",arr3) |> ignore
}
async {
if wr.First then
wr.Ds.Add("spawned_by",[|"time"; "particle";|]) |> ignore
else
wr.Ds.Append("spawned_by",arr4) |> ignore
}
|]
|> Async.Parallel
|> Async.RunSynchronously
|> fun x -> wr.Ds.Commit ()
在 SDSlite 中引发异常:Microsoft.Research.Science.Data.NetCDF4.NetCDFException: String match to name in use
我还能做些什么来加快速度吗?我对 HPC 还很陌生,此刻我感到有些失落。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)