pdlmagic.c (PDL-2.074) | : | pdlmagic.c (PDL-2.075) | ||
---|---|---|---|---|
skipping to change at line 279 | skipping to change at line 279 | |||
} | } | |||
int pdl_magic_get_thread(pdl *it) { | int pdl_magic_get_thread(pdl *it) { | |||
pdl_magic_pthread *ptr = (pdl_magic_pthread *)pdl__find_magic(it, PDL_MAG IC_THREADING); | pdl_magic_pthread *ptr = (pdl_magic_pthread *)pdl__find_magic(it, PDL_MAG IC_THREADING); | |||
if(!ptr) return -1; | if(!ptr) return -1; | |||
int *p = (int*)pthread_getspecific(ptr->key); | int *p = (int*)pthread_getspecific(ptr->key); | |||
if(!p) return -1; | if(!p) return -1; | |||
return *p; | return *p; | |||
} | } | |||
pdl_error pdl_magic_thread_cast(pdl *it,pdl_error (*func)(pdl_trans *),pdl_trans *t, pdl_thread *thread) { | pdl_error pdl_magic_thread_cast(pdl *it,pdl_error (*func)(pdl_trans *),pdl_trans *t, pdl_broadcast *broadcast) { | |||
pdl_error PDL_err = {0, NULL, 0}; | pdl_error PDL_err = {0, NULL, 0}; | |||
PDL_Indx i; | PDL_Indx i; | |||
int clearMagic = 0; /* Flag = 1 if we are temporarily creating pthreading magic in the | int clearMagic = 0; /* Flag = 1 if we are temporarily creating pthreading magic in the | |||
supplied pdl. */ | supplied pdl. */ | |||
pdl_magic_pthread *ptr = (pdl_magic_pthread *)pdl__find_magic(it, PDL_MAG IC_THREADING); | pdl_magic_pthread *ptr = (pdl_magic_pthread *)pdl__find_magic(it, PDL_MAG IC_THREADING); | |||
if(!ptr) { | if(!ptr) { | |||
/* Magic doesn't exist, create it | /* Magic doesn't exist, create it | |||
Probably was deleted before the transformation performed, due to | Probably was deleted before the transformation performed, due to | |||
pdl lazy evaluation. | pdl lazy evaluation. | |||
*/ | */ | |||
PDL_RETERROR(PDL_err, pdl_add_threading_magic(it, thread->mag_nth , thread->mag_nthr)); | PDL_RETERROR(PDL_err, pdl_add_threading_magic(it, broadcast->mag_ nth, broadcast->mag_nthr)); | |||
clearMagic = 1; /* Set flag to delete magic later */ | clearMagic = 1; /* Set flag to delete magic later */ | |||
/* Try to get magic again */ | /* Try to get magic again */ | |||
ptr = (pdl_magic_pthread *)pdl__find_magic(it, PDL_MAGIC_THREADIN G); | ptr = (pdl_magic_pthread *)pdl__find_magic(it, PDL_MAGIC_THREADIN G); | |||
if(!ptr) {return pdl_make_error_simple(PDL_EFATAL, "Invalid pdl_m agic_thread_cast!");} | if(!ptr) {return pdl_make_error_simple(PDL_EFATAL, "Invalid pdl_m agic_thread_cast!");} | |||
} | } | |||
pthread_t tp[thread->mag_nthr]; | pthread_t tp[broadcast->mag_nthr]; | |||
ptarg tparg[thread->mag_nthr]; | ptarg tparg[broadcast->mag_nthr]; | |||
pthread_key_create(&(ptr->key),NULL); | pthread_key_create(&(ptr->key),NULL); | |||
/* Get the pthread ID of this main thread we are in. | /* Get the pthread ID of this main thread we are in. | |||
* Any barf, warn, etc calls in the spawned pthreads can use this | * Any barf, warn, etc calls in the spawned pthreads can use this | |||
* to tell if its a spawned pthread | * to tell if its a spawned pthread | |||
*/ | */ | |||
pdl_main_pthreadID = pthread_self(); | pdl_main_pthreadID = pthread_self(); | |||
done_pdl_main_pthreadID_init = 1; | done_pdl_main_pthreadID_init = 1; | |||
PDLDEBUG_f(printf("CREATING THREADS, ME: TBD, key: %ld\n", (unsigned long )(ptr->key))); | PDLDEBUG_f(printf("CREATING THREADS, ME: TBD, key: %ld\n", (unsigned long )(ptr->key))); | |||
for(i=0; i<thread->mag_nthr; i++) { | for(i=0; i<broadcast->mag_nthr; i++) { | |||
tparg[i].mag = ptr; | tparg[i].mag = ptr; | |||
tparg[i].func = func; | tparg[i].func = func; | |||
tparg[i].t = t; | tparg[i].t = t; | |||
tparg[i].no = i; | tparg[i].no = i; | |||
tparg[i].error_return = PDL_err; | tparg[i].error_return = PDL_err; | |||
if (pthread_create(tp+i, NULL, pthread_perform, tparg+i)) { | if (pthread_create(tp+i, NULL, pthread_perform, tparg+i)) { | |||
return pdl_make_error_simple(PDL_EFATAL, "Unable to create pthrea ds!"); | return pdl_make_error_simple(PDL_EFATAL, "Unable to create pthrea ds!"); | |||
} | } | |||
} | } | |||
PDLDEBUG_f(printf("JOINING THREADS, ME: TBD, key: %ld\n", (unsigned long) (ptr->key))); | PDLDEBUG_f(printf("JOINING THREADS, ME: TBD, key: %ld\n", (unsigned long) (ptr->key))); | |||
for(i=0; i<thread->mag_nthr; i++) { | for(i=0; i<broadcast->mag_nthr; i++) { | |||
pthread_join(tp[i], NULL); | pthread_join(tp[i], NULL); | |||
} | } | |||
PDLDEBUG_f(printf("FINISHED THREADS, ME: TBD, key: %ld\n", (unsigned long )(ptr->key))); | PDLDEBUG_f(printf("FINISHED THREADS, ME: TBD, key: %ld\n", (unsigned long )(ptr->key))); | |||
pthread_key_delete((ptr->key)); | pthread_key_delete((ptr->key)); | |||
done_pdl_main_pthreadID_init = 0; | done_pdl_main_pthreadID_init = 0; | |||
/* Remove pthread magic if we created in this function */ | /* Remove pthread magic if we created in this function */ | |||
if( clearMagic ){ | if( clearMagic ){ | |||
PDL_RETERROR(PDL_err, pdl_add_threading_magic(it, -1, -1)); | PDL_RETERROR(PDL_err, pdl_add_threading_magic(it, -1, -1)); | |||
skipping to change at line 350 | skipping to change at line 350 | |||
{ \ | { \ | |||
pdl_pthread_##type##_msgs_len = 0; \ | pdl_pthread_##type##_msgs_len = 0; \ | |||
action; \ | action; \ | |||
free(pdl_pthread_##type##_msgs); \ | free(pdl_pthread_##type##_msgs); \ | |||
pdl_pthread_##type##_msgs = NULL; \ | pdl_pthread_##type##_msgs = NULL; \ | |||
} \ | } \ | |||
} while(0) | } while(0) | |||
handle_deferred_errors(warn, pdl_pdl_warn("%s", pdl_pthread_warn_msgs)); | handle_deferred_errors(warn, pdl_pdl_warn("%s", pdl_pthread_warn_msgs)); | |||
handle_deferred_errors(barf, PDL_err = pdl_error_accumulate(PDL_err, pdl_ make_error(PDL_EFATAL, "%s", pdl_pthread_barf_msgs))); | handle_deferred_errors(barf, PDL_err = pdl_error_accumulate(PDL_err, pdl_ make_error(PDL_EFATAL, "%s", pdl_pthread_barf_msgs))); | |||
for(i=0; i<thread->mag_nthr; i++) { | for(i=0; i<broadcast->mag_nthr; i++) { | |||
PDL_err = pdl_error_accumulate(PDL_err, tparg[i].error_return); | PDL_err = pdl_error_accumulate(PDL_err, tparg[i].error_return); | |||
} | } | |||
return PDL_err; | return PDL_err; | |||
} | } | |||
/* Function to remove threading magic (added by pdl_add_threading_magic) */ | /* Function to remove threading magic (added by pdl_add_threading_magic) */ | |||
pdl_error pdl_rm_threading_magic(pdl *it) | pdl_error pdl_rm_threading_magic(pdl *it) | |||
{ | { | |||
pdl_error PDL_err = {0, NULL, 0}; | pdl_error PDL_err = {0, NULL, 0}; | |||
pdl_magic_pthread *ptr = (pdl_magic_pthread *)pdl__find_magic(it, PDL_MAG IC_THREADING); | pdl_magic_pthread *ptr = (pdl_magic_pthread *)pdl__find_magic(it, PDL_MAG IC_THREADING); | |||
skipping to change at line 525 | skipping to change at line 525 | |||
return (int)ncpus; | return (int)ncpus; | |||
#endif | #endif | |||
return 1; | return 1; | |||
} | } | |||
#else | #else | |||
/* Dummy versions */ | /* Dummy versions */ | |||
pdl_error pdl_add_threading_magic(pdl *it,PDL_Indx nthdim,PDL_Indx nthreads) {pd l_error PDL_err = {0,NULL,0}; return PDL_err;} | pdl_error pdl_add_threading_magic(pdl *it,PDL_Indx nthdim,PDL_Indx nthreads) {pd l_error PDL_err = {0,NULL,0}; return PDL_err;} | |||
char pdl_pthread_main_thread() { return 1; } | char pdl_pthread_main_thread() { return 1; } | |||
int pdl_magic_get_thread(pdl *it) {return 0;} | int pdl_magic_get_thread(pdl *it) {return 0;} | |||
pdl_error pdl_magic_thread_cast(pdl *it,pdl_error (*func)(pdl_trans *),pdl_trans *t, pdl_thread *thread) {pdl_error PDL_err = {0,NULL,0}; return PDL_err;} | pdl_error pdl_magic_thread_cast(pdl *it,pdl_error (*func)(pdl_trans *),pdl_trans *t, pdl_broadcast *broadcast) {pdl_error PDL_err = {0,NULL,0}; return PDL_err;} | |||
int pdl_magic_thread_nthreads(pdl *it,PDL_Indx *nthdim) {return 0;} | int pdl_magic_thread_nthreads(pdl *it,PDL_Indx *nthdim) {return 0;} | |||
int pdl_pthreads_enabled() {return 0;} | int pdl_pthreads_enabled() {return 0;} | |||
int pdl_pthread_barf_or_warn(const char* pat, int iswarn, va_list *args){ return 0;} | int pdl_pthread_barf_or_warn(const char* pat, int iswarn, va_list *args){ return 0;} | |||
int pdl_online_cpus() {return 1;} | int pdl_online_cpus() {return 1;} | |||
#endif | #endif | |||
/*************************** | /*************************** | |||
* | * | |||
* Delete magic | * Delete magic | |||
* | * | |||
End of changes. 7 change blocks. | ||||
8 lines changed or deleted | 8 lines changed or added |