#
# Probabilistic approach to locate maximum heights
# Hill Climbing + Montecarlo
#
# Parallel computing (Degree in Computer Engineering)
# 2021/2022
#
# (c) 2022 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=climb_seq climb_omp climb_mpi climb_cuda

# Rules. By default show help
help:
	@echo
	@echo "Hill climbing with Montecarlo"
	@echo
	@echo "Group Trasgo, Universidad de Valladolid (Spain)"
	@echo
	@echo "make climb_seq	Build only the sequential version"
	@echo "make climb_omp	Build only the OpenMP version"
	@echo "make climb_mpi	Build only the MPI version"
	@echo "make climb_cuda	Build only the CUDA version"
	@echo
	@echo "make all	Build all versions (Sequential, OpenMP)"
	@echo "make debug	Build all version with demo output for small surfaces"
	@echo "make clean	Remove targets"
	@echo

all: $(OBJS)

climb_seq: climb.c
	$(CC) $(FLAGS) $(DEBUG) $< $(LIBS) -o $@

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

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

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


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

# Compile in debug mode
debug:
	make DEBUG="-DDEBUG -g" FLAGS= all

