Skip to content

Commit

Permalink
Fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Mellich committed Feb 28, 2023
1 parent a7bcc8c commit 9d3e792
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 27 deletions.
2 changes: 1 addition & 1 deletion example/mpi_trapezoidal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ tape_merged = MPITape.merge()
if rank == 0 # Master
MPITape.print_merged(tape_merged)
display(MPITape.plot_sequence_merged(tape_merged))
MPITape.plot_merged(tape_merged)
MPITape.plot_merged(tape_merged)
end

# MPITape.save()
Expand Down
2 changes: 1 addition & 1 deletion example_collectives/mpi_trapezoidal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ tape_merged = MPITape.merge()
if rank == 0 # Master
MPITape.print_merged(tape_merged)
display(MPITape.plot_sequence_merged(tape_merged))
MPITape.plot_merged(tape_merged)
MPITape.plot_merged(tape_merged)
end

# MPITape.save()
Expand Down
20 changes: 11 additions & 9 deletions src/communication_graph.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

function _srcdest_to_rankarray(srcdest)
if srcdest in ["all", "each", "some"]
return collect(0:getcommsize()-1)
return collect(0:(getcommsize() - 1))
end
if typeof(srcdest) <: Integer
return [srcdest]
Expand Down Expand Up @@ -36,7 +36,7 @@ function MPIEventNeighbors(ev::MPIEvent)
end
if length(opendests) == 1 && (opendests[1] in opensrcs)
deleteat!(opensrcs, findfirst(isequal(opendests[1]), opensrcs))
end
end
# remove other ranks on own communication side
if ev.rank in opendests
opendests = [ev.rank]
Expand All @@ -52,7 +52,7 @@ $(SIGNATURES)
Generates the edges of a directed communication graph, where the edges represent
communication between two MPIEvents.
"""
function get_edges(tape::Array{MPIEvent}; check=true)
function get_edges(tape::Array{MPIEvent}; check = true)
# Data structure containing communication edges
edges = Tuple{MPIEvent, MPIEvent}[]
# temporary data to keep track of left communication pairs
Expand All @@ -75,27 +75,29 @@ function get_edges(tape::Array{MPIEvent}; check=true)
verbose() && println("Check: $recvevent")
# identify receive call and matching signature
if d == recvevent.rank &&
any(e.rank == s for s in l_recv.open_srcs) &&
gettag(e) == gettag(recvevent)
any(e.rank == s for s in l_recv.open_srcs) &&
gettag(e) == gettag(recvevent)
verbose() && println("Matched $(e) and $(recvevent)")
deleteat!(l_recv.open_srcs,findfirst(x->x==e.rank, l_recv.open_srcs))
deleteat!(l_recv.open_srcs,
findfirst(x -> x == e.rank, l_recv.open_srcs))
push!(found_dsts, d)
push!(edges, (e, recvevent))
break
end
end
end
deleteat!(l.open_dst,findall(x->any(x==d for d in found_dsts), l.open_dst))
deleteat!(l.open_dst, findall(x -> any(x == d for d in found_dsts), l.open_dst))
# check for errors in graph
if !isempty(l.open_dst)
check && error("Not all destinations found for $(e): $(l.open_dst)")
end
deleteat!(l.open_srcs,findfirst(x->x==e.rank, l.open_srcs))
deleteat!(l.open_srcs, findfirst(x -> x == e.rank, l.open_srcs))
end
end
for (ol, e) in zip(open_links, tape)
if !isempty(ol.open_srcs)
check && error("Not all transmissions are linked correctly: Sources left: $(ol.open_srcs) $(e)")
check &&
error("Not all transmissions are linked correctly: Sources left: $(ol.open_srcs) $(e)")
end
end
return edges
Expand Down
2 changes: 1 addition & 1 deletion src/mpievent.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ function gettag(ev::MPIEvent)
return ev.args_subset[:tag]
end
return nothing
end
end
12 changes: 6 additions & 6 deletions src/mpifuncs_overdubbing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ for (mpifunc, srcdest) in MPIFunctions
start_time = MPI.Wtime() - TIME_START[]
ret = f(args...)
push!(TAPE,
MPIEvent(rank,
string(f),
argtypes,
argvals,
start_time,
MPI.Wtime() - TIME_START[]))
MPIEvent(rank,
string(f),
argtypes,
argvals,
start_time,
MPI.Wtime() - TIME_START[]))
return ret
end
end)
Expand Down
22 changes: 13 additions & 9 deletions src/plotting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,33 @@ using Kroki

function _plot_edges(edges::Array{Tuple{MPIEvent, MPIEvent}})
for (src, dst) in edges
plot!([src.t_end,dst.t_end], [src.rank, dst.rank], arrow=true, color=:black, label="")
plot!([src.t_end, dst.t_end], [src.rank, dst.rank], arrow = true, color = :black,
label = "")
end
end

function _event_to_rect(ev::MPIEvent; color=:blue)
plot!(Shape([ev.t_start, ev.t_end, ev.t_end, ev.t_start],
[ev.rank - 0.25, ev.rank - 0.25, ev.rank + 0.25, ev.rank + 0.25]), color=color,
label="")
function _event_to_rect(ev::MPIEvent; color = :blue)
plot!(Shape([ev.t_start, ev.t_end, ev.t_end, ev.t_start],
[ev.rank - 0.25, ev.rank - 0.25, ev.rank + 0.25, ev.rank + 0.25]),
color = color,
label = "")
end

"""
$(SIGNATURES)
Plots a gannt chart of the recorded MPI API calls and store it to a file.
Additionally draws arrows between communicating MPIEvents.
"""
function plot_merged(tape::Array{MPIEvent}; palette=palette(:Accent_8), fname="gantt.png")
function plot_merged(tape::Array{MPIEvent}; palette = palette(:Accent_8),
fname = "gantt.png")
plot()
unique_calls = unique([ev.f for ev in tape])
for mpievent in tape
_event_to_rect(mpievent, color=palette[findall(x->x==mpievent.f, unique_calls)[1]])
_event_to_rect(mpievent,
color = palette[findall(x -> x == mpievent.f, unique_calls)[1]])
end
for (col, call) in zip(palette[1:length(unique_calls)], unique_calls)
plot!(Shape([0],[0]), color=col, label=string(call))
plot!(Shape([0], [0]), color = col, label = string(call))
end
edges = get_edges(tape)
_plot_edges(edges)
Expand All @@ -51,4 +55,4 @@ Plot a sequence diagram of the communication between ranks.
function plot_sequence_merged(tape)
edges = get_edges(tape)
return plantuml"$(_generate_plantuml(edges))"
end
end

0 comments on commit 9d3e792

Please sign in to comment.