Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Introduce a SwappedContextFactory to further reduce code duplication, working WIP
[simgrid.git] / src / include / xbt / parmap.hpp
index b8fbed6..2e998ea 100644 (file)
@@ -163,21 +163,17 @@ template <typename T> Parmap<T>::Parmap(unsigned num_workers, e_xbt_parmap_mode_
   this->num_workers = num_workers;
   this->synchro     = new_synchro(mode);
 
-  /* Create the pool of worker threads */
+  /* Create the pool of worker threads (the caller of apply() will be worker[0]) */
   this->workers[0] = nullptr;
-#if HAVE_PTHREAD_SETAFFINITY
-  int core_bind = 0;
-#endif
+  unsigned int core_bind = 0;
   for (unsigned i = 1; i < num_workers; i++) {
     ThreadData* data = new ThreadData(*this, i);
-    this->workers[i] = xbt_os_thread_create(nullptr, worker_main, data, nullptr);
-#if HAVE_PTHREAD_SETAFFINITY
+    this->workers[i] = xbt_os_thread_create(worker_main, data);
     xbt_os_thread_bind(this->workers[i], core_bind);
-    if (core_bind != xbt_os_get_numcores() - 1)
+    if (core_bind != std::thread::hardware_concurrency() - 1)
       core_bind++;
     else
       core_bind = 0;
-#endif
   }
 }
 
@@ -276,22 +272,20 @@ template <typename T> typename Parmap<T>::Synchro* Parmap<T>::new_synchro(e_xbt_
   return res;
 }
 
-/**
- * @brief Main function of a worker thread.
- */
+/** @brief Main function of a worker thread */
 template <typename T> void* Parmap<T>::worker_main(void* arg)
 {
   ThreadData* data      = static_cast<ThreadData*>(arg);
   Parmap<T>& parmap     = data->parmap;
   unsigned round        = 0;
   smx_context_t context = SIMIX_context_new(std::function<void()>(), nullptr, nullptr);
-  SIMIX_context_set_current(context);
+  kernel::context::Context::set_current(context);
 
   XBT_CDEBUG(xbt_parmap, "New worker thread created");
 
   /* Worker's main loop */
   while (1) {
-    round++;
+    round++; // New scheduling round
     parmap.synchro->worker_wait(round);
     if (parmap.status == PARMAP_DESTROY)
       break;