예제 #1
0
/* evaluate crosspoints in recursive way */
static GtUword evaluatelinearcrosspoints(LinspaceManagement *spacemanager,
                                         GtScoreHandler *scorehandler,
                                         const GtUchar *useq,
                                         GtUword ustart, GtUword ulen,
                                         const GtUchar *vseq,
                                         GtUword vstart, GtUword vlen,
                                         GtUword *Ctab,
                                         GtUword rowoffset,
                                         GT_UNUSED GtUword threadidx,
                                         GT_UNUSED GtUword *threadcount)
{
  GtUword midrow, midcol, distance, *EDtabcolumn = NULL, *Rtabcolumn = NULL;
#ifdef GT_THREADS_ENABLED
  GtThread *t1 = NULL, *t2 = NULL;
  GtLinearCrosspointthreadinfo threadinfo1, threadinfo2;
#endif

  if (vlen >= 2UL)
  {
    if (ulen == 0)
    {
      GtUword i;
      for (i = 0; i <= vlen; i++)
        Ctab[i] = rowoffset;
      return rowoffset;
    }
#ifndef GT_THREADS_ENABLED
    if (gt_linspaceManagement_checksquare(spacemanager, ulen,vlen,
                                               sizeof (GtUword),
                                               sizeof (Rtabcolumn)))
    { /* product of subsquences is lower than space allocated already or
       * lower than timesquarfactor * ulen*/
      return ctab_in_square_space(spacemanager, scorehandler, Ctab, useq,
                                  ustart, ulen, vseq, vstart, vlen, rowoffset);
    }
#endif

    midcol = GT_DIV2(vlen);
    Rtabcolumn = gt_linspaceManagement_get_rTabspace(spacemanager);
    EDtabcolumn = gt_linspaceManagement_get_valueTabspace(spacemanager);
    Rtabcolumn = Rtabcolumn + rowoffset + threadidx;
    EDtabcolumn = EDtabcolumn + rowoffset + threadidx;

    distance = evaluateallEDtabRtabcolumns(EDtabcolumn, Rtabcolumn,
                                           scorehandler, midcol,
                                           useq, ustart, ulen,
                                           vseq, vstart, vlen);
    midrow = Rtabcolumn[ulen];
    Ctab[midcol] = rowoffset + midrow;

#ifdef GT_THREADS_ENABLED
    if (*threadcount + 2 > gt_jobs)
    {
#endif
      /* upper left corner */
      (void) evaluatelinearcrosspoints(spacemanager, scorehandler,
                                       useq, ustart, midrow,
                                       vseq, vstart, midcol,
                                       Ctab, rowoffset,
                                       threadidx, threadcount);

      /* bottom right corner */
      (void) evaluatelinearcrosspoints(spacemanager, scorehandler,
                                       useq, ustart + midrow,
                                       ulen - midrow,
                                       vseq, vstart + midcol,
                                       vlen - midcol,
                                       Ctab + midcol,
                                       rowoffset + midrow,
                                       threadidx, threadcount);
#ifdef GT_THREADS_ENABLED
    }
    else
    {
      threadinfo1 = set_LinearCrosspointthreadinfo(spacemanager, scorehandler,
                                                   useq, ustart, midrow,
                                                   vseq, vstart, midcol,
                                                   Ctab, rowoffset,
                                                   threadidx, threadcount);
      (*threadcount)++;
      t1 = gt_thread_new(evaluatelinearcrosspoints_thread_caller,
                         &threadinfo1, NULL);

      threadinfo2 = set_LinearCrosspointthreadinfo(spacemanager, scorehandler,
                                                   useq, ustart + midrow,
                                                   ulen - midrow,
                                                   vseq, vstart + midcol,
                                                   vlen - midcol,
                                                   Ctab + midcol,
                                                   rowoffset + midrow,
                                                   threadidx + GT_DIV2(midcol),
                                                   threadcount);
      (*threadcount)++;
      t2 = gt_thread_new(evaluatelinearcrosspoints_thread_caller,
                         &threadinfo2, NULL);

      gt_thread_join(t1);
      (*threadcount)--;
      gt_thread_join(t2);
      (*threadcount)--;
      gt_thread_delete(t1);
      gt_thread_delete(t2);
    }
#endif
    return distance;
  }
  return 0;
}
예제 #2
0
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
  }
}