From c39150b27aa523cfe6bd399087577fe8ee913d6a Mon Sep 17 00:00:00 2001 From: fredrikr79 Date: Thu, 11 Sep 2025 11:55:18 +0200 Subject: [PATCH] ex2: re-add argc/argv interactivity --- exercise2/Makefile | 4 ++-- exercise2/mandel_mpi.c | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/exercise2/Makefile b/exercise2/Makefile index 666c2fe..fc8584d 100644 --- a/exercise2/Makefile +++ b/exercise2/Makefile @@ -8,7 +8,7 @@ ARGS := 1 NBENCH := 1 NPROC := 3 -.PHONY: all clean run +.PHONY: all clean run parallel all: clean parallel show @@ -26,7 +26,7 @@ time: $(TARGET) parallel: $(SRC) mpicc -o $(OUT) $(SRC) - cd $(OUTDIR) && mpirun -np $(NPROC) $(TARGET) + cd $(OUTDIR) && mpirun -np $(NPROC) $(TARGET) $(ARGS) show: $(OUTDIR)/mandel.bmp feh $< diff --git a/exercise2/mandel_mpi.c b/exercise2/mandel_mpi.c index cf8ef36..f729a8f 100644 --- a/exercise2/mandel_mpi.c +++ b/exercise2/mandel_mpi.c @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -24,6 +25,7 @@ typedef struct { } complex_t; int rank, size; +bool save = false; void calculate() { for (int i = 0; i < XSIZE; i++) { @@ -85,6 +87,15 @@ void fancycolour(uchar *p, int iter) { } int main(int argc, char **argv) { + if (argc <= 1) { + printf("usage: mandel_mpi [y/n]\n"); + printf("y/n denotes if you want to save the resulting\n"); + printf("calculations to mandel.bmp or not.\n"); + return 1; + } else { + char arg = argv[1][0]; + save = arg == 'y' || arg == '1'; + } MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &size); @@ -137,8 +148,9 @@ int main(int argc, char **argv) { #undef YSIZE #define YSIZE 2048 - savebmp("mandel.bmp", total, XSIZE, YSIZE); - printf("after save\n"); + if (save) + savebmp("mandel.bmp", total, XSIZE, YSIZE); + printf("after save %d\n", save); } MPI_Finalize();