From e7e9a7389c98151689a794935d9570e8b39327aa Mon Sep 17 00:00:00 2001 From: antonl Date: Sun, 15 Mar 2026 13:02:55 +0100 Subject: [PATCH] some results but includes too big matrix for my RAM, start of C --- goSparseResults.json | 54 ++++++++++++++++++++++++++++++ src/main.c | 23 +++++++++++++ src/main.go | 46 +++++++++++++++++++++---- suitesparse_test_matrices/urls.txt | 13 +++++-- 4 files changed, 127 insertions(+), 9 deletions(-) create mode 100644 goSparseResults.json create mode 100644 src/main.c diff --git a/goSparseResults.json b/goSparseResults.json new file mode 100644 index 0000000..0d4d2b2 --- /dev/null +++ b/goSparseResults.json @@ -0,0 +1,54 @@ +[ + { + "label": "FEM_3D_thermal2", + "rows": 147900, + "cols": 147900, + "nnz": 3489300, + "matmul_runs": 16, + "matmul_total_ns": 1413419300, + "matmul_avg_ns": 88338706, + "matmul_output_nnz": 14335500, + "spmv_runs": 16, + "spmv_total_ns": 21010700, + "spmv_avg_ns": 1313168 + }, + { + "label": "ldoor", + "rows": 952203, + "cols": 952203, + "nnz": 23737339, + "matmul_runs": 16, + "matmul_total_ns": 6835373200, + "matmul_avg_ns": 427210825, + "matmul_output_nnz": 43783061, + "spmv_runs": 16, + "spmv_total_ns": 156246400, + "spmv_avg_ns": 9765400 + }, + { + "label": "Cube_Coup_dt0", + "rows": 2164760, + "cols": 2164760, + "nnz": 64685452, + "matmul_runs": 16, + "matmul_total_ns": 32192429900, + "matmul_avg_ns": 2012026868, + "matmul_output_nnz": 234465452, + "spmv_runs": 16, + "spmv_total_ns": 392950200, + "spmv_avg_ns": 24559387 + }, + { + "label": "nlpkkt240", + "rows": 27993600, + "cols": 27993600, + "nnz": 401232976, + "matmul_runs": 16, + "matmul_total_ns": 38319352500, + "matmul_avg_ns": 2394959531, + "matmul_output_nnz": 401232976, + "spmv_runs": 16, + "spmv_total_ns": 3164097400, + "spmv_avg_ns": 197756087 + } +] diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..463ea0e --- /dev/null +++ b/src/main.c @@ -0,0 +1,23 @@ +#include +#include +#include + +typedef int32_t S32; +typedef uint32_t U32; +typedef float F32; +typedef double F64; +typedef int32_t B32; + + + + +int main() { + + + + printf(" ******* \n HELLO WARRUDU \n ****); + + + + return 0; +} diff --git a/src/main.go b/src/main.go index 1dc44ec..f398ff2 100644 --- a/src/main.go +++ b/src/main.go @@ -2,6 +2,7 @@ package main import ( "bufio" + "encoding/json" "fmt" "os" "path/filepath" @@ -13,7 +14,7 @@ import ( "gonum.org/v1/gonum/mat" ) -var gNumTestIterations = 30 +var gNumTestIterations = 16 type SparseMatrixTiming struct { Label string `json:"label"` @@ -21,9 +22,10 @@ type SparseMatrixTiming struct { Cols int `json:"cols"` NNZ int `json:"nnz"` - MatMulRuns int `json:"matmul_runs"` - MatMulTotalNs int64 `json:"matmul_total_ns"` - MatMulAvgNs int64 `json:"matmul_avg_ns"` + MatMulRuns int `json:"matmul_runs"` + MatMulTotalNs int64 `json:"matmul_total_ns"` + MatMulAvgNs int64 `json:"matmul_avg_ns"` + MatMulOutputNNZ int `json:"matmul_output_nnz"` SpMVRuns int `json:"spmv_runs"` SpMVTotalNs int64 `json:"spmv_total_ns"` @@ -35,6 +37,21 @@ type SparseBenchmarkCase struct { Matrix *sparse.CSR } +func writeTimingJSON(all []SparseMatrixTiming, outPath string) { + f, err := os.Create(outPath) + if err != nil { + panic(err) + } + defer f.Close() + + enc := json.NewEncoder(f) + enc.SetIndent("", " ") + + if err := enc.Encode(all); err != nil { + panic(err) + } +} + // The "SuiteSparse" collection of matrices come in a format called // "market matrix" and so we parse and load them to a sparse.COO format here. func matrixLoadMarket(path string) *sparse.CSR { @@ -144,6 +161,7 @@ func timeSparseMatmuls(bcase *SparseBenchmarkCase) { panic("Sparsity pattern changed unexpectedly after matmul!") } + bcase.Timing.MatMulOutputNNZ = out.NNZ() bcase.Timing.MatMulRuns = numberOfMults bcase.Timing.MatMulTotalNs = timeElapsed.Nanoseconds() @@ -192,7 +210,7 @@ func timeNanoToMS(timeNS int64) float64 { return float64(timeNS) / float64(1e6) } -func doTimings(path string) { +func doTimings(path string) SparseMatrixTiming { bcase := getSparseBenchmarkCase(path) rows := bcase.Timing.Rows cols := bcase.Timing.Cols @@ -217,13 +235,27 @@ func doTimings(path string) { avgSpMVTimeMS := timeNanoToMS(bcase.Timing.SpMVAvgNs) fmt.Printf("Avg SpMV time for %s: %.4f ms\n", bcase.Timing.Label, avgSpMVTimeMS) } + + return bcase.Timing } func main() { mainBegin := time.Now() - thermal2Path := "suitesparse_test_matrices/thermal2.mtx" - doTimings(thermal2Path) + paths := []string{ + "suitesparse_test_matrices/FEM_3D_thermal2.mtx", + "suitesparse_test_matrices/ldoor.mtx", + "suitesparse_test_matrices/Cube_Coup_dt0.mtx", + "suitesparse_test_matrices/nlpkkt240.mtx", + } + + results := make([]SparseMatrixTiming, 0, len(paths)) + + for _, path := range paths { + results = append(results, doTimings(path)) + } + + writeTimingJSON(results, "goSparseResults.json") mainElapsed := time.Since(mainBegin) diff --git a/suitesparse_test_matrices/urls.txt b/suitesparse_test_matrices/urls.txt index aabe188..5171a86 100644 --- a/suitesparse_test_matrices/urls.txt +++ b/suitesparse_test_matrices/urls.txt @@ -1,6 +1,15 @@ # This is just a small matrix for debugging / validating code https://suitesparse-collection-website.herokuapp.com/MM/HB/1138_bus.tar.gz +# 3.5M NNZ 3d thermal problem +https://suitesparse-collection-website.herokuapp.com/MM/Botonakis/FEM_3D_thermal2.tar.gz -# This is a real large (not really, but ok) sparse matrix with 8.5 million non-zero elements -https://suitesparse-collection-website.herokuapp.com/MM/Schmid/thermal2.tar.gz +# Almost 43M NNZ, structural problem +https://suitesparse-collection-website.herokuapp.com/MM/GHS_psdef/ldoor.tar.gz + +# Almost 125M non-zero elements from a structural problem, 420mb compressed, 1.1GB uncompressed .mtx +https://suitesparse-collection-website.herokuapp.com/MM/Janna/Cube_Coup_dt0.tar.gz + +# 760M NNZ, optimization problem 1.23GB compressed, 8.4 GB uncompressed +# This was too large for my 32 GB memory and I went into swap... probably should exclude +https://suitesparse-collection-website.herokuapp.com/MM/Schenk/nlpkkt240.tar.gz \ No newline at end of file