@@ -877,34 +877,34 @@ void gotoblas_affinity_init(void) {
877
877
nums = sysconf (_SC_NPROCESSORS_CONF );
878
878
879
879
#if !defined(__GLIBC_PREREQ )
880
- common -> num_procs = nums ;
880
+ common -> num_procs = nums > 0 ? nums : 2 ;
881
881
#else
882
882
883
883
#if !__GLIBC_PREREQ (2 , 3 )
884
- common -> num_procs = nums ;
884
+ common -> num_procs = nums > 0 ? nums : 2 ;
885
885
#elif __GLIBC_PREREQ (2 , 7 )
886
- cpusetp = CPU_ALLOC (nums );
886
+ cpusetp = CPU_ALLOC (nums > 0 ? nums : 1024 );
887
887
if (cpusetp == NULL ) {
888
- common -> num_procs = nums ;
888
+ common -> num_procs = nums > 0 ? nums : 2 ;
889
889
} else {
890
890
size_t size ;
891
- size = CPU_ALLOC_SIZE (nums );
891
+ size = CPU_ALLOC_SIZE (nums > 0 ? nums : 1024 );
892
892
ret = sched_getaffinity (0 ,size ,cpusetp );
893
893
if (ret != 0 )
894
- common -> num_procs = nums ;
894
+ common -> num_procs = nums > 0 ? nums : 1 ;
895
895
else
896
896
common -> num_procs = CPU_COUNT_S (size ,cpusetp );
897
897
}
898
898
CPU_FREE (cpusetp );
899
899
#else
900
900
ret = sched_getaffinity (0 ,sizeof (cpu_set_t ), & cpuset );
901
901
if (ret != 0 ) {
902
- common -> num_procs = nums ;
902
+ common -> num_procs = nums > 0 ? nums : 2 ;
903
903
} else {
904
904
#if !__GLIBC_PREREQ (2 , 6 )
905
905
int i ;
906
906
int n = 0 ;
907
- for (i = 0 ;i < nums ;i ++ )
907
+ for (i = 0 ;i < ( nums > 0 ? nums : 1024 ) ;i ++ )
908
908
if (CPU_ISSET (i ,& cpuset )) n ++ ;
909
909
common -> num_procs = n ;
910
910
}
@@ -1022,7 +1022,7 @@ void gotoblas_set_affinity2(int threads) {};
1022
1022
1023
1023
void gotoblas_affinity_reschedule (void ) {};
1024
1024
1025
- int get_num_procs (void ) { return sysconf (_SC_NPROCESSORS_CONF ); }
1025
+ int get_num_procs (void ) { int num = sysconf (_SC_NPROCESSORS_CONF ); return ( nums > 0 ? nums : 2 ); }
1026
1026
1027
1027
int get_num_nodes (void ) { return 1 ; }
1028
1028
0 commit comments