diff --git a/Makefile b/Makefile index 07ba5f9556..25d0f8a776 100644 --- a/Makefile +++ b/Makefile @@ -777,14 +777,33 @@ endif LIBS += $(NCLIB) endif -ifneq "$(SCOTCH)" "" - SCOTCH_INCLUDES += -I$(SCOTCH)/include - SCOTCH_LIBS += -L$(SCOTCH)/lib64 -lptscotch -lscotch -lptscotcherr -lm +export SCOTCH ?= false +ifeq "$(SCOTCH)" "true" + ifeq ($(wildcard $(SCOTCH_ROOT)), ) + export SCOTCH_RELPATH=src/external/scotch + export SCOTCH_ROOT=${CURDIR}/${SCOTCH_RELPATH}/install + export SCOTCH_LIB_DIR=lib + else + ifneq ($(wildcard $(SCOTCH_ROOT)/lib/libptscotch.a), ) + SCOTCH_LIB_DIR=lib + else ifneq ($(wildcard $(SCOTCH_ROOT)/lib64/libptscotch.a), ) + SCOTCH_LIB_DIR=lib64 + else + $(error Could not find SCOTCH library in $(SCOTCH_ROOT)/lib or $(SCOTCH_ROOT)/lib64) + export SCOTCH = false + endif + endif + SCOTCH_INCLUDES += -I$(SCOTCH_ROOT)/include + SCOTCH_LIBS += -L$(SCOTCH_ROOT)/$(SCOTCH_LIB_DIR) -lptscotch -lscotch -lptscotcherr -lm SCOTCH_FLAGS = -DMPAS_SCOTCH - CPPINCLUDES += $(SCOTCH_INCLUDES) LIBS += $(SCOTCH_LIBS) override CPPFLAGS += $(SCOTCH_FLAGS) + SCOTCH_MESSAGE="MPAS was built with an external SCOTCH library using SCOTCH path" +else ifeq "$(SCOTCH)" "false" + SCOTCH_MESSAGE="MPAS was built with the embedded SCOTCH library." +else + $(error Invalid SCOTCH option: $(SCOTCH) - valid options "true", "false") endif ifneq "$(PNETCDF)" "" @@ -1086,6 +1105,7 @@ rebuild_check: OPENMP=$(OPENMP)\n$\ OPENMP_OFFLOAD=$(OPENMP_OFFLOAD)\n$\ OPENACC=$(OPENACC)\n$\ + SCOTCH=$(SCOTCH)\n$\ TAU=$(TAU)\n$\ PICFLAG=$(PICFLAG)\n$\ TIMER_LIB=$(TIMER_LIB)\n$\ @@ -1442,11 +1462,26 @@ musica_fortran_test: $(eval MUSICA_FORTRAN_VERSION := $(shell pkg-config --modversion musica-fortran)) $(if $(findstring 1,$(MUSICA_FORTRAN_TEST)), $(info Built a simple test program with MUSICA-Fortran version $(MUSICA_FORTRAN_VERSION)), ) -scotch_c_test: +$(SCOTCH_ROOT)/$(SCOTCH_LIB_DIR)/libptscotch.a: + @# + @# Build the Scotch library if it is not already built + @# + ifeq "$(SCOTCH)" "false" + $(error Could not find SCOTCH library in $(SCOTCH_ROOT)/lib or $(SCOTCH_ROOT)/lib64) + endif + + $(info Building Scotch library...) + src/core_atmosphere/tools/manage_externals/checkout_externals --externals src/Externals.cfg; + cd ${SCOTCH_RELPATH} && mkdir -p build; + cd ${SCOTCH_RELPATH}/build && cmake .. -DCMAKE_INSTALL_PREFIX=$(SCOTCH_ROOT) -DCMAKE_INSTALL_LIBDIR=$(SCOTCH_LIB_DIR) -DCMAKE_BUILD_TYPE=Release; + cd ${SCOTCH_RELPATH}/build && make -j$(nproc); + cd ${SCOTCH_RELPATH}/build && make install; + +scotch_c_test: $(SCOTCH_ROOT)/$(SCOTCH_LIB_DIR)/libptscotch.a @# @# Create a C test program and try to build against the PT-SCOTCH library @# - $(info Checking for a working Scotch library...) + $(info Checking for a working Scotch library in $(SCOTCH_ROOT)...) $(eval SCOTCH_C_TEST := $(shell $\ printf "#include \n\ &#include \"mpi.h\"\n\ @@ -1529,7 +1564,7 @@ else MUSICA_MESSAGE = "MPAS was not linked with the MUSICA-Fortran library." endif -ifneq "$(SCOTCH)" "" +ifeq "$(SCOTCH)" "true" MAIN_DEPS += scotch_c_test SCOTCH_MESSAGE = "MPAS has been linked with the Scotch graph partitioning library." else diff --git a/src/Externals.cfg b/src/Externals.cfg new file mode 100644 index 0000000000..4a537a0c9c --- /dev/null +++ b/src/Externals.cfg @@ -0,0 +1,9 @@ +[SCOTCH] +local_path = ./src/external/scotch +protocol = git +repo_url = https://gitlab.inria.fr/scotch/scotch.git +tag = v7.0.11 +required = True + +[externals_description] +schema_version = 1.0.0 diff --git a/src/external/Makefile b/src/external/Makefile index b6161562e8..7400e65fde 100644 --- a/src/external/Makefile +++ b/src/external/Makefile @@ -20,4 +20,5 @@ smiol-lib: clean: ( cd esmf_time_f90; $(MAKE) clean ) ( cd ezxml; $(MAKE) clean ) + ( cd scotch; $(RM) -r build install ) $(MAKE) -C SMIOL clean