#
# Simulation of Life Evolution
#
# Parallel computing (Degree in Computer Engineering)
# 2018/2019
#
# EduHPC 2020: Peachy assignment
#
# (c) 2020 Arturo Gonzalez-Escribano, Yuri Torres
# Grupo Trasgo, Universidad de Valladolid (Spain)
#
# This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
# https://creativecommons.org/licenses/by-sa/4.0/
#
#
# The current Parallel Computing course includes contests using:
# OpenMP, MPI, and CUDA.
#

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

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

# Targets to build
OBJS=evolution_seq evolution_omp evolution_mpi evolution_cuda

# Rules. By default show help
help:
	@echo
	@echo "Simulation of Life Evolution"
	@echo
	@echo "Group Trasgo, Universidad de Valladolid (Spain)"
	@echo "EduHPC 2020: Peachy assignment"
	@echo
	@echo "make evolution_seq	Build only the sequential version"
	@echo "make evolution_omp	Build only the OpenMP version"
	@echo "make evolution_mpi	Build only the MPI version"
	@echo "make evolution_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 clean	Remove targets"
	@echo

all: $(OBJS)

evolution_seq: evolution.c
	$(CC) $(DEBUG) $< $(LIBS) -o $@

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

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

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

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

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