ex2: re-add argc/argv interactivity
This commit is contained in:
+2
-2
@@ -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 $<
|
||||
|
||||
+14
-2
@@ -1,5 +1,6 @@
|
||||
#include <math.h>
|
||||
#include <mpi.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user