diff --git a/Makefile b/Makefile old mode 100755 new mode 100644 index 6094ef5..06da859 --- a/Makefile +++ b/Makefile @@ -1,97 +1,124 @@ - -CFLAGS = $(shell gsl-config --cflags) -std=c++0x -##CFLAGS += -ggdb -gdwarf-2 -Wall -I include -O -CFLAGS +=-O3 -I include -##CFLAGS += -D _DEBUG # comment this line if you don't need compile with debug; if you don't need tracing function, define TRACING_DISABLED -MPCFLAG = -I /cm/shared/mpi/openmpi/2.1/intel/17.0/include -LIBS = $(shell gsl-config --libs) - -##CC = icpc -##MPCC = mpiicpc +# +# Update 2020-01-06: +# o Use VPATH for finding cpp file in different directories -- this simplifies rules +# o Abort if gsl-config isn't available +# o Fixed (INTEL) compiler search 0=found | 1=notfound ; make conditional simple (ifeq 0|1) +# o Also use conditional for GCC +# o For objects, use basename to get base file name +# o Clean up directory prefix (shorten variable names and group) +# o Simplified obj and bin rule logic and readability. +# o put rules in canonical order +# -- now the makefile looks a bit cleaner Kent milfeld@tacc.utexas.edu +# +# TODO: use function to create VPATH +# TODO: Fix MPI after learning purpose +# TODO: Make rules for *.hpp's +# +# +VPATH=src/boundary_conditions:src/classes:src/io:src/math:src/parser:src/reactions:src/system_setup:src/trajectory_functions BDIR = bin ODIR = obj SDIR = src EDIR = EXEs -EPDIR = EXE_PAR -OS := $(shell uname) -INTEL := $(shell which icpc) +EPDIR = EXE_PAR + +.PHONY: any + +# REQUIREMENTS: gls and directories -ifndef INTEL - CC = g++ - MPCC = mpicxx +hasGSL = $(shell type gsl-config >/dev/null 2>&1; echo $$?) +ifeq ($(hasGSL),1) +$(error " GSL must be installed, and gsl-config must be in path.") else - CC = icpc - MPCC = mpiicpc +$(shell mkdir -p bin) +$(shell mkdir -p obj) endif -##ifeq ($(OS),Linux) -## _OBJS = $(shell find $(SDIR) -name "*.cpp" | sed -r 's/(\.cc|.cpp)/.o/') -##else - _OBJS = $(shell find $(SDIR) -name "*.cpp" | sed -E 's/(\.cc|.cpp)/.o/' | sed -E 's/src/./') -##endif +# EXECUTABLE SETUP for serial, MPI, OpenMP (omp) +# +ifeq (serial,$(MAKECMDGOALS)) + _EXEC = nerdss +endif -_EXECUTABLES = nerdss \ -## template \ -## test_angles \ -## test_loops \ -## rd_gen_reweightPBC \ - rd_boundfraconly \ +ifeq (mpi,$(MAKECMDGOALS)) + _EXEC = nerdss_mpi + DEFS = -DMPI +endif -_PAREXECUTABLES = nerdss_mpi \ +ifeq (omp,$(MAKECMDGOALS)) + _EXEC = nerdss_omp + DEFS = -DOMP + PLANG = -fopenmp +endif +ifeq (clean,$(MAKECMDGOALS)) + MAKECMDGOALS = dummy +endif + EXEC = $(patsubst %,$(BDIR)/%,$(_EXEC)) -OBJS = $(patsubst %,$(ODIR)/%,$(_OBJS)) -EXECUTABLES = $(patsubst %,$(BDIR)/%,$(_EXECUTABLES)) +OS := $(shell uname) +INTEL = $(shell type icpc >/dev/null 2>&1; echo $$?) +GCC = $(shell type g++ >/dev/null 2>&1; echo $$?) -PAREXECUTABLES = $(patsubst %,$(BDIR)/%,$(_PAREXECUTABLES)) +CFLAGS = $(shell gsl-config --cflags) -std=c++0x +LIBS = $(shell gsl-config --libs) +#---------------COMPILER SETUP -_SOURCES = ${_EXECUTABLES:=.cpp} -SOURCES = $(patsubst %,$(EDIR)/%,$(_SOURCES)) +ifeq ($(GCC),0) # Found/Use Intel icpc compiler + CC = g++ + MPCC = mpicxx + CFLAGS += -O3 -I include +# MPCFLAG = -I /cm/shared/mpi/openmpi/2.1/intel/17.0/include +endif -_PARSOURCES = ${_PAREXECUTABLES:=.cpp} -PARSOURCES = $(patsubst %,$(EPDIR)/%,$(_PARSOURCES)) +ifeq ($(INTEL),0) # Found/Use Intel icpc compiler + CC = icpc + MPCC = mpicxx + CFLAGS += -O3 -I include +endif +#---------------OBJECT FILES -all: dirs $(EXECUTABLES) -#$(PAREXECUTABLES) +ifeq ($(OS),Linux) + _OBJS = $(shell find $(SDIR) -name "*.cpp" | xargs -n 1 basename | sed -r 's/(\.cc|.cpp)/.o/') +else + _OBJS = $(shell find $(SDIR) -name "*.cpp" | xargs -n 1 basename | sed -E 's/(\.cc|.cpp)/.o/') +endif -$(ODIR)/%.o: $(SDIR)/%.cpp - @echo "Compiling $<" - $(CC) $(CFLAGS) $(CFLAGS2) -c $< -o $@ - @echo "------------" + OBJS = $(patsubst %,$(ODIR)/%,$(_OBJS)) -$(EXECUTABLES): $(OBJS) - @echo "Compiling $(EDIR)/$(@F).cpp" - $(CC) $(CFLAGS) $(CFLAGS2) -o $@ $(EDIR)/$(@F).cpp $(OBJS) $(LIBS) - @echo "------------" -$(PAREXECUTABLES): $(OBJS) - @echo "Compiling $(EPDIR)/$(@F).cpp" - $(MPCC) $(CFLAGS) $(CFLAGS2) -o $@ $(EPDIR)/$(@F).cpp $(OBJS) $(LIBS) - @echo "------------" +#---------------RULES + +syntax: + @echo "------------------------------------" + @printf '\033[31m%s\033[0m\n' " USAGE: make serial|mpi|omp" + @echo "------------------------------------" + exit 0 +# Rules: for $(MAKECMDGOALS) serial, mpi, or omp build +# $(EXEC) bin/nerdss, bin/nerdss_mpi or /binnerdss_omp +$(MAKECMDGOALS):$(EXEC) + @echo "Finished making (re-)building $(MAKECMDGOALS) version, $(EXEC)." -dirs: - mkdir -p bin - mkdir -p obj - mkdir -p obj/classes - mkdir -p obj/math - mkdir -p obj/parser - mkdir -p obj/shared - mkdir -p obj/reactions - mkdir -p obj/system_setup - mkdir -p obj/boundary_conditions - mkdir -p obj/trajectory_functions - mkdir -p obj/io +$(EXEC): $(OBJS) + @echo "Compiling $(EDIR)/$(@F).cpp" + $(CC) $(CFLAGS) $(CFLAGS2) -o $@ $(EDIR)/$(@F).cpp -Iinclude $(OBJS) $(LIBS) $(PLANG) + @echo "------------" +obj/%.o: %.cpp + @echo "Compiling $< at $(