X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/f0238a1756865dc95a37642025ef8022958dfaf9..014c65d0044e87e37b1ab403923401234e0605da:/src/include/xbt/parmap.hpp diff --git a/src/include/xbt/parmap.hpp b/src/include/xbt/parmap.hpp index f0fbb1dfc4..bc65ff9274 100644 --- a/src/include/xbt/parmap.hpp +++ b/src/include/xbt/parmap.hpp @@ -38,6 +38,7 @@ namespace xbt { template class Parmap { public: Parmap(unsigned num_workers, e_xbt_parmap_mode_t mode); + Parmap(const Parmap&) = delete; ~Parmap(); void apply(void (*fun)(T), const std::vector& data); boost::optional next(); @@ -61,25 +62,25 @@ private: class Synchro { public: explicit Synchro(Parmap& parmap) : parmap(parmap) {} - virtual ~Synchro() {} + virtual ~Synchro() = default; /** * \brief Wakes all workers and waits for them to finish the tasks. * * This function is called by the controller thread. */ - virtual void master_signal() = 0; + virtual void master_signal() = 0; /** * \brief Starts the parmap: waits for all workers to be ready and returns. * * This function is called by the controller thread. */ - virtual void master_wait() = 0; + virtual void master_wait() = 0; /** * \brief Ends the parmap: wakes the controller thread when all workers terminate. * * This function is called by all worker threads when they end (not including the controller). */ - virtual void worker_signal() = 0; + virtual void worker_signal() = 0; /** * \brief Waits for some work to process. * @@ -89,7 +90,6 @@ private: */ virtual void worker_wait(unsigned) = 0; - protected: Parmap& parmap; }; @@ -137,15 +137,16 @@ private: Synchro* new_synchro(e_xbt_parmap_mode_t mode); void work(); - Flag status; /**< is the parmap active or being destroyed? */ - unsigned work_round; /**< index of the current round */ - unsigned thread_counter; /**< number of workers that have done the work */ - unsigned num_workers; /**< total number of worker threads including the controller */ - xbt_os_thread_t* workers; /**< worker thread handlers */ - void (*fun)(const T); /**< function to run in parallel on each element of data */ - const std::vector* data; /**< parameters to pass to fun in parallel */ - std::atomic index; /**< index of the next element of data to pick */ - Synchro* synchro; /**< synchronization object */ + Flag status; /**< is the parmap active or being destroyed? */ + unsigned work_round; /**< index of the current round */ + xbt_os_thread_t* workers; /**< worker thread handlers */ + unsigned num_workers; /**< total number of worker threads including the controller */ + Synchro* synchro; /**< synchronization object */ + + unsigned thread_counter = 0; /**< number of workers that have done the work */ + void (*fun)(const T) = nullptr; /**< function to run in parallel on each element of data */ + const std::vector* data = nullptr; /**< parameters to pass to fun in parallel */ + std::atomic index; /**< index of the next element of data to pick */ }; /**