@@ -115,6 +115,27 @@ int blas_server_avail __attribute__((aligned(ATTRIBUTE_SIZE))) = 0;
115115
116116int blas_omp_threads_local = 1 ;
117117
118+ #ifdef BLAS_THREAD_LOCAL
119+ BLAS_THREAD_LOCAL int blas_thread_in_job = 0 ;
120+ #define blas_set_in_job (v ) (blas_thread_in_job = (v))
121+ #else
122+ static pthread_key_t blas_in_job_key ;
123+ static pthread_once_t blas_in_job_once = PTHREAD_ONCE_INIT ;
124+ static int blas_in_job_key_ok = 0 ;
125+ static void blas_in_job_key_init (void ) {
126+ blas_in_job_key_ok = (pthread_key_create (& blas_in_job_key , NULL ) == 0 );
127+ }
128+ int blas_in_job (void ) {
129+ pthread_once (& blas_in_job_once , blas_in_job_key_init );
130+ return blas_in_job_key_ok && pthread_getspecific (blas_in_job_key ) != NULL ;
131+ }
132+ static void blas_set_in_job (int v ) {
133+ pthread_once (& blas_in_job_once , blas_in_job_key_init );
134+ if (blas_in_job_key_ok )
135+ pthread_setspecific (blas_in_job_key , v ? (void * )1 : NULL );
136+ }
137+ #endif
138+
118139static void * blas_thread_buffer [MAX_CPU_NUMBER ];
119140
120141/* Local Variables */
@@ -390,6 +411,9 @@ blas_queue_t *tscq;
390411 unsigned long start , stop ;
391412#endif
392413
414+ /* this thread only ever runs jobs of the pool */
415+ blas_set_in_job (1 );
416+
393417#if defined(OS_LINUX ) && !defined(NO_AFFINITY )
394418 if (!increased_threads )
395419 thread_status [cpu ].node = gotoblas_set_affinity (cpu + 1 );
@@ -795,6 +819,7 @@ int exec_blas(BLASLONG num, blas_queue_t *queue){
795819 if (unlikely (blas_server_avail == 0 )) blas_thread_init ();
796820#endif
797821 int (* routine )(blas_arg_t * , void * , void * , double * , double * , BLASLONG );
822+ int in_job ;
798823
799824#ifdef TIMING_DEBUG
800825 BLASULONG start , stop ;
@@ -839,6 +864,9 @@ if (openblas_threads_callback_) {
839864 routine = (int (* )(blas_arg_t * , void * , void * , double * , double * , BLASLONG ))queue -> routine ;
840865 queue -> worker_sb = queue -> sb ;
841866
867+ in_job = blas_in_job ();
868+ blas_set_in_job (1 );
869+
842870 if (queue -> mode & BLAS_LEGACY ) {
843871 legacy_exec (routine , queue -> mode , queue -> args , queue -> sb );
844872 } else
@@ -849,6 +877,8 @@ if (openblas_threads_callback_) {
849877 (routine )(queue -> args , queue -> range_m , queue -> range_n ,
850878 queue -> sa , queue -> sb , 0 );
851879
880+ blas_set_in_job (in_job );
881+
852882#ifdef TIMING_DEBUG
853883 stop = rpcc ();
854884#endif
@@ -1059,6 +1089,7 @@ static void adjust_thread_buffers() {
10591089static void exec_threads (int cpu , blas_queue_t * queue , int buf_index ) {
10601090
10611091 int (* routine )(blas_arg_t * , void * , void * , void * , void * , BLASLONG ) = (int (* )(blas_arg_t * , void * , void * , void * , void * , BLASLONG ))queue -> routine ;
1092+ int in_job = blas_in_job ();
10621093
10631094 atomic_store_queue (& thread_status [cpu ].queue , (blas_queue_t * )1 );
10641095
@@ -1149,6 +1180,8 @@ if (!(queue -> mode & BLAS_COMPLEX)){
11491180main_status [cpu ] = MAIN_RUNNING2 ;
11501181#endif
11511182
1183+ blas_set_in_job (1 );
1184+
11521185 if (queue -> mode & BLAS_LEGACY ) {
11531186legacy_exec (routine , queue -> mode , queue -> args , sb );
11541187 } else
@@ -1158,6 +1191,8 @@ if (queue -> mode & BLAS_PTHREAD) {
11581191} else
11591192 (routine )(queue -> args , queue -> range_m , queue -> range_n , sa , sb , queue -> position );
11601193
1194+ blas_set_in_job (in_job );
1195+
11611196#ifdef SMP_DEBUG
11621197 fprintf (STDERR , "Server[%2ld] Calculation finished!\n" , cpu );
11631198#endif
0 commit comments