diff --git a/qpms/oshacks.h b/qpms/oshacks.h new file mode 100644 index 0000000..3ea658f --- /dev/null +++ b/qpms/oshacks.h @@ -0,0 +1,23 @@ +#ifndef _QPMS_OSHACKS_H +#define _QPMS_OSHACKS_H +#include + +#ifdef _SC_NPROCESSORS_ONLN +static inline long get_ncpus(void) { + return sysconf(_SC_NPROCESSORS_ONLN); +} +#elif (0) +#include +#include +static inline long get_ncpus(void) { + int32_t ncpu; + size_t len = sizeof(ncpu); + sysctlbyname("hw.physicalcpu", &ncpu, &len, NULL, 0); + return ncpu; +} +#else +static inline long get_ncpus(void) { return -1; } +#endif + + +#endif // _QPMS_OSHACKS_H diff --git a/qpms/tmatrices.c b/qpms/tmatrices.c index bed7088..44b8ed0 100644 --- a/qpms/tmatrices.c +++ b/qpms/tmatrices.c @@ -14,7 +14,6 @@ #include "groups.h" #include "symmetries.h" #include -#include #include "vectors.h" #include "quaternions.h" #include @@ -27,6 +26,7 @@ #include #include #include "optim.h" +#include "oshacks.h" // These are quite arbitrarily chosen constants for the quadrature in qpms_tmatrix_axialsym_fill() #define TMATRIX_AXIALSYM_INTEGRAL_EPSREL (1e-5) @@ -850,7 +850,7 @@ qpms_errno_t qpms_tmatrix_axialsym_fill( QPMS_DEBUG(QPMS_DBGMSG_THREADS, "Using overriding value of %ld thread(s).", nthreads); } else { - nthreads = sysconf(_SC_NPROCESSORS_ONLN); + nthreads = get_ncpus(); if (nthreads < 1) { QPMS_DEBUG(QPMS_DBGMSG_THREADS, "_SC_NPROCESSORS_ONLN returned %ld, using %ld thread(s) instead.", nthreads, qpms_axsym_tmatrix_integration_nthreads_default);