Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
start threads only if I have more than 1 element to handle
authormquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Thu, 15 Oct 2009 16:25:42 +0000 (16:25 +0000)
committermquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Thu, 15 Oct 2009 16:25:42 +0000 (16:25 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@6790 48e7efb5-ca39-0410-a469-dd3cf9ba447f

src/xbt/xbt_synchro.c

index 216b6f7..eb9e0af 100644 (file)
@@ -32,7 +32,15 @@ void xbt_dynar_dopar(xbt_dynar_t datas, void_f_int_pvoid_t function) {
   xbt_dynar_t workers = xbt_dynar_new(sizeof(worker_data_t),worker_wait_n_free);
   unsigned int cursor;
   void *data;
+  if (xbt_dynar_length(datas)==0)
+    return; /* nothing to do */
+  if (xbt_dynar_length(datas)==1) {
+    /* don't start any new thread, do it directly */
+    (*function)(0,xbt_dynar_get_ptr(datas,0));
+    return;
+  }
   /* Start all workers */
+  INFO1("Dopar for %ld elements",xbt_dynar_length(datas));
   xbt_dynar_foreach(datas,cursor,data){
     worker_data_t w = xbt_new0(s_worker_data_t,1);
     w->data = datas;