+ return NULL;
+ }
+ }
+}
+
+#ifdef 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);