-
Notifications
You must be signed in to change notification settings - Fork 88
BSc thesis "Coloring Data Race Interference Graphs" #2061
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
sim642
wants to merge
11
commits into
master
Choose a base branch
from
race-coloring
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+298
−3
Draft
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
357beca
Add graph coloring algorithms
vaartnou eb9e9d8
Add race graph coloring
vaartnou d48f2c2
Make race coloring per component
vaartnou 2ca1b6d
Add ocamlgraph to locked dependencies
sim642 7706507
Inline Access.InterferenceGraph.Vertex
sim642 6d33962
Extract goblint.ocamlgraph library
sim642 bd6dc3d
Remove now-unused Access.InterferenceGraph.of_warn_accs
sim642 901a7d2
Simplify warn.race-coloring option handling
sim642 35e8e53
Simplify Access.InterferenceGraph
sim642 73ba8f4
Move Access.InterferenceGraph down
sim642 7abfd0e
Simplify graph coloring module usage in Access
sim642 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,213 @@ | ||
| module Make (G : Graph.Coloring.G) = struct | ||
| module C = Graph.Coloring.Make (G) | ||
| module IntSet = Set.Make (Int) | ||
|
|
||
| type coloring = int C.H.t | ||
|
|
||
| module type ALGORITHM = sig | ||
| val color : G.t -> coloring | ||
| end | ||
|
|
||
| let k_color g k = C.coloring g k | ||
| let color_with (module A : ALGORITHM) g = A.color g | ||
| let color_of coloring v = C.H.find_opt coloring v | ||
| let colors_used coloring = C.H.fold (fun _ c acc -> max acc c) coloring 0 | ||
|
|
||
| module Greedy : ALGORITHM = struct | ||
| let color g = | ||
| let n = G.nb_vertex g in | ||
| let coloring = C.H.create n in | ||
| let vertices = | ||
| G.fold_vertex (fun v acc -> (G.out_degree g v, v) :: acc) g [] | ||
| |> List.sort (fun (d1, _) (d2, _) -> compare d2 d1) | ||
| |> List.map snd | ||
| in | ||
| let next_color v = | ||
| let used = ref IntSet.empty in | ||
| G.iter_succ (fun u -> | ||
| match C.H.find_opt coloring u with | ||
| | None -> () | ||
| | Some c -> used := IntSet.add c !used | ||
| ) g v; | ||
| let rec pick c = | ||
| if IntSet.mem c !used then | ||
| pick (c + 1) | ||
| else | ||
| c | ||
| in | ||
| pick 1 | ||
| in | ||
| List.iter (fun v -> C.H.add coloring v (next_color v)) vertices; | ||
| coloring | ||
| end | ||
|
|
||
| module Optimal : ALGORITHM = struct | ||
| let color g = | ||
| let max_colors = max 1 (G.nb_vertex g) in | ||
| let rec loop k = | ||
| if k > max_colors then | ||
| raise Graph.Coloring.NoColoring | ||
| else | ||
| try C.coloring g k with | ||
| | Graph.Coloring.NoColoring -> loop (k + 1) | ||
| in | ||
| loop 1 | ||
| end | ||
|
|
||
| module Dsatur : ALGORITHM = struct | ||
| let color g = | ||
| let n = G.nb_vertex g in | ||
| let coloring = C.H.create n in | ||
| let saturation = C.H.create n in | ||
| let degree = C.H.create n in | ||
| G.iter_vertex (fun v -> | ||
| C.H.replace saturation v IntSet.empty; | ||
| C.H.replace degree v (G.out_degree g v) | ||
| ) g; | ||
| let is_colored v = C.H.mem coloring v in | ||
| let sat_count v = | ||
| match C.H.find_opt saturation v with | ||
| | None -> 0 | ||
| | Some s -> IntSet.cardinal s | ||
| in | ||
| let choose_vertex () = | ||
| let pick v best_opt = | ||
| if is_colored v then | ||
| best_opt | ||
| else | ||
| match best_opt with | ||
| | None -> Some v | ||
| | Some best -> | ||
| let sv = sat_count v in | ||
| let sb = sat_count best in | ||
| if sv > sb then | ||
| Some v | ||
| else if sv < sb then | ||
| Some best | ||
| else ( | ||
| let dv = C.H.find degree v in | ||
| let db = C.H.find degree best in | ||
| if dv > db then Some v else Some best | ||
| ) | ||
| in | ||
| G.fold_vertex pick g None | ||
| in | ||
| let pick_color v = | ||
| let used = | ||
| match C.H.find_opt saturation v with | ||
| | None -> IntSet.empty | ||
| | Some s -> s | ||
| in | ||
| let rec pick c = | ||
| if IntSet.mem c used then | ||
| pick (c + 1) | ||
| else | ||
| c | ||
| in | ||
| pick 1 | ||
| in | ||
| let rec loop () = | ||
| match choose_vertex () with | ||
| | None -> () | ||
| | Some v -> | ||
| let c = pick_color v in | ||
| C.H.add coloring v c; | ||
| G.iter_succ (fun u -> | ||
| if not (is_colored u) then | ||
| let s = | ||
| match C.H.find_opt saturation u with | ||
| | None -> IntSet.empty | ||
| | Some s -> s | ||
| in | ||
| C.H.replace saturation u (IntSet.add c s) | ||
| ) g v; | ||
| loop () | ||
| in | ||
| loop (); | ||
| coloring | ||
| end | ||
|
|
||
| module Rlf : ALGORITHM = struct | ||
| module VSet = struct | ||
| let create n = C.H.create n | ||
| let mem s v = C.H.mem s v | ||
| let add s v = C.H.replace s v () | ||
| let remove s v = C.H.remove s v | ||
| end | ||
|
|
||
| let color g = | ||
| let n = G.nb_vertex g in | ||
| let coloring = C.H.create n in | ||
| let uncolored = VSet.create n in | ||
| G.iter_vertex (fun v -> VSet.add uncolored v) g; | ||
| let degree v = G.out_degree g v in | ||
| let pick_start () = | ||
| G.fold_vertex (fun v best -> | ||
| if not (VSet.mem uncolored v) then | ||
| best | ||
| else | ||
| match best with | ||
| | None -> Some v | ||
| | Some b -> | ||
| if degree v > degree b then Some v else Some b | ||
| ) g None | ||
| in | ||
| let add_forbidden forbidden v = | ||
| G.iter_succ (fun u -> | ||
| if VSet.mem uncolored u then | ||
| VSet.add forbidden u | ||
| ) g v | ||
| in | ||
| let candidate_score forbidden v = | ||
| let count = ref 0 in | ||
| G.iter_succ (fun u -> | ||
| if VSet.mem forbidden u then | ||
| incr count | ||
| ) g v; | ||
| !count | ||
| in | ||
| let pick_candidate forbidden = | ||
| G.fold_vertex (fun v best -> | ||
| if not (VSet.mem uncolored v) || VSet.mem forbidden v then | ||
| best | ||
| else | ||
| match best with | ||
| | None -> Some v | ||
| | Some b -> | ||
| let sv = candidate_score forbidden v in | ||
| let sb = candidate_score forbidden b in | ||
| if sv > sb then | ||
| Some v | ||
| else if sv < sb then | ||
| Some b | ||
| else if degree v > degree b then | ||
| Some v | ||
| else | ||
| Some b | ||
| ) g None | ||
| in | ||
| let rec color_class color = | ||
| match pick_start () with | ||
| | None -> () | ||
| | Some v0 -> | ||
| let forbidden = VSet.create n in | ||
| let add_vertex v = | ||
| C.H.add coloring v color; | ||
| VSet.remove uncolored v; | ||
| add_forbidden forbidden v | ||
| in | ||
| add_vertex v0; | ||
| let rec fill () = | ||
| match pick_candidate forbidden with | ||
| | None -> () | ||
| | Some v -> | ||
| add_vertex v; | ||
| fill () | ||
| in | ||
| fill (); | ||
| color_class (color + 1) | ||
| in | ||
| color_class 1; | ||
| coloring | ||
| end | ||
| end |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| (include_subdirs no) | ||
|
|
||
| (library | ||
| (name goblint_ocamlgraph) | ||
| (public_name goblint.ocamlgraph) | ||
| (libraries | ||
| ocamlgraph) | ||
| (instrumentation (backend bisect_ppx))) |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| (** OCamlgraph library extensions which are completely independent of Goblint. *) | ||
|
|
||
| module Coloring = Coloring |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be some explanation of what this would achieve from a user-level perspective.