File tree 1 file changed +26
-0
lines changed 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -105,6 +105,7 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
105
105
106
106
#if defined(OS_FREEBSD ) || defined(OS_DARWIN )
107
107
#include <sys/sysctl.h>
108
+ #include <sys/resource.h>
108
109
#endif
109
110
110
111
#if defined(OS_WINDOWS ) && (defined(__MINGW32__ ) || defined(__MINGW64__ ))
@@ -216,6 +217,24 @@ int get_num_procs(void) {
216
217
}
217
218
return nums ;
218
219
}
220
+
221
+ void set_stack_limit (int limitMB ){
222
+ int result = 0 ;
223
+ struct rlimit rl ;
224
+ rlim_t StackSize ;
225
+
226
+ StackSize = limitMB * 1024 * 1024 ;
227
+ result = getrlimit (RLIMIT_STACK , & rl );
228
+ if (result == 0 ){
229
+ if (rl .rlim_cur < StackSize ){
230
+ rl .rlim_cur = StackSize ;
231
+ result = setrlimit (RLIMIT_STACK , & rl );
232
+ if (result != 0 ){
233
+ fprintf (stderr , "OpenBLAS: set stack limit error =%d\n" , result );
234
+ }
235
+ }
236
+ }
237
+ }
219
238
#endif
220
239
221
240
/*
@@ -1248,11 +1267,18 @@ void CONSTRUCTOR gotoblas_init(void) {
1248
1267
1249
1268
if (gotoblas_initialized ) return ;
1250
1269
1270
+
1251
1271
#ifdef PROFILE
1252
1272
moncontrol (0 );
1253
1273
#endif
1254
1274
1255
1275
#ifdef DYNAMIC_ARCH
1276
+ #if defined(SMP ) && defined(OS_DARWIN ) && MAX_CPU_NUMBER > 128
1277
+ //Set stack limit to 16MB on Mac OS X
1278
+ //when NUM_THREADS>128 and DYNAMIC_ARCH=1.
1279
+ //Prevent the SEGFAULT bug.
1280
+ set_stack_limit (16 );
1281
+ #endif
1256
1282
gotoblas_dynamic_init ();
1257
1283
#endif
1258
1284
You can’t perform that action at this time.
0 commit comments