Educational material on the SciPy implementation of numerical linear algebra algorithms
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) {