ex2: make parallel job init

This commit is contained in:
2025-09-10 17:51:06 +02:00
parent e2a04f7cc0
commit efd1fa4922
2 changed files with 16 additions and 3 deletions

View File

@@ -2,9 +2,11 @@ CC := gcc
CFLAGS := -Wall -Wextra -std=c17
SRC := mandel_mpi.c
TARGET := $(SRC:.c=)
ARGS := 1
OUTDIR := out
OUT := $(OUTDIR)/$(TARGET)
ARGS := 1
NBENCH := 1
NPROC := 3
.PHONY: all clean run
@@ -12,7 +14,7 @@ all: clean run
$(TARGET): $(SRC)
mkdir -p $(OUTDIR)
$(CC) $(CFLAGS) -o $(OUTDIR)/$@ $<
$(CC) $(CFLAGS) -o $(OUT) $<
run: $(TARGET)
cd $(OUTDIR) && ./$< $(ARGS)
@@ -21,4 +23,8 @@ clean:
rm -rf $(OUTDIR)
time: $(TARGET)
python3 bench.py '$(OUTDIR)/$(TARGET) 0' $(NBENCH)
python3 bench.py './$(OUT) 0' $(NBENCH)
parallel: $(SRC)
mpicc -o $(OUT) $(SRC)
mpirun -np $(NPROC) $(OUT)

View File

@@ -1,4 +1,5 @@
#include <math.h>
#include <mpi.h>
#include <stdio.h>
#include <stdlib.h>
@@ -81,6 +82,11 @@ void fancycolour(uchar *p, int iter) {
}
int main(int argc, char **argv) {
MPI_Init(&argc, &argv);
int rank, size;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
printf("hello from rank %d/%d", rank, size);
if (argc == 1) {
puts("Usage: MANDEL n");
puts("n decides whether image should be written to disk (1=yes, 0=no)");
@@ -107,5 +113,6 @@ int main(int argc, char **argv) {
/* write image to disk */
savebmp("mandel.bmp", buffer, XSIZE, YSIZE);
}
MPI_Finalize();
return 0;
}