From 031b3ad5bb6a4bd78de8f96abce47f23adb201b6 Mon Sep 17 00:00:00 2001 From: John ZuHone Date: Mon, 30 Dec 2024 11:38:33 -0600 Subject: [PATCH 01/11] rpath handling that macOS is ok with --- src/Makefile_base | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Makefile_base b/src/Makefile_base index ab7a97e41..6c472576a 100644 --- a/src/Makefile_base +++ b/src/Makefile_base @@ -406,7 +406,7 @@ endif # ------------------------------------------------------------------------------- ifeq "$(filter -DGPU, $(SIMU_OPTION))" "-DGPU" LIB += -L$(CUDA_PATH)/lib64 -LIB += -Wl,-rpath=$(CUDA_PATH)/lib64 +LIB += -Wl,-rpath,$(CUDA_PATH)/lib64 LIB += -lcudart endif @@ -416,7 +416,7 @@ endif ifeq "$(filter -DSUPPORT_FFTW=FFTW3, $(SIMU_OPTION))" "-DSUPPORT_FFTW=FFTW3" LIB += -L$(FFTW3_PATH)/lib - LIB += -Wl,-rpath=$(FFTW3_PATH)/lib + LIB += -Wl,-rpath,$(FFTW3_PATH)/lib ifeq "$(filter -DSERIAL, $(SIMU_OPTION))" "-DSERIAL" LIB += -lfftw3 -lfftw3f -lm else @@ -430,7 +430,7 @@ endif ifeq "$(filter -DSUPPORT_FFTW=FFTW2, $(SIMU_OPTION))" "-DSUPPORT_FFTW=FFTW2" LIB += -L$(FFTW2_PATH)/lib - LIB += -Wl,-rpath=$(FFTW2_PATH)/lib + LIB += -Wl,-rpath,$(FFTW2_PATH)/lib ifeq "$(filter -DFLOAT8, $(SIMU_OPTION))" "-DFLOAT8" ifeq "$(filter -DSERIAL, $(SIMU_OPTION))" "-DSERIAL" LIB += -ldrfftw -ldfftw @@ -448,22 +448,22 @@ endif ifeq "$(filter -DSUPPORT_GRACKLE, $(SIMU_OPTION))" "-DSUPPORT_GRACKLE" LIB += -L$(GRACKLE_PATH)/lib -lgrackle -LIB += -Wl,-rpath=$(GRACKLE_PATH)/lib +LIB += -Wl,-rpath,$(GRACKLE_PATH)/lib endif ifeq "$(filter -DSUPPORT_HDF5, $(SIMU_OPTION))" "-DSUPPORT_HDF5" LIB += -L$(HDF5_PATH)/lib -lhdf5 -LIB += -Wl,-rpath=$(HDF5_PATH)/lib +LIB += -Wl,-rpath,$(HDF5_PATH)/lib endif ifeq "$(filter -DSUPPORT_GSL, $(SIMU_OPTION))" "-DSUPPORT_GSL" LIB += -L$(GSL_PATH)/lib -lgsl -lgslcblas -LIB += -Wl,-rpath=$(GSL_PATH)/lib +LIB += -Wl,-rpath,$(GSL_PATH)/lib endif ifeq "$(filter -DSUPPORT_LIBYT, $(SIMU_OPTION))" "-DSUPPORT_LIBYT" LIB += -L$(LIBYT_PATH)/lib -lyt -LIB += -Wl,-rpath=$(LIBYT_PATH)/lib +LIB += -Wl,-rpath,$(LIBYT_PATH)/lib endif From 2043e655bc45f4eaf6421e634fd2173588132916 Mon Sep 17 00:00:00 2001 From: John ZuHone Date: Mon, 30 Dec 2024 11:56:33 -0600 Subject: [PATCH 02/11] Silence CPU and memory reporting on macOS --- src/Auxiliary/Aux_Check_MemFree.cpp | 5 +++++ src/Auxiliary/Aux_GetCPUInfo.cpp | 7 +++++++ src/Auxiliary/Aux_TakeNote.cpp | 16 +++------------- src/Main/Main.cpp | 11 ++++++++++- 4 files changed, 25 insertions(+), 14 deletions(-) diff --git a/src/Auxiliary/Aux_Check_MemFree.cpp b/src/Auxiliary/Aux_Check_MemFree.cpp index bfbe6b431..e69121838 100644 --- a/src/Auxiliary/Aux_Check_MemFree.cpp +++ b/src/Auxiliary/Aux_Check_MemFree.cpp @@ -18,6 +18,11 @@ void Aux_Check_MemFree( const double MinMemFree_Total, const char *comment ) { +#ifdef __APPLE__ + // memory reporting is not currently supported on macOS + return; +#endif + const int StrSize = 128; const char FileName_Mem[StrSize] = "/proc/meminfo"; diff --git a/src/Auxiliary/Aux_GetCPUInfo.cpp b/src/Auxiliary/Aux_GetCPUInfo.cpp index d8828be4f..a88d55f3a 100644 --- a/src/Auxiliary/Aux_GetCPUInfo.cpp +++ b/src/Auxiliary/Aux_GetCPUInfo.cpp @@ -12,6 +12,13 @@ void Aux_GetCPUInfo( const char *FileName ) { +#ifdef __APPLE__ + + Aux_Message( stderr, "WARNING : function \"%s\" is not supported on macOS !!\n", __FUNCTION__ ); + return; + +#endif + FILE *Note = fopen( FileName, "a" ); char *line = NULL; size_t len = 0; diff --git a/src/Auxiliary/Aux_TakeNote.cpp b/src/Auxiliary/Aux_TakeNote.cpp index 76a749111..2fef66da4 100644 --- a/src/Auxiliary/Aux_TakeNote.cpp +++ b/src/Auxiliary/Aux_TakeNote.cpp @@ -4,9 +4,6 @@ #include "CUPOT.h" #endif #include -#ifdef __APPLE__ -#include -#endif #include "time.h" static int get_cpuid(); @@ -2054,23 +2051,16 @@ void Aux_TakeNote() // Function : get_cpuid // Description : Get the CPU ID // -// Note : Work on both macOS and Linux systems +// Note : Works only on Linux systems; macOS is ignored //------------------------------------------------------------------------------------------------------- int get_cpuid() { -// See https://stackoverflow.com/questions/33745364/sched-getcpu-equivalent-for-os-x int CPU; # ifdef __APPLE__ - uint32_t CPUInfo[4]; - __cpuid_count(1, 0, CPUInfo[0], CPUInfo[1], CPUInfo[2], CPUInfo[3]); - if ((CPUInfo[3] & (1 << 9)) == 0) { - CPU = -1; /* no APIC on chip */ - } else { - CPU = (unsigned)CPUInfo[1] >> 24; - } - if (CPU < 0) CPU = 0; + // macOS does not have an implementation of sched_getcpu that works cross-arch + CPU = -1; # else CPU = sched_getcpu(); # endif diff --git a/src/Main/Main.cpp b/src/Main/Main.cpp index c2993e750..739dfa63e 100644 --- a/src/Main/Main.cpp +++ b/src/Main/Main.cpp @@ -619,7 +619,13 @@ int main( int argc, char *argv[] ) Output_DumpData( 0 ); if ( OPT__PATCH_COUNT > 0 ) Aux_Record_PatchCount(); - if ( OPT__RECORD_MEMORY ) Aux_GetMemInfo(); + if ( OPT__RECORD_MEMORY ) +# ifdef __APPLE__ + Aux_Message( stderr, "WARNING : memory reporting is not currently supported on macOS !!\n" ); +# else + Aux_GetMemInfo(); +# endif + if ( OPT__RECORD_USER ) { if ( Aux_Record_User_Ptr != NULL ) Aux_Record_User_Ptr(); else @@ -711,7 +717,10 @@ int main( int argc, char *argv[] ) TIMING_FUNC( Aux_Record_PatchCount(), Timer_Main[4], TIMER_ON ); if ( OPT__RECORD_MEMORY ) +# ifndef __APPLE__ + // memory reporting is not currently supported on macOS TIMING_FUNC( Aux_GetMemInfo(), Timer_Main[4], TIMER_ON ); +# endif if ( OPT__RECORD_USER ) TIMING_FUNC( Aux_Record_User_Ptr(), Timer_Main[4], TIMER_ON ); From cb93202d96d3ca2f1fbc46938ca1619c5ea41415 Mon Sep 17 00:00:00 2001 From: John ZuHone Date: Mon, 30 Dec 2024 12:41:01 -0600 Subject: [PATCH 03/11] Two configs for macOS based on arch --- configs/mac_clang.config | 41 ++++++++++++++++++++++++++ configs/{mac.config => mac_gnu.config} | 6 ++-- 2 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 configs/mac_clang.config rename configs/{mac.config => mac_gnu.config} (90%) diff --git a/configs/mac_clang.config b/configs/mac_clang.config new file mode 100644 index 000000000..8596c4dbd --- /dev/null +++ b/configs/mac_clang.config @@ -0,0 +1,41 @@ +# A "typical" macOS installation without GPU +FFTW2_PATH /usr/local/fftw-2.1.5 +MPI_PATH /usr/local/mpich-3.2 +GSL_PATH /usr/local/gsl-1.16 +HDF5_PATH ${HOME}/mambaforge/envs/py312 + +# compilers +CXX clang++ +CXX_MPI mpicxx + +# gnu flags +CXXFLAG -g +CXXFLAG -O3 +CXXFLAG -std=c++11 +#CXXFLAG -Ofast +CXXFLAG -Wall +CXXFLAG -Wextra +CXXFLAG -Wno-unused-variable +CXXFLAG -Wno-unused-parameter +CXXFLAG -Wno-uninitialized +CXXFLAG -Wno-unused-but-set-variable +CXXFLAG -Wno-unused-function +CXXFLAG -Wno-unused-result +CXXFLAG -Wno-implicit-fallthrough +CXXFLAG -Wno-parentheses +CXXFLAG -Wno-unknown-pragmas +CXXFLAG -Wno-mismatched-tags +CXXFLAG -Wno-deprecated-declarations +CXXFLAG -Wno-missing-braces + +OPENMPFLAG -fopenmp + +LIBFLAG + +NVCCFLAG_COM -O3 +#NVCCFLAG_COM -use_fast_math +NVCCFLAG_FLU -Xptxas -dlcm=ca -prec-div=false -ftz=true +NVCCFLAG_POT -Xptxas -dlcm=ca + +#gpu +GPU_COMPUTE_CAPABILITY -1 diff --git a/configs/mac.config b/configs/mac_gnu.config similarity index 90% rename from configs/mac.config rename to configs/mac_gnu.config index fc963cb87..bf1c46444 100644 --- a/configs/mac.config +++ b/configs/mac_gnu.config @@ -1,17 +1,17 @@ # A "typical" macOS installation without GPU FFTW2_PATH /usr/local/fftw-2.1.5 MPI_PATH /usr/local/mpich-3.2 -HDF5_PATH ${HOME}/miniconda3 GSL_PATH /usr/local/gsl-1.16 +HDF5_PATH ${HOME}/mambaforge/envs/py312 # compilers -CXX g++ +CXX g++-12 CXX_MPI mpicxx # gnu flags CXXFLAG -g CXXFLAG -O3 -#CXXFLAG -std=c++11 +CXXFLAG -std=c++11 #CXXFLAG -Ofast CXXFLAG -Wall CXXFLAG -Wextra From b29cc857089dba16a6300dc33327b335ab4768dd Mon Sep 17 00:00:00 2001 From: John ZuHone Date: Fri, 3 Jan 2025 15:56:21 -0500 Subject: [PATCH 04/11] Let the architecture determine the rng by default --- src/configure.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/configure.py b/src/configure.py index 4b220889e..e1b4b3be7 100755 --- a/src/configure.py +++ b/src/configure.py @@ -686,7 +686,7 @@ def load_arguments(): ) parser.add_argument( "--rng", type=str, metavar="TYPE", gamer_name="RANDOM_NUMBER", - default="RNG_GNU_EXT", + default=None, choices=["RNG_GNU_EXT", "RNG_CPP11"], help="Select the random number generator (RNG_GNU_EXT: GNU extension drand48_r, RNG_CPP11: c++11 ).\nRNG_GNU_EXT may not be supported on some macOS.\nFor RNG_CPP11, add -std=c++11 to CXXFLAG in your config file.\n" ) @@ -783,6 +783,10 @@ def set_conditional_defaults( args ): if args["barotropic"] is None: args["barotropic"] = (args["eos"] == "ISOTHERMAL") + + if args["rng"] is None: + args["rng"] = "RNG_CPP11" if sys.platform == "darwin" else "RNG_GNU_EXT" + return args def set_gpu( gpus, flags, args ): From 812b73fe49afad50c7a57be3074b6f2cab536172 Mon Sep 17 00:00:00 2001 From: John ZuHone Date: Fri, 3 Jan 2025 16:06:55 -0500 Subject: [PATCH 05/11] Raise an error in configure if we try to set a different random number generator than CPP11 for macOS --- src/configure.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/configure.py b/src/configure.py index e1b4b3be7..6c5fdb604 100755 --- a/src/configure.py +++ b/src/configure.py @@ -957,6 +957,10 @@ def validation( paths, depends, constraints, **kwargs ): LOGGER.error("<--overlap_mpi> is not supported yet.") success = False + if kwargs["rng"] != "RNG_CPP11" and sys.platform == "darwin": + LOGGER.error("<--rng=RNG_CPP11> is required for macOS.") + success = False + if not success: raise BaseException( "The above vaildation failed." ) return From 92160d314070c7eb7f55e5881059ec4048655415 Mon Sep 17 00:00:00 2001 From: John ZuHone Date: Fri, 3 Jan 2025 16:19:11 -0500 Subject: [PATCH 06/11] Update openmp flags for clang --- configs/mac_clang.config | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/configs/mac_clang.config b/configs/mac_clang.config index 8596c4dbd..d9c9e6601 100644 --- a/configs/mac_clang.config +++ b/configs/mac_clang.config @@ -28,9 +28,9 @@ CXXFLAG -Wno-mismatched-tags CXXFLAG -Wno-deprecated-declarations CXXFLAG -Wno-missing-braces -OPENMPFLAG -fopenmp +OPENMPFLAG -Xclang -fopenmp -LIBFLAG +LIBFLAG -lomp NVCCFLAG_COM -O3 #NVCCFLAG_COM -use_fast_math From cc23257d37c89efa16419d761cffc99bde5e5565 Mon Sep 17 00:00:00 2001 From: John ZuHone Date: Fri, 3 Jan 2025 16:19:43 -0500 Subject: [PATCH 07/11] Add an error message when trying to compile with RANDOM_NUMBER != RNG_CPP11 --- include/RandomNumber.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/RandomNumber.h b/include/RandomNumber.h index 02973cee3..3fdcdfa85 100644 --- a/include/RandomNumber.h +++ b/include/RandomNumber.h @@ -13,6 +13,10 @@ #error : ERROR : unsupported RANDOM_NUMBER !! #endif +#if ( ( defined (__APPLE__) || defined (__MACH__) ) && RANDOM_NUMBER != RNG_CPP11 ) +#error : ERROR : macOS requires RANDOM_NUMBER == RNG_CPP11 !! +#endif + void Aux_Error( const char *File, const int Line, const char *Func, const char *Format, ... ); From 25ee54d373b29eef347a2d0e27cb580f56c87bf6 Mon Sep 17 00:00:00 2001 From: John ZuHone Date: Thu, 9 Jan 2025 11:27:11 -0500 Subject: [PATCH 08/11] Apply suggestions from code review Co-authored-by: Chun-Yen Chen <70311975+ChunYen-Chen@users.noreply.github.com> --- configs/mac_clang.config | 2 +- src/Auxiliary/Aux_Check_MemFree.cpp | 2 +- src/Auxiliary/Aux_GetCPUInfo.cpp | 2 -- src/Auxiliary/Aux_TakeNote.cpp | 2 +- src/Main/Main.cpp | 2 +- 5 files changed, 4 insertions(+), 6 deletions(-) diff --git a/configs/mac_clang.config b/configs/mac_clang.config index d9c9e6601..592511a21 100644 --- a/configs/mac_clang.config +++ b/configs/mac_clang.config @@ -8,7 +8,7 @@ HDF5_PATH ${HOME}/mambaforge/envs/py312 CXX clang++ CXX_MPI mpicxx -# gnu flags +# clang flags CXXFLAG -g CXXFLAG -O3 CXXFLAG -std=c++11 diff --git a/src/Auxiliary/Aux_Check_MemFree.cpp b/src/Auxiliary/Aux_Check_MemFree.cpp index e69121838..57bc32bfc 100644 --- a/src/Auxiliary/Aux_Check_MemFree.cpp +++ b/src/Auxiliary/Aux_Check_MemFree.cpp @@ -19,7 +19,7 @@ void Aux_Check_MemFree( const double MinMemFree_Total, const char *comment ) { #ifdef __APPLE__ - // memory reporting is not currently supported on macOS +// memory reporting is not currently supported on macOS return; #endif diff --git a/src/Auxiliary/Aux_GetCPUInfo.cpp b/src/Auxiliary/Aux_GetCPUInfo.cpp index a88d55f3a..135c208ac 100644 --- a/src/Auxiliary/Aux_GetCPUInfo.cpp +++ b/src/Auxiliary/Aux_GetCPUInfo.cpp @@ -13,10 +13,8 @@ void Aux_GetCPUInfo( const char *FileName ) { #ifdef __APPLE__ - Aux_Message( stderr, "WARNING : function \"%s\" is not supported on macOS !!\n", __FUNCTION__ ); return; - #endif FILE *Note = fopen( FileName, "a" ); diff --git a/src/Auxiliary/Aux_TakeNote.cpp b/src/Auxiliary/Aux_TakeNote.cpp index 2fef66da4..74f5726cc 100644 --- a/src/Auxiliary/Aux_TakeNote.cpp +++ b/src/Auxiliary/Aux_TakeNote.cpp @@ -2059,7 +2059,7 @@ int get_cpuid() int CPU; # ifdef __APPLE__ - // macOS does not have an implementation of sched_getcpu that works cross-arch +// macOS does not have an implementation of sched_getcpu that works cross-arch CPU = -1; # else CPU = sched_getcpu(); diff --git a/src/Main/Main.cpp b/src/Main/Main.cpp index 739dfa63e..6af040103 100644 --- a/src/Main/Main.cpp +++ b/src/Main/Main.cpp @@ -718,7 +718,7 @@ int main( int argc, char *argv[] ) if ( OPT__RECORD_MEMORY ) # ifndef __APPLE__ - // memory reporting is not currently supported on macOS +// memory reporting is not currently supported on macOS TIMING_FUNC( Aux_GetMemInfo(), Timer_Main[4], TIMER_ON ); # endif From dda2216b3c46616634b165df742b057a1fa62220 Mon Sep 17 00:00:00 2001 From: John ZuHone Date: Sun, 19 Jan 2025 01:24:23 -0500 Subject: [PATCH 09/11] Simplify this by dropping out of Aux_GetMemInfo immediately if we are on macOS --- src/Auxiliary/Aux_GetMemInfo.cpp | 5 +++++ src/Main/Main.cpp | 10 +--------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/Auxiliary/Aux_GetMemInfo.cpp b/src/Auxiliary/Aux_GetMemInfo.cpp index 1eec0d743..60513a39a 100644 --- a/src/Auxiliary/Aux_GetMemInfo.cpp +++ b/src/Auxiliary/Aux_GetMemInfo.cpp @@ -17,6 +17,11 @@ void Aux_GetMemInfo() { +// memory reporting is not currently supported on macOS +# ifdef __APPLE__ + return; +# endif + const char FileName_Record[] = "Record__MemInfo"; const int PID = getpid(); const int NInfo = 4; // number of memory information to be recorded (VmSize/Peak, VmRSS/HWM) diff --git a/src/Main/Main.cpp b/src/Main/Main.cpp index 6af040103..269c90dd9 100644 --- a/src/Main/Main.cpp +++ b/src/Main/Main.cpp @@ -619,12 +619,7 @@ int main( int argc, char *argv[] ) Output_DumpData( 0 ); if ( OPT__PATCH_COUNT > 0 ) Aux_Record_PatchCount(); - if ( OPT__RECORD_MEMORY ) -# ifdef __APPLE__ - Aux_Message( stderr, "WARNING : memory reporting is not currently supported on macOS !!\n" ); -# else - Aux_GetMemInfo(); -# endif + if ( OPT__RECORD_MEMORY ) Aux_GetMemInfo(); if ( OPT__RECORD_USER ) { if ( Aux_Record_User_Ptr != NULL ) Aux_Record_User_Ptr(); @@ -717,10 +712,7 @@ int main( int argc, char *argv[] ) TIMING_FUNC( Aux_Record_PatchCount(), Timer_Main[4], TIMER_ON ); if ( OPT__RECORD_MEMORY ) -# ifndef __APPLE__ -// memory reporting is not currently supported on macOS TIMING_FUNC( Aux_GetMemInfo(), Timer_Main[4], TIMER_ON ); -# endif if ( OPT__RECORD_USER ) TIMING_FUNC( Aux_Record_User_Ptr(), Timer_Main[4], TIMER_ON ); From ceb09238cbd78d7dc6d1646f267ad7d336ddb51d Mon Sep 17 00:00:00 2001 From: John ZuHone Date: Sun, 19 Jan 2025 01:24:49 -0500 Subject: [PATCH 10/11] Add the warning message here --- src/Auxiliary/Aux_Check_Parameter.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Auxiliary/Aux_Check_Parameter.cpp b/src/Auxiliary/Aux_Check_Parameter.cpp index c8da7feba..4e0ba1d21 100644 --- a/src/Auxiliary/Aux_Check_Parameter.cpp +++ b/src/Auxiliary/Aux_Check_Parameter.cpp @@ -243,6 +243,11 @@ void Aux_Check_Parameter() if ( OPT__MEMORY_POOL && !OPT__REUSE_MEMORY ) Aux_Error( ERROR_INFO, "please turn on OPT__REUSE_MEMORY for OPT__MEMORY_POOL !!\n" ); +# ifdef __APPLE__ + if ( OPT__RECORD_MEMORY ) + Aux_Message( stderr, "WARNING : memory reporting is not currently supported on macOS !!\n" ); +# endif + if ( OPT__CORR_AFTER_ALL_SYNC != CORR_AFTER_SYNC_NONE && OPT__CORR_AFTER_ALL_SYNC != CORR_AFTER_SYNC_EVERY_STEP && OPT__CORR_AFTER_ALL_SYNC != CORR_AFTER_SYNC_BEFORE_DUMP ) Aux_Error( ERROR_INFO, "incorrect option \"OPT__CORR_AFTER_ALL_SYNC = %d\" [0/1/2] !!\n", OPT__CORR_AFTER_ALL_SYNC ); From 4bce5dd9454a7afccf1b13a5eb2bf7c9bc1b458e Mon Sep 17 00:00:00 2001 From: John ZuHone Date: Sun, 19 Jan 2025 01:29:06 -0500 Subject: [PATCH 11/11] Remove line I added --- src/Main/Main.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Main/Main.cpp b/src/Main/Main.cpp index 0ebd94e3b..8cdbe9629 100644 --- a/src/Main/Main.cpp +++ b/src/Main/Main.cpp @@ -626,7 +626,6 @@ int main( int argc, char *argv[] ) if ( OPT__PATCH_COUNT > 0 ) Aux_Record_PatchCount(); if ( OPT__RECORD_MEMORY ) Aux_GetMemInfo(); - if ( OPT__RECORD_USER ) { if ( Aux_Record_User_Ptr != NULL ) Aux_Record_User_Ptr(); else