Index: trunk/platforms/tsar_generic_xbar/scripts/counter_defs.py
===================================================================
--- trunk/platforms/tsar_generic_xbar/scripts/counter_defs.py	(revision 752)
+++ trunk/platforms/tsar_generic_xbar/scripts/counter_defs.py	(revision 779)
@@ -5,4 +5,9 @@
 
 stacked_metrics = [ 'nonwrite_broadcast', 'write_broadcast', 'local_m_inv', 'remote_m_inv', 'local_update', 'remote_update' ]
+
+m_prot_name = {}
+m_prot_name['dhccp'] = "DHCCP"
+m_prot_name['rwt'] = "RWT"
+m_prot_name['mesi'] = "HMESI"
 
 m_app_name = {}
@@ -32,56 +37,72 @@
 m_metric_tag['counter_reset']      = "[000]"
 m_metric_tag['ncycles']            = "[001]"
-m_metric_tag['local_read']         = "[002]"
-m_metric_tag['remote_read']        = "[003]"
-m_metric_tag['read_cost']          = "[004]"
-m_metric_tag['local_write']        = "[005]"
-m_metric_tag['remote_write']       = "[006]"
-m_metric_tag['write_flits_local']  = "[007]"
-m_metric_tag['write_flits_remote'] = "[008]"
-m_metric_tag['write_cost']         = "[009]"
-m_metric_tag['local_ll']           = "[010]"
-m_metric_tag['remote_ll']          = "[011]"
-m_metric_tag['ll_cost']            = "[012]"
-m_metric_tag['local_sc']           = "[013]"
-m_metric_tag['remote_sc']          = "[014]"
-m_metric_tag['sc_cost']            = "[015]"
-m_metric_tag['local_cas']          = "[016]"
-m_metric_tag['remote_cas']         = "[017]"
-m_metric_tag['cas_cost']           = "[018]"
-m_metric_tag['req_trig_update']    = "[019]"
-m_metric_tag['local_update']       = "[020]"
-m_metric_tag['remote_update']      = "[021]"
-m_metric_tag['update_cost']        = "[022]"
-m_metric_tag['req_trig_m_inv']     = "[023]"
-m_metric_tag['local_m_inv']        = "[024]"
-m_metric_tag['remote_m_inv']       = "[025]"
-m_metric_tag['m_inv_cost']         = "[026]"
-m_metric_tag['broadcast']          = "[027]"
-m_metric_tag['local_cleanup']      = "[028]"
-m_metric_tag['remote_cleanup']     = "[029]"
-m_metric_tag['cleanup_cost']       = "[030]"
-m_metric_tag['nb_read_miss']       = "[031]"
-m_metric_tag['write_miss']         = "[032]"
-m_metric_tag['write_dirty']        = "[033]"
-m_metric_tag['read_hit_trt']       = "[034]" # Reads blocked by a hit in the TRT
-m_metric_tag['trans_full_trt']     = "[035]" # Transactions blocked because the TRT is full
-m_metric_tag['put']                = "[036]"
-m_metric_tag['get']                = "[037]"
-m_metric_tag['write_broadcast']    = "[038]"
-
-m_metric_tag['total_read']         = "[040]"
-m_metric_tag['total_write']        = "[041]"
-m_metric_tag['total_ll']           = "[042]"
-m_metric_tag['total_sc']           = "[043]"
-m_metric_tag['total_cas']          = "[044]"
-m_metric_tag['total_update']       = "[045]"
-m_metric_tag['total_m_inv']        = "[046]"
-m_metric_tag['total_cleanup']      = "[047]"
-m_metric_tag['total_direct']       = "[048]"
-
-m_metric_tag['nonwrite_broadcast'] = "[050]"
-m_metric_tag['broadcast_cost']     = "[051]"
-m_metric_tag['direct_cost']        = "[052]"
-m_metric_tag['total_stacked']      = "|060]"
+
+m_metric_tag['local_read']         = "[010]"
+m_metric_tag['remote_read']        = "[011]"
+m_metric_tag['read_cost']          = "[012]"
+
+m_metric_tag['local_write']        = "[020]"
+m_metric_tag['remote_write']       = "[021]"
+m_metric_tag['write_flits_local']  = "[022]"
+m_metric_tag['write_flits_remote'] = "[023]"
+m_metric_tag['write_cost']         = "[024]"
+m_metric_tag['write_l1_miss_ncc']  = "[025]"
+
+m_metric_tag['local_ll']           = "[030]"
+m_metric_tag['remote_ll']          = "[031]"
+m_metric_tag['ll_cost']            = "[032]"
+
+m_metric_tag['local_sc']           = "[040]"
+m_metric_tag['remote_sc']          = "[041]"
+m_metric_tag['sc_cost']            = "[042]"
+
+m_metric_tag['local_cas']          = "[050]"
+m_metric_tag['remote_cas']         = "[051]"
+m_metric_tag['cas_cost']           = "[052]"
+
+m_metric_tag['req_trig_update']    = "[060]"
+m_metric_tag['local_update']       = "[061]"
+m_metric_tag['remote_update']      = "[062]"
+m_metric_tag['update_cost']        = "[063]"
+
+m_metric_tag['req_trig_m_inv']     = "[070]"
+m_metric_tag['local_m_inv']        = "[071]"
+m_metric_tag['remote_m_inv']       = "[072]"
+m_metric_tag['m_inv_cost']         = "[073]"
+
+m_metric_tag['broadcast']          = "[080]"
+m_metric_tag['write_broadcast']    = "[081]"
+
+m_metric_tag['local_cleanup']      = "[090]"
+m_metric_tag['remote_cleanup']     = "[091]"
+m_metric_tag['cleanup_cost']       = "[092]"
+m_metric_tag['cleanup_data_flits'] = "[093]"
+
+m_metric_tag['read_miss']          = "[100]"
+m_metric_tag['write_miss']         = "[101]"
+m_metric_tag['write_dirty']        = "[102]"
+m_metric_tag['read_hit_trt']       = "[110]" # Reads blocked by a hit in the TRT
+m_metric_tag['trans_full_trt']     = "[111]" # Transactions blocked because the TRT is full
+m_metric_tag['put']                = "[120]"
+m_metric_tag['get']                = "[121]"
+m_metric_tag['min_heap_slots_av']  = "[130]"
+
+m_metric_tag['ncc_to_cc_read']     = "[140]"
+m_metric_tag['ncc_to_cc_write']    = "[141]"
+
+m_metric_tag['total_read']         = "[500]"
+m_metric_tag['total_write']        = "[501]"
+m_metric_tag['total_ll']           = "[502]"
+m_metric_tag['total_sc']           = "[503]"
+m_metric_tag['total_cas']          = "[504]"
+m_metric_tag['total_update']       = "[505]"
+m_metric_tag['total_m_inv']        = "[506]"
+m_metric_tag['total_cleanup']      = "[507]"
+m_metric_tag['total_direct']       = "[508]"
+m_metric_tag['total_ncc_to_cc']    = "[509]"
+
+m_metric_tag['nonwrite_broadcast'] = "[600]"
+m_metric_tag['broadcast_cost']     = "[601]"
+m_metric_tag['direct_cost']        = "[602]"
 
 all_metrics = m_metric_tag.keys()
@@ -91,7 +112,9 @@
 m_metric_name['counter_reset']      = "Counters reset at cycle"
 m_metric_name['ncycles']            = "Number of Cycles"
+
 m_metric_name['local_read']         = "Number of Local Reads (Miss in L1)"
 m_metric_name['remote_read']        = "Number of Remote Reads (Miss in L1)"
 m_metric_name['read_cost']          = "Read Cost"
+
 m_metric_name['local_write']        = "Number of Local Writes"
 m_metric_name['remote_write']       = "Number of Remote Writes"
@@ -99,27 +122,36 @@
 m_metric_name['write_flits_remote'] = "Number of Remote Write Flits"
 m_metric_name['write_cost']         = "Write Cost"
+
 m_metric_name['local_ll']           = "Number of Local LL"
 m_metric_name['remote_ll']          = "Number of Remote LL"
 m_metric_name['ll_cost']            = "LL Cost"
+
 m_metric_name['local_sc']           = "Number of Local SC"
 m_metric_name['remote_sc']          = "Number of Remote SC"
 m_metric_name['sc_cost']            = "SC Cost"
+
 m_metric_name['local_cas']          = "Number of Local CAS"
 m_metric_name['remote_cas']         = "Number of Remote CAS"
 m_metric_name['cas_cost']           = "CAS Cost"
+
 m_metric_name['req_trig_update']    = "Number of Requests Triggering an Update"
 m_metric_name['local_update']       = "Number of Local Updates"
 m_metric_name['remote_update']      = "Number of Remote Updates"
 m_metric_name['update_cost']        = "Update Cost"
+
 m_metric_name['req_trig_m_inv']     = "Number of Requests Triggering a M.inv"
 m_metric_name['local_m_inv']        = "Number of Local Multi Inval"
 m_metric_name['remote_m_inv']       = "Number of Remote Multi Inval"
 m_metric_name['m_inv_cost']         = "Multi Inval Cost"
-m_metric_name['broadcast']          = "Number of Broadcasts"
+
 m_metric_name['broadcast']          = "Total Number of Broadcasts"
+m_metric_name['write_broadcast']    = "Number of Broadcasts Trig. by Writes"
+m_metric_name['nonwrite_broadcast'] = "Number of Broadcasts not Trig. by Writes"
+
 m_metric_name['local_cleanup']      = "Number of Local Cleanups"
 m_metric_name['remote_cleanup']     = "Number of Remote Cleanups"
 m_metric_name['cleanup_cost']       = "Cleanup Cost"
-m_metric_name['nb_read_miss']       = "Number of Read Miss (in L2)"
+
+m_metric_name['read_miss']          = "Number of Read Miss (in L2)"
 m_metric_name['write_miss']         = "Number of Write Miss (in L2)"
 m_metric_name['write_dirty']        = "Number of Write Dirty (from L2 to Memory)"
@@ -128,5 +160,8 @@
 m_metric_name['put']                = "Number of PUT to Memory"
 m_metric_name['get']                = "Number of GET from Memory"
-m_metric_name['write_broadcast']    = "Number of Broadcasts Trig. by Writes"
+m_metric_name['min_heap_slots_av']  = "Minimum Number of Heap Slots available"
+
+m_metric_name['ncc_to_cc_read']     = "Number or Reads trig. NCC to CC"
+m_metric_name['ncc_to_cc_write']    = "Number of Writes trig. NCC to CC"
 
 m_metric_name['total_read']         = "Total Number of Reads"
@@ -139,8 +174,8 @@
 m_metric_name['total_cleanup']      = "Total Number of Cleanups"
 m_metric_name['total_direct']       = "Total Number of Direct Requests"
-m_metric_name['nonwrite_broadcast'] = "Number of Broadcasts not Trig. by Writes"
+m_metric_name['total_ncc_to_cc']    = "Total Number of NCC to CC Changes"
 m_metric_name['broadcast_cost']     = "Broadcast Cost"
 m_metric_name['direct_cost']        = "Direct Requests Cost"
-m_metric_name['total_stacked']      = "??" # Normalization factor
+m_metric_name['total_stacked']      = "??" # Normalization factor, does not have a name (unused)
 
 
Index: trunk/platforms/tsar_generic_xbar/scripts/create_graphs.py
===================================================================
--- trunk/platforms/tsar_generic_xbar/scripts/create_graphs.py	(revision 752)
+++ trunk/platforms/tsar_generic_xbar/scripts/create_graphs.py	(revision 779)
@@ -4,9 +4,14 @@
 import os
 import re
-
-
-
+import sys
+
+
+#apps = [ 'histogram', 'mandel', 'filter', 'radix', 'fft_ga' ]
 apps = [ 'histogram', 'mandel', 'filter', 'radix', 'radix_ga', 'fft', 'fft_ga', 'filt_ga', 'kmeans', 'pca', 'lu' ]
+#apps = [ 'fft' ]
 nb_procs = [ 1, 4, 8, 16, 32, 64, 128, 256 ]
+single_protocols = ['dhccp']
+#joint_protocols = ['dhccp', 'rwt']
+joint_protocols = []
 
 top_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..")
@@ -21,6 +26,6 @@
 data_dir = 'data'
 
-log_init_name = 'log_init_'
-log_term_name = 'log_term_'
+log_stdo_name = '_stdo_'
+log_term_name = '_term_'
 
 coherence_tmpl = os.path.join(scripts_path, template_dir, 'coherence_template.gp') # 1 graph per appli
@@ -70,60 +75,73 @@
 exec_time = {}
 metrics_val = {}
-for app in apps:
-   exec_time[app] = {}
-   metrics_val[app] = {}
-   for i in nb_procs:
-      metrics_val[app][i] = {}
-      log_init_file = os.path.join(scripts_path, data_dir, app + '_' + log_init_name + str(i))
-      log_term_file = os.path.join(scripts_path, data_dir, app + '_' + log_term_name + str(i))
-
-      # Term
-      lines = open(log_term_file, 'r')
-      for line in lines:
-         tokens = line[:-1].split()
-         if len(tokens) > 0 and tokens[0] == "[PARALLEL_COMPUTE]":
-            exec_time[app][i] = int(tokens[len(tokens) - 1])
-
-      # Init files
-      lines = open(log_init_file, 'r')
-      for line in lines:
-         tokens = line[:-1].split()
-         if len(tokens) == 0:
-            continue
-         tag = tokens[0]
-         value = tokens[len(tokens) - 1]
-         pattern = re.compile('\[0[0-9][0-9]\]')
-         if pattern.match(tag):
-            metric = m_metric_id[tag]
-            if (not metrics_val[app][i].has_key(metric) or tag == "[000]" or tag == "[001]"):
-               # We don't add cycles of all Memcaches (they must be the same for all)
-               metrics_val[app][i][metric] = int(value)
-            else:
-               metrics_val[app][i][metric] += int(value)
-            
+for prot in single_protocols:
+   metrics_val[prot] = {}
+   exec_time[prot] = {}
+   for app in apps:
+      exec_time[prot][app] = {}
+      metrics_val[prot][app] = {}
+      for i in nb_procs:
+         metrics_val[prot][app][i] = {}
+         log_stdo_file = os.path.join(scripts_path, data_dir, app + '_' + prot + log_stdo_name + str(i))
+         log_term_file = os.path.join(scripts_path, data_dir, app + '_' + prot + log_term_name + str(i))
+   
+         # Term
+         lines = open(log_term_file, 'r')
+         for line in lines:
+            tokens = line[:-1].split()
+            if len(tokens) > 0 and tokens[0] == "[PARALLEL_COMPUTE]":
+               exec_time[prot][app][i] = int(tokens[len(tokens) - 1])
+   
+         # Init files
+         lines = open(log_stdo_file, 'r')
+         for line in lines:
+            tokens = line[:-1].split()
+            if len(tokens) == 0:
+               continue
+            tag = tokens[0]
+            value = tokens[len(tokens) - 1]
+            pattern = re.compile('\[0[0-9][0-9]\]')
+            if pattern.match(tag):
+               metric = m_metric_id[tag]
+               if (not metrics_val[prot][app][i].has_key(metric) or tag == "[000]" or tag == "[001]"):
+                  # We don't add cycles of all Memcaches (they must be the same for all)
+                  metrics_val[prot][app][i][metric] = int(value)
+               else:
+                  metrics_val[prot][app][i][metric] += int(value)
+    
+# Completing unset metrics (i.e. they are not present in the data file) with 0
+for prot in single_protocols:
+   for app in apps:
+      for i in nb_procs:
+         for metric in all_metrics:
+            if metric not in metrics_val[prot][app][i]:
+               metrics_val[prot][app][i][metric] = 0
+
 # We make a 2nd pass to fill the derived fields, e.g. nb_total_updates
-for app in apps:
-   for i in nb_procs:
-      x, y = get_x_y(i)
-      metrics_val[app][i]['total_read']     = metrics_val[app][i]['local_read']    + metrics_val[app][i]['remote_read']
-      metrics_val[app][i]['total_write']    = metrics_val[app][i]['local_write']   + metrics_val[app][i]['remote_write']
-      metrics_val[app][i]['total_ll']       = metrics_val[app][i]['local_ll']      + metrics_val[app][i]['remote_ll']
-      metrics_val[app][i]['total_sc']       = metrics_val[app][i]['local_sc']      + metrics_val[app][i]['remote_sc']
-      metrics_val[app][i]['total_cas']      = metrics_val[app][i]['local_cas']     + metrics_val[app][i]['remote_cas']
-      metrics_val[app][i]['total_update']   = metrics_val[app][i]['local_update']  + metrics_val[app][i]['remote_update']
-      metrics_val[app][i]['total_m_inv']    = metrics_val[app][i]['local_m_inv']   + metrics_val[app][i]['remote_m_inv']
-      metrics_val[app][i]['total_cleanup']  = metrics_val[app][i]['local_cleanup'] + metrics_val[app][i]['remote_cleanup']
-      metrics_val[app][i]['total_direct']   = metrics_val[app][i]['total_read']    + metrics_val[app][i]['total_write']
-      metrics_val[app][i]['direct_cost']    = metrics_val[app][i]['read_cost']     + metrics_val[app][i]['write_cost']
-      metrics_val[app][i]['broadcast_cost'] = metrics_val[app][i]['broadcast'] * (x * y - 1)
-      if metrics_val[app][i]['broadcast'] < metrics_val[app][i]['write_broadcast']:
-         # test to patch a bug in mem_cache
-         metrics_val[app][i]['nonwrite_broadcast'] = 0
-      else:
-         metrics_val[app][i]['nonwrite_broadcast'] = metrics_val[app][i]['broadcast'] - metrics_val[app][i]['write_broadcast']
-
-      metrics_val[app][i]['total_stacked'] = 0
-      for stacked_metric in stacked_metrics:
-         metrics_val[app][i]['total_stacked'] += metrics_val[app][i][stacked_metric]
+for prot in single_protocols:
+   for app in apps:
+      for i in nb_procs:
+         x, y = get_x_y(i)
+         metrics_val[prot][app][i]['total_read']      = metrics_val[prot][app][i]['local_read']     + metrics_val[prot][app][i]['remote_read']
+         metrics_val[prot][app][i]['total_write']     = metrics_val[prot][app][i]['local_write']    + metrics_val[prot][app][i]['remote_write']
+         metrics_val[prot][app][i]['total_ll']        = metrics_val[prot][app][i]['local_ll']       + metrics_val[prot][app][i]['remote_ll']
+         metrics_val[prot][app][i]['total_sc']        = metrics_val[prot][app][i]['local_sc']       + metrics_val[prot][app][i]['remote_sc']
+         metrics_val[prot][app][i]['total_cas']       = metrics_val[prot][app][i]['local_cas']      + metrics_val[prot][app][i]['remote_cas']
+         metrics_val[prot][app][i]['total_update']    = metrics_val[prot][app][i]['local_update']   + metrics_val[prot][app][i]['remote_update']
+         metrics_val[prot][app][i]['total_m_inv']     = metrics_val[prot][app][i]['local_m_inv']    + metrics_val[prot][app][i]['remote_m_inv']
+         metrics_val[prot][app][i]['total_cleanup']   = metrics_val[prot][app][i]['local_cleanup']  + metrics_val[prot][app][i]['remote_cleanup']
+         metrics_val[prot][app][i]['total_direct']    = metrics_val[prot][app][i]['total_read']     + metrics_val[prot][app][i]['total_write']
+         metrics_val[prot][app][i]['total_ncc_to_cc'] = metrics_val[prot][app][i]['ncc_to_cc_read'] + metrics_val[prot][app][i]['ncc_to_cc_write']
+         metrics_val[prot][app][i]['direct_cost']     = metrics_val[prot][app][i]['read_cost']      + metrics_val[prot][app][i]['write_cost']
+         metrics_val[prot][app][i]['broadcast_cost']  = metrics_val[prot][app][i]['broadcast'] * (x * y - 1)
+         if metrics_val[prot][app][i]['broadcast'] < metrics_val[prot][app][i]['write_broadcast']:
+            # test to patch a bug in mem_cache
+            metrics_val[prot][app][i]['nonwrite_broadcast'] = 0
+         else:
+            metrics_val[prot][app][i]['nonwrite_broadcast'] = metrics_val[prot][app][i]['broadcast'] - metrics_val[prot][app][i]['write_broadcast']
+   
+         metrics_val[prot][app][i]['total_stacked'] = 0
+         for stacked_metric in stacked_metrics:
+            metrics_val[prot][app][i]['total_stacked'] += metrics_val[prot][app][i][stacked_metric]
 
             
@@ -138,55 +156,413 @@
 ############################################################
 
-for app in apps:
-   data_coherence_name = os.path.join(scripts_path, gen_dir, app + '_coherence.dat')
-   gp_coherence_name   = os.path.join(scripts_path, gen_dir, app + '_coherence.gp')
-
-   # Creating the data file
+for prot in single_protocols:
+   for app in apps:
+      data_coherence_name = os.path.join(scripts_path, gen_dir, prot + '_' + app + '_coherence.dat')
+      gp_coherence_name   = os.path.join(scripts_path, gen_dir, prot + '_' + app + '_coherence.gp')
+   
+      # Creating the data file
+      width = 15
+      content = ""
+      
+      for metric in [ '#nb_procs' ] + grouped_metrics:
+         content += metric + " "
+         nb_spaces = width - len(metric)
+         content += nb_spaces * ' '
+      content += "\n"
+   
+      for i in nb_procs:
+         content += "%-15d " % i
+         for metric in grouped_metrics:
+            val = float(metrics_val[prot][app][i][metric]) / exec_time[prot][app][i] * 1000
+            content += "%-15f " % val
+         content += "\n"
+      
+      create_file(data_coherence_name, content)
+   
+      # Creating the gp file
+      template_file = open(coherence_tmpl, 'r')
+      template = template_file.read()
+      
+      plot_str = ""
+      col = 2
+      for metric in grouped_metrics:
+         if metric != grouped_metrics[0]:
+            plot_str += ", \\\n    "
+         plot_str += "\"" + data_coherence_name + "\" using ($1):($" + str(col) + ") lc rgb " + colors[col - 2] + " title \"" + m_metric_name[metric] + "\" with linespoint"
+         col += 1
+      gp_commands = template % dict(app_name = m_app_name[app], nb_procs = nb_procs[-1] + 1, plot_str = plot_str, svg_name = os.path.join(graph_dir, prot + '_' + app + '_coherence'))
+      
+      create_file(gp_coherence_name, gp_commands)
+      
+      # Calling gnuplot
+      print "gnuplot", gp_coherence_name
+      subprocess.call([ 'gnuplot', gp_coherence_name ])
+
+
+############################################################
+### Graph 2 : Speedup per Application                    ###
+############################################################
+
+for prot in single_protocols:
+   for app in apps:
+   
+      data_speedup_name = os.path.join(scripts_path, gen_dir, prot + '_' + app + '_speedup.dat')
+      gp_speedup_name   = os.path.join(scripts_path, gen_dir, prot + '_' + app + '_speedup.gp')
+      
+      # Creating data file
+      width = 15
+      content = "#nb_procs"
+      nb_spaces = width - len(content)
+      content += nb_spaces * ' '
+      content += "speedup\n"
+   
+      for i in nb_procs:
+         content += "%-15d " % i
+         val = exec_time[prot][app][i]
+         content += "%-15f\n" % (exec_time[prot][app][1] / float(val))
+   
+      plot_str = "\"" + data_speedup_name + "\" using ($1):($2) lc rgb \"#654387\" title \"Speedup\" with linespoint"
+      
+      create_file(data_speedup_name, content)
+      
+      # Creating the gp file
+      template_file = open(speedup_tmpl, 'r')
+      template = template_file.read()
+      
+      gp_commands = template % dict(appli = m_app_name[app], nb_procs = nb_procs[-1] + 1, plot_str = plot_str, svg_name = os.path.join(graph_dir, prot + '_' + app + '_speedup'))
+      
+      create_file(gp_speedup_name, gp_commands)
+      
+      # Calling gnuplot
+      print "gnuplot", gp_speedup_name
+      subprocess.call([ 'gnuplot', gp_speedup_name ])
+
+
+############################################################
+### Graph 3 : All speedups on the same Graph             ###
+############################################################
+
+for prot in single_protocols:
+   # This graph uses the same template as the graph 2
+   data_speedup_name = os.path.join(scripts_path, gen_dir, prot + '_all_speedup.dat')
+   gp_speedup_name   = os.path.join(scripts_path, gen_dir, prot + '_all_speedup.gp')
+   
+   # Creating data file
    width = 15
-   content = ""
-   
-   for metric in [ '#nb_procs' ] + grouped_metrics:
-      content += metric + " "
-      nb_spaces = width - len(metric)
-      content += nb_spaces * ' '
+   content = "#nb_procs"
+   nb_spaces = width - len(content)
+   content += (nb_spaces + 1) * ' '
+   for app in apps:
+      content += app + " "
+      content += (width - len(app)) * " "
    content += "\n"
-
+   
    for i in nb_procs:
       content += "%-15d " % i
-      for metric in grouped_metrics:
-         val = float(metrics_val[app][i][metric]) / exec_time[app][i] * 1000
-         content += "%-15f " % val
+      for app in apps:
+         val = exec_time[prot][app][i]
+         content += "%-15f " % (exec_time[prot][app][1] / float(val))
       content += "\n"
    
-   create_file(data_coherence_name, content)
-
-   # Creating the gp file
-   template_file = open(coherence_tmpl, 'r')
+   create_file(data_speedup_name, content)
+   
+   # Creating gp file
+   template_file = open(speedup_tmpl, 'r')
    template = template_file.read()
    
    plot_str = ""
    col = 2
-   for metric in grouped_metrics:
-      if metric != grouped_metrics[0]:
-         plot_str += ", \\\n    "
-      plot_str += "\"" + data_coherence_name + "\" using ($1):($" + str(col) + ") lc rgb " + colors[col - 2] + " title \"" + m_metric_name[metric] + "\" with linespoint"
+   for app in apps:
+      if app != apps[0]:
+         plot_str += ", \\\n     "
+      plot_str += "\"" + data_speedup_name + "\" using ($1):($" + str(col) + ") lc rgb %s title \"" % (colors[col - 2])  + m_app_name[app] + "\" with linespoint"
       col += 1
-   gp_commands = template % dict(app_name = m_app_name[app], nb_procs = nb_procs[-1] + 1, plot_str = plot_str, svg_name = os.path.join(graph_dir, app + '_coherence'))
-   
-   create_file(gp_coherence_name, gp_commands)
-   
+   
+   gp_commands = template % dict(appli = "All Applications", nb_procs = nb_procs[-1] + 1, plot_str = plot_str, svg_name = os.path.join(graph_dir, prot + '_all_speedup'))
+      
+   create_file(gp_speedup_name, gp_commands)
+      
    # Calling gnuplot
-   print "gnuplot", gp_coherence_name
-   subprocess.call([ 'gnuplot', gp_coherence_name ])
-
-
-############################################################
-### Graph 2 : Speedup per Application                    ###
-############################################################
+   print "gnuplot", gp_speedup_name
+   subprocess.call([ 'gnuplot', gp_speedup_name ])
+
+
+############################################################
+### Graph 4 : Graph per metric                           ###
+############################################################
+
+# The following section creates the graphs grouped by measure (e.g. #broadcasts)
+# The template file cannot be easily created otherwise it would not be generic
+# in many ways. This is why it is mainly created here.
+# Graphs are created for metric in the "individual_metrics" list
+
+for prot in single_protocols:
+   for metric in individual_metrics:
+      data_metric_name = os.path.join(scripts_path, gen_dir, prot + '_' + metric + '.dat')
+      gp_metric_name   = os.path.join(scripts_path, gen_dir, prot + '_' + metric + '.gp')
+   
+      # Creating the gp file
+      # Setting xtics, i.e. number of procs for each application
+      xtics_str = "("
+      first = True
+      xpos = 1
+      app_labels = ""
+      for num_appli in range(0, len(apps)):
+         for i in nb_procs:
+            if not first:
+               xtics_str += ", "
+            first = False
+            if i == nb_procs[0]:
+               xpos_first = xpos
+            xtics_str += "\"%d\" %.1f" % (i, xpos)
+            xpos_last = xpos
+            xpos += 1.5
+         xpos += 0.5
+         app_name_xpos = float((xpos_first + xpos_last)) / 2
+         app_labels += "set label \"%s\" at first %f,character 1 center font \"Times,12\"\n" % (m_app_name[apps[num_appli]], app_name_xpos)
+      xtics_str += ")"
+   
+      xmax_val = float(xpos - 1)
+   
+      # Writing the lines of "plot"
+      plot_str = ""
+      xpos = 0
+      first = True
+      column = 2
+      for i in range(0, len(nb_procs)):
+         if not first:
+            plot_str += ", \\\n    "
+         first = False
+         plot_str += "\"%s\" using ($1+%.1f):($%d) lc rgb %s notitle with boxes" % (data_metric_name, xpos, column, colors[i])
+         column += 1
+         xpos += 1.5
+   
+      template_file = open(metric_tmpl, 'r')
+      template = template_file.read()
+   
+      gp_commands = template % dict(xtics_str = xtics_str, app_labels = app_labels, ylabel_str = m_metric_name[metric], norm_factor_str = m_norm_factor_name[m_metric_norm[metric]], xmax_val = xmax_val, plot_str = plot_str, svg_name = os.path.join(graph_dir, prot + '_' + metric))
+   
+      create_file(gp_metric_name, gp_commands)
+      
+      # Creating the data file
+      width = 15
+      content = "#x_pos"
+      nb_spaces = width - len(content)
+      content += nb_spaces * ' '
+      for i in nb_procs:
+         content += "%-15d" % i
+      content += "\n"
+   
+      x_pos = 1
+      for app in apps:
+         # Computation of x_pos
+         content += "%-15f" % x_pos
+         x_pos += len(nb_procs) * 1.5 + 0.5
+         for i in nb_procs:
+            if m_metric_norm[metric] == "N":
+               content += "%-15d" % (metrics_val[prot][app][i][metric])
+            elif m_metric_norm[metric] == "P":
+               content += "%-15f" % (float(metrics_val[prot][app][i][metric]) / i)
+            elif m_metric_norm[metric] == "C":
+               content += "%-15f" % (float(metrics_val[prot][app][i][metric]) / exec_time[prot][app][i] * 1000)
+            elif m_metric_norm[metric] == "W":
+               content += "%-15f" % (float(metrics_val[prot][app][i][metric]) / float(metrics_val[prot][app][i]['total_write'])) # Number of writes
+            elif m_metric_norm[metric] == "R":
+               content += "%-15f" % (float(metrics_val[prot][app][i][metric]) / float(metrics_val[prot][app][i]['total_read'])) # Number of reads
+            elif m_metric_norm[metric] == "D":
+               content += "%-15f" % (float(metrics_val[prot][app][i][metric]) / float(metrics_val[prot][app][i]['total_direct'])) # Number of req.
+            elif is_numeric(m_metric_norm[metric]):
+               content += "%-15f" % (float(metrics_val[prot][app][i][metric]) / float(metrics_val[prot][app][int(m_metric_norm[metric])][metric]))
+            else:
+               assert(False)
+   
+         app_name = m_app_name[app]
+         content += "#" + app_name + "\n"
+      
+      create_file(data_metric_name, content)
+   
+      # Calling gnuplot
+      print "gnuplot", gp_metric_name
+      subprocess.call([ 'gnuplot', gp_metric_name ])
+
+
+############################################################
+### Graph 5 : Stacked histogram with counters            ###
+############################################################
+
+# The following section creates a stacked histogram containing
+# the metrics in the "stacked_metric" list
+# It is normalized per application w.r.t the values on 256 procs
+
+for prot in single_protocols:
+   data_stacked_name = os.path.join(scripts_path, gen_dir, prot + '_stacked.dat')
+   gp_stacked_name   = os.path.join(scripts_path, gen_dir, prot + '_stacked.gp')
+   
+   norm_factor_value = 256
+   
+   # Creating the gp file
+   template_file = open(stacked_tmpl, 'r')
+   template = template_file.read()
+   
+   xtics_str = "("
+   first = True
+   xpos = 1
+   app_labels = ""
+   for num_appli in range(0, len(apps)):
+      for i in nb_procs:
+         if not first:
+            xtics_str += ", "
+         first = False
+         if i == nb_procs[0]:
+            xpos_first = xpos
+         xtics_str += "\"%d\" %d -1" % (i, xpos)
+         xpos_last = xpos
+         xpos += 1
+      xpos += 1
+      app_name_xpos = float((xpos_first + xpos_last)) / 2
+      app_labels += "set label \"%s\" at first %f,character 1 center font \"Times,12\"\n" % (m_app_name[apps[num_appli]], app_name_xpos)
+   xtics_str += ")"
+   
+   plot_str = "newhistogram \"\""
+   n = 1
+   for stacked_metric in stacked_metrics:
+      plot_str += ", \\\n    " + "'" + data_stacked_name + "'" + " using " + str(n) + " lc rgb " + colors[n] + " title \"" + m_metric_name[stacked_metric] + "\""
+      n += 1
+   
+   ylabel_str = "Breakdown of Coherence Traffic Normalized w.r.t. \\nthe Values on %d Processors" % norm_factor_value
+   content = template % dict(svg_name = os.path.join(graph_dir, prot + '_stacked'), xtics_str = xtics_str, plot_str = plot_str, ylabel_str = ylabel_str, app_labels = app_labels, prot_labels = "")
+   
+   create_file(gp_stacked_name, content)
+   
+   # Creating the data file
+   # Values are normalized by application, w.r.t. the number of requests for a given number of procs
+   content = "#"
+   for stacked_metric in stacked_metrics:
+      content += stacked_metric
+      content += ' ' + ' ' * (15 - len(stacked_metric))
+   content += "\n"
+   for app in apps:
+      if app != apps[0]:
+         for i in range(0, len(stacked_metrics)):
+            content += "%-15f" % 0.0
+         content += "\n"
+      for i in nb_procs:
+         for stacked_metric in stacked_metrics:
+            content += "%-15f" % (float(metrics_val[prot][app][i][stacked_metric]) / metrics_val[prot][app][norm_factor_value]['total_stacked'])
+         content += "\n"
+   
+   create_file(data_stacked_name, content)
+   # Calling gnuplot
+   print "gnuplot", gp_stacked_name
+   subprocess.call([ 'gnuplot', gp_stacked_name ])
+
+
+
+#################################################################################
+### Graph 6 : Stacked histogram with coherence cost compared to r/w cost      ###
+#################################################################################
+
+# The following section creates pairs of stacked histograms, normalized w.r.t. the first one.
+# The first one contains the cost of reads and writes, the second contains the cost
+# of m_inv, m_up and broadcasts (extrapolated)
+
+for prot in single_protocols:
+   data_cost_filename = os.path.join(scripts_path, gen_dir, prot + '_relative_cost.dat')
+   gp_cost_filename   = os.path.join(scripts_path, gen_dir, prot + '_relative_cost.gp')
+   
+   direct_cost_metrics = [ 'read_cost', 'write_cost' ]
+   coherence_cost_metrics = ['update_cost', 'm_inv_cost', 'broadcast_cost' ]
+   
+   # Creating the gp file
+   template_file = open(stacked_tmpl, 'r')
+   template = template_file.read()
+   
+   xtics_str = "("
+   first = True
+   xpos = 1
+   app_labels = ""
+   for num_appli in range(0, len(apps)):
+      first_proc = True
+      for i in nb_procs:
+         if i > 4:
+            if not first:
+               xtics_str += ", "
+            first = False
+            if first_proc:
+               first_proc = False
+               xpos_first = xpos
+            xtics_str += "\"%d\" %f -1" % (i, float(xpos + 0.5))
+            xpos_last = xpos
+            xpos += 3
+      app_name_xpos = float((xpos_first + xpos_last)) / 2
+      app_labels += "set label \"%s\" at first %f,character 1 center font \"Times,12\"\n" % (m_app_name[apps[num_appli]], app_name_xpos)
+      #xpos += 1
+   xtics_str += ")"
+   
+   plot_str = "newhistogram \"\""
+   n = 1
+   for cost_metric in direct_cost_metrics + coherence_cost_metrics:
+      plot_str += ", \\\n    " + "'" + data_cost_filename + "'" + " using " + str(n) + " lc rgb " + colors[n] + " title \"" + m_metric_name[cost_metric] + "\""
+      n += 1
+   
+   ylabel_str = "Coherence Cost Compared to Direct Requests Cost,\\nNormalized per Application for each Number of Processors"
+   content = template % dict(svg_name = os.path.join(graph_dir, prot + '_rel_cost'), xtics_str = xtics_str, plot_str = plot_str, ylabel_str = ylabel_str, app_labels = app_labels, prot_labels = "")
+   
+   create_file(gp_cost_filename, content)
+   
+   # Creating the data file
+   # Values are normalized by application, w.r.t. the number of requests for a given number of procs
+   content = "#"
+   for cost_metric in direct_cost_metrics:
+      content += cost_metric
+      content += ' ' + ' ' * (15 - len(cost_metric))
+   for cost_metric in coherence_cost_metrics:
+      content += cost_metric
+      content += ' ' + ' ' * (15 - len(cost_metric))
+   content += "\n"
+   for app in apps:
+      if app != apps[0]:
+         for i in range(0, len(direct_cost_metrics) + len(coherence_cost_metrics)):
+            content += "%-15f" % 0.0
+         content += "\n"
+      for i in nb_procs:
+         if i > 4:
+            for cost_metric in direct_cost_metrics:
+               content += "%-15f" % (float(metrics_val[prot][app][i][cost_metric]) / metrics_val[prot][app][i]['direct_cost'])
+            for cost_metric in coherence_cost_metrics:
+               content += "%-15f" % 0.0
+            content += "\n"
+            for cost_metric in direct_cost_metrics:
+               content += "%-15f" % 0.0
+            for cost_metric in coherence_cost_metrics:
+               content += "%-15f" % (float(metrics_val[prot][app][i][cost_metric]) / metrics_val[prot][app][i]['direct_cost'])
+            content += "\n"
+            if i != nb_procs[-1]:
+               for j in range(0, len(direct_cost_metrics) + len(coherence_cost_metrics)):
+                  content += "%-15f" % 0.0
+               content += "\n"
+   
+   create_file(data_cost_filename, content)
+   # Calling gnuplot
+   print "gnuplot", gp_cost_filename
+   subprocess.call([ 'gnuplot', gp_cost_filename ])
+
+
+#################################################################################
+### Joint Graphs to several architectures                                     ###
+#################################################################################
+
+if len(joint_protocols) == 0:
+   sys.exit()
+
+#################################################################################
+### Graph 7: Comparison of Speedups (normalized w.r.t. 1 proc on first arch)  ###
+#################################################################################
+
 
 for app in apps:
 
-   data_speedup_name   = os.path.join(scripts_path, gen_dir, app + '_speedup.dat')
-   gp_speedup_name     = os.path.join(scripts_path, gen_dir, app + '_speedup.gp')
+   data_speedup_name = os.path.join(scripts_path, gen_dir, 'joint_' + app + '_speedup.dat')
+   gp_speedup_name   = os.path.join(scripts_path, gen_dir, 'joint_' + app + '_speedup.gp')
    
    # Creating data file
@@ -199,9 +575,9 @@
    for i in nb_procs:
       content += "%-15d " % i
-      val = exec_time[app][i]
-      content += "%-15f\n" % (exec_time[app][1] / float(val))
-
-   plot_str = "\"" + data_speedup_name + "\" using ($1):($2) lc rgb \"#654387\" title \"Speedup\" with linespoint"
-   
+      for prot in joint_protocols:
+         val = exec_time[prot][app][i]
+         content += "%-15f " % (exec_time[joint_protocols[0]][app][1] / float(val))
+      content += "\n"
+
    create_file(data_speedup_name, content)
    
@@ -209,6 +585,14 @@
    template_file = open(speedup_tmpl, 'r')
    template = template_file.read()
-   
-   gp_commands = template % dict(appli = m_app_name[app], nb_procs = nb_procs[-1] + 1, plot_str = plot_str, svg_name = os.path.join(graph_dir, app + '_speedup'))
+  
+   plot_str = ""
+   col = 2
+   for prot in joint_protocols:
+      if prot != joint_protocols[0]:
+         plot_str += ", \\\n     "
+      plot_str += "\"" + data_speedup_name + "\" using ($1):($" + str(col) + ") lc rgb %s title \"" % (colors[col - 2])  + m_prot_name[prot] + "\" with linespoint"
+      col += 1
+  
+   gp_commands = template % dict(appli = m_app_name[app] + " Normalized w.r.t. " + m_prot_name[joint_protocols[0]] + " on 1 Processor", nb_procs = nb_procs[-1] + 1, plot_str = plot_str, svg_name = os.path.join(graph_dir, 'joint_' + app + '_speedup'))
    
    create_file(gp_speedup_name, gp_commands)
@@ -219,248 +603,34 @@
 
 
-############################################################
-### Graph 3 : All speedups on the same Graph             ###
-############################################################
-
-# This graph uses the same template as the graph 2
-
-data_speedup_name = os.path.join(scripts_path, gen_dir, 'all_speedup.dat')
-gp_speedup_name   = os.path.join(scripts_path, gen_dir, 'all_speedup.gp')
-
-# Creating data file
-width = 15
-content = "#nb_procs"
-nb_spaces = width - len(content)
-content += (nb_spaces + 1) * ' '
-for app in apps:
-   content += app + " "
-   content += (width - len(app)) * " "
-content += "\n"
-
-for i in nb_procs:
-   content += "%-15d " % i
-   for app in apps:
-      val = exec_time[app][i]
-      content += "%-15f " % (exec_time[app][1] / float(val))
-   content += "\n"
-
-create_file(data_speedup_name, content)
-
-# Creating gp file
-template_file = open(speedup_tmpl, 'r')
-template = template_file.read()
-
-plot_str = ""
-col = 2
-for app in apps:
-   if app != apps[0]:
-      plot_str += ", \\\n     "
-   plot_str += "\"" + data_speedup_name + "\" using ($1):($" + str(col) + ") lc rgb %s title \"" % (colors[col - 2])  + m_app_name[app] + "\" with linespoint"
-   col += 1
-
-gp_commands = template % dict(appli = "All Applications", nb_procs = nb_procs[-1] + 1, plot_str = plot_str, svg_name = os.path.join(graph_dir, 'all_speedup'))
-   
-create_file(gp_speedup_name, gp_commands)
-   
-# Calling gnuplot
-print "gnuplot", gp_speedup_name
-subprocess.call([ 'gnuplot', gp_speedup_name ])
-
-
-############################################################
-### Graph 4 : Graph per metric                           ###
-############################################################
-
-# The following section creates the graphs grouped by measure (e.g. #broadcasts)
-# The template file cannot be easily created otherwise it would not be generic
-# in many ways. This is why it is mainly created here.
-# Graphs are created for metric in the "individual_metrics" list
-
-for metric in individual_metrics:
-   data_metric_name = os.path.join(scripts_path, gen_dir, metric + '.dat')
-   gp_metric_name   = os.path.join(scripts_path, gen_dir, metric + '.gp')
-
-   # Creating the gp file
-   # Setting xtics, i.e. number of procs for each application
-   xtics_str = "("
-   first = True
-   xpos = 1
-   app_labels = ""
-   for num_appli in range(0, len(apps)):
-      for i in nb_procs:
-         if not first:
-            xtics_str += ", "
-         first = False
-         if i == nb_procs[0]:
-            xpos_first = xpos
-         xtics_str += "\"%d\" %.1f" % (i, xpos)
-         xpos_last = xpos
-         xpos += 1.5
-      xpos += 0.5
-      app_name_xpos = float((xpos_first + xpos_last)) / 2
-      app_labels += "set label \"%s\" at first %f,character 1 center font\"Times,12\"\n" % (m_app_name[apps[num_appli]], app_name_xpos)
-   xtics_str += ")"
-
-   xmax_val = xpos + 0.5
-
-   # Writing the lines of "plot"
-   plot_str = ""
-   xpos = 0
-   first = True
-   column = 2
-   for i in range(0, len(nb_procs)):
-      if not first:
-         plot_str += ", \\\n    "
-      first = False
-      plot_str += "\"%s\" using ($1+%.1f):($%d) lc rgb %s notitle with boxes" % (data_metric_name, xpos, column, colors[i])
-      column += 1
-      xpos += 1.5
-
-   template_file = open(metric_tmpl, 'r')
-   template = template_file.read()
-
-   gp_commands = template % dict(xtics_str = xtics_str, app_labels = app_labels, ylabel_str = m_metric_name[metric], norm_factor_str = m_norm_factor_name[m_metric_norm[metric]], xmax_val = xmax_val, plot_str = plot_str, svg_name = os.path.join(graph_dir, metric))
-
-   create_file(gp_metric_name, gp_commands)
-   
-   # Creating the data file
-   width = 15
-   content = "#x_pos"
-   nb_spaces = width - len(content)
-   content += nb_spaces * ' '
-   for i in nb_procs:
-      content += "%-15d" % i
-   content += "\n"
-
-   x_pos = 1
-   for app in apps:
-      # Computation of x_pos
-      content += "%-15f" % x_pos
-      x_pos += len(nb_procs) * 1.5 + 0.5
-      for i in nb_procs:
-         if m_metric_norm[metric] == "N":
-            content += "%-15d" % (metrics_val[app][i][metric])
-         elif m_metric_norm[metric] == "P":
-            content += "%-15f" % (float(metrics_val[app][i][metric]) / i)
-         elif m_metric_norm[metric] == "C":
-            content += "%-15f" % (float(metrics_val[app][i][metric]) / exec_time[app][i] * 1000)
-         elif m_metric_norm[metric] == "W":
-            content += "%-15f" % (float(metrics_val[app][i][metric]) / float(metrics_val[app][i]['total_write'])) # Number of writes
-         elif m_metric_norm[metric] == "R":
-            content += "%-15f" % (float(metrics_val[app][i][metric]) / float(metrics_val[app][i]['total_read'])) # Number of reads
-         elif m_metric_norm[metric] == "D":
-            content += "%-15f" % (float(metrics_val[app][i][metric]) / float(metrics_val[app][i]['total_direct'])) # Number of req.
-         elif is_numeric(m_metric_norm[metric]):
-            content += "%-15f" % (float(metrics_val[app][i][metric]) / float(metrics_val[app][int(m_metric_norm[metric])][metric]))
-         else:
-            assert(False)
-
-      app_name = m_app_name[app]
-      content += "#" + app_name + "\n"
-   
-   create_file(data_metric_name, content)
-
-   # Calling gnuplot
-   print "gnuplot", gp_metric_name
-   subprocess.call([ 'gnuplot', gp_metric_name ])
-
-
-############################################################
-### Graph 5 : Stacked histogram with counters            ###
-############################################################
-
-# The following section creates a stacked histogram containing
-# the metrics in the "stacked_metric" list
-# It is normalized per application w.r.t the values on 256 procs
-
-data_stacked_name = os.path.join(scripts_path, gen_dir, 'stacked.dat')
-gp_stacked_name   = os.path.join(scripts_path, gen_dir, 'stacked.gp')
-
-norm_factor_value = 256
-
+#################################################################################
+### Graph 8 : Joint Stacked histogram with coherence cost and r/w cost        ###
+#################################################################################
+
+# The following section creates pairs of stacked histograms for each arch for each number of proc for each app, normalized by (app x number of procs) (with first arch, R/W cost, first of the 2*num_arch histo). It is close to Graph 6
+
+data_cost_filename = os.path.join(scripts_path, gen_dir, 'joint_relative_cost.dat')
+gp_cost_filename   = os.path.join(scripts_path, gen_dir, 'joint_relative_cost.gp')
+   
+direct_cost_metrics = [ 'read_cost', 'write_cost' ]
+coherence_cost_metrics = ['update_cost', 'm_inv_cost', 'broadcast_cost' ]
+   
 # Creating the gp file
 template_file = open(stacked_tmpl, 'r')
 template = template_file.read()
-
+   
 xtics_str = "("
 first = True
-xpos = 1
+xpos = 1 # successive x position of the center of the first bar in a application
 app_labels = ""
-for num_appli in range(0, len(apps)):
-   for i in nb_procs:
-      if not first:
-         xtics_str += ", "
-      first = False
-      if i == nb_procs[0]:
-         xpos_first = xpos
-      xtics_str += "\"%d\" %d -1" % (i, xpos)
-      xpos_last = xpos
-      xpos += 1
-   xpos += 1
-   app_name_xpos = float((xpos_first + xpos_last)) / 2
-   app_labels += "set label \"%s\" at first %f,character 1 center font\"Times,12\"\n" % (m_app_name[apps[num_appli]], app_name_xpos)
-xtics_str += ")"
-
-plot_str = "newhistogram \"\""
-n = 1
-for stacked_metric in stacked_metrics:
-   plot_str += ", \\\n    " + "'" + data_stacked_name + "'" + " using " + str(n) + " lc rgb " + colors[n] + " title \"" + m_metric_name[stacked_metric] + "\""
-   n += 1
-
-ylabel_str = "Breakdown of Coherence Traffic Normalized w.r.t. \\nthe Values on %d Processors" % norm_factor_value
-content = template % dict(svg_name = os.path.join(graph_dir, 'stacked'), xtics_str = xtics_str, plot_str = plot_str, ylabel_str = ylabel_str, app_labels = app_labels)
-
-create_file(gp_stacked_name, content)
-
-# Creating the data file
-# Values are normalized by application, w.r.t. the number of requests for a given number of procs
-content = "#"
-for stacked_metric in stacked_metrics:
-   content += stacked_metric
-   content += ' ' + ' ' * (15 - len(stacked_metric))
-content += "\n"
-for app in apps:
-   if app != apps[0]:
-      for i in range(0, len(stacked_metrics)):
-         content += "%-15f" % 0.0
-      content += "\n"
-   for i in nb_procs:
-      for stacked_metric in stacked_metrics:
-         content += "%-15f" % (float(metrics_val[app][i][stacked_metric]) / metrics_val[app][norm_factor_value]['total_stacked'])
-      content += "\n"
-
-create_file(data_stacked_name, content)
-# Calling gnuplot
-print "gnuplot", gp_stacked_name
-subprocess.call([ 'gnuplot', gp_stacked_name ])
-
-
-
-#################################################################################
-### Graph 6 : Stacked histogram with coherence cost compared to r/w cost      ###
-#################################################################################
-
-# The following section creates pairs of stacked histograms, normalized w.r.t. the first one.
-# The first one contains the cost of reads and writes, the second contains the cost
-# of m_inv, m_up and broadcasts (extrapolated)
-
-data_cost_filename = os.path.join(scripts_path, gen_dir, 'relative_cost.dat')
-gp_cost_filename   = os.path.join(scripts_path, gen_dir, 'relative_cost.gp')
-
-direct_cost_metrics = [ 'read_cost', 'write_cost' ]
-coherence_cost_metrics = ['update_cost', 'm_inv_cost', 'broadcast_cost' ]
-
-# Creating the gp file
-template_file = open(stacked_tmpl, 'r')
-template = template_file.read()
-
-xtics_str = "("
-first = True
-xpos = 1.5
-app_labels = ""
+prot_labels = ""
 for num_appli in range(0, len(apps)):
    first_proc = True
    for i in nb_procs:
       if i > 4:
+         x = 0 # local var for computing position of protocol names
+         for prot in joint_protocols:
+            prot_labels += "set label \"%s\" at first %f, character 2 center font \"Times,10\"\n" % (m_prot_name[prot], float((xpos - 0.5)) + x) # -0.5 instead of +0.5, don't know why... (bug gnuplot?)
+            x += 2
+
          if not first:
             xtics_str += ", "
@@ -469,9 +639,9 @@
             first_proc = False
             xpos_first = xpos
-         xtics_str += "\"%d\" %f -1" % (i, xpos)
+         xtics_str += "\"%d\" %f -1" % (i, float(xpos - 0.5 + len(joint_protocols)))
          xpos_last = xpos
-         xpos += 3
+         xpos += 1 + len(joint_protocols) * 2
    app_name_xpos = float((xpos_first + xpos_last)) / 2
-   app_labels += "set label \"%s\" at first %f,character 1 center font\"Times,12\"\n" % (m_app_name[apps[num_appli]], app_name_xpos)
+   app_labels += "set label \"%s\" at first %f,character 1 center font \"Times,12\"\n" % (m_app_name[apps[num_appli]], app_name_xpos)
    xpos += 1
 xtics_str += ")"
@@ -483,6 +653,6 @@
    n += 1
 
-ylabel_str = "Coherence Cost Compared to Direct Requests Cost,\\nNormalized per Application for each Number of Processors"
-content = template % dict(svg_name = os.path.join(graph_dir, 'rel_cost'), xtics_str = xtics_str, plot_str = plot_str, ylabel_str = ylabel_str, app_labels = app_labels)
+ylabel_str = "Coherence Cost and Direct Requests Cost,\\nNormalized per Application for each Number of Processors"
+content = template % dict(svg_name = os.path.join(graph_dir, 'joint_rel_cost'), xtics_str = xtics_str, plot_str = plot_str, ylabel_str = ylabel_str, app_labels = app_labels, prot_labels = prot_labels)
 
 create_file(gp_cost_filename, content)
@@ -500,22 +670,24 @@
 for app in apps:
    if app != apps[0]:
-      for i in range(0, len(direct_cost_metrics) + len(coherence_cost_metrics)):
+      for j in range(0, len(direct_cost_metrics) + len(coherence_cost_metrics)):
          content += "%-15f" % 0.0
       content += "\n"
    for i in nb_procs:
       if i > 4:
-         for cost_metric in direct_cost_metrics:
-            content += "%-15f" % (float(metrics_val[app][i][cost_metric]) / metrics_val[app][i]['direct_cost'])
-         for cost_metric in coherence_cost_metrics:
-            content += "%-15f" % 0.0
-         content += "\n"
-         for cost_metric in direct_cost_metrics:
-            content += "%-15f" % 0.0
-         for cost_metric in coherence_cost_metrics:
-            content += "%-15f" % (float(metrics_val[app][i][cost_metric]) / metrics_val[app][i]['direct_cost'])
-         content += "\n"
-         for i in range(0, len(direct_cost_metrics) + len(coherence_cost_metrics)):
-            content += "%-15f" % 0.0
-         content += "\n"
+         for prot in joint_protocols:
+            for cost_metric in direct_cost_metrics:
+               content += "%-15f" % (float(metrics_val[prot][app][i][cost_metric]) / metrics_val[joint_protocols[0]][app][i]['direct_cost'])
+            for cost_metric in coherence_cost_metrics:
+               content += "%-15f" % 0.0
+            content += "\n"
+            for cost_metric in direct_cost_metrics:
+               content += "%-15f" % 0.0
+            for cost_metric in coherence_cost_metrics:
+               content += "%-15f" % (float(metrics_val[prot][app][i][cost_metric]) / metrics_val[joint_protocols[0]][app][i]['direct_cost'])
+            content += "\n"
+         if i != nb_procs[-1]:
+            for j in range(0, len(direct_cost_metrics) + len(coherence_cost_metrics)):
+               content += "%-15f" % 0.0
+            content += "\n"
 
 create_file(data_cost_filename, content)
@@ -525,2 +697,5 @@
 
 
+
+
+
Index: trunk/platforms/tsar_generic_xbar/scripts/run_simus.py
===================================================================
--- trunk/platforms/tsar_generic_xbar/scripts/run_simus.py	(revision 752)
+++ trunk/platforms/tsar_generic_xbar/scripts/run_simus.py	(revision 779)
@@ -6,30 +6,61 @@
 import shutil
 
-#TODO: recopier les fichiers d'entrees dans le script en fonction de l'appli selectionnee
+#TODO (?): recopier les fichiers d'entrees dans le script en fonction de l'appli selectionnee
 # Par exemple, tk14.O pour LU, img.raw pour ep_filter, etc.
 
-data_dir = 'data'
-log_init_name = 'log_init_'
-log_term_name = 'log_term_'
-
-
+
+# User parameters
 nb_procs = [ 4 ]
 #nb_procs = [ 16, 32, 64, 128, 256 ]
-rerun_stats = True
+rerun_stats = False
 use_omp = False
+protocol = 'rwt'
 
 #apps = [ 'histogram', 'mandel', 'filter', 'radix_ga', 'fft_ga', 'kmeans' ]
 #apps = [ 'histogram', 'mandel', 'filter', 'radix_ga', 'fft_ga' ]
-
+apps = [ 'radix' ]
+
+
+# Variables which could be changed but ought not to because they are reflected in the create_graphs.py script
+data_dir = 'data'
+log_init_name = protocol + '_stdo_'
+log_term_name = protocol + '_term_'
+
+# Global Variables
 
 all_apps = [ 'cholesky', 'fft', 'fft_ga', 'filter', 'filt_ga', 'histogram', 'kmeans', 'lu', 'mandel', 'mat_mult', 'pca', 'radix', 'radix_ga', 'showimg', ]
 # to come: 'barnes', 'fmm', 'ocean', 'raytrace', 'radiosity', 'waters', 'watern'
 
-apps = [ 'cholesky' ]
-
-
+all_protocols = [ 'dhccp', 'rwt', 'mesi' ]
+
+top_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..")
 config_name = os.path.join(os.path.dirname(os.path.realpath(__file__)), "config.py")
+
+scripts_path       = os.path.join(top_path, 'scripts')
+almos_path         = os.path.join(top_path, 'almos')
+soclib_conf_name   = os.path.join(top_path, "soclib.conf")
+topcell_name       = os.path.join(top_path, "top.cpp")
+arch_info_name     = os.path.join(almos_path, "arch-info-gen.info")
+arch_info_bib_name = os.path.join(almos_path, 'arch-info.bib')
+hdd_img_file_name  = os.path.join(almos_path, "hdd-img.bin")
+shrc_file_name     = os.path.join(almos_path, "shrc")
+hard_config_name   = os.path.join(almos_path, "hard_config.h")
+
+
+# Checks
+if protocol not in all_protocols:
+    help_str = '''
+*** Error: variable protocol has an unsupported value
+'''
+    print help_str
+    sys.exit()
+
+for the_app in apps:
+    if the_app not in all_apps:
+        print "*** Error: application %s is not defined" % (the_app)
+        sys.exit()
+
 if not os.path.isfile(config_name):
-   help_str = '''
+    help_str = '''
 You should create a file named config.py in this directory with the following definitions:
  - apps_dir:      path to almos-tsar-mipsel/apps directory
@@ -38,20 +69,36 @@
 *** Stopping execution
 '''
-   print help_str
-   sys.exit()
-
+    print help_str
+    sys.exit()
+
+# Loading config
 exec(file(config_name))
 
-top_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..")
-
-scripts_path       = os.path.join(top_path, 'scripts')
-almos_path         = os.path.join(top_path, 'almos')
-arch_info_name     = os.path.join(almos_path, "arch-info-gen.info")
-arch_info_bib_name = os.path.join(almos_path, 'arch-info.bib')
-hdd_img_file_name  = os.path.join(almos_path, "hdd-img.bin")
-shrc_file_name     = os.path.join(almos_path, "shrc")
-hard_config_name   = os.path.join(almos_path, "hard_config.h")
-
-topcell_name = "top.cpp"
+# Check that variables and paths exist
+for var in [ 'apps_dir', 'almos_src_dir', 'hdd_img_name', 'tsar_dir' ]:
+    if eval(var) == "":
+        print "*** Error: variable %s not defined in config file" % (var)
+        sys.exit()
+    if not os.path.exists(eval(var)):
+        print "*** Error: variable %s does not define a valid path" % (var)
+        sys.exit()
+
+if protocol == "rwt":
+    if rwt_dir == "":
+        print "*** Error: variable rwt_dir not defined in config file"
+        sys.exit()
+    if not os.path.exists(rwt_dir):
+        print "*** Error: variable rwt_dir does not define a valid path"
+        sys.exit()
+
+if protocol == "mesi":
+    if mesi_dir == "":
+        print "*** Error: variable mesi_dir not defined in config file"
+        sys.exit()
+    if not os.path.exists(mesi_dir):
+        print "*** Error: variable mesi_dir does not define a valid path"
+        sys.exit()
+
+
 
 
@@ -65,27 +112,79 @@
 #splash_app_dir['watern'] = 'apps/water-nsquared'
 #splash_app_dir['waters'] = 'apps/water-spatial'
-#
-#splash_app_dir['cholesky'] = 'kernels/cholesky'
-#splash_app_dir['fft'] = 'kernels/fft'
-#splash_app_dir['lu'] = 'kernels/lu/contiguous_blocks'
-#splash_app_dir['radix'] = 'kernels/radix'
-#
-#splash_ga_app_dir = {}
-#splash_ga_app_dir['radix_ga'] = 'apps/radix'
-#splash_ga_app_dir['fft_ga'] = 'apps/fft'
 
 
 def get_x_y(nb_procs):
-   x = 1
-   y = 1
-   to_x = True
-   while (x * y * 4 < nb_procs):
-      if to_x:
-         x = x * 2
-      else:
-         y = y * 2
-      to_x = not to_x
-   return x, y
-
+    x = 1
+    y = 1
+    to_x = True
+    while (x * y * 4 < nb_procs):
+        if to_x:
+            x = x * 2
+        else:
+            y = y * 2
+        to_x = not to_x
+    return x, y
+
+
+def gen_soclib_conf():
+
+    if os.path.isfile(soclib_conf_name):
+        print "Updating file %s" % (soclib_conf_name)
+        # First, remove lines containing "addDescPath"
+        f = open(soclib_conf_name, "r")
+        lines = f.readlines()
+        f.close()
+
+        f = open(soclib_conf_name, "w")
+
+        for line in lines:
+            if not ("addDescPath" in line):
+                f.write(line)
+        f.close()
+    else:
+        print "Creating file %s" % (soclib_conf_name)
+        f = open(soclib_conf_name, "w")
+        f.close()
+
+    # Defining common and specific modules 
+    common_modules = [
+            'lib/generic_llsc_global_table',
+            'modules/dspin_router_tsar', 
+            'modules/sdmmc',
+            'modules/vci_block_device_tsar',
+            'modules/vci_ethernet_tsar',
+            'modules/vci_io_bridge',
+            'modules/vci_iox_network',
+            'modules/vci_spi'
+            'platforms/tsar_generic_xbar/tsar_xbar_cluster'
+    ]
+
+    specific_modules = [
+            'communication',
+            'lib/generic_cache_tsar',
+            'modules/vci_cc_vcache_wrapper',
+            'modules/vci_mem_cache'
+    ]
+
+    f = open(soclib_conf_name, "a")
+    # Adding common modules
+    for common_module in common_modules:
+        f.write("config.addDescPath(\"%s/%s\")\n" % (tsar_dir, common_module))
+    #f.write("\n")
+
+    if protocol == "dhccp":
+        arch_dir = tsar_dir
+    elif protocol == "rwt":
+        arch_dir = rwt_dir
+    elif protocol == "mesi":
+        archi_dir = mesi_dir
+    else:
+        assert(False)
+
+    for specific_module in specific_modules:
+        f.write("config.addDescPath(\"%s/%s\")\n" % (arch_dir, specific_module))
+
+    #f.write("\n")
+    f.close()
 
 
@@ -97,20 +196,20 @@
 #define _HD_CONFIG_H
 
-#define	 X_SIZE              %(x)d
-#define	 Y_SIZE              %(y)d
-#define	 NB_CLUSTERS         %(nb_clus)d
-#define	 NB_PROCS_MAX        4
-#define	 NB_TASKS_MAX        8
-
-#define	 NB_TIM_CHANNELS     32
-#define	 NB_DMA_CHANNELS     1
-
-#define	 NB_TTY_CHANNELS     4
-#define	 NB_IOC_CHANNELS     1
-#define	 NB_NIC_CHANNELS     0
-#define	 NB_CMA_CHANNELS     0
-
-#define	 USE_XICU            1
-#define	 IOMMU_ACTIVE        0
+#define X_SIZE              %(x)d
+#define Y_SIZE              %(y)d
+#define NB_CLUSTERS         %(nb_clus)d
+#define NB_PROCS_MAX        4
+#define NB_TASKS_MAX        8
+
+#define NB_TIM_CHANNELS     32
+#define NB_DMA_CHANNELS     1
+
+#define NB_TTY_CHANNELS     4
+#define NB_IOC_CHANNELS     1
+#define NB_NIC_CHANNELS     0
+#define NB_CMA_CHANNELS     0
+
+#define USE_XICU            1
+#define IOMMU_ACTIVE        0
 
 #define   IRQ_PER_PROCESSOR   1
@@ -194,11 +293,4 @@
    #   subprocess.call([ 'make' ])
 
-   #elif app_name in splash2_ga:
-   #   print "make clean"
-   #   subprocess.call([ 'make', 'clean' ])
-
-   #   print "make"
-   #   subprocess.call([ 'make' ])
-
    #else:
    #   print "make clean"
@@ -212,5 +304,7 @@
  
    print "make TARGET=tsar"
-   subprocess.call([ 'make', 'TARGET=tsar' ])
+   retval = subprocess.call([ 'make', 'TARGET=tsar' ])
+   if retval != 0:
+       sys.exit()
    
    # Creation/Modification du shrc de almos
@@ -281,4 +375,5 @@
 
 gen_sym_links()
+gen_soclib_conf()
 
 for i in nb_procs:
@@ -293,6 +388,8 @@
    subprocess.call([ 'touch', topcell_name ])
    print "make"
-   subprocess.call([ 'make' ])
-   
+   retval = subprocess.call([ 'make' ])
+   if retval != 0:
+       sys.exit()
+
    for app in apps:
       print "cd", top_path
Index: trunk/platforms/tsar_generic_xbar/scripts/templates/metric_template.gp
===================================================================
--- trunk/platforms/tsar_generic_xbar/scripts/templates/metric_template.gp	(revision 752)
+++ trunk/platforms/tsar_generic_xbar/scripts/templates/metric_template.gp	(revision 779)
@@ -14,5 +14,5 @@
 %(app_labels)s
 
-set xrange [0:%(xmax_val)d]
+set xrange [0:%(xmax_val)f]
 
 #set mytics 0.1
Index: trunk/platforms/tsar_generic_xbar/scripts/templates/stacked_template.gp
===================================================================
--- trunk/platforms/tsar_generic_xbar/scripts/templates/stacked_template.gp	(revision 752)
+++ trunk/platforms/tsar_generic_xbar/scripts/templates/stacked_template.gp	(revision 779)
@@ -33,4 +33,5 @@
 
 %(app_labels)s
+%(prot_labels)s
 
 plot %(plot_str)s
