X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/bc48db087894fd960073b3120cebf90e6b2f8c02..972162bac11e3df7266030562100d2f8e43870b2:/src/xbt/parmap.cpp diff --git a/src/xbt/parmap.cpp b/src/xbt/parmap.cpp index f5748846b6..95abdcea15 100644 --- a/src/xbt/parmap.cpp +++ b/src/xbt/parmap.cpp @@ -59,11 +59,6 @@ static void xbt_parmap_busy_worker_signal(xbt_parmap_t parmap); static void xbt_parmap_busy_master_signal(xbt_parmap_t parmap); static void xbt_parmap_busy_worker_wait(xbt_parmap_t parmap, unsigned round); -#if HAVE_MC -static void xbt_parmap_mc_work(xbt_parmap_t parmap, int worker_id); -static void *xbt_parmap_mc_worker_main(void *arg); -#endif - /** * \brief Parallel map structure */ @@ -78,14 +73,6 @@ typedef struct s_xbt_parmap { xbt_dynar_t data; /**< parameters to pass to fun in parallel */ std::atomic index; /**< index of the next element of data to pick */ -#if HAVE_MC - int finish; - void* ref_snapshot; - int_f_pvoid_pvoid_t snapshot_compare; - unsigned int length; - void* mc_data; -#endif - /* posix only */ xbt_os_cond_t ready_cond; xbt_os_mutex_t ready_mutex; @@ -145,45 +132,10 @@ xbt_parmap_t xbt_parmap_new(unsigned int num_workers, e_xbt_parmap_mode_t mode) core_bind++; else core_bind = 0; -#endif - } - return parmap; -} - -#if HAVE_MC -/** - * \brief Creates a parallel map object - * \param num_workers number of worker threads to create - * \param mode how to synchronize the worker threads - * \return the parmap created - */ -xbt_parmap_t xbt_parmap_mc_new(unsigned int num_workers, e_xbt_parmap_mode_t mode) -{ - unsigned int i; - - XBT_DEBUG("Create new parmap (%u workers)", num_workers); - - /* Initialize the thread pool data structure */ - xbt_parmap_t parmap = new s_xbt_parmap_t(); - parmap->workers = xbt_new(xbt_os_thread_t, num_workers); - - parmap->num_workers = num_workers; - parmap->status = XBT_PARMAP_WORK; - xbt_parmap_set_mode(parmap, mode); - - /* Create the pool of worker threads */ - xbt_parmap_thread_data_t data; - parmap->workers[0] = NULL; - for (i = 1; i < num_workers; i++) { - data = xbt_new0(s_xbt_parmap_thread_data_t, 1); - data->parmap = parmap; - data->worker_id = i; - parmap->workers[i] = xbt_os_thread_create(NULL, xbt_parmap_mc_worker_main, - data, NULL); +#endif } return parmap; } -#endif /** * \brief Destroys a parmap @@ -228,7 +180,6 @@ static void xbt_parmap_set_mode(xbt_parmap_t parmap, e_xbt_parmap_mode_t mode) parmap->mode = mode; switch (mode) { - case XBT_PARMAP_POSIX: parmap->master_wait_f = xbt_parmap_posix_master_wait; parmap->worker_signal_f = xbt_parmap_posix_worker_signal; @@ -240,8 +191,6 @@ static void xbt_parmap_set_mode(xbt_parmap_t parmap, e_xbt_parmap_mode_t mode) parmap->done_cond = xbt_os_cond_init(); parmap->done_mutex = xbt_os_mutex_init(); break; - - case XBT_PARMAP_FUTEX: #if HAVE_FUTEX_H parmap->master_wait_f = xbt_parmap_futex_master_wait; @@ -257,9 +206,7 @@ static void xbt_parmap_set_mode(xbt_parmap_t parmap, e_xbt_parmap_mode_t mode) #else xbt_die("Futex is not available on this OS."); #endif - case XBT_PARMAP_BUSY_WAIT: -#ifndef _MSC_VER parmap->master_wait_f = xbt_parmap_busy_master_wait; parmap->worker_signal_f = xbt_parmap_busy_worker_signal; parmap->master_signal_f = xbt_parmap_busy_master_signal; @@ -270,10 +217,6 @@ static void xbt_parmap_set_mode(xbt_parmap_t parmap, e_xbt_parmap_mode_t mode) xbt_os_cond_destroy(parmap->done_cond); xbt_os_mutex_destroy(parmap->done_mutex); break; -#else - xbt_die("Busy waiting not implemented on Windows yet."); -#endif - case XBT_PARMAP_DEFAULT: THROW_IMPOSSIBLE; break; @@ -317,8 +260,7 @@ void* xbt_parmap_next(xbt_parmap_t parmap) static void xbt_parmap_work(xbt_parmap_t parmap) { unsigned index; - while ((index = parmap->index++) - < xbt_dynar_length(parmap->data)) + while ((index = parmap->index++) < xbt_dynar_length(parmap->data)) parmap->fun(xbt_dynar_get_as(parmap->data, index, void*)); } @@ -340,105 +282,21 @@ static void *xbt_parmap_worker_main(void *arg) while (1) { parmap->worker_wait_f(parmap, ++round); if (parmap->status == XBT_PARMAP_WORK) { - XBT_DEBUG("Worker %d got a job", data->worker_id); xbt_parmap_work(parmap); parmap->worker_signal_f(parmap); XBT_DEBUG("Worker %d has finished", data->worker_id); - /* We are destroying the parmap */ } else { - SIMIX_context_free(context); + delete context; xbt_free(data); return NULL; } } } -#if HAVE_MC - -/** - * \brief Applies a list of tasks in parallel. - * \param parmap a parallel map object - * \param fun the function to call in parallel - * \param data each element of this dynar will be passed as an argument to fun - */ -int xbt_parmap_mc_apply(xbt_parmap_t parmap, int_f_pvoid_pvoid_t fun, - void* data, unsigned int length, void* ref_snapshot) -{ - /* Assign resources to worker threads */ - parmap->snapshot_compare = fun; - parmap->mc_data = data; - parmap->index = 0; - parmap->finish = -1; - parmap->length = length; - parmap->ref_snapshot = ref_snapshot; - parmap->master_signal_f(parmap); - xbt_parmap_mc_work(parmap, 0); - parmap->master_wait_f(parmap); - XBT_DEBUG("Job done"); - return parmap->finish; -} - -static void xbt_parmap_mc_work(xbt_parmap_t parmap, int worker_id) -{ - unsigned int data_size = (parmap->length / parmap->num_workers) + - ((parmap->length % parmap->num_workers) ? 1 :0); - void* start = (char*)parmap->mc_data + (data_size*worker_id*sizeof(void*)); - void* end = MIN((char *)start + data_size* sizeof(void*), (char*)parmap->mc_data + parmap->length*sizeof(void*)); - - //XBT_CRITICAL("Worker %d : %p -> %p (%d)", worker_id, start, end, data_size); - - while ( start < end && parmap->finish == -1) { - //XBT_CRITICAL("Starting with %p", start); - int res = parmap->snapshot_compare(*(void**)start, parmap->ref_snapshot); - start = (char *)start + sizeof(start); - if (!res){ - - parmap->finish = ((char*)start - (char*)parmap->mc_data) / sizeof(void*); - //XBT_CRITICAL("Find good one %p (%p)", start, parmap->mc_data); - break; - } - } -} - -/** - * \brief Main function of a worker thread. - * \param arg the parmap - */ -static void *xbt_parmap_mc_worker_main(void *arg) -{ - xbt_parmap_thread_data_t data = (xbt_parmap_thread_data_t) arg; - xbt_parmap_t parmap = data->parmap; - unsigned round = 0; - /* smx_context_t context = SIMIX_context_new(NULL, 0, NULL, NULL, NULL); */ - /* SIMIX_context_set_current(context); */ - - XBT_DEBUG("New worker thread created"); - - /* Worker's main loop */ - while (1) { - parmap->worker_wait_f(parmap, ++round); - if (parmap->status == XBT_PARMAP_WORK) { - - XBT_DEBUG("Worker %d got a job", data->worker_id); - - xbt_parmap_mc_work(parmap, data->worker_id); - parmap->worker_signal_f(parmap); - - XBT_DEBUG("Worker %d has finished", data->worker_id); - - /* We are destroying the parmap */ - } else { - xbt_free(data); - return NULL; - } - } -} -#endif - #if HAVE_FUTEX_H static void futex_wait(unsigned *uaddr, unsigned val) { @@ -473,8 +331,7 @@ static void xbt_parmap_posix_master_wait(xbt_parmap_t parmap) /** * \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). + * This function is called by all worker threads when they end (not including the controller). * * \param parmap a parmap */ @@ -508,8 +365,7 @@ static void xbt_parmap_posix_master_signal(xbt_parmap_t parmap) /** * \brief Waits for some work to process. * - * This function is called by each worker thread (not including the controller) - * when it has no more work to do. + * This function is called by each worker thread (not including the controller) when it has no more work to do. * * \param parmap a parmap * \param round the expected round number @@ -545,8 +401,7 @@ static void xbt_parmap_futex_master_wait(xbt_parmap_t parmap) /** * \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). + * This function is called by all worker threads when they end (not including the controller). * * \param parmap a parmap */ @@ -577,8 +432,7 @@ static void xbt_parmap_futex_master_signal(xbt_parmap_t parmap) /** * \brief Waits for some work to process. * - * This function is called by each worker thread (not including the controller) - * when it has no more work to do. + * This function is called by each worker thread (not including the controller) when it has no more work to do. * * \param parmap a parmap * \param round the expected round number @@ -594,7 +448,6 @@ static void xbt_parmap_futex_worker_wait(xbt_parmap_t parmap, unsigned round) } #endif -#ifndef _MSC_VER /** * \brief Starts the parmap: waits for all workers to be ready and returns. * @@ -637,8 +490,7 @@ static void xbt_parmap_busy_master_signal(xbt_parmap_t parmap) /** * \brief Waits for some work to process. * - * This function is called by each worker thread (not including the controller) - * when it has no more work to do. + * This function is called by each worker thread (not including the controller) when it has no more work to do. * * \param parmap a parmap * \param round the expected round number @@ -650,4 +502,3 @@ static void xbt_parmap_busy_worker_wait(xbt_parmap_t parmap, unsigned round) xbt_os_thread_yield(); } } -#endif /* ! _MSC_VER */