#
# Simulation of rainwater flooding
# 
#
# Parallel computing (Degree in Computer Engineering)
# 2024/2025
#
# (c) 2025 Arturo Gonzalez-Escribano
# Grupo Trasgo, Universidad de Valladolid (Spain)
#

# Compilers
CC=gcc
OMPFLAG=-fopenmp
MPICC=mpicc
CUDACC=nvcc

# Flags for optimization and libs
FLAGS=-O3 -Wall
LIBS=-lm

# Targets to build
OBJS=flood_seq flood_omp flood_mpi

# Rules. By default show help
help:
	@echo
	@echo "Simulation of rainwater flooding"
	@echo
	@echo "Group Trasgo, Universidad de Valladolid (Spain)"
	@echo
	@echo "make flood_seq	Build only the sequential version"
	@echo "make flood_omp	Build only the OpenMP version"
	@echo "make flood_mpi	Build only the MPI version"
	@echo "make flood_cuda	Build only the CUDA version"
	@echo
	@echo "make all	Build all versions (Sequential, OpenMP, MPI, CUDA)"
	@echo "make debug	Build all version with demo output for small surfaces"
	@echo "make animation	Build the sequential version to produce the animation data"
	@echo "make clean	Remove targets"
	@echo

all: $(OBJS)

flood_seq: flood.c
	$(CC) $(FLAGS) $(DEBUG) $< $(LIBS) -o $@

flood_omp: flood_omp.c
	$(CC) $(FLAGS) $(DEBUG) $(OMPFLAG) $< $(LIBS) -o $@

flood_mpi: flood_mpi.c
	$(MPICC) $(FLAGS) $(DEBUG) $< $(LIBS) -o $@

flood_cuda: flood_cuda.cu
	$(CUDACC) $(DEBUG) $< $(LIBS) -o $@


# Remove the target files
clean:
	rm -rf $(OBJS)

# Compile in debug mode
debug:
	make FLAGS="$(FLAGS) -DDEBUG -g" flood_seq

# Compile to generate animation
animation:
	make FLAGS="$(FLAGS) -DDEBUG -DANIMATION -g" flood_seq

