void VTThrd_registerThread(uint32_t ptid)
{
  uint32_t *tid;
  uint8_t tid_reuse = 0;

  if (!vt_is_alive) return;

  /* check whether an ID is already created for this thread */
  tid = (uint32_t*)pthread_getspecific(pthreadKey);
  if (tid == NULL)
  {
    tid = (uint32_t*)malloc(sizeof(uint32_t));
    if (tid == NULL) vt_error();

    /* try to get idle thread-ID for reuse, if desired */
    if (reuseThreadIds)
    {
      pthread_mutex_lock(&threadReuseMutex);
      if (idle_tid_list_size(ptid) > 0)
      {
        *tid = idle_tid_list_pop_front(ptid);
        tid_reuse = 1;
      }
      pthread_mutex_unlock(&threadReuseMutex);
    }

    /* create new thread-ID, if not reusing */
    if (!tid_reuse)
      *tid = VTThrd_create(NULL, ptid, 0);

    /* put (new) thread-ID to thread-specific data */
    pthread_setspecific(pthreadKey, tid);

    /* open thread associated trace file, if new thread object was created */
    if (!tid_reuse )
    {
      VTThrd_open(*tid);
    }
    /* otherwise, re-create metrics for reused thread object */
    else
    {
#if defined(VT_METR)
      if (vt_metric_num() > 0 && !VTThrdv[*tid]->metv)
        VTThrdv[*tid]->metv = vt_metric_create();
#endif /* VT_METR */

#if defined(VT_PLUGIN_CNTR)
      /* if we really use plugins and this thread also uses some */
      if (vt_plugin_cntr_used && VTThrdv[*tid]->plugin_cntr_defines)
        vt_plugin_cntr_thread_enable_counters(VTThrdv[*tid]);
#endif /* VT_PLUGIN_CNTR */
    }
  }
}
Пример #2
0
void VTThrd_open(uint32_t tid)
{
  VTThrd* thrd = VTThrdv[tid];
  size_t bsize = vt_env_bsize();
#if (defined(VT_MT) || defined(VT_HYB) || defined(VT_JAVA))
  size_t tbsize = vt_env_thread_bsize();
  if( tbsize != 0 )
  {
    if( tid != 0 )
      bsize = tbsize;
  }
  else
  {
    if( tid == 0 ) /* master thread gets most buffer space */
      bsize = (bsize / 10) * 7;
    else           /* worker threads get less buffer space */
      bsize = (bsize / 10);
  }
#endif /* VT_MT || VT_HYB || VT_JAVA */

  if ( thrd )
  {
    thrd->gen = VTGen_open(thrd->name, thrd->name_suffix,
                           thrd->parent_tid, tid, bsize);
  }

#if (defined(VT_PLUGIN_CNTR) || defined(VT_CUDARTWRAP))
  if ( tid != 0 && VTThrdv[tid]->is_virtual_thread )
    return;
#endif /* VT_PLUGIN_CNTR || VT_CUDARTWRAP */

#if (defined (VT_MPI) || defined (VT_HYB))
  /* initialize first matching ID for MPI collective ops. */
  thrd->mpicoll_next_matchingid = 1;
#endif /* VT_MPI || VT_HYB */

#if (defined (VT_IOWRAP) || (defined(HAVE_MPI2_IO) && HAVE_MPI2_IO))
  /* initialize first matching ID and handle */
  thrd->io_next_matchingid = 1;
  thrd->io_next_handle = 1;
#endif /* VT_IOWRAP || HAVE_MPI2_IO */
#if defined(VT_IOWRAP)
  if ( vt_env_iotrace() )
  {
    vt_iowrap_init();
    VT_ENABLE_IO_TRACING();
  }
#endif /* VT_IOWRAP */

#if defined(VT_PLUGIN_CNTR)
  /* if we really use plugins */
  if ( vt_plugin_cntr_used && tid != 0 )
  {
    /* if this is no dummy thread */
    if ( !vt_plugin_cntr_is_registered_monitor_thread() )
    {
      vt_plugin_cntr_thread_init(thrd, tid);

      /* if this thread uses plugins */
      if ( thrd->plugin_cntr_defines )
        vt_plugin_cntr_thread_enable_counters(thrd);
    }
  }
#endif /* VT_PLUGIN_CNTR */

  /* if MPI-rank is disabled, switch tracing off for this thread */
  if( vt_my_trace_is_disabled )
    vt_trace_off(tid, 0, 1);
}