From 5c3f1527e65cacb1b20ed3353d9b37b3a59e2432 Mon Sep 17 00:00:00 2001 From: Yuan-Ming Hsu <48866415+technic960183@users.noreply.github.com> Date: Sat, 8 Nov 2025 07:45:46 -0800 Subject: [PATCH 1/2] Prepare `Makefile_base` and update `.gitignore` for GAMER_CompareData, GAMER_ExtractProfile, and GAMER_ExtractUniform --- .gitignore | 12 ++++++++++-- .../gamer_compare_data/{Makefile => Makefile_base} | 0 .../{Makefile => Makefile_base} | 0 .../{Makefile => Makefile_base} | 0 4 files changed, 10 insertions(+), 2 deletions(-) rename tool/analysis/gamer_compare_data/{Makefile => Makefile_base} (100%) rename tool/analysis/gamer_extract_profile/{Makefile => Makefile_base} (100%) rename tool/analysis/gamer_extract_uniform/{Makefile => Makefile_base} (100%) diff --git a/.gitignore b/.gitignore index 07d505edba..26098d5dee 100644 --- a/.gitignore +++ b/.gitignore @@ -5,13 +5,21 @@ *.bin *~ +# Executables and binaries bin/** -src/generate_make.sh gamer GAMER_CompareData GAMER_ExtractUniform GAMER_ExtractProfile -.vscode + +# Build files +src/generate_make.sh src/Makefile src/Makefile.log +tool/analysis/gamer_compare_data/Makefile +tool/analysis/gamer_extract_profile/Makefile +tool/analysis/gamer_extract_uniform/Makefile + +# Settings +.vscode src/.local_settings diff --git a/tool/analysis/gamer_compare_data/Makefile b/tool/analysis/gamer_compare_data/Makefile_base similarity index 100% rename from tool/analysis/gamer_compare_data/Makefile rename to tool/analysis/gamer_compare_data/Makefile_base diff --git a/tool/analysis/gamer_extract_profile/Makefile b/tool/analysis/gamer_extract_profile/Makefile_base similarity index 100% rename from tool/analysis/gamer_extract_profile/Makefile rename to tool/analysis/gamer_extract_profile/Makefile_base diff --git a/tool/analysis/gamer_extract_uniform/Makefile b/tool/analysis/gamer_extract_uniform/Makefile_base similarity index 100% rename from tool/analysis/gamer_extract_uniform/Makefile rename to tool/analysis/gamer_extract_uniform/Makefile_base From 6f2b9a14440627e9bb80f36ca5ade8d1bf24250b Mon Sep 17 00:00:00 2001 From: Yuan-Ming Hsu <48866415+technic960183@users.noreply.github.com> Date: Sat, 8 Nov 2025 11:47:27 -0800 Subject: [PATCH 2/2] Generate Makefile for tools by `src/configure.py` --- src/configure.py | 41 ++++++++++++- .../analysis/gamer_compare_data/Makefile_base | 39 ++---------- .../gamer_extract_profile/Makefile_base | 46 ++------------ .../gamer_extract_uniform/Makefile_base | 60 +++---------------- 4 files changed, 58 insertions(+), 128 deletions(-) diff --git a/src/configure.py b/src/configure.py index 4a8a8e215e..15a1d601d9 100755 --- a/src/configure.py +++ b/src/configure.py @@ -44,6 +44,11 @@ "Default values are marked by '*'.\n"\ "Use -lh to show a detailed help message.\n" GAMER_EPILOG = "2023 Computational Astrophysics Lab, NTU. All rights reserved.\n" +GAMER_TOOL_PATHS = [ + os.path.join("..", "tool", "analysis", "gamer_compare_data"), + os.path.join("..", "tool", "analysis", "gamer_extract_uniform"), + os.path.join("..", "tool", "analysis", "gamer_extract_profile"), + ] LOGGER = logging.getLogger() LOG_FORMAT = "%(asctime)s %(levelname)-8s: %(message)s" @@ -455,6 +460,12 @@ def load_arguments( sys_setting : SystemSetting ): help="Output detailed compilation commands.\n" ) + # generate Makefile for tools + parser.add_argument( "--tools", type=str2bool, metavar="BOOLEAN", + default=False, + help="Generate Makefile for the analysis tools.\n" + ) + # A. options of diffierent physical models parser.add_argument( "--model", type=str, metavar="TYPE", gamer_name="MODEL", default="HYDRO", choices=["HYDRO", "ELBDM", "PAR_ONLY"], @@ -1168,7 +1179,7 @@ def warning( paths, **kwargs ): # 5.5 Set the GPU gpu_setup = set_gpu( gpus, flags, args ) - # 6. Create Makefile + # 6. Create Makefile for GAMER # 6.1 Read with open( GAMER_MAKE_BASE, "r" ) as make_base: makefile = make_base.read() @@ -1212,5 +1223,33 @@ def warning( paths, **kwargs ): LOGGER.info("========================================") LOGGER.info("%s is created."%GAMER_MAKE_OUT) + + # 7. Create Makefile for tools + if args['tools']: + all_key_vals = { **sims, **paths, **compiles, **gpu_setup } + for tool_path in GAMER_TOOL_PATHS: + tool_make_base = os.path.join( tool_path, GAMER_MAKE_BASE ) + tool_make_out = os.path.join( tool_path, GAMER_MAKE_OUT ) + + # 7.1 Read + with open( tool_make_base, "r" ) as make_base: + makefile = make_base.read() + + # 7.2 Replace + for key, val in all_key_vals.items(): + makefile, num = re.subn(r"@@@%s@@@"%key, val, makefile) + if num > 0: LOGGER.debug("%-25s : %s"%(key, val)) + + for key in re.findall(r"@@@(.+?)@@@", makefile): + makefile, num = re.subn(r"@@@%s@@@"%key, "", makefile) + if num == 0: raise BaseException("The string @@@%s@@@ is not replaced correctly."%key) + LOGGER.warning("@@@%s@@@ is replaced to '' since the value is not given or the related option is disabled."%key) + + # 7.3 Write + with open( tool_make_out, "w") as make_out: + make_out.write( command + makefile ) + + LOGGER.info("%s is created."%tool_make_out) + if args["verbose_make"]: LOGGER.info("%s is in verbose mode."%GAMER_MAKE_OUT) LOGGER.info("========================================") diff --git a/tool/analysis/gamer_compare_data/Makefile_base b/tool/analysis/gamer_compare_data/Makefile_base index 01909455cb..b189339363 100644 --- a/tool/analysis/gamer_compare_data/Makefile_base +++ b/tool/analysis/gamer_compare_data/Makefile_base @@ -9,35 +9,7 @@ EXECUTABLE := GAMER_CompareData # simulation options ####################################################################################################### -# model: HYDRO/ELBDM -SIMU_OPTION += -DMODEL=HYDRO - -# double precision -#SIMU_OPTION += -DFLOAT8 - -# double precision for particle floating-point attributes -#SIMU_OPTION += -DFLOAT8_PAR - -# long integer for particle integer attributes -SIMU_OPTION += -DINT8_PAR - -# debug mode -#SIMU_OPTION += -DGAMER_DEBUG - -# support HDF5 format -SIMU_OPTION += -DSUPPORT_HDF5 - - - -# siimulation parameters -####################################################################################################### -NLEVEL := 10 # level : 0 ~ NLEVEL-1 -MAX_PATCH := 2000000 # maximum number of patches in each level - -NLEVEL := $(strip $(NLEVEL)) -MAX_PATCH := $(strip $(MAX_PATCH)) - -SIMU_PARA = -DNLEVEL=$(NLEVEL) -DMAX_PATCH=$(MAX_PATCH) +SIMU_OPTION := @@@SIMU_OPTION@@@ @@ -54,11 +26,10 @@ vpath %.cpp ./ GAMER_Functions # rules and targets ####################################################################################################### -HDF5_PATH := /software/hdf5/default -#HDF5_PATH := /software/hdf5/1.10.6-intel-2023.1.0 +HDF5_PATH := @@@HDF5_PATH@@@ -CC := icpc -CFLAG := -O3 -w1 -g -diag-disable=10441 +CC := @@@CXX@@@ +CFLAG := @@@CXXFLAG@@@ INCLUDE := -I./Header ifeq "$(findstring SUPPORT_HDF5, $(SIMU_OPTION))" "SUPPORT_HDF5" @@ -75,7 +46,7 @@ OBJ := $(patsubst %.cpp, $(OBJ_DIR)/%.o, $(SOURCE)) $(OBJ_DIR)/%.o : %.cpp - $(CC) $(CFLAG) $(SIMU_PARA) $(SIMU_OPTION) $(INCLUDE) -o $@ -c $< + $(CC) $(CFLAG) $(SIMU_OPTION) $(INCLUDE) -o $@ -c $< $(EXECUTABLE): $(OBJ) $(CC) $(CFLAG) -o $@ $^ $(LIB) diff --git a/tool/analysis/gamer_extract_profile/Makefile_base b/tool/analysis/gamer_extract_profile/Makefile_base index 075a445800..2c940f7de9 100644 --- a/tool/analysis/gamer_extract_profile/Makefile_base +++ b/tool/analysis/gamer_extract_profile/Makefile_base @@ -7,39 +7,9 @@ EXECUTABLE := GAMER_ExtractProfile -# siimulation options +# simulation options ####################################################################################################### -# model: HYDRO/MHD/ELBDM -SIMU_OPTION += -DMODEL=HYDRO - -# double precision -#SIMU_OPTION += -DFLOAT8 - -# double precision for particle floating-point attributes -#SIMU_OPTION += -DFLOAT8_PAR - -# long integer for particle integer attributes -SIMU_OPTION += -DINT8_PAR - -# debug mode -#SIMU_OPTION += -DGAMER_DEBUG - -# support HDF5 format -SIMU_OPTION += -DSUPPORT_HDF5 - - - -# siimulation parameters -####################################################################################################### -NLEVEL := 10 # level : 0 ~ NLEVEL-1 -NCOMP_PASSIVE := 0 # number of passive scalars -MAX_PATCH := 2000000 # the maximum number of patches in each level - -NLEVEL := $(strip $(NLEVEL)) -NCOMP_PASSIVE := $(strip $(NCOMP_PASSIVE)) -MAX_PATCH := $(strip $(MAX_PATCH)) - -SIMU_PARA = -DNLEVEL=$(NLEVEL) -DMAX_PATCH=$(MAX_PATCH) -DNCOMP_PASSIVE=$(NCOMP_PASSIVE) +SIMU_OPTION := @@@SIMU_OPTION@@@ @@ -65,14 +35,10 @@ vpath %.cpp ./ GAMER_Functions GAMER_Functions/Interpolation # rules and targets ####################################################################################################### -HDF5_PATH := /software/hdf5/default - -CC := icpc -CFLAG := -O3 -w1 -g #-xSSE4.2 -fp-model precise -#CFLAG := -O3 -w1 -mp1 +HDF5_PATH := @@@HDF5_PATH@@@ -#CC := g++ -#CFLAG := -O3 -Wall +CC := @@@CXX@@@ +CFLAG := @@@CXXFLAG@@@ #LIB := -limf @@ -95,7 +61,7 @@ OBJ := $(patsubst %.cpp, $(OBJ_DIR)/%.o, $(SOURCE)) $(OBJ_DIR)/%.o : %.cpp - $(CC) $(CFLAG) $(SIMU_PARA) $(SIMU_OPTION) $(INCLUDE) -o $@ -c $< + $(CC) $(CFLAG) $(SIMU_OPTION) $(INCLUDE) -o $@ -c $< $(EXECUTABLE): $(OBJ) $(CC) $(CFLAG) -o $@ $^ $(LIB) diff --git a/tool/analysis/gamer_extract_uniform/Makefile_base b/tool/analysis/gamer_extract_uniform/Makefile_base index b00c119432..6b4041ff60 100644 --- a/tool/analysis/gamer_extract_uniform/Makefile_base +++ b/tool/analysis/gamer_extract_uniform/Makefile_base @@ -7,45 +7,9 @@ EXECUTABLE = GAMER_ExtractUniform -# siimulation options +# simulation options ####################################################################################################### -# model: HYDRO/MHD/ELBDM -SIMU_OPTION += -DMODEL=HYDRO - -# double precision -#SIMU_OPTION += -DFLOAT8 - -# double precision for particle floating-point attributes -#SIMU_OPTION += -DFLOAT8_PAR - -# long integer for particle integer attributes -SIMU_OPTION += -DINT8_PAR - -# enable OpenMP parallelization -SIMU_OPTION += -DOPENMP - -# debug mode -#SIMU_OPTION += -DGAMER_DEBUG - -# support HDF5 format -SIMU_OPTION += -DSUPPORT_HDF5 - -# serial version (no MPI is required) -#SIMU_OPTION += -DSERIAL - - - -# siimulation parameters -####################################################################################################### -NLEVEL = 10 # level : 0 ~ NLEVEL-1 -NCOMP_PASSIVE = 0 # number of passive scalars -MAX_PATCH = 1000000 # the maximum number of patches in each level - -NLEVEL := $(strip $(NLEVEL)) -NCOMP_PASSIVE := $(strip $(NCOMP_PASSIVE)) -MAX_PATCH := $(strip $(MAX_PATCH)) - -SIMU_PARA = -DNLEVEL=$(NLEVEL) -DMAX_PATCH=$(MAX_PATCH) -DNCOMP_PASSIVE=$(NCOMP_PASSIVE) +SIMU_OPTION := @@@SIMU_OPTION@@@ @@ -75,21 +39,11 @@ vpath %.cpp ./ GAMER_Functions GAMER_Functions/Interpolation # rules and targets ####################################################################################################### -HDF5_PATH := /software/hdf5/default -MPI_PATH := /software/openmpi/default -#MPI_PATH := /opt/mpi/openmpi/1.6.0-intel -#MPI_PATH := /usr/local/mpi/openmpi-1.8.4-intel-15.0 -#HDF5_PATH := /projects/ncsa/grav/softwares/miniconda2 - - -ifeq "$(findstring SERIAL, $(SIMU_OPTION))" "" -CXX := $(MPI_PATH)/bin/mpicxx -else -CXX := icpc -endif +HDF5_PATH := @@@HDF5_PATH@@@ +MPI_PATH := @@@MPI_PATH@@@ -CFLAG := -O3 -w1 -#CFLAG := -O3 -Wall +CXX := @@@CXX@@@ +CFLAG := @@@CXXFLAG@@@ ifeq "$(findstring GAMER_DEBUG, $(SIMU_OPTION))" "GAMER_DEBUG" CFLAG += -g @@ -119,7 +73,7 @@ OBJ := $(patsubst %.cpp, $(OBJ_PATH)/%.o, $(SOURCE)) $(OBJ_PATH)/%.o : %.cpp - $(CXX) $(CFLAG) $(SIMU_PARA) $(SIMU_OPTION) $(INCLUDE) -o $@ -c $< + $(CXX) $(CFLAG) $(SIMU_OPTION) $(INCLUDE) -o $@ -c $< $(EXECUTABLE): $(OBJ) $(CXX) $(CFLAG) -o $@ $^ $(LIB)