Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates to support macOS #393

Merged
merged 13 commits into from
Jan 22, 2025
Merged
41 changes: 41 additions & 0 deletions configs/mac_clang.config
Original file line number Diff line number Diff line change
@@ -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

# clang 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 -Xclang -fopenmp

LIBFLAG -lomp

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
6 changes: 3 additions & 3 deletions configs/mac.config → configs/mac_gnu.config
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 4 additions & 0 deletions include/RandomNumber.h
Original file line number Diff line number Diff line change
Expand Up @@ -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, ... );


Expand Down
5 changes: 5 additions & 0 deletions src/Auxiliary/Aux_Check_MemFree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
5 changes: 5 additions & 0 deletions src/Auxiliary/Aux_Check_Parameter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
5 changes: 5 additions & 0 deletions src/Auxiliary/Aux_GetCPUInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
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;
Expand Down
5 changes: 5 additions & 0 deletions src/Auxiliary/Aux_GetMemInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
void Aux_GetMemInfo()
{

// memory reporting is not currently supported on macOS
# ifdef __APPLE__
return;
# endif

const int PID = getpid();
const int NInfo = 4; // number of memory information to be recorded (VmSize/Peak, VmRSS/HWM)

Expand Down
16 changes: 3 additions & 13 deletions src/Auxiliary/Aux_TakeNote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
#include "CUPOT.h"
#endif
#include <sched.h>
#ifdef __APPLE__
#include <cpuid.h>
#endif
#include "time.h"

static int get_cpuid();
Expand Down Expand Up @@ -2107,23 +2104,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
Expand Down
14 changes: 7 additions & 7 deletions src/Makefile_base
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,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

Expand All @@ -417,7 +417,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
Expand All @@ -431,7 +431,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
Expand All @@ -449,22 +449,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


Expand Down
10 changes: 9 additions & 1 deletion src/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ def load_arguments( sys_setting : SystemSetting ):
)

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 <random>).\nRNG_GNU_EXT may not be supported on some macOS.\nFor RNG_CPP11, add -std=c++11 to CXXFLAG in your config file.\n"
)
Expand Down Expand Up @@ -820,6 +820,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 ):
Expand Down Expand Up @@ -993,6 +997,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

Expand Down
Loading