| @@ -105,6 +105,7 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||||
| #if defined(OS_FREEBSD) || defined(OS_DARWIN) | #if defined(OS_FREEBSD) || defined(OS_DARWIN) | ||||
| #include <sys/sysctl.h> | #include <sys/sysctl.h> | ||||
| #include <sys/resource.h> | |||||
| #endif | #endif | ||||
| #if defined(OS_WINDOWS) && (defined(__MINGW32__) || defined(__MINGW64__)) | #if defined(OS_WINDOWS) && (defined(__MINGW32__) || defined(__MINGW64__)) | ||||
| @@ -216,6 +217,24 @@ int get_num_procs(void) { | |||||
| } | } | ||||
| return nums; | return nums; | ||||
| } | } | ||||
| void set_stack_limit(int limitMB){ | |||||
| int result=0; | |||||
| struct rlimit rl; | |||||
| rlim_t StackSize; | |||||
| StackSize=limitMB*1024*1024; | |||||
| result=getrlimit(RLIMIT_STACK, &rl); | |||||
| if(result==0){ | |||||
| if(rl.rlim_cur < StackSize){ | |||||
| rl.rlim_cur=StackSize; | |||||
| result=setrlimit(RLIMIT_STACK, &rl); | |||||
| if(result !=0){ | |||||
| fprintf(stderr, "OpenBLAS: set stack limit error =%d\n", result); | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| #endif | #endif | ||||
| /* | /* | ||||
| @@ -1248,11 +1267,18 @@ void CONSTRUCTOR gotoblas_init(void) { | |||||
| if (gotoblas_initialized) return; | if (gotoblas_initialized) return; | ||||
| #ifdef PROFILE | #ifdef PROFILE | ||||
| moncontrol (0); | moncontrol (0); | ||||
| #endif | #endif | ||||
| #ifdef DYNAMIC_ARCH | #ifdef DYNAMIC_ARCH | ||||
| #if defined(SMP) && defined(OS_DARWIN) && MAX_CPU_NUMBER > 128 | |||||
| //Set stack limit to 16MB on Mac OS X | |||||
| //when NUM_THREADS>128 and DYNAMIC_ARCH=1. | |||||
| //Prevent the SEGFAULT bug. | |||||
| set_stack_limit(16); | |||||
| #endif | |||||
| gotoblas_dynamic_init(); | gotoblas_dynamic_init(); | ||||
| #endif | #endif | ||||