From fef55ee95a7d02b7c704953c7b7f3da53cf4e0af Mon Sep 17 00:00:00 2001 From: Abishek Gopal Date: Sun, 14 Jun 2026 20:32:35 -0600 Subject: [PATCH 1/5] First draft --- Makefile | 46 +++++++++++++++++++++++++++++++++++++++++++--- src/Externals.cfg | 9 +++++++++ 2 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 src/Externals.cfg diff --git a/Makefile b/Makefile index 07ba5f9556..717553c818 100644 --- a/Makefile +++ b/Makefile @@ -777,6 +777,34 @@ endif LIBS += $(NCLIB) endif +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=lib64 + 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) + 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 "$(SCOTCH)" "" SCOTCH_INCLUDES += -I$(SCOTCH)/include SCOTCH_LIBS += -L$(SCOTCH)/lib64 -lptscotch -lscotch -lptscotcherr -lm @@ -1086,6 +1114,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 +1471,22 @@ 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 + @# + $(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 +1569,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 From 22e033a68f7774d034a947248f2bccbf4f90b7f0 Mon Sep 17 00:00:00 2001 From: Abishek Gopal Date: Tue, 15 Sep 2026 17:02:22 -0600 Subject: [PATCH 2/5] Remove old Makefile block --- Makefile | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/Makefile b/Makefile index 717553c818..b1ba6d7ba5 100644 --- a/Makefile +++ b/Makefile @@ -805,16 +805,6 @@ else $(error Invalid SCOTCH option: $(SCOTCH) - valid options "true", "false") endif -ifneq "$(SCOTCH)" "" - SCOTCH_INCLUDES += -I$(SCOTCH)/include - SCOTCH_LIBS += -L$(SCOTCH)/lib64 -lptscotch -lscotch -lptscotcherr -lm - SCOTCH_FLAGS = -DMPAS_SCOTCH - - CPPINCLUDES += $(SCOTCH_INCLUDES) - LIBS += $(SCOTCH_LIBS) - override CPPFLAGS += $(SCOTCH_FLAGS) -endif - ifneq "$(PNETCDF)" "" ifneq ($(wildcard $(PNETCDF)/lib/libpnetcdf.*), ) PNETCDFLIBLOC = lib From 9572644bdbd9124455754a6722d922bd5918552b Mon Sep 17 00:00:00 2001 From: Abishek Gopal Date: Tue, 15 Sep 2026 17:05:12 -0600 Subject: [PATCH 3/5] Fix bug in library search --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index b1ba6d7ba5..44b795c1d4 100644 --- a/Makefile +++ b/Makefile @@ -785,7 +785,7 @@ ifeq "$(SCOTCH)" "true" export SCOTCH_LIB_DIR=lib else ifneq ($(wildcard $(SCOTCH_ROOT)/lib/libptscotch.a), ) - SCOTCH_LIB_DIR=lib64 + SCOTCH_LIB_DIR=lib else ifneq ($(wildcard $(SCOTCH_ROOT)/lib64/libptscotch.a), ) SCOTCH_LIB_DIR=lib64 else From 6469e319d41416bc37b1e9e18740d916b06c9df3 Mon Sep 17 00:00:00 2001 From: Abishek Gopal Date: Tue, 15 Sep 2026 17:44:48 -0600 Subject: [PATCH 4/5] Steps to clean Scotch external --- src/external/Makefile | 1 + 1 file changed, 1 insertion(+) 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 From ac3a2277032e97cbc250a2a58cf78079c241ecf2 Mon Sep 17 00:00:00 2001 From: Abishek Gopal Date: Wed, 16 Sep 2026 09:24:29 -0600 Subject: [PATCH 5/5] Checks to force parallel builds to fail immediately --- Makefile | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Makefile b/Makefile index 44b795c1d4..25d0f8a776 100644 --- a/Makefile +++ b/Makefile @@ -790,6 +790,7 @@ ifeq "$(SCOTCH)" "true" 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 @@ -1465,6 +1466,10 @@ $(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;