Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
cosmetics
[simgrid.git] / src / gras / DataDesc / ddt_exchange.c
index 6519ec0..d4b10ea 100644 (file)
@@ -13,7 +13,7 @@
 #include "gras/DataDesc/datadesc_private.h"
 #include "gras/Transport/transport_interface.h" /* gras_trp_send/recv */
 
-XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ddt_exchange,datadesc,
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(gras_ddt_exchange,gras_ddt,
                                 "Sending data over the network");
 const char *gras_datadesc_cat_names[9] = { 
   "undefined", 
@@ -23,7 +23,7 @@ const char *gras_datadesc_cat_names[9] = {
 static gras_datadesc_type_t int_type = NULL;
 static gras_datadesc_type_t pointer_type = NULL;    
 
-static _XBT_INLINE void
+static XBT_INLINE void
 gras_dd_send_int(gras_socket_t sock,int *i, int stable) {
 
   if (!int_type) {
@@ -35,7 +35,7 @@ gras_dd_send_int(gras_socket_t sock,int *i, int stable) {
   gras_trp_send(sock, (char*)i, int_type->size[GRAS_THISARCH], stable);
 }
 
-static _XBT_INLINE void
+static XBT_INLINE void
 gras_dd_recv_int(gras_socket_t sock, int r_arch, int *i) {
 
   if (!int_type) {
@@ -63,7 +63,7 @@ gras_dd_recv_int(gras_socket_t sock, int r_arch, int *i) {
  *       of 'length' bytes set to 0.
  * FIXME: Check in configure?
  */
-static _XBT_INLINE int 
+static XBT_INLINE int 
 gras_dd_is_r_null(char **r_ptr, long int length) {
   int i;
 
@@ -76,7 +76,7 @@ gras_dd_is_r_null(char **r_ptr, long int length) {
   return 1;
 }
 
-static _XBT_INLINE void
+static XBT_INLINE void
 gras_dd_alloc_ref(xbt_dict_t  refs,
                  long int     size,
                  char       **r_ref,
@@ -95,11 +95,10 @@ gras_dd_alloc_ref(xbt_dict_t  refs,
   if (detect_cycle && r_ref && !gras_dd_is_r_null( r_ref, r_len)) {
     void *ptr = xbt_malloc(sizeof(void *));
 
-    CRITICAL0("Check for cycles");
     memcpy(ptr,l_ref, sizeof(void *));
 
     DEBUG2("Insert l_ref=%p under r_ref=%p",*(void**)ptr, *(void**)r_ref);
-
+     
     if (detect_cycle)
        xbt_dict_set_ext(refs,(const char *) r_ref, r_len, ptr, free);
   }
@@ -122,8 +121,8 @@ gras_datadesc_copy_rec(gras_cbps_t           state,
 
   VERB4("Copy a %s (%s) from %p to %p", 
        type->name, gras_datadesc_cat_names[type->category_code],
-       src,dst);
-
+       src,dst);       
+   
   if (type->send) {
     type->send(type,state,src);
   }
@@ -154,9 +153,27 @@ gras_datadesc_copy_rec(gras_cbps_t           state,
       if (field->send)
        field->send(type,state,field_src);
       
-      VERB1("Copy field %s",field->name);
+      DEBUG1("Copy field %s",field->name);
       count += gras_datadesc_copy_rec(state,refs,sub_type, field_src, field_dst, 0,
                                      detect_cycle || sub_type->cycle);
+       
+       if (XBT_LOG_ISENABLED(gras_ddt_exchange,xbt_log_priority_verbose)) {
+         if (sub_type == gras_datadesc_by_name("unsigned int")) {
+            VERB2("Copied value for field '%s': %d (type: unsigned int)",field->name, *(unsigned int*)field_dst);
+         } else if (sub_type == gras_datadesc_by_name("int")) {
+            VERB2("Copied value for field '%s': %d (type: int)",field->name, *(int*)field_dst);
+            
+         } else if (sub_type == gras_datadesc_by_name("unsigned long int")) {
+            VERB2("Copied value for field '%s': %ld (type: unsigned long int)",field->name, *(unsigned long int*)field_dst);
+         } else if (sub_type == gras_datadesc_by_name("long int")) {
+            VERB2("Copied value for field '%s': %ld (type: long int)",field->name, *(long int*)field_dst);
+
+         } else if (sub_type == gras_datadesc_by_name("string")) {
+            VERB2("Copied value for field '%s': '%s' (type: string)", field->name, *(char**)field_dst);         
+         } else {
+            VERB1("Copied a value for field '%s' (type not scalar?)", field->name);
+         }
+       }
       
     }
     VERB1("<< Copied all fields of the structure %s", type->name);
@@ -222,11 +239,12 @@ gras_datadesc_copy_rec(gras_cbps_t           state,
 
     reference_is_to_cpy = 0;
     TRY {
-      if (detect_cycle)
+      if (detect_cycle) {
        /* return ignored. Just checking whether it's known or not */
        n_ref=xbt_dict_get_ext(refs,(char*)o_ref, sizeof(char*));
-      else 
+      } else {
        reference_is_to_cpy = 1;
+      }
     } CATCH(e) {
       if (e.category != not_found_error)
        RETHROW;
@@ -287,7 +305,7 @@ gras_datadesc_copy_rec(gras_cbps_t           state,
 
   case e_gras_datadesc_type_cat_array: {
     gras_dd_cat_array_t    array_data;
-    long int               count;
+    long int               array_count;
     char                  *src_ptr=src;
     char                  *dst_ptr=dst;
     long int               elm_size;
@@ -295,12 +313,12 @@ gras_datadesc_copy_rec(gras_cbps_t           state,
     array_data = type->category.array_data;
     
     /* determine and send the element count */
-    count = array_data.fixed_size;
-    if (count == 0)
-      count = subsize;
-    if (count == 0) {
-      count = array_data.dynamic_size(type,state,src);
-      xbt_assert1(count >=0,
+    array_count = array_data.fixed_size;
+    if (array_count == 0)
+      array_count = subsize;
+    if (array_count == 0) {
+      array_count = array_data.dynamic_size(type,state,src);
+      xbt_assert1(array_count >=0,
                   "Invalid (negative) array size for type %s",type->name);
     }
     
@@ -308,21 +326,24 @@ gras_datadesc_copy_rec(gras_cbps_t           state,
     sub_type = array_data.type;
     elm_size = sub_type->aligned_size[GRAS_THISARCH];
     if (sub_type->category_code == e_gras_datadesc_type_cat_scalar) {
-      VERB1("Array of %ld scalars, copy it in one shot",count);
-      memcpy(dst, src, sub_type->aligned_size[GRAS_THISARCH] * count);
-      count += sub_type->aligned_size[GRAS_THISARCH] * count;
+      VERB1("Array of %ld scalars, copy it in one shot",array_count);
+      memcpy(dst, src, sub_type->aligned_size[GRAS_THISARCH] * array_count);
+      count += sub_type->aligned_size[GRAS_THISARCH] * array_count;
     } else if (sub_type->category_code == e_gras_datadesc_type_cat_array &&
               sub_type->category.array_data.fixed_size > 0 &&
               sub_type->category.array_data.type->category_code == e_gras_datadesc_type_cat_scalar) {
        
-      VERB1("Array of %ld fixed array of scalars, copy it in one shot",count);
+      VERB1("Array of %ld fixed array of scalars, copy it in one shot",
+           array_count);
       memcpy(dst,src,sub_type->category.array_data.type->aligned_size[GRAS_THISARCH] 
-                    * count * sub_type->category.array_data.fixed_size);
+                    * array_count * sub_type->category.array_data.fixed_size);
       count += sub_type->category.array_data.type->aligned_size[GRAS_THISARCH] 
-              * count * sub_type->category.array_data.fixed_size;
+              * array_count * sub_type->category.array_data.fixed_size;
        
     } else {
-      for (cpt=0; cpt<count; cpt++) {
+      VERB1("Array of %ld stuff, copy it in one after the other",array_count);
+      for (cpt=0; cpt<array_count; cpt++) {
+       VERB2("Copy the %dth stuff out of %ld",cpt,array_count);
        count += gras_datadesc_copy_rec(state,refs, sub_type, src_ptr, dst_ptr, 0,
                                        detect_cycle || sub_type->cycle);
        src_ptr += elm_size;
@@ -335,6 +356,7 @@ gras_datadesc_copy_rec(gras_cbps_t           state,
   default:
     xbt_assert0(0, "Invalid type");
   }
+   
   return count;
 }
 /**
@@ -347,21 +369,23 @@ gras_datadesc_copy_rec(gras_cbps_t           state,
 int gras_datadesc_copy(gras_datadesc_type_t type, 
                       void *src, void *dst) {
   xbt_ex_t e;
-  gras_cbps_t  state;
-  xbt_dict_t  refs; /* all references already sent */
+  static gras_cbps_t state=NULL;
+  static xbt_dict_t  refs=NULL; /* all references already sent */
   int size=0;
  
   xbt_assert0(type,"called with NULL type descriptor");
 
-  refs = xbt_dict_new();
-  state = gras_cbps_new();
+  if (!state) {
+    state = gras_cbps_new();
+    refs = xbt_dict_new();
+  }
   
   TRY {
     size = gras_datadesc_copy_rec(state,refs,type,(char*)src,(char*)dst,0, 
                                  type->cycle);
   } CLEANUP {
-    xbt_dict_free(&refs);
-    gras_cbps_free(&state);
+    xbt_dict_reset(refs);
+    gras_cbps_reset(state);
   } CATCH(e) {
     RETHROW;
   }
@@ -387,8 +411,12 @@ gras_datadesc_send_rec(gras_socket_t         sock,
   VERB2("Send a %s (%s)", 
        type->name, gras_datadesc_cat_names[type->category_code]);
 
+  if (!strcmp(type->name,"string"))
+    VERB1("value: '%s'",*(char**)data);
+
   if (type->send) {
     type->send(type,state,data);
+    DEBUG0("Run the emission callback");
   }
 
   switch (type->category_code) {
@@ -412,8 +440,10 @@ gras_datadesc_send_rec(gras_socket_t         sock,
       
       sub_type = field->type;
       
-      if (field->send)
+      if (field->send) {
+       DEBUG1("Run the emission callback of field %s", field->name);
        field->send(type,state,field_data);
+      }
       
       VERB1("Send field %s",field->name);
       gras_datadesc_send_rec(sock,state,refs,sub_type, field_data, 
@@ -473,7 +503,7 @@ gras_datadesc_send_rec(gras_socket_t         sock,
     sub_type = ref_data.type;
     if (sub_type == NULL) {
       sub_type = (*ref_data.selector)(type,state,data);
-      gras_dd_send_int(sock, &(sub_type->code),1 /*stable*/);
+      gras_dd_send_int(sock, (int*) &(sub_type->code),1 /*stable*/);
     }
     
     /* Send the actual value of the pointer for cycle handling */
@@ -580,19 +610,21 @@ void gras_datadesc_send(gras_socket_t        sock,
                        void *src) {
 
   xbt_ex_t e;
-  gras_cbps_t  state;
-  xbt_dict_t  refs; /* all references already sent */
+  static gras_cbps_t state=NULL;
+  static xbt_dict_t  refs=NULL; /* all references already sent */
  
   xbt_assert0(type,"called with NULL type descriptor");
 
-  refs = xbt_dict_new();
-  state = gras_cbps_new();
-  
+  if (!state) {
+    state = gras_cbps_new();
+    refs = xbt_dict_new();
+  }
+   
   TRY {
     gras_datadesc_send_rec(sock,state,refs,type,(char*)src, type->cycle);
   } CLEANUP {
-    xbt_dict_free(&refs);
-    gras_cbps_free(&state);
+    xbt_dict_reset(refs);
+    gras_cbps_reset(state);
   } CATCH(e) {
     RETHROW;
   }
@@ -665,8 +697,10 @@ gras_datadesc_recv_rec(gras_socket_t         sock,
                             field_data,-1, 
                             detect_cycle || sub_type->cycle);
        
-      if (field->recv)
+      if (field->recv) {
+       DEBUG1("Run the reception callback of field %s", field->name);
         field->recv(type,state,(void*)l_data);
+      }
     
     }
     VERB1("<< Received all fields of the structure %s", type->name);
@@ -746,16 +780,18 @@ gras_datadesc_recv_rec(gras_socket_t         sock,
          
     reference_is_to_recv = 0;
     TRY {
-      if (detect_cycle)
+      if (detect_cycle) {
        l_ref = xbt_dict_get_ext(refs, (char*)r_ref, pointer_type->size[r_arch]);
-      else 
+      } else {
        reference_is_to_recv = 1;
+      }
     } CATCH(e) {
       if (e.category != not_found_error)
         RETHROW;
       reference_is_to_recv = 1;
       xbt_ex_free(e);
     }
+
     if (reference_is_to_recv) {
       int subsubcount = 0;
       void *l_referenced=NULL;
@@ -893,6 +929,9 @@ gras_datadesc_recv_rec(gras_socket_t         sock,
   if (type->recv)
     type->recv(type,state,l_data);
 
+  if (!strcmp(type->name,"string"))
+    VERB1("value: '%s'",*(char**)l_data);
+
 }
 
 /**
@@ -909,12 +948,14 @@ gras_datadesc_recv(gras_socket_t         sock,
                   void                 *dst) {
 
   xbt_ex_t e;
-  gras_cbps_t  state; /* callback persistent state */
-  xbt_dict_t  refs;  /* all references already sent */
-
-  refs = xbt_dict_new();
-  state = gras_cbps_new();
+  static gras_cbps_t state=NULL; /* callback persistent state */
+  static xbt_dict_t  refs=NULL;  /* all references already sent */
 
+  if (!state) {
+    state = gras_cbps_new();
+    refs = xbt_dict_new();
+  }
+   
   xbt_assert0(type,"called with NULL type descriptor");
   TRY {
     gras_datadesc_recv_rec(sock, state, refs, type, 
@@ -922,8 +963,8 @@ gras_datadesc_recv(gras_socket_t         sock,
                           (char *) dst,-1, 
                           type->cycle);
   } CLEANUP {
-    xbt_dict_free(&refs);
-    gras_cbps_free(&state);
+    xbt_dict_reset(refs);
+    gras_cbps_reset(state);
   } CATCH(e) {
     RETHROW;
   }