utilities-pthread/mergesort-pthread/mergesort-pthread.c
void mergesort_pthread(void *elts,
		       size_t count,
		       size_t elt_size,
		       size_t sbase_count,
		       size_t mbase_count,
		       int (*cmp)(const void *, const void *)){
  mergesort_arg_t msa;
  if (count < 1) return;
  msa.p = 0;
  msa.r = count - 1;
  msa.sbase_count = sbase_count;
  msa.mbase_count = mbase_count;
  msa.elt_size = elt_size;
  msa.num_onthread_rec = 0;
  msa.elts = elts;
  msa.cat_elts = malloc_perror(count, elt_size);
  msa.cmp = cmp;
  mergesort_thread(&msa);
  free(msa.cat_elts);
}
/**
   Sorts a given array pointed to by elts in ascending order according to
   cmp. The array contains count elements of elt_size bytes. The first
   thread entry is placed on the thread stack of the caller.
   elts        : pointer to the array to sort
   count       : > 0, < 2^{CHAR_BIT * sizeof(size_t) - 1} count of elements
                 in the array
   elt_size    : size of each element in the array in bytes
   sbase_count : > 0 base case upper bound for parallel sorting; if the count
                 of an unsorted subarray is less or equal to sbase_count,
                 then the subarray is sorted with serial sort routine (qsort)
   mbase_count : > 1 base case upper bound for parallel merging; if the sum
                 of the counts of two sorted subarrays is less or equal to
                 mbase_count, then the two subarrays are merged with a serial
                 merge routine
   cmp         : comparison function which returns a negative integer value
                 if the element pointed to by the first argument is less than
                 the element pointed to by the second, a positive integer
                 value if the element pointed to by the first argument is
                 greater than the element pointed to by the second, and zero
                 integer value if the two elements are equal
*/
Sorts a given array pointed to by elts in ascending order according to
cmp. The array contains count elements of elt_size bytes. The first
thread entry is placed on the thread stack of the caller.
Sorts a given array pointed to by elts in ascending order according to cmp . The array contains count elements of elt_size bytes . The first thread entry is placed on the thread stack of the caller .
void mergesort_pthread(void *elts,
		       size_t count,
		       size_t elt_size,
		       size_t sbase_count,
		       size_t mbase_count,
		       int (*cmp)(const void *, const void *)){
  mergesort_arg_t msa;
  if (count < 1) return;
  msa.p = 0;
  msa.r = count - 1;
  msa.sbase_count = sbase_count;
  msa.mbase_count = mbase_count;
  msa.elt_size = elt_size;
  msa.num_onthread_rec = 0;
  msa.elts = elts;
  msa.cat_elts = malloc_perror(count, elt_size);
  msa.cmp = cmp;
  mergesort_thread(&msa);
  free(msa.cat_elts);
}
void mergesort_pthread ( void * elts , size_t count , size_t elt_size , size_t sbase_count , size_t mbase_count , int ( * cmp ) ( const void * , const void * ) ) { mergesort_arg_t msa ; if ( count < 1 ) return ; msa . p = 0 ; msa . r = count - 1 ; msa . sbase_count = sbase_count ; msa . mbase_count = mbase_count ; msa . elt_size = elt_size ; msa . num_onthread_rec = 0 ; msa . elts = elts ; msa . cat_elts = malloc_perror ( count , elt_size ) ; msa . cmp = cmp ; mergesort_thread ( & msa ) ; free ( msa . cat_elts ) ; }
Sorts a given array pointed to by elts in ascending order according to
cmp.
Sorts a given array pointed to by elts in ascending order according to cmp .