Skip to content

Commit 853c3b9

Browse files
committed
DGraph: Add cluster load/save support
1 parent e6a647f commit 853c3b9

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

lib/DaggerGraphs/Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ version = "0.1.0"
55

66
[deps]
77
Dagger = "d58978e5-989f-55fb-8d15-ea34adc7bf54"
8+
DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab"
89
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
910
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
1011
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"

lib/DaggerGraphs/src/DaggerGraphs.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export DGraph
1111
include("dgraph.jl")
1212
include("adjlist.jl")
1313
include("edgeiter.jl")
14+
include("io.jl")
1415
include("tables.jl")
1516

1617
function DGraph{T}(x; kwargs...) where T

lib/DaggerGraphs/src/io.jl

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using DelimitedFiles
2+
3+
function load_dir(dir::String; freeze::Bool=false)
4+
files = map(file->joinpath(dir, file), readdir(dir))
5+
part_files = filter(file->endswith(file, ".part.lgz"), files)
6+
back_files = filter(file->endswith(file, ".back.txt"), files)
7+
dg = DGraph()
8+
for file in part_files
9+
g = loadgraph(file)
10+
add_partition!(dg, g)
11+
end
12+
for file in back_files
13+
stat(file).size > 0 || continue
14+
edges = readdlm(file)
15+
srcs = edges[:,1]
16+
dsts = edges[:,2]
17+
add_edges!(dg, zip(srcs, dsts))
18+
end
19+
freeze && freeze!(dg)
20+
return dg
21+
end
22+
function save_dir(dir::String, g)
23+
mkpath(dir)
24+
nd = ndigits(nparts(g))
25+
for part in 1:nparts(g)
26+
part_name = lpad(part, nd, '0')
27+
sg = get_partition(g, part)
28+
savegraph(joinpath(dir, part_name*".part.lgz"), sg)
29+
bg = map(Tuple, edges(get_background(g, part)))
30+
writedlm(joinpath(dir, part_name*".back.txt"), bg)
31+
end
32+
end

0 commit comments

Comments
 (0)