diff --git a/.gitignore b/.gitignore index c54ae8b623..07d505edba 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ GAMER_ExtractProfile .vscode src/Makefile src/Makefile.log +src/.local_settings diff --git a/doc/wiki/Installation-related/Installation:-Machine-Configuration-File.md b/doc/wiki/Installation-related/Installation:-Machine-Configuration-File.md index 9bc9f15ce0..93e7de28c0 100644 --- a/doc/wiki/Installation-related/Installation:-Machine-Configuration-File.md +++ b/doc/wiki/Installation-related/Installation:-Machine-Configuration-File.md @@ -1,7 +1,18 @@ +The machine configuration file is located under `configs`. It specifies the library paths, compiler types, compilation flags, and GPU compute capability. + > [!TIP] -> To set up your machine configuration file, make a copy of `template.config` and modify it. +> Check the `configs` directory to see if a configuration file is already available for your machine. + +## Set Up the Machine Configuration File + +To set up your machine configuration file, go to `configs` and make a copy of `template.config` to modify: + +```bash +cd configs +cp template.config your_machine.config +``` -The machine configuration file is under `configs`. The configuration file contains the library paths, the compiler types, the compilation flags, and the GPU compute capability. +Please refer to the following sections to set up your machine configuration file. ### 0. Rules of the configuration file * Comments must start with `#`. diff --git a/doc/wiki/Installation-related/Installation:-Option-List.md b/doc/wiki/Installation-related/Installation:-Option-List.md index ac4741ff2f..ed1c0aff93 100644 --- a/doc/wiki/Installation-related/Installation:-Option-List.md +++ b/doc/wiki/Installation-related/Installation:-Option-List.md @@ -22,9 +22,9 @@ disabled). See the "Restriction" of each option carefully. | Option | Value | Description | |:---:|:---:|---| -| `-h` | - | Show a short help message. | -| `-lh` | - | Show a detailed help message. | -| `--machine` | Filename string | Select the `*.config` file from the `configs` directory. | +| `-h` | - | Show a short help message. | +| `-lh` | - | Show a detailed help message. | +| `--machine` | Filename string | Select the `*.config` file from the `configs` directory. It will overwrite the default machine set in the [[default setting file \| Installation#default_setting]]. |                  diff --git a/doc/wiki/Installation.md b/doc/wiki/Installation.md index 64439b570d..5f1e1e85f9 100644 --- a/doc/wiki/Installation.md +++ b/doc/wiki/Installation.md @@ -2,33 +2,46 @@ Please see [[Machine Configuration File | Installation:-Machine-Configuration-File]]. -2. Go to the source directory + + +2. Set your machine configuration file as default + + ```bash + sh tool/config/set_settings.sh --local --machine=your_machine + ``` + +> [!NOTE] +> If you want to set the default machine configuration file for all GAMER copies under your user account, use the `--global` option instead of `--local`. +You can still override the global setting for individual GAMER copies using the `--local` option. +Furthermore, you can override the default setting by passing the [[--machine | Installation:-Option-List#--machine]]=`your_machine` when executing `configure.py`. + +3. Go to the source directory ```bash cd src ``` -3. Generate `Makefile` using the Python script `configure.py` +4. Generate `Makefile` using the Python script `configure.py` To get the `Makefile`, please execute the following command: ```bash - python configure.py --machine=your_configuration_file [--your_arguments] + python configure.py [--your_arguments] ``` - `your_configuration_file` is the configuration filename you got from step 1, and `[--your_arguments]` should match your simulation requirements. Please check out [[Option List | Installation:-Option-List]] for all the available options. + `[--your_arguments]` represent the options that should align with your simulation requirements. Refer to [[Option List | Installation:-Option-List]] for a complete list of available options. - For example, the following command uses the `configs/pleiades.config` machine configuration, sets the FFTW method to `FFTW2`, and enables gravity and GPU. + For example, the following command sets the FFTW method to `FFTW2` and enables gravity and GPU. ``` bash - python configure.py --machine=pleiades --fftw=FFTW2 --gravity=true --gpu=true + python configure.py --fftw=FFTW2 --gravity=true --gpu=true ``` > [!TIP] > An example script `generate_make.sh` to generate Makefile can be found in each test problem folder, e.g., `example/test_problem/Hydro/AcousticWave/generate_make.sh`. -4. Compile the code +5. Compile the code ```bash make clean diff --git a/doc/wiki/Quick-Start-related/Quick-Start:-1D-Shock-Tube.md b/doc/wiki/Quick-Start-related/Quick-Start:-1D-Shock-Tube.md index a6d22fa763..e3f480de30 100644 --- a/doc/wiki/Quick-Start-related/Quick-Start:-1D-Shock-Tube.md +++ b/doc/wiki/Quick-Start-related/Quick-Start:-1D-Shock-Tube.md @@ -236,7 +236,7 @@ following modifications. 1\. Re-generate `Makefile` by [[configure.py | Installation]] and recompile `gamer`. ``` bash -sh generate_make.sh --machine=YOUR_MACHINE --openmp=true --gpu=true +sh generate_make.sh --openmp=true --gpu=true make clean make -j4 ``` diff --git a/doc/wiki/Quick-Start.md b/doc/wiki/Quick-Start.md index e44b22220b..17a46b92f0 100644 --- a/doc/wiki/Quick-Start.md +++ b/doc/wiki/Quick-Start.md @@ -4,9 +4,21 @@ Follow the instructions in [[Download]] to get the latest version of GAMER. ### Setup Your Machine Configuration File -Follow the instructions in [[Machine Configuration File | Installation:-Machine-Configuration-File]] to set the configuration file of your machine. +The machine configuration file is located under `configs`. This file contains the library paths, compiler types, compilation flags, and GPU compute capability. Check the existing configuration files to see if one matches your machine. + +If no suitable configuration file is available, you will need to create a new one. Follow the instructions in [[Machine Configuration File | Installation:-Machine-Configuration-File]] to set up a configuration file for your machine. + +If a configuration file matches your machine, you can set it as the default by running + +```bash +sh tool/config/set_settings.sh --local --machine=your_machine +``` + +For example, setting `--machine=pleiades` with the above command will use the `configs/pleiades.config` machine configuration when compiling the code. ### Quick Demos +Read the following guides to learn how to configure, compile, and run GAMER. + 1. [[1D Shock Tube: OpenMP with/without GPU acceleration | Quick-Start:-1D-Shock-Tube]] 2. [[3D Blast Wave: hybrid MPI/OpenMP/GPU + yt analysis | Quick-Start:-3D-Blast-Wave]] diff --git a/example/test_problem/ELBDM/DiskHeating/generate_make.sh b/example/test_problem/ELBDM/DiskHeating/generate_make.sh index 10febea161..19d04c42bc 100644 --- a/example/test_problem/ELBDM/DiskHeating/generate_make.sh +++ b/example/test_problem/ELBDM/DiskHeating/generate_make.sh @@ -2,6 +2,6 @@ PYTHON=python3 -${PYTHON} configure.py --machine=eureka_intel --mpi=true --hdf5=true --fftw=FFTW3 --gpu=true \ +${PYTHON} configure.py --mpi=true --hdf5=true --fftw=FFTW3 --gpu=true \ --model=ELBDM --gravity=true --particle=true --store_par_acc=true \ --gsl=true --max_patch=20000000 "$@" diff --git a/example/test_problem/ELBDM/ExtPot/generate_make.sh b/example/test_problem/ELBDM/ExtPot/generate_make.sh index ea1818b24a..fab2dfe0c6 100644 --- a/example/test_problem/ELBDM/ExtPot/generate_make.sh +++ b/example/test_problem/ELBDM/ExtPot/generate_make.sh @@ -2,5 +2,5 @@ PYTHON=python3 -${PYTHON} configure.py --machine=eureka_intel --mpi=true --hdf5=true --fftw=FFTW3 --gpu=true \ +${PYTHON} configure.py --mpi=true --hdf5=true --fftw=FFTW3 --gpu=true \ --model=ELBDM --gravity=true "$@" diff --git a/example/test_problem/ELBDM/GaussianWavePacket/generate_make.sh b/example/test_problem/ELBDM/GaussianWavePacket/generate_make.sh index 36d72b4969..68b0c3d80b 100644 --- a/example/test_problem/ELBDM/GaussianWavePacket/generate_make.sh +++ b/example/test_problem/ELBDM/GaussianWavePacket/generate_make.sh @@ -2,4 +2,4 @@ PYTHON=python3 -${PYTHON} configure.py --machine=eureka_intel --model=ELBDM "$@" +${PYTHON} configure.py --model=ELBDM "$@" diff --git a/example/test_problem/ELBDM/HaloMerger/generate_make.sh b/example/test_problem/ELBDM/HaloMerger/generate_make.sh index b7c2d9fa1a..3e16ee04f2 100644 --- a/example/test_problem/ELBDM/HaloMerger/generate_make.sh +++ b/example/test_problem/ELBDM/HaloMerger/generate_make.sh @@ -2,5 +2,5 @@ PYTHON=python3 -${PYTHON} configure.py --machine=eureka_intel --mpi=true --hdf5=true --fftw=FFTW3 --gpu=true \ +${PYTHON} configure.py --mpi=true --hdf5=true --fftw=FFTW3 --gpu=true \ --model=ELBDM --gravity=true --particle=true --gsl=true "$@" diff --git a/example/test_problem/ELBDM/IsolatedHalo/generate_make.sh b/example/test_problem/ELBDM/IsolatedHalo/generate_make.sh index ea1818b24a..fab2dfe0c6 100644 --- a/example/test_problem/ELBDM/IsolatedHalo/generate_make.sh +++ b/example/test_problem/ELBDM/IsolatedHalo/generate_make.sh @@ -2,5 +2,5 @@ PYTHON=python3 -${PYTHON} configure.py --machine=eureka_intel --mpi=true --hdf5=true --fftw=FFTW3 --gpu=true \ +${PYTHON} configure.py --mpi=true --hdf5=true --fftw=FFTW3 --gpu=true \ --model=ELBDM --gravity=true "$@" diff --git a/example/test_problem/ELBDM/JeansInstabilityComoving/generate_make.sh b/example/test_problem/ELBDM/JeansInstabilityComoving/generate_make.sh index 29f50a3115..8d1303f304 100644 --- a/example/test_problem/ELBDM/JeansInstabilityComoving/generate_make.sh +++ b/example/test_problem/ELBDM/JeansInstabilityComoving/generate_make.sh @@ -2,5 +2,5 @@ PYTHON=python3 -${PYTHON} configure.py --machine=eureka_intel --hdf5=true --gpu=true --fftw=FFTW3 --double=true \ +${PYTHON} configure.py --hdf5=true --gpu=true --fftw=FFTW3 --double=true \ --model=ELBDM --gravity=true --comoving=true "$@" diff --git a/example/test_problem/ELBDM/LSS/generate_make.sh b/example/test_problem/ELBDM/LSS/generate_make.sh index 3d3c4e9786..2a102095a1 100644 --- a/example/test_problem/ELBDM/LSS/generate_make.sh +++ b/example/test_problem/ELBDM/LSS/generate_make.sh @@ -2,5 +2,5 @@ PYTHON=python3 -${PYTHON} configure.py --machine=eureka_intel --mpi=true --hdf5=true --fftw=FFTW3 --gpu=true \ +${PYTHON} configure.py --mpi=true --hdf5=true --fftw=FFTW3 --gpu=true \ --model=ELBDM --gravity=true --comoving=true "$@" diff --git a/example/test_problem/ELBDM/LSS_Hybrid/generate_make.sh b/example/test_problem/ELBDM/LSS_Hybrid/generate_make.sh index 50a8a69744..81c9fba21b 100644 --- a/example/test_problem/ELBDM/LSS_Hybrid/generate_make.sh +++ b/example/test_problem/ELBDM/LSS_Hybrid/generate_make.sh @@ -2,6 +2,6 @@ PYTHON=python3 -${PYTHON} configure.py --machine=eureka_intel --mpi=true --hdf5=true --fftw=FFTW3 --gpu=true \ +${PYTHON} configure.py --mpi=true --hdf5=true --fftw=FFTW3 --gpu=true \ --model=ELBDM --elbdm_scheme=ELBDM_HYBRID --wave_scheme=WAVE_GRAMFE --gramfe_scheme=GRAMFE_MATMUL \ --gravity=true --comoving=true --gsl=true --spectral_interpolation=true "$@" diff --git a/example/test_problem/ELBDM/Perturbation/generate_make.sh b/example/test_problem/ELBDM/Perturbation/generate_make.sh index fd8e2b6300..382fd3e78a 100644 --- a/example/test_problem/ELBDM/Perturbation/generate_make.sh +++ b/example/test_problem/ELBDM/Perturbation/generate_make.sh @@ -2,6 +2,6 @@ PYTHON=python3 -${PYTHON} configure.py --machine=eureka_intel --mpi=true --hdf5=true --fftw=FFTW3 --gpu=true \ +${PYTHON} configure.py --mpi=true --hdf5=true --fftw=FFTW3 --gpu=true \ --model=ELBDM --elbdm_scheme=ELBDM_HYBRID --wave_scheme=WAVE_GRAMFE --gramfe_scheme=GRAMFE_MATMUL \ --gravity=true --comoving=false --gsl=true --spectral_interpolation=true "$@" diff --git a/example/test_problem/ELBDM/Perturbation/generate_make_BaseSpectral.sh b/example/test_problem/ELBDM/Perturbation/generate_make_BaseSpectral.sh index 5ac98961d2..18f8a3ea65 100644 --- a/example/test_problem/ELBDM/Perturbation/generate_make_BaseSpectral.sh +++ b/example/test_problem/ELBDM/Perturbation/generate_make_BaseSpectral.sh @@ -2,6 +2,6 @@ PYTHON=python3 -${PYTHON} configure.py --machine=eureka_intel --mpi=true --hdf5=true --fftw=FFTW3 \ +${PYTHON} configure.py --mpi=true --hdf5=true --fftw=FFTW3 \ --model=ELBDM --elbdm_scheme=ELBDM_WAVE \ --gravity=true --comoving=false \ No newline at end of file diff --git a/example/test_problem/ELBDM/PlaneWave/generate_make.sh b/example/test_problem/ELBDM/PlaneWave/generate_make.sh index 269c26b977..7ab268371e 100644 --- a/example/test_problem/ELBDM/PlaneWave/generate_make.sh +++ b/example/test_problem/ELBDM/PlaneWave/generate_make.sh @@ -2,4 +2,4 @@ PYTHON=python3 -${PYTHON} configure.py --machine=eureka_intel --model=ELBDM --double=True --passive=1 "$@" +${PYTHON} configure.py --model=ELBDM --double=True --passive=1 "$@" diff --git a/example/test_problem/ELBDM/RestrictionMismatch/generate_make.sh b/example/test_problem/ELBDM/RestrictionMismatch/generate_make.sh index 34da26ce5c..45dc152737 100644 --- a/example/test_problem/ELBDM/RestrictionMismatch/generate_make.sh +++ b/example/test_problem/ELBDM/RestrictionMismatch/generate_make.sh @@ -2,4 +2,4 @@ PYTHON=python3 -${PYTHON} configure.py --machine=eureka_intel --model=ELBDM --double=True --hdf5=true --fftw=FFTW3 "$@" +${PYTHON} configure.py --model=ELBDM --double=True --hdf5=true --fftw=FFTW3 "$@" diff --git a/example/test_problem/ELBDM/SelfSimilarHalo/generate_make.sh b/example/test_problem/ELBDM/SelfSimilarHalo/generate_make.sh index 3d3c4e9786..2a102095a1 100644 --- a/example/test_problem/ELBDM/SelfSimilarHalo/generate_make.sh +++ b/example/test_problem/ELBDM/SelfSimilarHalo/generate_make.sh @@ -2,5 +2,5 @@ PYTHON=python3 -${PYTHON} configure.py --machine=eureka_intel --mpi=true --hdf5=true --fftw=FFTW3 --gpu=true \ +${PYTHON} configure.py --mpi=true --hdf5=true --fftw=FFTW3 --gpu=true \ --model=ELBDM --gravity=true --comoving=true "$@" diff --git a/example/test_problem/ELBDM/Soliton/generate_make.sh b/example/test_problem/ELBDM/Soliton/generate_make.sh index ea1818b24a..fab2dfe0c6 100644 --- a/example/test_problem/ELBDM/Soliton/generate_make.sh +++ b/example/test_problem/ELBDM/Soliton/generate_make.sh @@ -2,5 +2,5 @@ PYTHON=python3 -${PYTHON} configure.py --machine=eureka_intel --mpi=true --hdf5=true --fftw=FFTW3 --gpu=true \ +${PYTHON} configure.py --mpi=true --hdf5=true --fftw=FFTW3 --gpu=true \ --model=ELBDM --gravity=true "$@" diff --git a/example/test_problem/ELBDM/VortexPairLinear/generate_make.sh b/example/test_problem/ELBDM/VortexPairLinear/generate_make.sh index 896d289303..2247fa2c3c 100644 --- a/example/test_problem/ELBDM/VortexPairLinear/generate_make.sh +++ b/example/test_problem/ELBDM/VortexPairLinear/generate_make.sh @@ -2,4 +2,4 @@ PYTHON=python3 -${PYTHON} configure.py --machine=eureka_intel --model=ELBDM --hdf5=true "$@" +${PYTHON} configure.py --model=ELBDM --hdf5=true "$@" diff --git a/example/test_problem/ELBDM/VortexPairLinear_Hybrid/generate_make.sh b/example/test_problem/ELBDM/VortexPairLinear_Hybrid/generate_make.sh index c50f009d30..c4f3150c8f 100644 --- a/example/test_problem/ELBDM/VortexPairLinear_Hybrid/generate_make.sh +++ b/example/test_problem/ELBDM/VortexPairLinear_Hybrid/generate_make.sh @@ -2,4 +2,4 @@ PYTHON=python3 -${PYTHON} configure.py --machine=eureka_intel --model=ELBDM --elbdm_scheme=ELBDM_HYBRID --hdf5=true --mpi=true "$@" +${PYTHON} configure.py --model=ELBDM --elbdm_scheme=ELBDM_HYBRID --hdf5=true --mpi=true "$@" diff --git a/example/test_problem/ELBDM/VortexPairRotating/generate_make.sh b/example/test_problem/ELBDM/VortexPairRotating/generate_make.sh index 896d289303..2247fa2c3c 100644 --- a/example/test_problem/ELBDM/VortexPairRotating/generate_make.sh +++ b/example/test_problem/ELBDM/VortexPairRotating/generate_make.sh @@ -2,4 +2,4 @@ PYTHON=python3 -${PYTHON} configure.py --machine=eureka_intel --model=ELBDM --hdf5=true "$@" +${PYTHON} configure.py --model=ELBDM --hdf5=true "$@" diff --git a/example/test_problem/ELBDM/VortexPairRotating_Hybrid/generate_make.sh b/example/test_problem/ELBDM/VortexPairRotating_Hybrid/generate_make.sh index c50f009d30..c4f3150c8f 100644 --- a/example/test_problem/ELBDM/VortexPairRotating_Hybrid/generate_make.sh +++ b/example/test_problem/ELBDM/VortexPairRotating_Hybrid/generate_make.sh @@ -2,4 +2,4 @@ PYTHON=python3 -${PYTHON} configure.py --machine=eureka_intel --model=ELBDM --elbdm_scheme=ELBDM_HYBRID --hdf5=true --mpi=true "$@" +${PYTHON} configure.py --model=ELBDM --elbdm_scheme=ELBDM_HYBRID --hdf5=true --mpi=true "$@" diff --git a/example/test_problem/Hydro/AGORA_IsolatedGalaxy/generate_make.sh b/example/test_problem/Hydro/AGORA_IsolatedGalaxy/generate_make.sh index 409e0efa24..22c9e42bda 100644 --- a/example/test_problem/Hydro/AGORA_IsolatedGalaxy/generate_make.sh +++ b/example/test_problem/Hydro/AGORA_IsolatedGalaxy/generate_make.sh @@ -2,6 +2,6 @@ PYTHON=python3 -${PYTHON} configure.py --machine=eureka_intel --mpi=true --hdf5=true --fftw=FFTW3 --gpu=true --model=HYDRO \ +${PYTHON} configure.py --mpi=true --hdf5=true --fftw=FFTW3 --gpu=true --model=HYDRO \ --particle=true --gravity=true --flu_scheme=MHM --flux=HLLC --passive=1 \ --par_attribute_flt=1 --dual=DE_ENPY --star_formation=true --grackle=true "$@" diff --git a/example/test_problem/Hydro/AcousticWave/generate_make.sh b/example/test_problem/Hydro/AcousticWave/generate_make.sh index 1e1a433d7b..b8fa682b4c 100644 --- a/example/test_problem/Hydro/AcousticWave/generate_make.sh +++ b/example/test_problem/Hydro/AcousticWave/generate_make.sh @@ -2,4 +2,4 @@ PYTHON=python3 -${PYTHON} configure.py --machine=eureka_intel --model=HYDRO --double=True "$@" +${PYTHON} configure.py --model=HYDRO --double=True "$@" diff --git a/example/test_problem/Hydro/BlastWave/generate_make.sh b/example/test_problem/Hydro/BlastWave/generate_make.sh index a6b02341cb..e6bab92044 100644 --- a/example/test_problem/Hydro/BlastWave/generate_make.sh +++ b/example/test_problem/Hydro/BlastWave/generate_make.sh @@ -2,4 +2,4 @@ PYTHON=python3 -${PYTHON} configure.py --machine=eureka_intel --model=HYDRO --hdf5=true "$@" +${PYTHON} configure.py --model=HYDRO --hdf5=true "$@" diff --git a/example/test_problem/Hydro/Bondi/generate_make.sh b/example/test_problem/Hydro/Bondi/generate_make.sh index 4e8ddae896..70de7de3a3 100644 --- a/example/test_problem/Hydro/Bondi/generate_make.sh +++ b/example/test_problem/Hydro/Bondi/generate_make.sh @@ -2,5 +2,5 @@ PYTHON=python3 -${PYTHON} configure.py --machine=eureka_intel --hdf5=true --gpu=true --fftw=FFTW3 \ +${PYTHON} configure.py --hdf5=true --gpu=true --fftw=FFTW3 \ --model=HYDRO --gravity=true --dual=DE_ENPY "$@" diff --git a/example/test_problem/Hydro/CDM_LSS/generate_make.sh b/example/test_problem/Hydro/CDM_LSS/generate_make.sh index b65dd79740..3625c38069 100644 --- a/example/test_problem/Hydro/CDM_LSS/generate_make.sh +++ b/example/test_problem/Hydro/CDM_LSS/generate_make.sh @@ -2,5 +2,5 @@ PYTHON=python3 -${PYTHON} configure.py --machine=eureka_intel --mpi=true --hdf5=true --fftw=FFTW3 --gpu=true \ +${PYTHON} configure.py --mpi=true --hdf5=true --fftw=FFTW3 --gpu=true \ --model=HYDRO --particle=true --gravity=true --comoving=true "$@" diff --git a/example/test_problem/Hydro/CMZ/generate_make.sh b/example/test_problem/Hydro/CMZ/generate_make.sh index 6c58cd78a9..3da93a0a6b 100644 --- a/example/test_problem/Hydro/CMZ/generate_make.sh +++ b/example/test_problem/Hydro/CMZ/generate_make.sh @@ -2,6 +2,6 @@ PYTHON=python3 -${PYTHON} configure.py --machine=eureka_intel --hdf5=true --gpu=true --fftw=FFTW3 \ +${PYTHON} configure.py --hdf5=true --gpu=true --fftw=FFTW3 \ --model=HYDRO --gravity=true --eos=ISOTHERMAL --barotropic=true \ --flu_scheme=MHM --flux=HLLC --passive=1 --par_attribute_flt=1 "$@" diff --git a/example/test_problem/Hydro/CR_Diffusion/generate_make.sh b/example/test_problem/Hydro/CR_Diffusion/generate_make.sh index 431a9e912e..da6ed33ade 100644 --- a/example/test_problem/Hydro/CR_Diffusion/generate_make.sh +++ b/example/test_problem/Hydro/CR_Diffusion/generate_make.sh @@ -2,5 +2,5 @@ PYTHON=python3 -${PYTHON} configure.py --machine=eureka_intel --model=HYDRO --flu_scheme=MHM_RP --flux=HLLD --mhd=true \ +${PYTHON} configure.py --model=HYDRO --flu_scheme=MHM_RP --flux=HLLD --mhd=true \ --cosmic_ray=true --eos=COSMIC_RAY --cr_diffusion=true --hdf5=true "$@" diff --git a/example/test_problem/Hydro/CR_ShockTube/generate_make.sh b/example/test_problem/Hydro/CR_ShockTube/generate_make.sh index 2b0048bba3..487fba62d0 100644 --- a/example/test_problem/Hydro/CR_ShockTube/generate_make.sh +++ b/example/test_problem/Hydro/CR_ShockTube/generate_make.sh @@ -2,7 +2,7 @@ PYTHON=python3 -${PYTHON} configure.py --machine=eureka_intel --model=HYDRO --flu_scheme=MHM_RP --mhd=false --flux=HLLE \ +${PYTHON} configure.py --model=HYDRO --flu_scheme=MHM_RP --mhd=false --flux=HLLE \ --cosmic_ray=true --eos=COSMIC_RAY "$@" -#${PYTHON} configure.py --machine=eureka_intel --model=HYDRO --flu_scheme=MHM_RP --mhd=true --flux=HLLD \ +#${PYTHON} configure.py --model=HYDRO --flu_scheme=MHM_RP --mhd=true --flux=HLLD \ # --cosmic_ray=true --eos=COSMIC_RAY "$@" diff --git a/example/test_problem/Hydro/CR_SoundWave/generate_make.sh b/example/test_problem/Hydro/CR_SoundWave/generate_make.sh index 15352871fb..36a09353b4 100644 --- a/example/test_problem/Hydro/CR_SoundWave/generate_make.sh +++ b/example/test_problem/Hydro/CR_SoundWave/generate_make.sh @@ -2,7 +2,7 @@ PYTHON=python3 -${PYTHON} configure.py --machine=eureka_intel --model=HYDRO --flu_scheme=MHM_RP --mhd=false --flux=HLLE \ +${PYTHON} configure.py --model=HYDRO --flu_scheme=MHM_RP --mhd=false --flux=HLLE \ --double=true --cosmic_ray=true --eos=COSMIC_RAY "$@" -#${PYTHON} configure.py --machine=eureka_intel --model=HYDRO --flu_scheme=MHM_RP --mhd=true --flux=HLLD \ +#${PYTHON} configure.py --model=HYDRO --flu_scheme=MHM_RP --mhd=true --flux=HLLD \ # --double=true --cosmic_ray=true --eos=COSMIC_RAY "$@" diff --git a/example/test_problem/Hydro/Caustic/generate_make.sh b/example/test_problem/Hydro/Caustic/generate_make.sh index 1e1a433d7b..b8fa682b4c 100644 --- a/example/test_problem/Hydro/Caustic/generate_make.sh +++ b/example/test_problem/Hydro/Caustic/generate_make.sh @@ -2,4 +2,4 @@ PYTHON=python3 -${PYTHON} configure.py --machine=eureka_intel --model=HYDRO --double=True "$@" +${PYTHON} configure.py --model=HYDRO --double=True "$@" diff --git a/example/test_problem/Hydro/ClusterMerger/generate_make.sh b/example/test_problem/Hydro/ClusterMerger/generate_make.sh index d0622ae176..8b00177e62 100644 --- a/example/test_problem/Hydro/ClusterMerger/generate_make.sh +++ b/example/test_problem/Hydro/ClusterMerger/generate_make.sh @@ -2,5 +2,5 @@ PYTHON=python3 -${PYTHON} configure.py --machine=eureka_intel --mpi=true --hdf5=true --fftw=FFTW3 --gpu=true \ +${PYTHON} configure.py --mpi=true --hdf5=true --fftw=FFTW3 --gpu=true \ --model=HYDRO --particle=true --gravity=true --passive=2 --par_attribute_int=1 "$@" diff --git a/example/test_problem/Hydro/EnergyPowerSpectrum/generate_make.sh b/example/test_problem/Hydro/EnergyPowerSpectrum/generate_make.sh index eddc712680..395fef457a 100644 --- a/example/test_problem/Hydro/EnergyPowerSpectrum/generate_make.sh +++ b/example/test_problem/Hydro/EnergyPowerSpectrum/generate_make.sh @@ -2,4 +2,4 @@ PYTHON=python3 -${PYTHON} configure.py --machine=eureka_intel --fftw=FFTW3 --model=HYDRO --eos=GAMMA --mpi=true "$@" +${PYTHON} configure.py --fftw=FFTW3 --model=HYDRO --eos=GAMMA --mpi=true "$@" diff --git a/example/test_problem/Hydro/Gravity/generate_make.sh b/example/test_problem/Hydro/Gravity/generate_make.sh index f79e63d5ba..7d876d0706 100644 --- a/example/test_problem/Hydro/Gravity/generate_make.sh +++ b/example/test_problem/Hydro/Gravity/generate_make.sh @@ -2,4 +2,4 @@ PYTHON=python3 -${PYTHON} configure.py --machine=eureka_intel --gpu=true --hdf5=true --fftw=FFTW3 --model=HYDRO --gravity=true "$@" +${PYTHON} configure.py --gpu=true --hdf5=true --fftw=FFTW3 --model=HYDRO --gravity=true "$@" diff --git a/example/test_problem/Hydro/JeansInstability/generate_make.sh b/example/test_problem/Hydro/JeansInstability/generate_make.sh index 4dcd3dbbd4..fa4ab9ee94 100644 --- a/example/test_problem/Hydro/JeansInstability/generate_make.sh +++ b/example/test_problem/Hydro/JeansInstability/generate_make.sh @@ -2,5 +2,5 @@ PYTHON=python3 -${PYTHON} configure.py --machine=eureka_intel --gpu=true --fftw=FFTW3 --double=true \ +${PYTHON} configure.py --gpu=true --fftw=FFTW3 --double=true \ --model=HYDRO --gravity=true --eos=GAMMA "$@" diff --git a/example/test_problem/Hydro/Jet/generate_make.sh b/example/test_problem/Hydro/Jet/generate_make.sh index 952e5053dd..3052779d2a 100644 --- a/example/test_problem/Hydro/Jet/generate_make.sh +++ b/example/test_problem/Hydro/Jet/generate_make.sh @@ -2,5 +2,5 @@ PYTHON=python3 -${PYTHON} configure.py --machine=eureka_intel --hdf5=true --gpu=true --mpi=true --fftw=FFTW3 \ +${PYTHON} configure.py --hdf5=true --gpu=true --mpi=true --fftw=FFTW3 \ --model=HYDRO --gravity=true "$@" diff --git a/example/test_problem/Hydro/JetICMWall/generate_make.sh b/example/test_problem/Hydro/JetICMWall/generate_make.sh index 035f4b5356..89094b3ed3 100644 --- a/example/test_problem/Hydro/JetICMWall/generate_make.sh +++ b/example/test_problem/Hydro/JetICMWall/generate_make.sh @@ -2,6 +2,6 @@ PYTHON=python3 -${PYTHON} configure.py --machine=eureka_intel --mpi=true --hdf5=true --gpu=true --model=HYDRO \ +${PYTHON} configure.py --mpi=true --hdf5=true --gpu=true --model=HYDRO \ --srhd=true --eos=TAUBMATHEWS --flux=HLLC --flu_scheme=MHM \ --passive=4 "$@" diff --git a/example/test_problem/Hydro/KelvinHelmholtzInstability/generate_make.sh b/example/test_problem/Hydro/KelvinHelmholtzInstability/generate_make.sh index 12521fa79f..e4dc316bea 100644 --- a/example/test_problem/Hydro/KelvinHelmholtzInstability/generate_make.sh +++ b/example/test_problem/Hydro/KelvinHelmholtzInstability/generate_make.sh @@ -2,4 +2,4 @@ PYTHON=python3 -${PYTHON} configure.py --machine=eureka_intel --hdf5=true --gpu=true --mpi=true --fftw=FFTW3 --model=HYDRO "$@" +${PYTHON} configure.py --hdf5=true --gpu=true --mpi=true --fftw=FFTW3 --model=HYDRO "$@" diff --git a/example/test_problem/Hydro/MHD_ABC/generate_make.sh b/example/test_problem/Hydro/MHD_ABC/generate_make.sh index 6b066a4162..e6179f90c0 100644 --- a/example/test_problem/Hydro/MHD_ABC/generate_make.sh +++ b/example/test_problem/Hydro/MHD_ABC/generate_make.sh @@ -2,5 +2,5 @@ PYTHON=python3 -${PYTHON} configure.py --machine=eureka_intel --hdf5=true --gpu=true --mpi=true \ +${PYTHON} configure.py --hdf5=true --gpu=true --mpi=true \ --model=HYDRO --mhd=true "$@" diff --git a/example/test_problem/Hydro/MHD_LinearWave/generate_make.sh b/example/test_problem/Hydro/MHD_LinearWave/generate_make.sh index f2e70fa968..751e715fdd 100644 --- a/example/test_problem/Hydro/MHD_LinearWave/generate_make.sh +++ b/example/test_problem/Hydro/MHD_LinearWave/generate_make.sh @@ -2,4 +2,4 @@ PYTHON=python3 -${PYTHON} configure.py --machine=eureka_intel --double=true --model=HYDRO --mhd=true --eos=GAMMA "$@" +${PYTHON} configure.py --double=true --model=HYDRO --mhd=true --eos=GAMMA "$@" diff --git a/example/test_problem/Hydro/MHD_OrszagTangVortex/generate_make.sh b/example/test_problem/Hydro/MHD_OrszagTangVortex/generate_make.sh index 6b066a4162..e6179f90c0 100644 --- a/example/test_problem/Hydro/MHD_OrszagTangVortex/generate_make.sh +++ b/example/test_problem/Hydro/MHD_OrszagTangVortex/generate_make.sh @@ -2,5 +2,5 @@ PYTHON=python3 -${PYTHON} configure.py --machine=eureka_intel --hdf5=true --gpu=true --mpi=true \ +${PYTHON} configure.py --hdf5=true --gpu=true --mpi=true \ --model=HYDRO --mhd=true "$@" diff --git a/example/test_problem/Hydro/ParticleEquilibriumIC/generate_make.sh b/example/test_problem/Hydro/ParticleEquilibriumIC/generate_make.sh index 7ff336392f..f028629dfc 100644 --- a/example/test_problem/Hydro/ParticleEquilibriumIC/generate_make.sh +++ b/example/test_problem/Hydro/ParticleEquilibriumIC/generate_make.sh @@ -2,5 +2,5 @@ PYTHON=python3 -${PYTHON} configure.py --machine=eureka_intel --mpi=true --hdf5=true --fftw=FFTW3 --gpu=true --gsl=true \ +${PYTHON} configure.py --mpi=true --hdf5=true --fftw=FFTW3 --gpu=true --gsl=true \ --model=HYDRO --particle=true --gravity=true "$@" diff --git a/example/test_problem/Hydro/ParticleTest/generate_make.sh b/example/test_problem/Hydro/ParticleTest/generate_make.sh index 40c13d3d6e..fe069d4ace 100644 --- a/example/test_problem/Hydro/ParticleTest/generate_make.sh +++ b/example/test_problem/Hydro/ParticleTest/generate_make.sh @@ -2,5 +2,5 @@ PYTHON=python3 -${PYTHON} configure.py --machine=eureka_intel --mpi=true --hdf5=true --fftw=FFTW3 --gpu=true \ +${PYTHON} configure.py --mpi=true --hdf5=true --fftw=FFTW3 --gpu=true \ --model=HYDRO --particle=true --tracer=true --gravity=true "$@" diff --git a/example/test_problem/Hydro/Plummer/generate_make.sh b/example/test_problem/Hydro/Plummer/generate_make.sh index fba86cf573..e022e8b448 100644 --- a/example/test_problem/Hydro/Plummer/generate_make.sh +++ b/example/test_problem/Hydro/Plummer/generate_make.sh @@ -2,5 +2,5 @@ PYTHON=python3 -${PYTHON} configure.py --machine=eureka_intel --mpi=true --hdf5=true --fftw=FFTW3 --gpu=true \ +${PYTHON} configure.py --mpi=true --hdf5=true --fftw=FFTW3 --gpu=true \ --model=HYDRO --particle=true --gravity=true "$@" diff --git a/example/test_problem/Hydro/Riemann/generate_make.sh b/example/test_problem/Hydro/Riemann/generate_make.sh index f06567704d..82120dfead 100644 --- a/example/test_problem/Hydro/Riemann/generate_make.sh +++ b/example/test_problem/Hydro/Riemann/generate_make.sh @@ -2,4 +2,4 @@ PYTHON=python3 -${PYTHON} configure.py --machine=eureka_intel --model=HYDRO "$@" +${PYTHON} configure.py --model=HYDRO "$@" diff --git a/example/test_problem/Hydro/Riemann/generate_make_Riemann_SRHD.sh b/example/test_problem/Hydro/Riemann/generate_make_Riemann_SRHD.sh index 3ce51d82d4..1805834732 100644 --- a/example/test_problem/Hydro/Riemann/generate_make_Riemann_SRHD.sh +++ b/example/test_problem/Hydro/Riemann/generate_make_Riemann_SRHD.sh @@ -2,4 +2,4 @@ PYTHON=python3 -${PYTHON} configure.py --machine=eureka_intel --model=HYDRO --srhd=true --double=true --eos=TAUBMATHEWS --flux=HLLC --flu_scheme=MHM --slope=PLM "$@" +${PYTHON} configure.py --model=HYDRO --srhd=true --double=true --eos=TAUBMATHEWS --flux=HLLC --flu_scheme=MHM --slope=PLM "$@" diff --git a/example/test_problem/Hydro/SphericalCollapse/generate_make.sh b/example/test_problem/Hydro/SphericalCollapse/generate_make.sh index 5849b640f0..6398a3fe92 100644 --- a/example/test_problem/Hydro/SphericalCollapse/generate_make.sh +++ b/example/test_problem/Hydro/SphericalCollapse/generate_make.sh @@ -2,5 +2,5 @@ PYTHON=python3 -${PYTHON} configure.py --machine=eureka_intel --mpi=true --hdf5=true --fftw=FFTW3 --gpu=true \ +${PYTHON} configure.py --mpi=true --hdf5=true --fftw=FFTW3 --gpu=true \ --model=HYDRO --gravity=true --comoving=true --dual=DE_ENPY "$@" diff --git a/example/test_problem/Hydro/Zeldovich/generate_make.sh b/example/test_problem/Hydro/Zeldovich/generate_make.sh index 0fa500a935..ac3b9a5f8b 100644 --- a/example/test_problem/Hydro/Zeldovich/generate_make.sh +++ b/example/test_problem/Hydro/Zeldovich/generate_make.sh @@ -2,6 +2,6 @@ PYTHON=python3 -${PYTHON} configure.py --machine=eureka_intel --mpi=true --hdf5=true --fftw=FFTW3 --gpu=true \ +${PYTHON} configure.py --mpi=true --hdf5=true --fftw=FFTW3 --gpu=true \ --gsl=true --double=true --model=HYDRO --gravity=true \ --comoving=true --dual=DE_ENPY --particle=true "$@" diff --git a/src/configure.py b/src/configure.py index 673bfd6604..eda31bda30 100755 --- a/src/configure.py +++ b/src/configure.py @@ -18,6 +18,15 @@ +#################################################################################################### +# Validation +#################################################################################################### +# Check the Python version +if sys.version_info[0] < 3 or sys.version_info[1] < 5: + raise BaseException("Python 3.5 or later is required.") + + + #################################################################################################### # Global variables #################################################################################################### @@ -26,15 +35,17 @@ CLOSE_DIST = 2 PRINT_WIDTH = 100 -GAMER_CONFIG_DIR = os.path.join("..", "configs") -GAMER_MAKE_BASE = "Makefile_base" -GAMER_MAKE_OUT = "Makefile" -GAMER_DESCRIPTION = "Prepare a customized Makefile for GAMER.\nDefault values are marked by '*'.\nUse -lh to show a detailed help message.\n" -GAMER_EPILOG = "2023 Computational Astrophysics Lab, NTU. All rights reserved.\n" +GAMER_CONFIG_DIR = os.path.join("..", "configs") +GAMER_MAKE_BASE = "Makefile_base" +GAMER_MAKE_OUT = "Makefile" +GAMER_LOCAL_SETTING = ".local_settings" +GAMER_GLOBAL_SETTING = os.path.expanduser("~/.config/gamer/global_settings") +GAMER_DESCRIPTION = "Prepare a customized Makefile for GAMER.\nDefault values are marked by '*'.\nUse -lh to show a detailed help message.\n" +GAMER_EPILOG = "2023 Computational Astrophysics Lab, NTU. All rights reserved.\n" LOGGER = logging.getLogger() -LOG_FORMAT = '%(asctime)s %(levelname)-8s: %(message)s' -logging.basicConfig( filename=GAMER_MAKE_OUT+'.log', filemode='w', level=logging.INFO, format=LOG_FORMAT ) +LOG_FORMAT = "%(asctime)s %(levelname)-8s: %(message)s" +logging.basicConfig( filename=GAMER_MAKE_OUT+".log", filemode="w", level=logging.INFO, format=LOG_FORMAT ) @@ -45,17 +56,17 @@ class CustomFormatter( logging.Formatter ): """ See: https://stackoverflow.com/questions/384076/how-can-i-color-python-logging-output """ - HEADER = '\033[95m' - OKBLUE = '\033[94m' - OKCYAN = '\033[96m' - OKGREEN = '\033[92m' - WARNING = '\033[93m' - FAIL = '\033[91m' - ENDC = '\033[0m' - BOLD = '\033[1m' - UNDERLINE = '\033[4m' - - CONSOLE_FORMAT = '%(levelname)-8s: %(message)s' + HEADER = "\033[95m" + OKBLUE = "\033[94m" + OKCYAN = "\033[96m" + OKGREEN = "\033[92m" + WARNING = "\033[93m" + FAIL = "\033[91m" + ENDC = "\033[0m" + BOLD = "\033[1m" + UNDERLINE = "\033[4m" + + CONSOLE_FORMAT = "%(levelname)-8s: %(message)s" FORMATS = { logging.DEBUG : HEADER + CONSOLE_FORMAT + ENDC, logging.INFO : ENDC + "%(message)s" + ENDC, logging.WARNING : WARNING + CONSOLE_FORMAT + ENDC, @@ -97,7 +108,7 @@ def parse_args( self, args=None, namespace=None ): msg = "\n" for arg in argv: if arg[0] != "-": - msg += 'Unrecognized positional argument: %s\n'%(arg) + msg += "Unrecognized positional argument: %s\n"%(arg) continue arg = arg.split("=")[0] # separate the assigned value. min_dist = 100000 @@ -107,48 +118,14 @@ def parse_args( self, args=None, namespace=None ): if dist >= min_dist: continue min_dist = dist pos_key = "--"+key - msg += 'Unrecognized argument: %s'%(arg) - if min_dist <= CLOSE_DIST: msg += ', do you mean: %s ?\n'%(pos_key) - msg += '\n' - if arg == '--gpu_arch': msg += "ERROR: <--gpu_arch> is deprecated. Please set in your machine *.config file (see ../configs/template.config).\n" + msg += "Unrecognized argument: %s"%(arg) + if min_dist <= CLOSE_DIST: msg += ", do you mean: %s ?\n"%(pos_key) + msg += "\n" + if arg == "--gpu_arch": msg += "ERROR: <--gpu_arch> is deprecated. Please set in your machine *.config file (see ../configs/template.config).\n" if len(argv) != 0: self.error( msg ) return args, self.gamer_names, self.depends, self.constraints - def _get_option_tuples(self, option_string): - # This function is directly from the source code of `argparse`. - # We decided to add the function manually because versions prior to Python 3.5 do not support `allow_abbrev`. - # See: https://github.com/python/cpython/blob/main/Lib/argparse.py - result = [] - - # option strings starting with two prefix characters are only split at the '=' - chars = self.prefix_chars - if option_string[0] in chars and option_string[1] in chars: - pass # we always use `allow_abbrev=False` - - # single character options can be concatenated with their arguments - # but multiple character options always have to have their arguments separate - elif option_string[0] in chars and option_string[1] not in chars: - option_prefix = option_string - short_option_prefix = option_string[:2] - short_explicit_arg = option_string[2:] - - for option_string in self._option_string_actions: - if option_string == short_option_prefix: - action = self._option_string_actions[option_string] - tup = action, option_string, '', short_explicit_arg - result.append(tup) - elif option_string.startswith(option_prefix): - action = self._option_string_actions[option_string] - tup = action, option_string, None, None - result.append(tup) - - # shouldn't ever get here - else: - self.error(_('unexpected option string: %s') % option_string) - - return result # return the collected option tuples - def print_usage( self, *args, **kwargs ): if "usage" in self.program: print("Usage: %s\n" % self.program["usage"]) @@ -219,6 +196,48 @@ def print_help( self, *args, **kwargs ): if "print_detail" in kwargs: self.print_option() if "epilog" in self.program: print(self.program["epilog"]) +class SystemSetting( dict ): + """ + Store the system settings from the default setting file. + + Format of the setting file: + 1. Comment starts with `#`. + 2. The line begins with the variable name, followed by one or multiple spaces, and then the value. + 3. Only the fisrt value of the line will be loaded. + 4. If a variable is defined multiple times, only the last occurrence will be used. + """ + def __init__( self, *args, **kwargs ): + super().__init__( *args, **kwargs ) + + def get_default( self, key, default_val ): + return self.get( key, default_val ) + + def load( self, pathname ): + """ + Load the system settings from the default setting file. If a setting exists, + it will be overwritten. Return `False` if the file does not exist. + + Parameters: + pathname : str - The path of the default setting file to be loaded. + + Returns: + bool - Whether the file exists. + """ + if not os.path.isfile(pathname): + return False + with open( pathname, "r" ) as f: + lines = f.readlines() + for line in lines: + tokens = line.strip().split() + if len(tokens) == 0: continue # empty line + if tokens[0][0] == "#": continue # skip comment line + if len(tokens) >= 2: + self[tokens[0]] = tokens[1] + else: # key without value + self[tokens[0]] = None + + return True + #################################################################################################### @@ -290,7 +309,7 @@ def get_gpu_compute_capability(): Others: https://en.wikipedia.org/wiki/CUDA#GPUs_supported """ CUDA_SUCCESS = 0 - libnames = ('libcuda.so', 'libcuda.dylib', 'cuda.dll') + libnames = ("libcuda.so", "libcuda.dylib", "cuda.dll") for libname in libnames: try: cuda = ctypes.CDLL(libname) @@ -299,7 +318,7 @@ def get_gpu_compute_capability(): else: break else: - raise OSError("could not load any of: " + ' '.join(libnames)) + raise OSError("could not load any of: " + " ".join(libnames)) nGpus, cc_major, cc_minor, device = ctypes.c_int(), ctypes.c_int(), ctypes.c_int(), ctypes.c_int() @@ -352,11 +371,12 @@ def string_align( string, indent_str, width, end_char ): if string[i] == end_char: new_line = True return new_str -def load_arguments(): +def load_arguments( sys_setting : SystemSetting ): parser = ArgumentParser( description = GAMER_DESCRIPTION, formatter_class = argparse.RawTextHelpFormatter, epilog = GAMER_EPILOG, - add_help = False + add_help = False, + allow_abbrev=False ) parser.add_argument( "-h", "--help", @@ -372,8 +392,8 @@ def load_arguments(): # machine config setup parser.add_argument( "--machine", type=str, metavar="MACHINE", - default="eureka_intel", - help="Select the MACHINE.config file under ../configs directory.\nChoice: [eureka_intel, YOUR_MACHINE_NAME] => " + default=sys_setting.get_default( "machine", "eureka_intel" ), + help="Select the *.config file from the ../configs directory. This will overwrite the default machine specified in the default setting file.\nChoice: [eureka_intel, spock_intel, ...] => " ) # A. options of diffierent physical models @@ -740,10 +760,14 @@ def load_arguments(): def load_config( config ): LOGGER.info("Using %s as the config."%(config)) + if not os.path.isfile( config ): + raise FileNotFoundError("The config file <%s> does not exist."%(config)) + paths, compilers = {}, {"CXX":"", "CXX_MPI":""} flags = {"CXXFLAG":"", "OPENMPFLAG":"", "LIBFLAG":"", "NVCCFLAG_COM":"", "NVCCFLAG_FLU":"", "NVCCFLAG_POT":""} gpus = {"GPU_COMPUTE_CAPABILITY":""} - with open( config, 'r') as f: + + with open( config, "r" ) as f: lines = f.readlines() for line in lines: @@ -766,10 +790,10 @@ def load_config( config ): if gpus[temp[0]] != "": LOGGER.warning("The original value will be overwritten. <%s>: %s --> %s"%(temp[0], gpus[temp[0]], temp[1])) gpus[temp[0]] = temp[1] else: - try: + if len(temp) >= 2: paths[temp[0]] = temp[1] - except: - paths[temp[0]] = '' + else: # key without value + paths[temp[0]] = "" return paths, compilers, flags, gpus @@ -903,7 +927,7 @@ def validation( paths, depends, constraints, **kwargs ): if type(check_val) != type([]): check_val = [check_val] # transform to list if kwargs[check_opt] in check_val: continue # satisify the validation - val_str = ', '.join(str(x) for x in check_val) + val_str = ", ".join(str(x) for x in check_val) LOGGER.error("The option <--%s=%s> requires <--%s> to be set to [%s]. Current: <--%s=%s>."%(opt, str(kwargs[opt]), check_opt, val_str, check_opt, kwargs[check_opt])) success = False @@ -1013,36 +1037,41 @@ def warning( paths, **kwargs ): command = " ".join(["# This makefile is generated by the following command:", "\n#", sys.executable] + sys.argv + ["\n"]) LOGGER.info( " ".join( [sys.executable] + sys.argv ) ) - # 2. Load the input arguments - args, name_table, depends, constraints = load_arguments() + # 2. Load system settings + sys_setting = SystemSetting() + sys_setting.load(GAMER_GLOBAL_SETTING) + sys_setting.load(GAMER_LOCAL_SETTING) + + # 3. Load the input arguments + args, name_table, depends, constraints = load_arguments( sys_setting ) - # 3. Prepare the makefile args - # 3.1 Load the machine setup + # 4. Prepare the makefile args + # 4.1 Load the machine setup paths, compilers, flags, gpus = load_config( os.path.join(GAMER_CONFIG_DIR, args["machine"]+".config") ) - # 3.2 Validate arguments + # 4.2 Validate arguments validation( paths, depends, constraints, **args ) warning( paths, **args ) - # 3.3 Add the SIMU_OPTION + # 4.3 Add the SIMU_OPTION LOGGER.info("========================================") LOGGER.info("GAMER has the following setting.") LOGGER.info("----------------------------------------") sims = set_sims( name_table, depends, **args ) - # 3.4 Set the compiler + # 4.4 Set the compiler compiles = set_compile( paths, compilers, flags, args ) - # 3.5 Set the GPU + # 4.5 Set the GPU gpu_setup = set_gpu( gpus, flags, args ) - # 4. Create Makefile - # 4.1 Read + # 5. Create Makefile + # 5.1 Read with open( GAMER_MAKE_BASE, "r" ) as make_base: makefile = make_base.read() - # 4.2 Replace + # 5.2 Replace LOGGER.info("----------------------------------------") for key, val in paths.items(): LOGGER.info("%-25s : %s"%(key, val)) @@ -1071,7 +1100,7 @@ def warning( paths, **kwargs ): 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) - # 4.3 Write + # 5.3 Write with open( GAMER_MAKE_OUT, "w") as make_out: make_out.write( command + makefile ) diff --git a/tool/config/set_settings.sh b/tool/config/set_settings.sh new file mode 100644 index 0000000000..69387c766b --- /dev/null +++ b/tool/config/set_settings.sh @@ -0,0 +1,296 @@ +#!/bin/bash + +################### DEFINE KEYS ################### +# The keys can not contain spaces or start with `-` +declare -A KEY_DESCRIPTIONS +KEY_DESCRIPTIONS=( + ["machine"]="Specify the machine name" +) +################################################### + +#################### UTILITIES #################### + +# List of valid keys +VALID_KEYS=("${!KEY_DESCRIPTIONS[@]}") + +# For padding keys with trailing spaces to format output +MAX_KEY_LENGTH=0 +for key in "${VALID_KEYS[@]}"; do + if [ ${#key} -gt $MAX_KEY_LENGTH ]; then + MAX_KEY_LENGTH=${#key} + fi +done + +# Print keys in a formatted way +print_key() { + # $1 : the key name + # $2 : the key value or additional message + # $3 : indent number (optional, default 0) + printf "%${3}s" "" + printf "%-${MAX_KEY_LENGTH}s %s\n" "$1" "$2" +} + +show_valid_keys() { + echo "Valid keys and their functionalities:" + for key in "${!KEY_DESCRIPTIONS[@]}"; do + print_key "$key" "${KEY_DESCRIPTIONS[$key]}" 2 + done +} + +show_help() { + echo "Usage:" + echo " $0 (--local | --global) [-l] --= ..." + echo " $0 (--local | --global) [-l] (-d | --delete) ..." + echo " $0 (--local | --global) (-l | --list)" + echo " $0 (-h | --help)" + echo "" + echo "Options:" + echo " --local Use local settings" + echo " --global Use global settings" + echo " --= Set a parameter" + echo " -d, --delete key Delete a parameter" + echo " --clear-all Clear all parameters" + echo " -l, --list List current settings" + echo " -h, --help Show this help message" + echo "" + show_valid_keys +} + +##################### PARSER ###################### + +# Parser parameters +LOCAL=false +GLOBAL=false +LIST=false +SET=false +DELETE=false +KEYS_PROCESSED=0 +declare -A SETTINGS +DELETE_KEYS=() + +# Parser utility functions +parse_set_parameter() { + local param="$1" + local key="${param%%=*}" + if [[ "$param" != *=* ]]; then + echo "Error: Invalid format for the key '$key'. Use --$key=." >&2 + exit 1 + fi + local value="${param#*=}" + SETTINGS["$key"]="$value" +} + +parse_delete_keys() { + KEYS_PROCESSED=0 + while [[ "$#" -gt 0 && "${1:0:1}" != "-" ]]; do + DELETE_KEYS+=("$1") + shift + KEYS_PROCESSED=$((KEYS_PROCESSED + 1)) + done +} + +# Main parser loop +while [[ "$#" -gt 0 ]]; do + if [[ "${1:0:1}" = "-" && "${1:0:2}" != "--" ]]; then # Short options + opt="${1:1}" + shift + while [[ -n "$opt" ]]; do # Possibly combined + case "${opt:0:1}" in + l) LIST=true ;; + h) show_help; exit 0 ;; + d) + DELETE=true + # Put the remaining combined short options back to the argument list + # Warning: This method will only apply if all other options are not order sensitive + if [[ -n "${opt:1}" ]]; then + set -- "$@" "-$(echo "${opt:1}" | tr -d 'd')" + fi + parse_delete_keys "$@" + shift $KEYS_PROCESSED + break ;; + *) + echo "Error: Unknown option: -${opt:0:1}" >&2 + printf "$(show_help)\n" >&2 + exit 1 ;; + esac + opt="${opt:1}" + done + else # Long options + case $1 in + --local) + LOCAL=true + SETTING_TYPE="local" + SETTING_FILE="../../src/.local_settings" + shift ;; + --global) + GLOBAL=true; + SETTING_TYPE="global" + SETTING_FILE="$HOME/.config/gamer/global_settings" + shift ;; + --list) LIST=true; shift ;; + --help) show_help; exit 0 ;; + --delete) + DELETE=true + shift + parse_delete_keys "$@" + shift $KEYS_PROCESSED ;; + --clear-all) + DELETE=true + DELETE_KEYS=("${VALID_KEYS[@]}") # Set DELETE_KEYS to all valid keys + shift ;; + --*) + SET=true + parse_set_parameter "${1#--}" + shift ;; + *) + echo "Error: Unknown option: $1" >&2 + printf "$(show_help)\n" >&2 + exit 1 ;; + esac + fi +done + +############### VALIDATE PARAMETERS ############### + +# Ensure at least one operation is specified +if [ "$SET" = false ] && [ "$DELETE" = false ] && [ "$LIST" = false ]; then + echo "Error: Specify at least one operation." >&2 + printf "$(show_help)\n" >&2 + exit 1 +fi + +# Validate the keys and values for setting +if [ "$SET" = true ]; then + for key in "${!SETTINGS[@]}"; do + if [[ ! " ${VALID_KEYS[@]} " =~ " $key " ]]; then + echo "Error: Invalid key '$key'." >&2 + printf "$(show_valid_keys)\n" >&2 + exit 1 + fi + if [[ -z "${SETTINGS[$key]}" ]]; then + echo "Error: The value for the key '$key' cannot be empty. Use --$key=." >&2 + exit 1 + fi + if [[ "${SETTINGS[$key]}" =~ \ ]]; then + echo "Error: The value for the key '$key' cannot contain spaces." >&2 + exit 1 + fi + done +fi + +# Ensure mutually exclusive operations +if [ "$SET" = true ] && [ "$DELETE" = true ]; then + echo "Error: Cannot set and delete parameters at the same time." >&2 + exit 1 +fi + +# Validate the keys for deletion +if [ "$DELETE" = true ]; then + if [ ${#DELETE_KEYS[@]} -eq 0 ]; then + echo "Error: No keys specified for deletion." >&2 + exit 1 + fi + for key in "${DELETE_KEYS[@]}"; do + if [[ ! " ${VALID_KEYS[@]} " =~ " $key " ]]; then + echo "Error: Invalid key '$key' for deletion." >&2 + printf "$(show_valid_keys)\n" >&2 + exit 1 + fi + done +fi + +# Ensure either --local or --global is specified +if [ "$LOCAL" = true ] && [ "$GLOBAL" = true ]; then + echo "Error: Cannot specify both --local and --global." >&2 + exit 1 +elif [ "$LOCAL" = false ] && [ "$GLOBAL" = false ]; then + echo "Error: Specify either --local or --global." >&2 + exit 1 +fi + +################ LOAD SETTINGS FILE ############### + +cd "$(dirname "$0")" + +# Load if the settings file exists +declare -A EXISTING_SETTINGS +if [ -f "$SETTING_FILE" ]; then + while read -r LINE; do + [[ "$LINE" =~ ^#.*$ ]] && continue + key="$(echo "$LINE" | awk '{print $1}')" + value="$(echo "$LINE" | awk '{print $2}')" + EXISTING_SETTINGS["$key"]="$value" + done < "$SETTING_FILE" +fi + +################# UPDATE SETTINGS ################# + +# The head of the list +if [ "$LIST" = true ]; then # Header for listing settings + echo "$SETTING_TYPE settings in $SETTING_FILE" + echo "---------------------------" +fi + +# Main loop to update or delete settings +for key in "${VALID_KEYS[@]}"; do + old_value="${EXISTING_SETTINGS[$key]}" + new_value="${SETTINGS[$key]}" + + if [ "$SET" = true ] && [ -n "$new_value" ]; then # The key will be set + + EXISTING_SETTINGS["$key"]="$new_value" # Update or set new value + if [ "$LIST" = true ]; then + if [ -z "$old_value" ]; then + print_key "$key" "$new_value (new)" + else + print_key "$key" "$old_value -> $new_value" + fi + fi + + elif [ "$DELETE" = true ] && [[ " ${DELETE_KEYS[@]} " =~ " $key " ]]; then # The key will be deleted + + unset EXISTING_SETTINGS["$key"] # Delete the key + if [ "$LIST" = true ] && [ -n "$old_value" ]; then + print_key "$key" "$old_value -> (deleted)" + fi + + elif [ "$LIST" = true ] && [ -n "$old_value" ]; then # List the existing settings + print_key "$key" "$old_value" + fi +done +[ "$LIST" = true ] && echo "---------------------------" + +################ SAVE SETTINGS FILE ############### + +if [ "$SET" = true ] || [ "$DELETE" = true ]; then + + # Create the directory and the settings file if it doesn't exist + dir="$(dirname "$SETTING_FILE")" + if [ ! -d "$dir" ]; then + mkdir -p "$dir" + echo "Created directory $dir." + fi + if [ ! -f "$SETTING_FILE" ]; then + if touch "$SETTING_FILE"; then + echo "Created file $(basename "$SETTING_FILE") in $dir." + else + echo "Fatal: Failed to create file $(basename "$SETTING_FILE") in $dir." >&2 + exit 1 + fi + fi + + # Write updated settings to file + { + echo "# GAMER setting file" + for key in "${!EXISTING_SETTINGS[@]}"; do + print_key "${key}" "${EXISTING_SETTINGS[$key]}" + done + } > "$SETTING_FILE" + + # Check if writing to file was successful + if [ $? -ne 0 ]; then + echo "Fatal: Failed to write to '$SETTING_FILE'." >&2 + exit 1 + fi + echo "Successfully updated $SETTING_TYPE settings." +fi