Beispiel #1
0
void SNetThreadingSpawn(snet_entity_t ent, int loc, const char *name,
                        snet_taskfun_t func, void *arg)
{
  int res;
  pthread_t p;
  pthread_attr_t attr;

  /* create snet_thread_t */
  snet_thread_t *thr = SNetMemAlloc(sizeof(snet_thread_t));
  thr->fun = func;
  pthread_mutex_init( &thr->lock, NULL );
  pthread_cond_init( &thr->pollcond, NULL );
  thr->wakeup_sd = NULL;
  thr->inarg = arg;
  thr->name = (char*) name;

  /* increment entity counter */
  pthread_mutex_lock( &entity_lock );
  entity_count += 1;
  pthread_mutex_unlock( &entity_lock );


  /* create pthread: */

  (void) pthread_attr_init( &attr);

  size_t stacksize = StackSize(ent);
  if (stacksize > 0) {
    res = pthread_attr_setstacksize(&attr, stacksize);
    if (res != 0) perror("Cannot set stack size!");
  }

  /* all threads are detached */
  res = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
  if (res != 0) perror("Cannot set detached!");

  /* spawn off thread */
  res = pthread_create( &p, &attr, &TaskWrapper, thr);
  if (res != 0) perror("Cannot create pthread!");
  pthread_attr_destroy( &attr);


  /* core affinity */
#ifdef USE_CORE_AFFINITY
  if (ent == ENTITY_other) {
    SetThreadAffinity( &p, STRICTLYFIRST);
  } else {
    SetThreadAffinity( &p, DEFAULT);
  }
#endif /* USE_CORE_AFFINITY */
}
Beispiel #2
0
int SNetThreadingInit(int argc, char **argv)
{
#ifdef USE_CORE_AFFINITY
  int i, num_cores;
#endif
  char fname[32];
  /* initialize the entity counter to 0 */
  entity_count = 0;
  (void) argc; /* NOT USED */
  (void) argv; /* NOT USED */

#ifndef HAVE___THREAD
  pthread_key_create(&thread_self_key, NULL);
#endif

#ifdef USE_CORE_AFFINITY
  for (i=0; i<argc; i++) {
    if(strcmp(argv[i], "-w") == 0 && i + 1 <= argc) {
      /* Number of cores */
      i = i + 1;
      num_cores = atoi(argv[i]);
      SetThreadAffinity( pthread_self(), MAXCORES,  num_cores);
    }
  }
#endif

  snprintf(fname, 31, "mon_n%02u_info.log", SNetDistribGetNodeId());
  SNetThreadingMonitoringInit(fname);

  return 0;
}
Beispiel #3
0
void InternalThread::entry(int device, Caffe::Brew mode, int rand_seed,
    int solver_count, bool root_solver) {
#ifndef CPU_ONLY
  CUDA_CHECK(cudaSetDevice(device));
#endif
  Caffe::set_mode(mode);
  Caffe::set_random_seed(rand_seed);
  Caffe::set_solver_count(solver_count);
  Caffe::set_root_solver(root_solver);

#ifdef _OPENMP
  caffe::cpu::OpenMpManager::bindCurrentThreadToNonPrimaryCoreIfPossible();
#endif

  SetThreadAffinity();
  
  InternalThreadEntry();
}
Beispiel #4
0
void AExecutable::SetThreadAffinity(boost::thread* daThread, int threadPriority, short CPUToBind, int scheduler) {
	std::vector<short> CPUsToBind;
	CPUsToBind.push_back(CPUToBind);
	SetThreadAffinity(daThread, threadPriority, CPUsToBind, scheduler);
}