static void *gt_radixsort_thread_caller(void *data) { GtRadixinplacethreadinfo *threadinfo = (GtRadixinplacethreadinfo *) data; if (threadinfo->rbuf->elemtype == GtRadixelemtypeGtUwordPair) { gt_radixsort_ulongpair_sub_inplace(threadinfo->rbuf,&threadinfo->stack); } else { if (threadinfo->rbuf->elemtype == GtRadixelemtypeGtUword) { gt_radixsort_ulong_sub_inplace(threadinfo->rbuf,&threadinfo->stack); } else { gt_radixsort_uint64keypair_sub_inplace(threadinfo->rbuf, &threadinfo->stack); } } return NULL; }
static void gt_radixsort_inplace(GtRadixsortinfo *radixsortinfo, GtRadixvalues *radixvalues, GtUword len) { const size_t shift = (sizeof (GtUword) - 1) * CHAR_BIT; #ifdef GT_THREADS_ENABLED const unsigned int threads = GT_THREADS_JOBS; #else const unsigned int threads = 1U; #endif if (len > (GtUword) GT_COUNTBASETYPE_MAX) { fprintf(stderr,"%s, line %d: assertion failed: if you want to sort arrays " "of length > 2^{32}-1, then recompile code by setting " "#define GT_RADIX_LARGEARRAYS\n",__FILE__,__LINE__); exit(GT_EXIT_PROGRAMMING_ERROR); } gt_assert(radixsortinfo != NULL); if (radixsortinfo->pairs) { gt_radixsort_ulongpair_shuffle(radixsortinfo->rbuf, radixvalues->ulongpairptr, (GtCountbasetype) len,shift); } else { gt_radixsort_ulong_shuffle(radixsortinfo->rbuf,radixvalues->ulongptr, (GtCountbasetype) len,shift); } GT_STACK_MAKEEMPTY(&radixsortinfo->stack); if (radixsortinfo->pairs) { gt_radixsort_ulongpair_process_bin(&radixsortinfo->stack, radixsortinfo->rbuf, radixvalues->ulongpairptr, shift); } else { gt_radixsort_ulong_process_bin(&radixsortinfo->stack, radixsortinfo->rbuf, radixvalues->ulongptr,shift); } if (threads == 1U || radixsortinfo->stack.nextfree < (GtUword) threads) { if (radixsortinfo->pairs) { gt_radixsort_ulongpair_sub_inplace(radixsortinfo->rbuf, &radixsortinfo->stack); } else { gt_radixsort_ulong_sub_inplace(radixsortinfo->rbuf,&radixsortinfo->stack); } } else { #ifdef GT_THREADS_ENABLED GtUword last = 0, j; unsigned int t; gt_assert(radixsortinfo->stack.nextfree <= UINT8_MAX+1); for (j=0; j<radixsortinfo->stack.nextfree; j++) { radixsortinfo->lentab[j] = (GtUword) radixsortinfo->stack.space[j].len; } gt_evenly_divide_lentab(radixsortinfo->endindexes, radixsortinfo->lentab, radixsortinfo->stack.nextfree,len,threads); for (t = 0; t < threads; t++) { GT_STACK_MAKEEMPTY(&radixsortinfo->threadinfo[t].stack); for (j = last; j <= radixsortinfo->endindexes[t]; j++) { GT_STACK_PUSH(&radixsortinfo->threadinfo[t].stack, radixsortinfo->stack.space[j]); } last = radixsortinfo->endindexes[t] + 1; radixsortinfo->threadinfo[t].thread = gt_thread_new (gt_radixsort_thread_caller, radixsortinfo->threadinfo + t,NULL); gt_assert (radixsortinfo->threadinfo[t].thread != NULL); } for (t = 0; t < threads; t++) { gt_thread_join(radixsortinfo->threadinfo[t].thread); gt_thread_delete(radixsortinfo->threadinfo[t].thread); } #endif } }