numeric-linalg

Educational material on the SciPy implementation of numerical linear algebra algorithms

Commit
6b443bd3d0dc759bc717df8f899c0b3af78baf47
Parent
829c3b808899c85c458c48c4f741a2c1469aa68b
Author
Pablo <pablo-pie@riseup.net>
Date

Made benchmark targets runtime args" "Made different benchmark targets runtime arguments instead of compiletime flags

Diffstat

4 files changed, 25 insertions, 21 deletions

Status File Name N° Changes Insertions Deletions
Modified getrf/benchmark/build.sh 5 2 3
Modified getrf/benchmark/main.c 41 23 18
Renamed getrf/benchmark/histogram-dgetrf.bin -> getrf/benchmark/output/histogram-dgetrf.bin 0 0 0
Renamed getrf/benchmark/histogram-naive.bin -> getrf/benchmark/output/histogram-naive.bin 0 0 0
diff --git a/getrf/benchmark/build.sh b/getrf/benchmark/build.sh
@@ -9,8 +9,7 @@ C_FLAGS="-Wall -Wextra $LD_FLAGS"
 ctags -R .
 
 # debug version
-cc ./main.c -o "./target/$EXE_NAME-debug" $C_FLAGS  -fsanitize=address -g -DDEBUG 
+cc ./main.c -o "./target/$EXE_NAME-debug" $C_FLAGS  -fsanitize=address -g
 
-# release versions
+# release version
 cc ./main.c -o "./target/$EXE_NAME"       $C_FLAGS -O2        
-cc ./main.c -o "./target/$EXE_NAME-naive" $C_FLAGS -O2 -DBENCHMARKNAIVE
diff --git a/getrf/benchmark/main.c b/getrf/benchmark/main.c
@@ -19,6 +19,7 @@
 #include "progress-bar.h"
 
 uint32_t histogram[HISTOGRAM_SIZE];
+void (*getrf)(int *m, int *n, double *A, int *lda, int *ipiv, int *info);
 
 // .data is a pointer because it should be allocated in the heap
 // (.data DOES NOT fit in the stack 🤡)
@@ -53,11 +54,7 @@ uint32_t thread_run_benchmark(Thread *thread, size_t n)
     l_n = n; l_m = n; lda = n;
 
     start = clock();
-#ifdef BENCHMARKNAIVE
-    dgetrfnaive_(&l_m, &l_n, thread->data, &lda, thread->ipiv, &info);
-#else
-    dgetrf_(&l_m, &l_n, thread->data, &lda, thread->ipiv, &info);
-#endif // BENCHMARKNAIVE
+    getrf(&l_m, &l_n, thread->data, &lda, thread->ipiv, &info);
     end = clock();
     total_time += (end - start)/CLOCKS_PER_MILLIS;
   }
@@ -118,20 +115,20 @@ void benchmarker_run(Benchmarker *bench)
   }
 }
 
-int main(void)
+int main(int argc, char **argv)
 {
-#ifdef BENCHMARKNAIVE
-  const char *output_path = "histogram-naive.bin";
-#else
-  const char *output_path = "histogram-dgetrf.bin";
-#endif // BENCHMARKNAIVE
-  FILE *output = fopen(output_path, "w");
-
-  if (output == NULL) {
-    fprintf(stderr,
-            "ERROR: Coundn't open output file \"%s\": %s",
-            output_path, strerror(errno));
-    return EXIT_FAILURE;
+  const char *output_path;
+
+  if (argc < 2 || strcmp(argv[1], "standard") == 0) {
+    getrf = dgetrf_;
+    output_path = "output/histogram-dgetrf.bin";
+  } else if (strcmp(argv[1], "naive") == 0) {
+    getrf = dgetrfnaive_;
+    output_path = "output/histogram-naive.bin";
+  } else {
+    fprintf(stderr, "ERROR: unknown command \"%s\"\n", argv[1]);
+    fprintf(stderr, "USAGE: %s [standard|naive]\n", argv[0]);
+    exit(EXIT_FAILURE);
   }
 
   // ========================================================================
@@ -162,6 +159,14 @@ int main(void)
   // ========================================================================
   printf("INFO: Done with benchmarking! Saving histogram to disk...\n");
 
+  FILE *output = fopen(output_path, "w");
+
+  if (output == NULL) {
+    fprintf(stderr,
+            "ERROR: Coundn't open output file \"%s\": %s",
+            output_path, strerror(errno));
+    return EXIT_FAILURE;
+  }
   size_t written = fwrite(histogram, sizeof(uint32_t), HISTOGRAM_SIZE, output);
 
   if (written < HISTOGRAM_SIZE) {
diff --git a/getrf/benchmark/histogram-dgetrf.bin b/getrf/benchmark/output/histogram-dgetrf.bin
Binary files differ.
diff --git a/getrf/benchmark/histogram-naive.bin b/getrf/benchmark/output/histogram-naive.bin
Binary files differ.