From 0bc467e89839b1453813681fb21997ecbf76db07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luca=20Pep=C3=A8=20Sciarria?= Date: Thu, 10 Apr 2025 16:12:30 +0200 Subject: [PATCH] init spmm output checker --- test/spmm/spmm_checker.c | 64 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/test/spmm/spmm_checker.c b/test/spmm/spmm_checker.c index d7e0ddea..7bdbd899 100644 --- a/test/spmm/spmm_checker.c +++ b/test/spmm/spmm_checker.c @@ -1,3 +1,67 @@ +/* Test program for checking if two arrays (output of alpha*A*x + beta*y) are the same +* Check the README.md to see all details about the tests. +* +* Author: Luca Pepé Sciarria, Staccone Simone (Tor Vergata University) +*/ + + + + + +#include +#include +#include + +void compare_files(const char *file1, const char *file2) { + FILE *file_s = fopen(file1, "r"); + FILE *file_p = fopen(file2, "r"); + + if (!file_s || !file_p) { + perror("Error opening files"); + exit(EXIT_FAILURE); + } + + int n_s, n_p; + fscanf(file_s, "%d", &n_s); + fscanf(file_p, "%d", &n_p); // Assuming both files have the same number of lines + + if (n_s != n_p) { + fprintf(stderr, "Error, differnet file sizes $d, $d", n_s, n_p); + exit(EXIT_FAILURE); + } + + double value_s, value_p; + + + for (int i = 0; i < n_s; i++) { + fscanf(file_s, "%lf", &value_s); + fscanf(file_p, "%lf", &value_p); + + if (value_s != value_p) { + printf("Index %d: %.2lf != %.2lf\n", i, value_s, value_p); + } + } + + fclose(file_s); + fclose(file_p); +} + +int main(int argc, char *argv[]) { + if (argc != 2) { + fprintf(stderr, "Usage: %s \n", argv[0]); + return EXIT_FAILURE; + } + + char file_s[256], file_p[256]; + snprintf(file_s, sizeof(file_s), "%s_serial.txt", argv[1]); + snprintf(file_p, sizeof(file_p), "%s_parallel.txt", argv[1]); + + compare_files(file_s, file_p); + + return EXIT_SUCCESS; +} + + #include #include #include