Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
d008ad5
Add mtx_to_coo.fsx script
Danil-Zaripov Mar 2, 2026
7838382
Add experiments
Danil-Zaripov Mar 2, 2026
65fe942
Add more experiments and info in README.md
Danil-Zaripov Mar 3, 2026
69ec234
Add mtx_to_experiment.fsx script
Danil-Zaripov Mar 3, 2026
24b9a1d
Update README.md
Danil-Zaripov Mar 3, 2026
908d7a0
Account for the upper half in mtx
Danil-Zaripov Mar 3, 2026
15b1914
Add run_experiments.sh script and update README.md
Danil-Zaripov Mar 4, 2026
7a9d048
Add results_to_data.fsx script
Danil-Zaripov Mar 4, 2026
c496d80
Make results_to_data.fsx print matrix name
Danil-Zaripov Mar 7, 2026
df8f0d8
Update instructions in README.md
Danil-Zaripov Mar 7, 2026
844d851
Add 2 to threads count in run_experiments.sh
Danil-Zaripov Mar 10, 2026
36052a5
Basic tools for matrix reordering.
gsvgit Mar 11, 2026
9c1d756
Add default output filename for py script
Danil-Zaripov Mar 11, 2026
308e01c
Rewrite mtx_to_experiment adding no_duplicate
Danil-Zaripov Mar 11, 2026
dfeacde
Add support for tc experiments
Danil-Zaripov Mar 18, 2026
5ac4b6a
Add support for automised tc experiments
Danil-Zaripov Mar 18, 2026
d6f175f
Add support for automatised sssp experiments
Danil-Zaripov Mar 22, 2026
d882010
Add support for multiple bench runs
Danil-Zaripov Mar 27, 2026
013e05d
Add grabbing values on the edges from mtx
Danil-Zaripov Mar 27, 2026
d6c1557
Update README.md
Danil-Zaripov Apr 12, 2026
5d9c4fd
Add more scripts and fix experiments exit codes
Danil-Zaripov Apr 14, 2026
ed453b7
Fix end of file
Danil-Zaripov May 4, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
experiments_bfs/results/
experiments_bfs/data/

experiments_tc/results/
experiments_tc/data/

experiments_sssp/results/
experiments_sssp/data/
matrices/


inpla/

*.mtx
48 changes: 48 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,54 @@

QuadTree linear algebra implementation in Inpla.

# How to run experiments

* Make threaded patched Inpla from `experiments` branch:
```sh
git clone https://github.com/Lamagraph/inpla.git -b experiments

# Compile single-threaded version first (bug in vanilla Inpla):

make -C inpla && make -C inpla clean && make -C inpla thread
```

* Use `ulimit -s unlimited` for unlimited stack

* Run `./scripts/run_experiments.sh $PATH_TO_INPLA $MAX_THREADS $NUMBER_OF_RUNS $(bfs|tc|sssp)` to run all experiments in `./experiments_$(bfs|tc|sssp)/` directory and collect the results OR run the experiments yourself: `./inpla/inpla -f ./experiments_bfs/bcspwr10.in -t 4 -Xms 22 -Xmt 0 > ./my_4threaded_result.txt`

* Using all the memory necessary for running the experiment is preferred as it may increase performance. Use `-Xmt 0` to disable geometric memory consumption. Use `-Xms 22` or greater to use more memory from the start. Not doing that will drag down running speed significantly. Make sure not to overallocate. Do note that memory consumption is proportional to the number of threads used.

* After `./scripts/run_experiments.sh` you can `./scripts/results_to_data.fsx $(bfs|tc|sssp)` to extract data on algorithm time and conversion time ready to be plotted

* Download mtx matrices from SuiteSparse matrix collection and convert them to experiments using `./scripts/mtx_to_experiment.fsx $PATH_TO_MTX_MATRIX $(bfs|tc|sssp)`

# How to preprocess graphs

Structured matrices should better fit to quad-trees.

You can use `./scripts/simple_mtx_reordering.py` to reorder matrices stored in `mtx` files.

```bash
python reorder_mtx.py input.mtx output.mtx --method rcm
```

For visual control of reordering you can use `./scripts/draw_mtx_sparsity.py`

```bash
python spy_mtx.py original.mtx original_spy.png --title "Original Matrix"
```

## Examples of reordering

| Original | Reordered |
| :--- | :--- |
| webbase-1M.mtx |
| ![Original webbase-1M](reordering_figures/original_webbase.png) | ![Reordered webbase-1M](reordering_figures/reordered_webbase.png) |
| coAuthorsCiteseer.mtx |
| ![Original coAuthorsCiteseer](reordering_figures/original_coAuthors.png) | ![Reordered coAuthorsCiteseer](reordering_figures/reordered_coAuthors.png) |
| arc130.mtx |
| ![Original arc130](reordering_figures/original_arc_130.png) | ![Reordered arc130](reordering_figures/reordered_arc_130.png) |

# How to run golden tests

Ensure dotnet is installed.
Expand Down
13 changes: 13 additions & 0 deletions experiments_bfs/3elt_dual.in

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions experiments_bfs/G57.in

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions experiments_bfs/bcspwr10.in

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions experiments_bfs/cti.in

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions experiments_sssp/big_positive.in

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions experiments_sssp/psmigr_1.in

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions experiments_tc/1138_bus.in

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions experiments_tc/3elt_dual.in

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions experiments_tc/G57.in

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions experiments_tc/bcspwr10.in

Large diffs are not rendered by default.

Binary file added reordering_figures/original_arc_130.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added reordering_figures/original_coAuthors.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added reordering_figures/original_webbase.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added reordering_figures/reordered_arc_130.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added reordering_figures/reordered_coAuthors.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added reordering_figures/reordered_webbase.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
272 changes: 272 additions & 0 deletions scripts/common_get_experiment.fsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,272 @@
let getBigCoo (linewords: string array array) =
linewords
|> Array.map (fun x -> int x.[0] - 1, int x.[1] - 1)
|> Array.map (fun (i, j) -> sprintf "(%d, %d, 1)" i j)
|> String.concat ", "
|> sprintf "[%s]"

let getBigCooDuplicate (linewords: string array array) =
linewords
|> Array.map (fun x -> int x.[0] - 1, int x.[1] - 1)
|> Array.map (fun (i, j) -> sprintf "(%d, %d, 1), (%d, %d, 1)" i j j i)
|> String.concat ", "
|> sprintf "[%s]"

let getBigCooValues (linewords: string array array) =
linewords
|> Array.map (fun x -> int x.[0] - 1, int x.[1] - 1, int x.[2])
|> Array.map (fun (i, j, v) -> sprintf "(%d, %d, %d)" i j v)
|> String.concat ", "
|> sprintf "[%s]"

let getBigCooDuplicateValues (linewords: string array array) =
linewords
|> Array.map (fun x -> int x.[0] - 1, int x.[1] - 1, int x.[2])
|> Array.map (fun (i, j, v) -> sprintf "(%d, %d, %d), (%d, %d, %d)" i j v j i v)
|> String.concat ", "
|> sprintf "[%s]"

type BinSearchTree<'value> =
| Leaf of 'value
| Node of BinSearchTree<'value> * 'value * BinSearchTree<'value>

let powersOfTwo =
[ 1UL
2UL
4UL
8UL
16UL
32UL
64UL

128UL

256UL
512UL
1024UL
2048UL
4096UL
8192UL
16384UL

32768UL

65536UL
131072UL
262144UL
524288UL
1048576UL
2097152UL
4194304UL

8388608UL

16777216UL
33554432UL
67108864UL
134217728UL
268435456UL
536870912UL
1073741824UL

2147483648UL

4294967296UL
8589934592UL
17179869184UL
34359738368UL
68719476736UL
137438953472UL
274877906944UL

549755813888UL

1099511627776UL
2199023255552UL
4398046511104UL
8796093022208UL
17592186044416UL
35184372088832UL
70368744177664UL

140737488355328UL

281474976710656UL
562949953421312UL
1125899906842624UL
2251799813685248UL
4503599627370496UL
9007199254740992UL
18014398509481984UL

36028797018963970UL

72057594037927940UL
144115188075855870UL
288230376151711740UL
576460752303423500UL
1152921504606847000UL
2305843009213694000UL
4611686018427388000UL

9223372036854776000UL ]

let treeOfPowersOfTwo =
BinSearchTree.Node(
BinSearchTree.Node(
BinSearchTree.Node(
BinSearchTree.Node(BinSearchTree.Leaf(1UL), 2UL, BinSearchTree.Leaf(4UL)),
8UL,
BinSearchTree.Node(BinSearchTree.Leaf(16UL), 32UL, BinSearchTree.Leaf(64UL))
),
128UL,
BinSearchTree.Node(
BinSearchTree.Node(BinSearchTree.Leaf(256UL), 512UL, BinSearchTree.Leaf(1024UL)),
2048UL,
BinSearchTree.Node(BinSearchTree.Leaf(4096UL), 8192UL, BinSearchTree.Leaf(16384UL))
)
),
32768UL,
BinSearchTree.Node(
BinSearchTree.Node(
BinSearchTree.Node(BinSearchTree.Leaf(65536UL), 131072UL, BinSearchTree.Leaf(262144UL)),
524288UL,
BinSearchTree.Node(BinSearchTree.Leaf(1048576UL), 2097152UL, BinSearchTree.Leaf(4194304UL))
),
8388608UL,
BinSearchTree.Node(
BinSearchTree.Node(BinSearchTree.Leaf(16777216UL), 33554432UL, BinSearchTree.Leaf(67108864UL)),
134217728UL,
BinSearchTree.Node(BinSearchTree.Leaf(268435456UL), 536870912UL, BinSearchTree.Leaf(1073741824UL))
)
)
)

let getNearestUpperPowerOfTwo (x: uint64) =
let MAX = 9223372036854776000UL

let rec find tree rightBound =
match tree with
| BinSearchTree.Node(left, v, right) ->
if x = v then v
elif x < v then find left v
else find right rightBound
| BinSearchTree.Leaf(v) -> if x <= v then v else rightBound

if x = MAX then
MAX
elif x < MAX then
find treeOfPowersOfTwo 9223372036854776000UL
else
failwithf "Argument is too large. Must be not greater then %A" MAX

let getExperimentBfs nrows coo =
let ssize = int <| getNearestUpperPowerOfTwo (uint64 nrows)

sprintf
@"use ""./src/bfs.in"";

coo ~ %s;

const SSIZE=%d;
const LENGTH=%d;
SMFromCoordinateList(graph) ~ (LENGTH, LENGTH, SSIZE, coo);
vcoo ~ [(0, 1)];
SVFromCoordinateList(startVertices) ~ (LENGTH, SSIZE, vcoo);
bfs_level(r) ~ (graph, startVertices);
// To see the result: r; free r;

exit;
"
coo
ssize
nrows

let getExperimentTc nrows coo =
let ssize = int <| getNearestUpperPowerOfTwo (uint64 nrows)

sprintf
@"use ""./src/triangle_count.in"";

coo ~ %s;

const SSIZE=%d;
const LENGTH=%d;
SMFromCoordinateList(graph) ~ (LENGTH, LENGTH, SSIZE, coo);
triangle_count(r) ~ (graph);
// To see the result: r; free r;

exit;
"
coo
ssize
nrows

let getExperimentSSSP nrows coo =
let ssize = int <| getNearestUpperPowerOfTwo (uint64 nrows)

sprintf
@"use ""./src/sssp.in"";

coo ~ %s;

const SSIZE=%d;
const LENGTH=%d;
const STARTING_VERTEX=0;
SMFromCoordinateList(graph) ~ (LENGTH, LENGTH, SSIZE, coo);
sssp(r) ~ (graph, STARTING_VERTEX);
// To see the result: r; free r;

exit;
"
coo
ssize
nrows

type Algorithm =
| BFS
| TC
| SSSP

let getExperiment alg nrows coo =
match alg with
| BFS -> getExperimentBfs nrows coo
| TC -> getExperimentTc nrows coo
| SSSP -> getExperimentSSSP nrows coo

let usage =
$"Usage: {fsi.CommandLineArgs[0]} path/to/matrix.mtx (bfs|tc|sssp) ((true|false): OPTIONAL get values on the edges. Default: true for sssp, false otherwise)"

let getEdgeValues (args: string array) =
if args.Length < 4 then
None
else if args.[3] = "true" then
printfn "Getting the values on the edges"
Some true
else
printfn "Not getting the values on the edges"
Some false

let chooseValueCooFunc alg args =
let arg = getEdgeValues args

match arg with
| None -> alg = SSSP
| Some v -> v


let getAlgorithm (str: string) =
match str.ToLower() with
| "bfs" -> BFS
| "tc" -> TC
| "sssp" -> SSSP
| _ -> failwith usage

let experimentsPath algorithm =
match algorithm with
| BFS -> "./experiments_bfs/"
| TC -> "./experiments_tc/"
| SSSP -> "./experiments_sssp/"


let inplaExtension = ".in"
Loading
Loading