From 35ced559ffd8e1487a16f22f437e4b7a2337127c Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Fri, 29 Nov 2013 13:36:06 -0500 Subject: [PATCH] Added CMakeLists.txt. --- src/CMakeLists.txt | 148 +++++++++++++++++++++++ src/Makefile | 289 ++------------------------------------------- 2 files changed, 156 insertions(+), 281 deletions(-) create mode 100644 src/CMakeLists.txt diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000000..5f4a6608f4 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,148 @@ +cmake_minimum_required(VERSION 2.8 FATAL_ERROR) +project(openmc Fortran) + +#=============================================================================== +# Command line options +#=============================================================================== + +option(openmp "Enable shared-memory parallelism with OpenMP" OFF) +option(profile "Compile with profiling flags" OFF) +option(hdf5 "Enable HDF5 binary output" OFF) +option(petsc "Enable PETSC for use in CMFD acceleration" OFF) +option(debug "Compile with debug flags" OFF) +option(optimize "Turn on all compiler optimization flags" OFF) + +#=============================================================================== +# MPI for distributed-memory parallelism +#=============================================================================== + +if($ENV{FC} MATCHES "mpi*") + find_package(MPI REQUIRED) + add_definitions(-DMPI) + include_directories(BEFORE "${MPI_Fortran_INCLUDE_PATH}") + set(f90flags ${MPI_Fortran_COMPILE_FLAGS} ${f90flags}) + set(libraries ${MPI_Fortran_LIBRARIES} ${libraries}) +endif() + +#=============================================================================== +# Set compile/link flags based on which compiler is being used +#=============================================================================== + +if(CMAKE_Fortran_COMPILER_ID STREQUAL "GNU") + # GNU Fortran compiler options + set(f90flags "-cpp -std=f2008 -fbacktrace") + if(debug) + set(f90flags "-g -Wall -pedantic -fbounds-check -ffpe-trap=invalid,overflow,underflow ${f90flags}") + set(ldflags "-g") + endif() + if(profile) + set(f90flags "-pg ${f90flags}") + set(ldflags "-pg ${ldflags}") + endif() + if(optimize) + set(f90flags "-O3 ${f90flags}") + endif() + if(openmp) + set(f90flags "-fopenmp ${f90flags}") + set(ldflags "-fopenmp ${ldflags}") + add_definitions(-DOPENMP) + endif() + +elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "Intel") + # Intel Fortran compiler options + set(f90flags "-fpp -warn -assume byterecl -traceback") + if(debug) + set(f90flags "-g -ftrapuv -fp-stack-check -check all -fpe0 ${f90flags}") + set(ldflags "-g") + endif() + if(profile) + set(f90flags "-pg ${f90flags}") + set(ldflags "-pg ${ldflags}") + endif() + if(optimize) + set(f90flags "-O3 ${f90flags}") + endif() + if(openmp) + set(f90flags "-openmp ${f90flags}") + set(ldflags "-openmp ${ldflags}") + add_definitions(-DOPENMP) + endif() + +elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "PGI") + # PGI Fortran compiler options + set(f90flags "-Mpreprocess -Minform=inform -traceback") + add_definitions(-DNO_F2008) + if(debug) + set(f90flags "-g -Mbounds -Mchkptr -Mchkstk ${f90flags}") + set(ldflags "-g") + endif() + if(profile) + set(f90flags "-pg ${f90flags}") + set(ldflags "-pg ${ldflags}") + endif() + if(optimize) + set(f90flags "-fast -Mipa ${f90flags}") + endif() + +elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "XL") + # IBM XL compiler options + set(f90flags "-WF,-DNO_F2008 -O2") + if(debug) + set(f90flags "-g -C -qflag=i:i -u") + set(ldflags "-g") + endif() + if(profile) + set(f90flags "-p ${f90flags}") + set(ldflags "-p ${ldflags}") + endif() + if(optimize) + set(f90flags "-O3 ${f90flags}") + endif() + if(openmp) + set(f90flags "-qsmp=omp -WF,-DOPENMP ${f90flags}") + set(ldflags "-qsmp=omp ${ldflags}") + endif() + +elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "Cray") + # Cray Fortran compiler options + set(f90flags "-e Z -m 0") + if(debug) + set(f90flags "-g -R abcnsp -O0 ${f90flags}") + set(ldflags "-g") + endif() + +endif() + +#=============================================================================== +# HDF5 for binary output +#=============================================================================== + +if(hdf5) + find_package(HDF5 COMPONENTS Fortran Fortran_HL REQUIRED) + add_definitions(-DHDF5) + include_directories(BEFORE ${HDF5_INCLUDE_DIRS}) + set(libraries ${HDF5_LIBRARIES} ${HDF5_Fortran_LIBRARIES} ${HDF5_Fortran_HL_LIBRARIES} ${libraries}) +endif() + +#=============================================================================== +# PETSc for CMFD functionality +#=============================================================================== + +#=============================================================================== +# FoX Fortran XML Library +#=============================================================================== + +file(GLOB_RECURSE source_fox xml/*.F90) +add_library(fox STATIC ${source_fox}) + +#=============================================================================== +# Build OpenMC executable +#=============================================================================== + +set(program "openmc") +file(GLOB source *.F90) +add_executable(${program} ${source}) +target_link_libraries(${program} ${libraries} fox) +set_target_properties(${program} PROPERTIES + COMPILE_FLAGS "${f90flags}" + COMPILE_DEFINITIONS "${definitions}") diff --git a/src/Makefile b/src/Makefile index 03c370e07a..7b292eca7d 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,283 +1,10 @@ -program = openmc -prefix = /usr/local - -source = $(wildcard *.F90) -objects = $(source:.F90=.o) -xml_lib = -Lxml/lib -lxml - -#=============================================================================== -# User Options -#=============================================================================== - -COMPILER = gnu -DEBUG = no -PROFILE = no -OPTIMIZE = no -MPI = no -OPENMP = no -HDF5 = no -PETSC = no - -#=============================================================================== -# External Library Paths -#=============================================================================== - -MPI_DIR = /opt/mpich/3.0.4-$(COMPILER) -HDF5_DIR = /opt/hdf5/1.8.11-$(COMPILER) -PHDF5_DIR = /opt/phdf5/1.8.11-$(COMPILER) -PETSC_DIR = /opt/petsc/3.4.2-$(COMPILER) - -#=============================================================================== -# Add git SHA-1 hash -#=============================================================================== - -GIT_SHA1 = $(shell git log -1 2>/dev/null | head -n 1 | awk '{print $$2}') - -#=============================================================================== -# GNU Fortran compiler options -#=============================================================================== - -ifeq ($(COMPILER),gnu) - F90 = gfortran - F90FLAGS := -cpp -std=f2008 -fbacktrace - LDFLAGS = - - # Debugging - ifeq ($(DEBUG),yes) - F90FLAGS += -g -Wall -pedantic -fbounds-check \ - -ffpe-trap=invalid,overflow,underflow - LDFLAGS += -g - endif - - # Profiling - ifeq ($(PROFILE),yes) - F90FLAGS += -pg - LDFLAGS += -pg - endif - - # Optimization - ifeq ($(OPTIMIZE),yes) - F90FLAGS += -O3 - endif -endif - -#=============================================================================== -# Intel Fortran compiler options -#=============================================================================== - -ifeq ($(COMPILER),intel) - F90 = ifort - F90FLAGS := -fpp -std08 -assume byterecl -traceback - LDFLAGS = - - # Debugging - ifeq ($(DEBUG),yes) - F90FLAGS += -g -warn -ftrapuv -fp-stack-check -check all -fpe0 - LDFLAGS += -g - endif - - # Profiling - ifeq ($(PROFILE),yes) - F90FLAGS += -pg - LDFLAGS += -pg - endif - - # Optimization - ifeq ($(OPTIMIZE),yes) - F90FLAGS += -O3 - endif -endif - -#=============================================================================== -# PGI compiler options -#=============================================================================== - -ifeq ($(COMPILER),pgi) - F90 = pgf90 - F90FLAGS := -Mpreprocess -DNO_F2008 -Minform=inform -traceback - LDFLAGS = - - # Debugging - ifeq ($(DEBUG),yes) - F90FLAGS += -g -Mbounds -Mchkptr -Mchkstk - LDFLAGS += -g - endif - - # Profiling - ifeq ($(PROFILE),yes) - F90FLAGS += -pg - LDFLAGS += -pg - endif - - # Optimization - ifeq ($(OPTIMIZE),yes) - F90FLAGS += -fast -Mipa - endif -endif - -#=============================================================================== -# IBM XL compiler options -#=============================================================================== - -ifeq ($(COMPILER),ibm) - F90 = xlf2003 - F90FLAGS := -WF,-DNO_F2008 -O2 - - # Debugging - ifeq ($(DEBUG),yes) - F90FLAGS += -g -C -qflag=i:i -u - LDFLAGS += -g - endif - - # Profiling - ifeq ($(PROFILE),yes) - F90FLAGS += -p - LDFLAGS += -p - endif - - # Optimization - ifeq ($(OPTIMIZE),yes) - F90FLAGS += -O3 - endif -endif - -#=============================================================================== -# Cray compiler options -#=============================================================================== - -ifeq ($(COMPILER),cray) - F90 = ftn - F90FLAGS := -e Z -m 0 - - # Debugging - ifeq ($(DEBUG),yes) - F90FLAGS += -g -R abcnsp -O0 - LDFLAGS += -g - endif -endif - -#=============================================================================== -# Setup External Libraries -#=============================================================================== - -# MPI for distributed-memory parallelism and HDF5 for I/O - -ifeq ($(MPI),yes) - ifeq ($(HDF5),yes) - F90 = $(PHDF5_DIR)/bin/h5pfc - F90FLAGS += -DHDF5 - else - F90 = $(MPI_DIR)/bin/mpif90 - endif - F90FLAGS += -DMPI -else - ifeq ($(HDF5),yes) - F90 = $(HDF5_DIR)/bin/h5fc - F90FLAGS += -DHDF5 - endif -endif - -# OpenMP for shared-memory parallelism - -ifeq ($(OPENMP),yes) - ifeq ($(COMPILER),intel) - F90FLAGS += -openmp -DOPENMP - LDFLAGS += -openmp - endif - - ifeq ($(COMPILER),gnu) - F90FLAGS += -fopenmp -DOPENMP - LDFLAGS += -fopenmp - endif - - ifeq ($(COMPILER),ibm) - F90FLAGS += -qsmp=omp -WF,-DOPENMP - LDFLAGS += -qsmp=omp - endif -endif - -# PETSC for CMFD functionality - -ifeq ($(PETSC),yes) - # Check to make sure MPI is set - ifneq ($(MPI),yes) - $(error MPI must be enabled to compile with PETSC!) - endif - - # Set up PETSc environment - include $(PETSC_DIR)/conf/petscvariables - F90FLAGS += -I$(PETSC_DIR)/include -DPETSC - LDFLAGS += $(PETSC_LIB) -endif - -#=============================================================================== -# Machine-specific setup -#=============================================================================== - -# IBM Blue Gene/P ANL supercomputer - -ifeq ($(MACHINE),bluegene) - F90 = /bgsys/drivers/ppcfloor/comm/xl/bin/mpixlf2003 - F90FLAGS = -WF,-DNO_F2008,-DMPI -O3 - LDFLAGS = -lmpich.cnkf90 -endif - -# Cray XK6 ORNL Titan supercomputer - -ifeq ($(MACHINE),crayxk6) - F90 = ftn - F90FLAGS += -DMPI -endif - -# IBM Blue Gene/Q ANL supercomputer - -ifeq ($(MACHINE),bluegeneq) - F90 = mpixlf2003 - F90FLAGS = -WF,-DNO_F2008,-DMPI -O5 -endif - -#=============================================================================== -# Targets -#=============================================================================== - -all: xml $(program) -xml: - cd xml; make MACHINE=$(MACHINE) F90=$(F90) F90FLAGS="$(F90FLAGS)" LDFLAGS="$(LDFLAGS)" -$(program): $(objects) - $(F90) $(objects) $(xml_lib) $(LDFLAGS) -o $@ -install: - @install -D $(program) $(DESTDIR)$(prefix)/bin/$(program) - @install -D utils/statepoint_cmp.py $(DESTDIR)$(prefix)/bin/statepoint_cmp - @install -D utils/statepoint_histogram.py $(DESTDIR)$(prefix)/bin/statepoint_histogram - @install -D utils/statepoint_meshplot.py $(DESTDIR)$(prefix)/bin/statepoint_meshplot - @install -D ../man/man1/openmc.1 $(DESTDIR)$(prefix)/share/man/man1/openmc.1 - @install -D ../LICENSE $(DESTDIR)$(prefix)/share/doc/$(program)/copyright -uninstall: - @rm $(DESTDIR)$(prefix)/bin/$(program) - @rm $(DESTDIR)$(prefix)/bin/statepoint_cmp - @rm $(DESTDIR)$(prefix)/bin/statepoint_histogram - @rm $(DESTDIR)$(prefix)/bin/statepoint_meshplot - @rm $(DESTDIR)$(prefix)/share/man/man1/openmc.1 - @rm $(DESTDIR)$(prefix)/share/doc/$(program)/copyright -distclean: clean - cd xml; make clean +all: + mkdir -p build + cmake -H. -Bbuild + make -s -C build clean: - @rm -f *.o *.mod $(program) -neat: - @rm -f *.o *.mod + make -s -C build clean +distclean: + rm -fr build -#=============================================================================== -# Rules -#=============================================================================== - -.SUFFIXES: .F90 .o -.PHONY: all xml install uninstall clean neat distclean - -%.o: %.F90 - $(F90) $(F90FLAGS) -DGIT_SHA1="\"$(GIT_SHA1)\"" -Ixml/include -c $< - -#=============================================================================== -# Dependencies -#=============================================================================== - -include DEPENDENCIES +.PHONY: all clean distclean