Skip to content

Commit

Permalink
Change makefile structure
Browse files Browse the repository at this point in the history
Get tool info from TOOLS variable and use base makefile for rules.
Doesn't copy src files/makefile into build dirs.
  • Loading branch information
Jason Sewall committed Feb 19, 2019
1 parent eeb25f5 commit 7bc4388
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 121 deletions.
136 changes: 39 additions & 97 deletions target/Makefile
Original file line number Diff line number Diff line change
@@ -1,110 +1,52 @@
# Multiple-machine Makefile
srcdir=.
include $(srcdir)/Makefile.$(TOOLS)

SHELL = /bin/sh
PREFIX?=.

# Files
ROOT=miniMD
TARGETS=
TARGETS+=$(PREFIX)/$(ROOT)_$(TOOLS)
CLEANFILES=$(TARGETS)

SRC = ljs.cpp input.cpp integrate.cpp atom.cpp force_lj.cpp neighbor.cpp \
OBJ_DIR=$(PREFIX)/Obj_$(TOOLS)

all: $(TARGETS)

#=======================================================================

SRC=ljs.cpp input.cpp integrate.cpp atom.cpp force_lj.cpp neighbor.cpp \
thermo.cpp comm.cpp timer.cpp output.cpp setup.cpp
INC = ljs.h atom.h force.h neighbor.h thermo.h timer.h comm.h integrate.h threadData.h variant.h openmp.h \
INC=ljs.h atom.h force.h neighbor.h thermo.h timer.h comm.h integrate.h threadData.h variant.h openmp.h \
types.h miniMD_math.h

# Definitions

ROOT = miniMD
EXE = $(ROOT)_$@
OBJ = $(SRC:.cpp=.o)

# Help

help:
@echo 'Type "make target {Options}" where target is one of:'
@echo ' openmpi (using OpenMPI)'
@echo ' intel (using intelMPI)'
@echo ' clang (using MPI-Stubs)'
@echo ' cray (using CrayCompiler for CPUs)'
@echo ' cray_intel (using Cray Wrapper for Intel compiler for CPUs)'
@echo 'Options (not all of which apply for each target):'
@echo ' KNC=yes (compile for XeonPhi)'
@echo ' SP=yes (compile for single precision [32bit floats])'
@echo ' DEBUG=yes (compile debug mode)'
@echo ' AVX=yes (compile for avx [DEFAULT])'
@echo ' SIMD=yes (use "pragma simd" [DEFAULT])'
@echo ' RED_PREC=yes (use reduced precision math intrinsics)'
@echo ' ANSI_ALIAS=yes (compile with ansi-alias flag)'
@echo ' GSUNROLL=yes (compile with flags for XeonPhi which unroll gather/scatter operations [DEFAULT])'
@echo ' LIBRT=yes (use librt for timing [more precise])'
@echo ' PAD=[3,4] (pad data to 3 or 4 elements [default 3 = no padding])'
@echo '(Good) Examples:'
@echo ' Modern CPUs (Intel Sandy Bridge, AMD Interlagos or newer):'
@echo ' make openmpi -j 32'
@echo ' Intel Xeon Phi:'
@echo ' make intel -j 32 KNC=yes ANSI_ALIAS=yes SIMD=no'

# Targets

openmpi:
@if [ ! -d Obj_$@ ]; then mkdir Obj_$@; fi
@cp -p $(SRC) $(INC) Obj_$@
@cp Makefile.$@ Obj_$@/Makefile
@cd Obj_$@; \
$(MAKE) "OBJ = $(OBJ)" "INC = $(INC)" "EXE = ../$(EXE)" ../$(EXE)
# @if [ -d Obj_$@ ]; then cd Obj_$@; rm $(SRC) $(INC) Makefile*; fi

cray:
@if [ ! -d Obj_$@ ]; then mkdir Obj_$@; fi
@cp -p $(SRC) $(INC) Obj_$@
@cp Makefile.$@ Obj_$@/Makefile
@cd Obj_$@; \
$(MAKE) "OBJ = $(OBJ)" "INC = $(INC)" "EXE = ../$(EXE)" ../$(EXE)

cray_intel:
@if [ ! -d Obj_$@ ]; then mkdir Obj_$@; fi
@cp -p $(SRC) $(INC) Obj_$@
@cp Makefile.$@ Obj_$@/Makefile
@cd Obj_$@; \
$(MAKE) "OBJ = $(OBJ)" "INC = $(INC)" "EXE = ../$(EXE)" ../$(EXE)

intel:
@if [ ! -d Obj_$@ ]; then mkdir Obj_$@; fi
@cp -p $(SRC) $(INC) Obj_$@
@cp Makefile.$@ Obj_$@/Makefile
@cd Obj_$@; \
$(MAKE) "OBJ = $(OBJ)" "INC = $(INC)" "EXE = ../$(EXE)" ../$(EXE)
# @if [ -d Obj_$@ ]; then cd Obj_$@; rm $(SRC) $(INC) Makefile*; fi

clang:
if [ ! -d Obj_$@ ]; then mkdir Obj_$@; fi
@cp -p $(SRC) $(INC) Obj_$@
@cp -r -p MPI-Stubs Obj_$@
@cp Makefile.$@ Obj_$@/Makefile
@cd Obj_$@; \
$(MAKE) "OBJ = $(OBJ)" "INC = $(INC)" "EXE = ../$(EXE)" ../$(EXE)


# Clean
OBJ_base = $(SRC:.cpp=.o)
OBJ= $(addprefix $(OBJ_DIR)/,$(OBJ_base))
DEP_base = $(SRC:.cpp=.d)
DEP= $(addprefix $(OBJ_DIR)/,$(DEP_base))

clean:
rm -r Obj_*
LDFLAGS = $(COMMON_LDFLAGS)

clean_openmpi:
rm -r Obj_openmpi
$(OBJ): | $(OBJ_DIR)

clean_intel:
rm -r Obj_intel
$(DEP): | $(OBJ_DIR)

clean_cray:
rm -r Obj_cray

clean_cray_intel:
rm -r Obj_cray_intel
$(OBJ_DIR):
mkdir -p $(OBJ_DIR)

# Test
$(OBJ_DIR)/%.o: $(srcdir)/%.cpp $(INC) $(srcdir)/Makefile $(srcdir)/Makefile.$(TOOLS)
$(OBJ_DIR)/%.o: $(srcdir)/%.cpp $(OBJ_DIR)/%.d $(srcdir)/Makefile $(srcdir)/Makefile.$(TOOLS)
$(CC) -o $@ -c $< $(CCFLAGS) -MD

scope=0
input=lj
halfneigh=0
path=""
-include $(DEPS)

$(PREFIX)/$(ROOT)_$(TOOLS): $(OBJ) $(srcdir)/Makefile $(srcdir)/Makefile.$(TOOLS)
$(LINK) $(OBJ) $(LINKFLAGS) $(USRLIB) $(SYSLIB)-o $@
$(SIZE) $@

CLEANFILES += $(OBJ)
CLEANFILES += $(DEP)

clean:
rm -rf $(CLEANFILES)

test:
bash run_tests ${scope} ${input} ${halfneigh} ${path}
#=======================================================================
32 changes: 8 additions & 24 deletions target/Makefile.clang
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ SIMD = no


CC = clang++
CCFLAGS = -O3 -I ./MPI-Stubs/ -fopenmp
CCFLAGS = -O3 -I $(srcdir)/MPI-Stubs/ -fopenmp -MD
LINK = clang++
LINKFLAGS = -O3 -fopenmp
USRLIB = -L ./MPI-Stubs/ -l mpi_stubs
SYSLIB =
USRLIB = -L $(srcdir)/MPI-Stubs/ -lmpi_stubs
SYSLIB =
SIZE = size

ifeq ($(SIMD), yes)
Expand All @@ -29,13 +29,13 @@ LINKFLAGS += -ffast-math
endif

ifeq ($(PAD), 3)
CCFLAGS += -DPAD=3
LINKFLAGS += -DPAD=3
CCFLAGS += -DPAD=3
LINKFLAGS += -DPAD=3
endif

ifeq ($(PAD), 4)
CCFLAGS += -DPAD=4
LINKFLAGS += -DPAD=4
CCFLAGS += -DPAD=4
LINKFLAGS += -DPAD=4
endif

ifeq ($(DEBUG), yes)
Expand All @@ -44,7 +44,7 @@ LINKFLAGS += -g -debug inline-debug-info
endif

ifeq ($(SP), yes)
CCFLAGS += -DPRECISION=1
CCFLAGS += -DPRECISION=1
LINKFLAGS += -DPRECISION=1
else
CCFLAGS += -DPRECISION=2
Expand All @@ -65,19 +65,3 @@ ifeq ($(OFFLOAD), nvptx)
CCFLAGS += -fopenmp-targets=nvptx64-nvidia-cuda -DUSE_OFFLOAD
LINKFLAGS += -fopenmp-targets=nvptx64-nvidia-cuda
endif

# Link rule

$(EXE): $(OBJ)
$(LINK) $(OBJ) $(LINKFLAGS) $(USRLIB) $(SYSLIB) -o $(EXE)
$(SIZE) $(EXE)


# Compilation rules

.cpp.o:
$(CC) $(CCFLAGS) -c $*.cpp -o $*.o

# Individual dependencies

$(OBJ): $(INC)

0 comments on commit 7bc4388

Please sign in to comment.