Index: trunk/platforms/tsar_generic_xbar/scripts/counter_defs.py
===================================================================
--- trunk/platforms/tsar_generic_xbar/scripts/counter_defs.py	(revision 836)
+++ trunk/platforms/tsar_generic_xbar/scripts/counter_defs.py	(revision 1012)
@@ -10,13 +10,20 @@
 m_prot_name['rwt'] = "RWT"
 m_prot_name['hmesi'] = "HMESI"
+m_prot_name['wtidl'] = "WT IDEAL"
 
 m_app_name = {}
 m_app_name['mandel'] = "Mandelbrot"
-m_app_name['filter'] = "Filter"
-m_app_name['filt_ga'] = "Filter (opt.)"
+m_app_name['filter'] = "Convol"
+m_app_name['filt_ga'] = "Convol"
 m_app_name['histogram'] = "Histogram"
+m_app_name['histogram-pad'] = "Histogram"
+m_app_name['histo-opt'] = "Histogram"
+m_app_name['histo-opt-nopad'] = "Histogram"
 m_app_name['kmeans'] = "Kmeans"
+m_app_name['kmeans-opt'] = "Kmeans"
 m_app_name['pca'] = "PCA"
+m_app_name['pca-opt'] = "PCA"
 m_app_name['mat_mult'] = "Matrix Mult."
+m_app_name['mat_mult-opt'] = "Matrix Mult."
 m_app_name['barnes'] = "Barnes"
 m_app_name['fmm'] = "FMM"
@@ -30,6 +37,6 @@
 m_app_name['fft'] = "FFT"
 m_app_name['radix'] = "Radix"
-m_app_name['fft_ga'] = "FFT (opt.)"
-m_app_name['radix_ga'] = "Radix (opt.)"
+m_app_name['fft_ga'] = "FFT"
+m_app_name['radix_ga'] = "Radix"
 
 m_metric_id = {}
@@ -192,4 +199,5 @@
 m_metric_name['total_ncc_to_cc']     = "Total Number of NCC to CC Changes"
 m_metric_name['broadcast_cost']      = "Broadcast Cost"
+m_metric_name['coherence_cost']      = "Coherence Cost"
 m_metric_name['direct_cost']         = "Direct Requests Cost"
 m_metric_name['total_stacked']       = "??" # Normalization factor, does not have a name (unused)
@@ -228,5 +236,6 @@
 
 
-colors = [ "\"#008000\"", "\"#000080\"", "\"#BADC98\"", "\"#BA98DC\"", "\"#98DCBA\"", "\"#98BADC\"", "\"#BA9876\"", "\"#BA7698\"", "\"#98BA76\"", "\"#9876BA\"", "\"#76BA98\"", "\"#7698BA\"" ]
-
-
+#colors = [ "\"#008000\"", "\"#000080\"", "\"#BADC98\"", "\"#BA98DC\"", "\"#98DCBA\"", "\"#98BADC\"", "\"#BA9876\"", "\"#BA7698\"", "\"#98BA76\"", "\"#9876BA\"", "\"#76BA98\"", "\"#7698BA\"" ]
+colors = [ "\"#008000\"", "\"#FEDCBA\"", "\"#BADC98\"", "\"#000080\"", "\"#98DCBA\"", "\"#98BADC\"", "\"#BA9876\"", "\"#BA7698\"", "\"#98BA76\"", "\"#9876BA\"", "\"#76BA98\"", "\"#7698BA\"" ]
+
+
Index: trunk/platforms/tsar_generic_xbar/scripts/create_graphs.py
===================================================================
--- trunk/platforms/tsar_generic_xbar/scripts/create_graphs.py	(revision 836)
+++ trunk/platforms/tsar_generic_xbar/scripts/create_graphs.py	(revision 1012)
@@ -7,10 +7,12 @@
 
 
-apps = [ 'filter', 'lu', 'fft_ga' ]
+#apps = [ 'histo-opt', 'mandel', 'filt_ga', 'radix_ga', 'fft_ga', 'pca-opt', 'fft', 'radix', 'filter', 'kmeans-opt' ]
+apps = [ 'fft_ga', 'filt_ga', 'lu', 'radix_ga', 'histo-opt', 'mandel', 'pca-opt', 'kmeans-opt' ]
 #apps = [ 'histogram', 'mandel', 'filter', 'fft', 'fft_ga', 'filt_ga', 'pca', 'lu' ]  # radix radix_ga kmeans
-#apps = [ 'filt_ga' ]
-nb_procs = [ 1, 4, 8, 16, 32, 64 ]
-single_protocols = ['dhccp', 'rwt' ]
-joint_protocols = ['dhccp', 'rwt' ]
+#apps = [ 'histo-opt', 'histogram2', 'histo-opt2' ]
+#nb_procs = [ 1, 4, 8, 16, 32, 64, 128, 256 ]
+nb_procs = [ 1, 4, 8, 16, 32, 64, 128, 256 ]
+single_protocols = ['dhccp', 'hmesi']
+joint_protocols = ['dhccp', 'hmesi']
 #joint_protocols = []
 
@@ -75,5 +77,5 @@
 exec_time = {}
 metrics_val = {}
-for prot in single_protocols:
+for prot in joint_protocols:
    metrics_val[prot] = {}
    exec_time[prot] = {}
@@ -111,5 +113,5 @@
     
 # Completing unset metrics (i.e. they are not present in the data file) with 0
-for prot in single_protocols:
+for prot in joint_protocols:
    for app in apps:
       for i in nb_procs:
@@ -119,5 +121,5 @@
 
 # We make a 2nd pass to fill the derived fields, e.g. nb_total_updates
-for prot in single_protocols:
+for prot in joint_protocols:
    for app in apps:
       for i in nb_procs:
@@ -137,5 +139,6 @@
          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)
+         metrics_val[prot][app][i]['broadcast_cost']  = metrics_val[prot][app][i]['broadcast'] * 2 * (x * y - 1)
+         metrics_val[prot][app][i]['coherence_cost']  = metrics_val[prot][app][i]['broadcast_cost']  + metrics_val[prot][app][i]['m_inv_cost'] + metrics_val[prot][app][i]['update_cost']
          if metrics_val[prot][app][i]['broadcast'] < metrics_val[prot][app][i]['write_broadcast']:
             # test to patch a bug in mem_cache
@@ -414,9 +417,9 @@
    app_labels = ""
    for num_appli in range(0, len(apps)):
-      for i in nb_procs:
+      for i in nb_procs[1:len(nb_procs)]: # skipping values for 1 proc
          if not first:
             xtics_str += ", "
          first = False
-         if i == nb_procs[0]:
+         if i == nb_procs[1]:
             xpos_first = xpos
          xtics_str += "\"%d\" %d -1" % (i, xpos)
@@ -451,7 +454,11 @@
             content += "%-15f" % 0.0
          content += "\n"
-      for i in nb_procs:
+      for i in nb_procs[1:len(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'])
+            metric_val = metrics_val[prot][app][norm_factor_value]['total_stacked'] # Normalisation
+            if metric_val != 0:
+               content += "%-15f" % (float(metrics_val[prot][app][i][stacked_metric]) / metric_val)
+            else:
+               content += "%-15f" % 0
          content += "\n"
    
@@ -476,5 +483,6 @@
    
    direct_cost_metrics = [ 'read_cost', 'write_cost' ]
-   coherence_cost_metrics = ['update_cost', 'm_inv_cost', 'broadcast_cost' ]
+   #coherence_cost_metrics = ['update_cost', 'm_inv_cost', 'broadcast_cost' ]
+   coherence_cost_metrics = ['coherence_cost']
    
    # Creating the gp file
@@ -533,5 +541,9 @@
          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'])
+               if metrics_val[prot][app][i]['direct_cost'] == 0:
+                  print "Error: prot : ", prot, " - app : ", app, " - i : ", i
+                  content += "%-15f" % 0
+               else:
+                  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
@@ -540,5 +552,9 @@
                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'])
+               if metrics_val[prot][app][i]['direct_cost'] == 0:
+                  print "Error: prot : ", prot, " - app : ", app, " - i : ", i
+                  content += "%-15f" % 0
+               else:
+                  content += "%-15f" % (float(metrics_val[prot][app][i][cost_metric]) / metrics_val[prot][app][i]['direct_cost'])
             content += "\n"
             if i != nb_procs[-1]:
@@ -680,4 +696,6 @@
       if i > 4:
          for prot in joint_protocols:
+            if metrics_val[joint_protocols[0]][app][i]['direct_cost'] == 0:
+               continue
             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'])
Index: trunk/platforms/tsar_generic_xbar/scripts/gen_arch_info.py
===================================================================
--- trunk/platforms/tsar_generic_xbar/scripts/gen_arch_info.py	(revision 1012)
+++ trunk/platforms/tsar_generic_xbar/scripts/gen_arch_info.py	(revision 1012)
@@ -0,0 +1,192 @@
+#--------------------------------------------------------------------
+# File      : gen_arch_info_large.sh
+#--------------------------------------------------------------------
+
+import getpass
+import socket
+import time
+import sys
+
+X_MAX = 0
+Y_MAX = 0
+CPU_PER_CLUSTER = 0
+BSCPU = 0
+BSTTY = 0
+BSDMA = 0
+MEMC_SIZE = 0
+P_WDITH = 4
+NB_TTY = 4
+TTY_CHANNEL_SIZE = 0X00000010
+TTY_SIZE = 0X00001000
+OUTPUT_IRQ_PER_PROC = 4
+DMA_SIZE = 0X00001000
+XCU_SIZE = 0X00001000
+BDV_SIZE = 0X00001000
+FBF_SIZE = 0X00200000
+
+MEMC_TGTID = 0
+XICU_TGTID = 1
+MDMA_TGTID = 2
+MTTY_TGTID = 3
+BDEV_TGTID = 4
+MNIC_TGTID = 5
+BROM_TGTID = 6
+CDMA_TGTID = 7
+SIMH_TGTID = 8
+FBUF_TGTID = 9
+
+
+# PHYSICAL ADDRESS WIDTH
+ADDR_WIDTH = 32
+
+# DEFAULT VALUES
+DEFAULT_X_MAX = 8
+DEFAULT_Y_MAX = 8
+DEFAULT_CPU_PER_CLUSTER = 4
+CLUSTER_INC = 0
+
+def print_comments(cmd):
+        print "# TSAR hardware description in BIB (Boot Information Block) format"
+        print "# This file is autogenerated by the command: " + cmd +  " %d %d %d %d" % (X_MAX, Y_MAX, CPU_PER_CLUSTER, BSCPU)
+        print "# It is ready to be passed to info2bib utility so the binary format can be generated"
+        print " "
+        print "# " + getpass.getuser() + " on " + socket.gethostname() + " " + time.strftime("%H:%M:%S")
+        print " "
+        print " "
+        
+def print_header():
+        print "[HEADER]"
+        print "        REVISION=1"
+        print "        ARCH=SOCLIB-TSAR"
+        print "        XMAX=%d" % X_MAX 
+        print "        YMAX=%d" % Y_MAX
+        print "        BSCPU=%d" % BSCPU
+        print "        BSTTY=0x%x" % BSTTY
+        print "        BSDMA=0x%x" % BSDMA
+        print " "
+        print " "
+
+def print_cluster(offset, cid):
+        mem_base = offset
+        mem_size = MEMC_SIZE
+        xcu_base = (offset + (CLUSTER_INC / 2) + (XICU_TGTID << 19))
+        dma_base = (offset + (CLUSTER_INC / 2) + (MDMA_TGTID << 19))
+        print "[CLUSTER]"
+        cpu_num=0;
+        while (cpu_num != CPU_PER_CLUSTER):
+                gid = (cid << CPU_PER_CLUSTER) + cpu_num
+                print "        [CPU]    ID=%d OUTIRQ=%d" % (gid, (cpu_num * OUTPUT_IRQ_PER_PROC)) 
+                cpu_num = cpu_num + 1
+        
+        print "        [DEV]    ID=RAM       BASE=%#.8x    SIZE=%#.8x    IRQ=-1    IRQTYPE=NONE" % (mem_base, mem_size)
+        print "        [DEV]    ID=XICU      BASE=%#.8x    SIZE=%#.8x    IRQ=-1    IRQTYPE=NONE" % (xcu_base, DMA_SIZE)
+        print "        [DEV]    ID=DMA       BASE=%#.8x    SIZE=%#.8x    IRQ=8     IRQTYPE=HWI"  % (dma_base, XCU_SIZE)
+        print " "
+        print " "
+
+def print_io_cluster(offset, cid):
+        mem_base = offset
+        mem_size = MEMC_SIZE
+        xcu_base = (offset + (CLUSTER_INC / 2) + (XICU_TGTID << 19))
+        dma_base = (offset + (CLUSTER_INC / 2) + (MDMA_TGTID << 19))
+        bdv_base = (offset + (CLUSTER_INC / 2) + (BDEV_TGTID << 19))
+        tty_base = (offset + (CLUSTER_INC / 2) + (MTTY_TGTID << 19))
+        fbf_base = (offset + (CLUSTER_INC / 2) + (FBUF_TGTID << 19))
+        
+        print "[CLUSTER]"
+        cpu_num = 0
+        while (cpu_num != CPU_PER_CLUSTER):
+                gid = (cid << CPU_PER_CLUSTER) + cpu_num
+                print "        [CPU]    ID=%d OUTIRQ=%d" % (gid, (cpu_num * OUTPUT_IRQ_PER_PROC)) 
+                cpu_num = cpu_num + 1
+        
+        print "        [DEV]    ID=RAM       BASE=%#.8x    SIZE=%#.8x    IRQ=-1    IRQTYPE=NONE" % (mem_base, mem_size)
+        print "        [DEV]    ID=XICU      BASE=%#.8x    SIZE=%#.8x    IRQ=-1    IRQTYPE=NONE" % (xcu_base, XCU_SIZE)
+        print "        [DEV]    ID=DMA       BASE=%#.8x    SIZE=%#.8x    IRQ=8     IRQTYPE=HWI"  % (dma_base, DMA_SIZE)
+        print "        [DEV]    ID=BLKDEV    BASE=%#.8x    SIZE=%#.8x    IRQ=31    IRQTYPE=HWI"  % (bdv_base, BDV_SIZE)
+        ntty = 0
+        irq = 16
+        while (ntty < NB_TTY):
+                tty_base_i = tty_base + ntty * TTY_CHANNEL_SIZE
+                print "        [DEV]    ID=TTY       BASE=%#.8x    SIZE=%#.8x    IRQ=%d    IRQTYPE=HWI" % (tty_base_i, TTY_CHANNEL_SIZE, irq)
+                irq = irq + 1
+                ntty = ntty + 1
+        print "        [DEV]    ID=FB        BASE=%#.8x    SIZE=%#.8x    IRQ=-1    IRQTYPE=NONE" % (fbf_base, FBF_SIZE)
+        print " "
+        print " "
+
+def gen_arch_info(x, y, x_width, y_width, bscpu, arch_info_name):
+        fp = open(arch_info_name, 'w')
+        stdout = sys.stdout
+        sys.stdout = fp
+        global X_MAX
+        global Y_MAX
+        global CPU_PER_CLUSTER
+        global CLUSTER_INC
+        global MEMC_SIZE
+        global BSCPU
+        global BSDMA
+        global BSTTY
+        
+        #------------------------
+        
+        X_MAX = x
+        Y_MAX = y
+        cpu_per_cluster = DEFAULT_CPU_PER_CLUSTER
+        CPU_PER_CLUSTER = cpu_per_cluster
+        
+        #------------------------
+        CLUSTER_INC = (0x80000000 >> (x_width + y_width)) * 2
+        max_memc_size = 0x40000000 / (X_MAX * Y_MAX)
+        size = min(max_memc_size, 0x10000000)
+        MEMC_SIZE = size
+
+        ##########################################################################################
+        #we force io_cid to 0 because this is the only cluster we know which will be present 
+        #in all platform where the number of clusters is independant of x_width and y_width values
+        io_cid = 0 
+        ##########################################################################################
+
+        BSCPU = bscpu
+        
+        break_loop = 0
+        xi = 0
+        yi = 0
+        while (xi < X_MAX):
+                while (yi < Y_MAX):
+                        cid = xi * (1 << y_width) + yi
+                        offset = cid << (ADDR_WIDTH - x_width - y_width)
+                        if cid == io_cid:
+                                BSDMA = offset + (CLUSTER_INC / 2) + (MDMA_TGTID << 19)
+                                BSTTY = offset + (CLUSTER_INC / 2) + (MTTY_TGTID << 19)
+                                break_loop = 1
+                                break
+                        else:
+                                bsdma="error"
+                        yi = yi + 1
+
+                if break_loop == 1:
+                        break
+                yi = 0
+                xi = xi + 1
+        
+        # Generate the description
+        print_comments(sys.argv[0])
+        print_header()
+        
+        xi = 0
+        yi = 0
+        while (xi < X_MAX):
+                while (yi < Y_MAX):
+                        cid = xi * (1 << y_width) + yi
+                        offset = cid  << (ADDR_WIDTH - (x_width + y_width))
+                        if cid == io_cid:
+                                print_io_cluster(offset, cid)
+                        else:
+                                print_cluster(offset, cid)
+                        yi = yi + 1
+                yi = 0
+                xi = xi + 1
+        sys.stdout = stdout
+        fp.close()
+
Index: trunk/platforms/tsar_generic_xbar/scripts/gen_arch_info_large.sh
===================================================================
--- trunk/platforms/tsar_generic_xbar/scripts/gen_arch_info_large.sh	(revision 836)
+++ 	(revision )
@@ -1,236 +1,0 @@
-#! /bin/bash
-
-#--------------------------------------------------------------------
-# File      : gen_arch_info_large.sh
-#--------------------------------------------------------------------
-
-NB_TTY=4
-TTY_CHANNEL_SIZE=0x10
-TTY_SIZE=0x1000
-
-DMA_SIZE=0x1000
-XICU_SIZE=0x1000
-BDEV_SIZE=0x1000
-# FrameBuffer size
-#FB_SIZE=0x80000
-FB_SIZE=0x200000
-
-MEMC_TGTID=0
-XICU_TGTID=1
-MDMA_TGTID=2
-MTTY_TGTID=3
-BDEV_TGTID=4
-MNIC_TGTID=5
-BROM_TGTID=6
-CDMA_TGTID=7
-SIMH_TGTID=8
-FBUF_TGTID=9
-
-
-# Physical address width
-ADDR_WIDTH=32
-
-# Default values
-DEFAULT_X_MAX=8
-DEFAULT_Y_MAX=8
-DEFAULT_CPU_PER_CLUSTER=4
-
-function mymin()
-{
-   if test $1 -lt $2 ; then
-      echo "$1"
-   else
-      echo "$2"
-   fi
-}
-
-#------------------------
-
-X_MAX=${1-$DEFAULT_X_MAX}
-Y_MAX=${2-$DEFAULT_Y_MAX}
-NPROCS=$DEFAULT_CPU_PER_CLUSTER
-
-#------------------------
-CLUSTER_INC=$((0x80000000 / (X_MAX * Y_MAX) * 2))
-MAX_MEMC_SIZE=$((0x40000000 / (X_MAX * Y_MAX)))
-size=$(mymin $MAX_MEMC_SIZE $((0x04000000)))
-MEMC_SIZE=$(printf "0x%X" $size)
-
-
-print_comments()
-{
-    date=$(date "+%c")
-    echo "# TSAR hardware description in BIB (Boot Information Block) format"
-    echo "# This file is autogenerated by the command: $0 $X_MAX $Y_MAX $NPROCS $BSCPU"
-    echo "# It is ready to be passed to info2bib utility so the binary format can be generated"
-    echo " "
-    echo "# $USER on $HOSTNAME $date" 
-    echo " "
-    echo " "
-}
-
-print_header()
-{
-    echo "[HEADER]"
-    echo "        REVISION=1"
-    echo "        ARCH=SOCLIB-TSAR"
-    echo "        XMAX=$X_MAX"
-    echo "        YMAX=$Y_MAX"
-    echo "        CPU_NR=$NPROCS"
-    echo "        BSCPU=$BSCPU"
-    echo "        BSTTY=$BSTTY"
-    echo "        BSDMA=$BSDMA"
-    echo " "
-    echo " "
-}
-
-print_cluster()
-{
-    offset=$1
-    cid=$2
-    memc_base=$(printf "0x%X" $offset)
-    memc_size=$(printf "0x%X" $MEMC_SIZE)
-    xicu_base=$(printf "0x%X" $((offset + (CLUSTER_INC / 2) + (XICU_TGTID << 19))))
-    dma_base=$(printf "0x%X" $((offset  + (CLUSTER_INC / 2) + (MDMA_TGTID << 19))))
-    
-    echo "[CLUSTER]"
-    echo "         CID="$cid
-    echo "         CPU_NR="$NPROCS
-    echo "         DEV_NR=3"
-    echo "         DEVID=RAM       BASE=$memc_base         SIZE=$memc_size     IRQ=-1"
-    echo "         DEVID=XICU      BASE=$xicu_base         SIZE=$DMA_SIZE         IRQ=-1"
-    echo "         DEVID=DMA       BASE=$dma_base         SIZE=$XICU_SIZE         IRQ=8"
-    echo " "
-    echo " "
-}
-
-print_io_cluster()
-{
-    offset=$1
-    cid=$2
-    memc_base=$(printf "0x%X" $offset)
-    memc_size=$(printf "0x%X" $MEMC_SIZE)
-    xicu_base=$(printf "0x%X" $((offset + (CLUSTER_INC / 2) + (XICU_TGTID << 19))))
-    dma_base=$(printf "0x%X" $((offset  + (CLUSTER_INC / 2) + (MDMA_TGTID << 19))))
-    bdev_base=$(printf "0x%X" $((offset + (CLUSTER_INC / 2) + (BDEV_TGTID << 19))))
-    tty_base=$(printf "0x%X" $((offset  + (CLUSTER_INC / 2) + (MTTY_TGTID << 19))))
-    fbf_base=$(printf "0x%X" $((offset  + (CLUSTER_INC / 2) + (FBUF_TGTID << 19))))
-
-    echo "[CLUSTER]"
-    echo "         CID="$cid
-    echo "         CPU_NR="$NPROCS
-    echo "         DEV_NR=9"
-    echo "         DEVID=RAM       BASE=$memc_base         SIZE=$memc_size     IRQ=-1"
-    echo "         DEVID=XICU      BASE=$xicu_base         SIZE=$XICU_SIZE         IRQ=-1"
-    echo "         DEVID=DMA       BASE=$dma_base         SIZE=$DMA_SIZE         IRQ=8"
-    echo "         DEVID=BLKDEV    BASE=$bdev_base         SIZE=$BDEV_SIZE         IRQ=31"
-    ntty=0
-    irq=16
-    while test $ntty -lt $NB_TTY
-    do
-       tty_base_i=$(printf "0x%X" $((tty_base + ntty * TTY_CHANNEL_SIZE)))
-       echo "         DEVID=TTY       BASE=$tty_base_i         SIZE=$TTY_CHANNEL_SIZE           IRQ=$irq"
-       irq=$((irq + 1))
-       ntty=$((ntty + 1))
-    done
-    echo "         DEVID=FB        BASE=$fbf_base         SIZE=$FB_SIZE        IRQ=-1"
-    echo " "
-    echo " "
-}
-
-# Derive X_WIDTH form X_MAX
-case $X_MAX in
-    1)      X_WIDTH=0
-   ;;
-
-    2)      X_WIDTH=1
-	;;
-    
-    [3-4])  X_WIDTH=2
-	;;
-
-    [5-8])  X_WIDTH=3
-	;;
-
-    *)      X_WIDTH=4
-	;;
-esac
-
-# Derive Y_WIDTH form Y_MAX
-case $Y_MAX in
-    1)      Y_WIDTH=0
-   ;;
-
-
-    2)      Y_WIDTH=1
-	;;
-    
-    [3-4])  Y_WIDTH=2
-	;;
-
-    [5-8])  Y_WIDTH=3
-	;;
-
-    *)      Y_WIDTH=4
-	;;
-esac
-
-x=0; y=0
-io_cid=$((0xbf >> (8 - X_WIDTH - Y_WIDTH)))
-BSCPU=$(($io_cid * $NPROCS))
-
-break_loop=0
-while test $x -lt $X_MAX
-do
-   while test $y -lt $Y_MAX
-   do
-      cid=$((x * Y_MAX + y))  
-      offset=$((cid  << (ADDR_WIDTH - X_WIDTH - Y_WIDTH)))
-
-      if [ $cid -eq $io_cid ]
-      then
-         BSDMA=$(printf "0x%X" $((offset  + (CLUSTER_INC / 2) + (MDMA_TGTID << 19))))
-         BSTTY=$(printf "0x%X" $((offset  + (CLUSTER_INC / 2) + (MTTY_TGTID << 19))))
-         break_loop=1
-         break
-      else
-         BSDMA="error"
-      fi
-
-      y=$((y + 1))
-   done
-   if test $break_loop -eq 1 ; then
-      break
-   fi
-   y=0
-   x=$((x + 1))
-done
-
-# Generate the description
-print_comments "$0"
-print_header
-
-x=0; y=0
-while test $x -lt $X_MAX
-do
-   while test $y -lt $Y_MAX
-   do
-      cid=$((x * Y_MAX + y))  
-      offset=$((cid  << (ADDR_WIDTH - X_WIDTH - Y_WIDTH)))
-
-      if [ $cid -eq $io_cid ]
-      then
-         print_io_cluster $offset $cid
-      else
-         print_cluster $offset $cid
-      fi
-
-      y=$((y + 1))
-   done
-   y=0
-   x=$((x + 1))
-done 
-
-#-------------------------------------------------------------------------#
-#                                End of script                            #
-#-------------------------------------------------------------------------#
Index: trunk/platforms/tsar_generic_xbar/scripts/gen_hard_config.py
===================================================================
--- trunk/platforms/tsar_generic_xbar/scripts/gen_hard_config.py	(revision 1012)
+++ trunk/platforms/tsar_generic_xbar/scripts/gen_hard_config.py	(revision 1012)
@@ -0,0 +1,233 @@
+
+
+
+def hard_config(x, y, x_width, y_width, p, hard_config, protocol):
+    
+    ram_tgtid = 0
+    xcu_tgtid = 1
+    dma_tgtid = 2
+    tty_tgtid = 3
+    ioc_tgtid = 4
+    nic_tgtid = 5
+    rom_tgtid = 6
+    cma_tgtid = 7
+    sim_tgtid = 8
+    fbf_tgtid = 9
+
+    nb_dma_channels = 1
+    nb_cma_channels = 0
+    nb_tty_channels = 4
+    nb_ioc_channels = 1
+
+    fbf_x_size = 1024
+    fbf_y_size = 1024
+
+    seg_rom_base = 0xbfc00000
+    seg_rom_size = 0x00100000
+
+    cluster_inc = 0x80000000 / (x * y) * 2
+    cluster_io_id = seg_rom_base >> (32 - x_width - y_width)
+    cluster_io_inc = cluster_io_id * cluster_inc
+    ram_max_size = 0x40000000 / (x * y) # 1 Go Max
+    
+    seg_ram_base = 0x00000000
+    seg_ram_size = min(0x10000000, ram_max_size)
+
+    seg_xcu_base = (cluster_inc >> 1) + (xcu_tgtid << 19)
+    seg_xcu_size = 0x00001000 # 4Ko
+
+    seg_dma_base = (cluster_inc >> 1) + (dma_tgtid << 19)
+    seg_dma_size = 0x00001000 * nb_dma_channels
+
+    def periph_address(tgtid):
+        return (cluster_inc >> 1) + cluster_io_inc + (tgtid << 19)
+
+    seg_ioc_base = periph_address(ioc_tgtid);
+    seg_ioc_size = 0x00001000
+
+    seg_tty_base = periph_address(tty_tgtid)
+    seg_tty_size = 0x00001000
+
+    seg_fbf_base = periph_address(fbf_tgtid)
+    seg_fbf_size = fbf_x_size * fbf_y_size * 2
+
+    seg_nic_base = periph_address(nic_tgtid)
+    seg_nic_size = 0x00080000
+
+    seg_cma_base = periph_address(cma_tgtid)
+    seg_cma_size = 0x00004000 * nb_cma_channels
+
+    seg_sim_base = periph_address(sim_tgtid)
+    seg_sim_size = 0x00001000
+
+    header = '''
+#ifndef _HARD_CONFIG_H_
+#define _HARD_CONFIG_H_
+
+/* Generated from run_simus.py */
+
+/* General platform parameters */
+
+#define X_SIZE                 %(x_size)d
+#define Y_SIZE                 %(y_size)d
+#define X_WIDTH                %(x_width)d
+#define Y_WIDTH                %(y_width)d
+#define P_WIDTH                4
+#define X_IO                   0
+#define Y_IO                   0
+#define NB_PROCS_MAX           %(proc_per_clus)d
+#define IRQ_PER_PROCESSOR      4
+#define RESET_ADDRESS          0x%(seg_rom_base)x
+
+
+/* Peripherals */
+
+#define RAM_TGTID              %(ram_tgtid)d
+#define XCU_TGTID              %(xcu_tgtid)d
+#define DMA_TGTID              %(dma_tgtid)d
+#define TTY_TGTID              %(tty_tgtid)d
+#define IOC_TGTID              %(ioc_tgtid)d
+#define NIC_TGTID              %(nic_tgtid)d
+#define ROM_TGTID              %(rom_tgtid)d
+#define CMA_TGTID              %(cma_tgtid)d
+#define SIM_TGTID              %(sim_tgtid)d
+#define FBF_TGTID              %(fbf_tgtid)d
+
+#define NB_TTY_CHANNELS        %(nb_tty_channels)d
+#define NB_IOC_CHANNELS        %(nb_ioc_channels)d
+#define NB_NIC_CHANNELS        0
+#define NB_CMA_CHANNELS        %(nb_cma_channels)d
+#define NB_TIM_CHANNELS        0
+#define NB_DMA_CHANNELS        %(nb_dma_channels)d
+
+#define USE_XCU                1
+#define USE_IOB                0
+#define USE_PIC                0
+#define USE_FBF                1
+
+#define USE_IOC_BDV            1
+#define USE_IOC_SDC            0
+#define USE_IOC_HBA            0
+#define USE_IOC_RDK            0
+
+#define FBF_X_SIZE             %(fbf_x_size)d
+#define FBF_Y_SIZE             %(fbf_y_size)d
+
+
+/* base addresses and sizes for physical segments */
+
+#define SEG_RAM_BASE           0x%(seg_ram_base)x
+#define SEG_RAM_SIZE           0x%(seg_ram_size)x
+
+#define SEG_CMA_BASE           0x0 // Component requires a multiple of 4K
+#define SEG_CMA_SIZE           0x0
+
+#define SEG_DMA_BASE           0x%(seg_dma_base)x
+#define SEG_DMA_SIZE           0x%(seg_dma_size)x
+
+#define SEG_FBF_BASE           0x%(seg_fbf_base)x
+#define SEG_FBF_SIZE           0x%(seg_fbf_size)x
+
+#define SEG_ICU_BASE           0xffffffff
+#define SEG_ICU_SIZE           0x0
+
+#define SEG_IOB_BASE           0xffffffff
+#define SEG_IOB_SIZE           0x0
+
+#define SEG_IOC_BASE           0x%(seg_ioc_base)x
+#define SEG_IOC_SIZE           0x%(seg_ioc_size)x
+
+#define SEG_MMC_BASE           0xffffffff
+#define SEG_MMC_SIZE           0x0
+
+#define SEG_MWR_BASE           0xffffffff
+#define SEG_MWR_SIZE           0x0
+
+#define SEG_ROM_BASE           0x%(seg_rom_base)x
+#define SEG_ROM_SIZE           0x%(seg_rom_size)x
+
+#define SEG_SIM_BASE           0x%(seg_sim_base)x
+#define SEG_SIM_SIZE           0x%(seg_sim_size)x
+
+#define SEG_NIC_BASE           0x%(seg_nic_base)x
+#define SEG_NIC_SIZE           0x%(seg_nic_size)x
+
+#define SEG_PIC_BASE           0xffffffff
+#define SEG_PIC_SIZE           0x0
+
+#define SEG_TIM_BASE           0xffffffff
+#define SEG_TIM_SIZE           0x0
+
+#define SEG_TTY_BASE           0x%(seg_tty_base)x
+#define SEG_TTY_SIZE           0x%(seg_tty_size)x
+
+#define SEG_XCU_BASE           0x%(seg_xcu_base)x
+#define SEG_XCU_SIZE           0x%(seg_xcu_size)x
+
+#define SEG_RDK_BASE           0xffffffff
+#define SEG_RDK_SIZE           0x0
+
+''' % dict(x_size = x, y_size = y, x_width = x_width, y_width = y_width,
+        proc_per_clus = p,
+        nb_tty_channels = nb_tty_channels,
+        nb_ioc_channels = nb_ioc_channels,
+        nb_cma_channels = nb_cma_channels,
+        nb_dma_channels = nb_dma_channels,
+        fbf_x_size = fbf_x_size, fbf_y_size = fbf_y_size,
+        ram_tgtid = ram_tgtid,
+        xcu_tgtid = xcu_tgtid,
+        dma_tgtid = dma_tgtid,
+        tty_tgtid = tty_tgtid,
+        ioc_tgtid = ioc_tgtid,
+        nic_tgtid = nic_tgtid,
+        rom_tgtid = rom_tgtid,
+        cma_tgtid = cma_tgtid,
+        sim_tgtid = sim_tgtid,
+        fbf_tgtid = fbf_tgtid,
+        seg_ram_base = seg_ram_base,
+        seg_ram_size = seg_ram_size,
+        seg_dma_base = seg_dma_base,
+        seg_dma_size = seg_dma_size,
+        seg_fbf_base = seg_fbf_base,
+        seg_fbf_size = seg_fbf_size,
+        seg_ioc_base = seg_ioc_base,
+        seg_ioc_size = seg_ioc_size,
+        seg_rom_base = seg_rom_base,
+        seg_rom_size = seg_rom_size,
+        seg_sim_base = seg_sim_base,
+        seg_sim_size = seg_sim_size,
+        seg_nic_base = seg_nic_base,
+        seg_nic_size = seg_nic_size,
+        seg_tty_base = seg_tty_base,
+        seg_tty_size = seg_tty_size,
+        seg_xcu_base = seg_xcu_base,
+        seg_xcu_size = seg_xcu_size)
+
+    if protocol == 'wtidl':
+        header += '#define WT_IDL\n'
+
+    header += '#endif //_HD_CONFIG_H\n'
+
+    file = open(hard_config, 'w')
+    file.write(header)
+    file.close()
+
+
+if __name__ == "__main__":
+    if len(sys.argv) != 6:
+        print "Usage: %s <x> <y> <p> <hard_config-filename> <protocol>" % argv[0]
+        print "with:"
+        print "<x>: number of clusters in X"
+        print "<y>: number of clusters in Y"
+        print "<p>: number of processors per clusters"
+        sys.exit(0)
+
+    x = argv[1]
+    y = argv[2]
+    p = argv[3]
+    hard_config_filename = argv[4]
+    protocol = argv[5]
+
+    hard_config(x, y, p, hard_config_filename, protocol)
+
+
Index: trunk/platforms/tsar_generic_xbar/scripts/gen_hdd.py
===================================================================
--- trunk/platforms/tsar_generic_xbar/scripts/gen_hdd.py	(revision 1012)
+++ trunk/platforms/tsar_generic_xbar/scripts/gen_hdd.py	(revision 1012)
@@ -0,0 +1,94 @@
+#!/usr/bin/python
+
+import os
+import sys
+import subprocess
+
+
+
+
+def hdd_img(partition_root, target, fs_type, bootloader_name):
+
+    # echo "Dont forget to check the numbers of sectors for each file"
+    # QM: what does that mean?
+    
+    if fs_type != "fat32" and fs_type != "ext2":
+        print "*** Error: unsupported filesystem type:", fs_type
+        sys.exit()
+    
+    if not(os.path.isdir(partition_root)):
+        print "*** Error: Partition root is not a valid directory"
+        sys.exit()
+    
+    
+    print sys.argv[0], ": Target = %s, fs type = %s, Partition root = %s" % (target, fs_type, partition_root)
+    
+    if not os.path.isfile(bootloader_name):
+        print "*** Error: bootloader file name invalid: %s" % (bootloader_name)
+        sys.exit()
+    
+    
+    size_bytes = 512000
+    sector_size = 4096 # must be 512 Bytes for generic_leti platform
+    sectors_per_cluster = 8
+    boot_size = os.path.getsize(bootloader_name)
+    
+    sectors_boot = (boot_size / sector_size) + 1
+    
+    # reserved sector will begin from sector 2 and will contain the boot_loader code,
+    # the kernel image and the architecture informations
+    # We put the backup of VBR (MBR) at the end of the reserved sector
+    offset = 2
+    reserved_sectors = offset + sectors_boot + 1
+    back_up_sector = reserved_sectors - 1 # last reserved sector
+    
+    print("******** HDD_IMG *********")
+    print("%d reserved sectors --> backup at back up sector %d" % (reserved_sectors, back_up_sector))
+    # the first two cluster are not in the data region
+    # data_region_clusters=$cluster_size-2
+    
+    #create partition
+    if fs_type == "fat32":
+        cmd = ['mkfs.vfat', '-C', '-F', '32', '-f', '1',
+                    '-r', '512',
+                    '-R', str(reserved_sectors),
+                    '-S', str(sector_size),
+                    '-s', str(sectors_per_cluster),
+                    '-b', str(back_up_sector),
+                    '-i', 'f7120c4f',
+                    '-n', 'hdd',
+                    '-v', target, str(size_bytes)]
+        print(subprocess.list2cmdline(cmd))
+        subprocess.call(cmd)
+        # copy root
+        for dir_or_file in os.listdir(partition_root):
+            cmd = ['mcopy', '-s', '-i', target, os.path.join(partition_root, dir_or_file), '::/']
+            print(subprocess.list2cmdline(cmd))
+            subprocess.call(cmd)
+    
+    else:
+        cmd = ['mkfs.ext2', target]
+        print(subprocess.list2cmdline(cmd))
+        subprocess.call(cmd)
+        
+    # copy bootloader, arch-info (boot-info) and kernel-img in reserved sectors from sector 2
+    print("Insert boot_loader at sector $offset")
+          
+    cmd = ['dd', 'bs=%d' % sector_size, 'seek=%d' % offset, 'count=%d' % sectors_boot, 'conv=notrunc', 'if=%s' % bootloader_name, 'of=%s' % target]
+    print(subprocess.list2cmdline(cmd))
+    subprocess.call(cmd)
+
+
+if __name__ == '__main__':
+
+    if len(sys.argv) != 5:
+        print("Usage: %s path/to/partition/root <hdd-filename> <fs_type> <bootloader-filename>" % sys.argv[0])
+        sys.exit()
+    
+    partition_root = sys.argv[1]
+    target = sys.argv[2] # hdd wanted filename 
+    fs_type = sys.argv[3]
+    bootloader_name = sys.argv[4]
+    
+    hdd_img(partition_root, target, fs_type, bootloader_name)
+
Index: trunk/platforms/tsar_generic_xbar/scripts/run_simus.py
===================================================================
--- trunk/platforms/tsar_generic_xbar/scripts/run_simus.py	(revision 836)
+++ trunk/platforms/tsar_generic_xbar/scripts/run_simus.py	(revision 1012)
@@ -6,4 +6,8 @@
 import shutil
 
+from gen_hdd import *
+from gen_hard_config import *
+from gen_arch_info import *
+
 #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.
@@ -11,17 +15,24 @@
 
 # User parameters
-nb_procs = [ 4 ]
-#nb_procs = [ 1, 4, 8, 16, 32, 64, 128, 256 ]
-rerun_stats = False
-use_omp = False
-protocol = 'wtidl'
-
+bscpu = 0
+#nb_procs = [ 4 ]
+nb_procs = [ 1, 4, 8, 16, 32, 64, 128, 256 ]
+rerun_stats = True
+use_omp = True
+protocol = 'rwt'
+cpu_per_cluster = 4
+# mode must be one of 'test' and 'simu'
+mode = 'simu'
+
+#apps = [ 'cholesky', 'fft', 'fft_ga', 'filter', 'filt_ga', 'histogram', 'kmeans', 'lu', 'mandel', 'mat_mult', 'pca', 'radix_ga' ]
 #apps = [ 'histogram', 'mandel', 'filter', 'radix_ga', 'fft_ga', 'kmeans' ]
-#apps = [ 'histogram', 'mandel', 'filter', 'radix_ga', 'fft_ga' ]
-apps = [ 'radix' ]
+apps = [ 'blackscholes', 'linear_regression', 'string_match', 'swaptions', 'fluidanimate' ]
 
 
 # Variables which could be changed but ought not to because they are reflected in the create_graphs.py script
-data_dir = 'data'
+if mode == 'test':
+    data_dir = 'data_test'
+else:
+    data_dir = 'data'
 log_init_name = protocol + '_stdo_'
 log_term_name = protocol + '_term_'
@@ -29,24 +40,33 @@
 # Global Variables
 
-all_apps = [ 'cholesky', 'fft', 'fft_ga', 'filter', 'filt_ga', 'histogram', 'kmeans', 'lu', 'mandel', 'mat_mult', 'pca', 'radix', 'radix_ga', 'showimg', ]
+all_apps = [ 'blackscholes', 'boot_only', 'cholesky', 'fft', 'fft_ga', 'filter', 'filt_ga', 'fluidanimate', 'histogram', 'histo-opt', 'kmeans', 'kmeans-opt', 'linear_regression', 'lu', 'mandel', 'mat_mult', 'mat_mult-opt', 'pca', 'pca-opt', 'radix', 'radix_ga', 'showimg', 'string_match', 'swaptions', ]
 # to come: 'barnes', 'fmm', 'ocean', 'raytrace', 'radiosity', 'waters', 'watern'
 
-all_protocols = [ 'dhccp', 'rwt', 'hmesi', 'wtidl' ]
+all_protocols = [ 'dhccp', 'rwt', 'hmesi', 'wtidl', 'snoop' ]
 
 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")
+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")
+partition_root_path  = os.path.join(top_path, "hdd_root")
+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")
+bootloader_link_name = os.path.join(almos_path, "bootloader-tsar-mipsel.bin")
 
 
 # Checks
+if mode != 'test' and mode != 'simu':
+    help_str = '''
+*** Error: variable mode must be one either 'test' (testing purpose, small data sets) or 'simu' (performance evaluation, large data sets)
+'''
+    print help_str
+    sys.exit()
+
 if protocol not in all_protocols:
     help_str = '''
@@ -64,12 +84,13 @@
     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
- - almos_src_dir: path to almos source directory (for kernel and bootloader binaries)
- - hdd_img_name:  path to the hdd image to use (will be copied but not modified)
- - tsar_dir:      path to tsar repository
+ - apps_dir:          path to almos-tsar-mipsel/apps directory
+ - almos_src_dir:     path to almos source directory (for kernel and bootloader binaries)
+ - preloader_src_dir: path to the preloader main directory (where to run make)
+ - hdd_img_name:      path to the hdd image to use (will be copied but not modified)
+ - tsar_dir:          path to tsar repository
 Optional definitions (necessary if you want to use alternative protocols):
- - rwt_dir:       path to the RWT repository
- - hmesi_dir:     path to HMESI directory
- - wtidl_dir:     path to the ideal write-through protocol directory
+ - rwt_dir:           path to the RWT repository
+ - hmesi_dir:         path to HMESI directory
+ - wtidl_dir:         path to the ideal write-through protocol directory
 *** Stopping execution
 '''
@@ -127,9 +148,21 @@
 
 
-def get_x_y(nb_procs):
+def print_and_call(cmd):
+    print subprocess.list2cmdline(cmd)
+    retval = subprocess.call(cmd)
+    return retval
+
+def print_and_popen(cmd, outfile):
+    print subprocess.list2cmdline(cmd),
+    print " >", outfile
+    output = subprocess.Popen(cmd, stdout = subprocess.PIPE).communicate()[0]
+    return output
+
+
+def get_x_y(nb_procs, cpu_per_cluster):
     x = 1
     y = 1
     to_x = True
-    while (x * y * 4 < nb_procs):
+    while (x * y * cpu_per_cluster < nb_procs):
         if to_x:
             x = x * 2
@@ -140,6 +173,13 @@
 
 
+def get_nb_bits(size):
+    i = 0
+    while 2**i < size:
+        i += 1
+    return i
+
+
+
 def gen_soclib_conf():
-
     if os.path.isfile(soclib_conf_name):
         print "Updating file %s" % (soclib_conf_name)
@@ -204,269 +244,341 @@
 
 
-def gen_hard_config(x, y, hard_config):
-   header = '''
-/* Generated from run_simus.py */
-
-#ifndef _HD_CONFIG_H
-#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 IRQ_PER_PROCESSOR   1
-''' % dict(x = x, y = y, nb_clus = x * y)
-
-   if protocol == 'wtidl':
-       header += '#define WT_IDL\n'
-
-   header += '#endif //_HD_CONFIG_H\n'
-
-   file = open(hard_config, 'w')
-   file.write(header)
-   file.close()
-
-
-
-def gen_arch_info(x, y, arch_info, arch_info_bib):
-   old_path = os.getcwd()
-   print "cd", scripts_path
-   os.chdir(scripts_path)
-   print "./gen_arch_info_large.sh", str(x), str(y), ">", arch_info
-   output = subprocess.Popen([ './gen_arch_info_large.sh', str(x), str(y) ], stdout = subprocess.PIPE).communicate()[0]
-   os.chdir(almos_path)
-   file = open(arch_info, 'w')
-   file.write(output)
-   file.close()
-   print "./info2bib -i", arch_info, "-o", arch_info_bib
-   subprocess.call([ './info2bib', '-i', arch_info, '-o', arch_info_bib ])
-   print "cd", old_path
-   os.chdir(old_path)
+
+def gen_arch_info_bib(x, y, arch_info, arch_info_bib):
+    old_path = os.getcwd()
+
+    print "cd", scripts_path
+    os.chdir(scripts_path)
+    gen_arch_info(x, y, x_width, y_width, bscpu, arch_info)
+    os.chdir(almos_path)
    
+    cmd = ['./info2bib', '-i', arch_info, '-o', arch_info_bib]
+    print_and_call(cmd)
+
+    print "cd", old_path
+    os.chdir(old_path)
+   
 
 def gen_sym_links():
-   old_path = os.getcwd()
-   print "cd", almos_path
-   os.chdir(almos_path)
-
-   target = os.path.join(almos_src_dir, 'tools/soclib-bootloader/bootloader-tsar-mipsel.bin')
-   link_name = 'bootloader-tsar-mipsel.bin'
-   if not os.path.isfile(link_name):
-      print "ln -s", target, link_name
-      os.symlink(target, link_name)
-
-   target = os.path.join(almos_src_dir, 'kernel/obj.tsar/almix-tsar-mipsel.bin')
-   link_name = 'kernel-soclib.bin'
-   if not os.path.isfile(link_name):
-      print "ln -s", target, link_name
-      os.symlink(target, link_name)
-
-   copied_hdd = 'hdd-img.bin'
-   print "cp", hdd_img_name, copied_hdd
-   shutil.copy(hdd_img_name, copied_hdd)
-
-   os.chdir(old_path)
-
-
-
-def compile_app(app_name, nprocs):
-
-   #if app_name in splash2:
-   #   app_dir_name = os.path.join(splash2_dir, splash_app_dir[app_name])
-   #elif app_name in splash2_ga:
-   #   app_dir_name = os.path.join(splash2_ga_dir, splash_ga_app_dir[app_name])
-   #else:
-   #   app_dir_name = os.path.join(apps_dir, app_name)
+    target = os.path.join(almos_src_dir, 'tools/soclib-bootloader/bootloader-tsar-mipsel.bin')
+    if not os.path.isfile(bootloader_link_name):
+        print "ln -s", target, bootloader_link_name
+        os.symlink(target, bootloader_link_name)
+
+    #target = os.path.join(almos_src_dir, 'kernel/obj.tsar/almix-tsar-mipsel.bin')
+    #link_name = 'kernel-soclib.bin'
+    #if not os.path.isfile(link_name):
+    #    print "ln -s", target, link_name
+    #    os.symlink(target, link_name)
+
+
+def compile_almos():
+    old_path = os.getcwd()
+
+    print "cd", almos_src_dir
+    os.chdir(almos_src_dir)
+    cmd = ['make']
+    print_and_call(cmd)
+    bootloader_dir = os.path.join(almos_src_dir, 'tools/soclib-bootloader')
+    print "cd", bootloader_dir
+    os.chdir(bootloader_dir)
+    print_and_call(cmd)
+
+    print "cd", old_path
+    os.chdir(old_path)
+ 
+
+def compile_preloader():
+    old_path = os.getcwd()
+    hard_conf_path_set = "HARD_CONFIG_PATH=" + almos_path
+    bscpu_set = "BS_PROC=%d" % bscpu
+
+    print "cd", preloader_src_dir
+    os.chdir(preloader_src_dir)
+    cmd = ['make', hard_conf_path_set, bscpu_set, 'USE_DT=0']
+    print_and_call(cmd)
+
+    print "cd", old_path
+    os.chdir(old_path)
+
+
+
+
+def compile_app(app_name):
+
+    #if app_name in splash2:
+    #   app_dir_name = os.path.join(splash2_dir, splash_app_dir[app_name])
+    #elif app_name in splash2_ga:
+    #   app_dir_name = os.path.join(splash2_ga_dir, splash_ga_app_dir[app_name])
+    #else:
+    #   app_dir_name = os.path.join(apps_dir, app_name)
 
      
-   app_dir_name = os.path.join(apps_dir, app_name)
-
-   old_path = os.getcwd()
-   print "cd", app_dir_name
-   os.chdir(app_dir_name)
-
-   # Compilation process is different in splash and other apps
-   #if app_name in splash2:
-   #   print "make clean"
-   #   subprocess.call([ 'make', 'clean' ])
-
-   #   print "rm Makefile"
-   #   subprocess.call([ 'rm', 'Makefile' ])
-
-   #   print "ln -s Makefile.soclib Makefile"
-   #   subprocess.call([ 'ln', '-s', 'Makefile.soclib', 'Makefile' ])
-
-   #   print "make"
-   #   subprocess.call([ 'make' ])
-
-   #else:
-   #   print "make clean"
-   #   subprocess.call([ 'make', 'clean' ])
- 
-   #   print "make TARGET=tsar"
-   #   subprocess.call([ 'make', 'TARGET=tsar' ])
-
-   print "make clean"
-   subprocess.call([ 'make', 'clean' ])
- 
-   print "make TARGET=tsar"
-   retval = subprocess.call([ 'make', 'TARGET=tsar' ])
-   if retval != 0:
-       sys.exit()
-   
-   # Creation/Modification du shrc de almos
-   if (app_name == "boot_only"):
-      shrc = "exec -p 0 /bin/boot_onl\n"
-   elif (app_name == "mandel"):
-      shrc = "exec -p 0 /bin/mandel -n%(nproc)d\n" % dict(nproc = nprocs)
-   elif (app_name == "filter"):
-      shrc = "exec -p 0 /bin/filter -l1024 -c1024 -n%(nproc)d /etc/img.raw\n" % dict(nproc = nprocs)
-   elif (app_name == "filt_ga"):
-      shrc = "exec -p 0 /bin/filt_ga -n%(nproc)d -i /etc/img.raw\n" % dict(nproc = nprocs)
-   elif (app_name == "histogram"):
-      shrc = "exec -p 0 /bin/histogra -n%(nproc)d /etc/histo.bmp\n" % dict(nproc = nprocs)
-   elif (app_name == "kmeans"):
-      shrc = "exec -p 0 /bin/kmeans -n %(nproc)d -p %(npoints)d\n" % dict(nproc = nprocs, npoints = 10000) # default npoints = 100000
-   elif (app_name == "pca"):
-      shrc = "exec -p 0 /bin/pca -n%(nproc)d\n" % dict(nproc = nprocs)
-   elif (app_name == "mat_mult"):
-      shrc = "exec -p 0 /bin/mat_mult -n%(nproc)d\n" % dict(nproc = nprocs)
-   elif (app_name == "showimg"):
-      shrc = "exec -p 0 /bin/showimg -i /etc/lena.sgi\n"
-   elif (app_name == "barnes"):
-      shrc = "exec -p 0 /bin/barnes -n%(nproc)d -b%(nbody)d\n" % dict(nproc = nprocs, nbody = 1024)
-   elif (app_name == "fmm"):
-      shrc = "exec -p 0 /bin/fmm -n%(nproc)d -p%(nparticles)d\n" % dict(nproc = nprocs, nparticles = 1024)
-   elif (app_name == "ocean"):
-      shrc = "exec -p 0 /bin/ocean -n%(nproc)d -m%(gridsize)d\n" % dict(nproc = nprocs, gridsize = 66)
-   elif (app_name == "radiosity"):
-      shrc = "exec -p 0 /bin/radiosit -n %(nproc)d -batch\n" % dict(nproc = nprocs)
-   elif (app_name == "raytrace"):
-      shrc = "exec -p 0 /bin/raytrace -n%(nproc)d /etc/tea.env\n" % dict(nproc = nprocs)
-   elif (app_name == "watern"):
-      shrc = "exec -p 0 /bin/watern -n%(nproc)d -m512\n" % dict(nproc = nprocs)
-   elif (app_name == "waters"):
-      shrc = "exec -p 0 /bin/waters -n%(nproc)d -m512\n" % dict(nproc = nprocs)
-   elif (app_name == "cholesky"):
-      shrc = "exec -p 0 /bin/cholesky -n%(nproc)d /etc/tk14.O\n" % dict(nproc = nprocs)
-   elif (app_name == "fft"):
-      shrc = "exec -p 0 /bin/fft -n%(nproc)d -m18\n" % dict(nproc = nprocs)
-   elif (app_name == "lu"):
-      shrc = "exec -p 0 /bin/lu -n%(nproc)d -m512\n" % dict(nproc = nprocs)
-   elif (app_name == "radix"):
-      shrc = "exec -p 0 /bin/radix -n%(nproc)d -k1024\n" % dict(nproc = nprocs) # test : 1024 ; simu : 2097152
-   elif (app_name == "radix_ga"):
-      shrc = "exec -p 0 /bin/radix_ga -n%(nproc)d -k2097152\n" % dict(nproc = nprocs) # p = proc, n = num_keys
-   elif (app_name == "fft_ga"):
-      shrc = "exec -p 0 /bin/fft_ga -n%(nproc)d -m18\n" % dict(nproc = nprocs)
-   else:
-      assert(False)
-   
-   file = open(shrc_file_name, 'w')
-   file.write(shrc)
-   file.close()
-
-   # Copie du binaire et du shrc dans l'image disque
-   print "mcopy -o -i", hdd_img_file_name, shrc_file_name, "::/etc/"
-   subprocess.call([ 'mcopy', '-o', '-i', hdd_img_file_name, shrc_file_name, '::/etc/' ])
-   print "mcopy -o -i", hdd_img_file_name, app_name, "::/bin/"
-   subprocess.call([ 'mcopy', '-o', '-i', hdd_img_file_name, app_name, '::/bin/' ])
-
-   print "cd", old_path
-   os.chdir(old_path)
+    app_dir_name = os.path.join(apps_dir, app_name)
+
+    old_path = os.getcwd()
+    print "cd", app_dir_name
+    os.chdir(app_dir_name)
+
+    # Compilation process is different in splash and other apps
+    #if app_name in splash2:
+    #   print "make clean"
+    #   subprocess.call([ 'make', 'clean' ])
+
+    #   print "rm Makefile"
+    #   subprocess.call([ 'rm', 'Makefile' ])
+
+    #   print "ln -s Makefile.soclib Makefile"
+    #   subprocess.call([ 'ln', '-s', 'Makefile.soclib', 'Makefile' ])
+
+    #   print "make"
+    #   subprocess.call([ 'make' ])
+
+    #else:
+    #   print "make clean"
+    #   subprocess.call([ 'make', 'clean' ])
+ 
+    #   print "make TARGET=tsar"
+    #   subprocess.call([ 'make', 'TARGET=tsar' ])
+
+    cmd = ['make', 'clean']
+    print_and_call(cmd)
+ 
+    cmd = ['make', 'TARGET=tsar']
+    retval = print_and_call(cmd)
+    if retval != 0:
+        sys.exit()
+
+    print "cd", old_path
+    os.chdir(old_path)
 # end of compile_app
 
 
-print "mkdir -p", os.path.join(scripts_path, data_dir)
-subprocess.call([ 'mkdir', '-p', os.path.join(scripts_path, data_dir) ])
+
+
+def gen_shrc(app_name, nprocs):
+    # Creation/Modification du shrc de almos
+    if mode == 'test':
+        if (app_name == "blackscholes"):
+            shrc = "exec -p 0 /bin/blacksch -n%(nproc)d /etc/black_16.txt\n" % dict(nproc = nprocs)
+        elif (app_name == "boot_only"):
+            shrc = "exec -p 0 /bin/boot_onl\n"
+        elif (app_name == "filter"):
+            shrc = "exec -p 0 /bin/filter -l 128 -c 128 -n %(nproc)d -i /etc/img128.raw\n" % dict(nproc = nprocs)
+        elif (app_name == "filt_ga"):
+            shrc = "exec -p 0 /bin/filt_ga -l 128 -c 128 -n %(nproc)d -i /etc/img128.raw\n" % dict(nproc = nprocs)
+        elif (app_name == "fft"):
+            shrc = "exec -p 0 /bin/fft -n%(nproc)d -m4\n" % dict(nproc = nprocs)
+        elif (app_name == "fft_ga"):
+            shrc = "exec -p 0 /bin/fft_ga -n%(nproc)d -m4\n" % dict(nproc = nprocs) # m = vector size
+        elif (app_name == "fluidanimate"):
+            shrc = "exec -p 0 /bin/fluidani -n%(nproc)d -i /etc/flui_15K.flu\n" % dict(nproc = nprocs)
+        elif (app_name == "histogram"):
+            shrc = "exec -p 0 /bin/histogra -n%(nproc)d /etc/histo_s.bmp\n" % dict(nproc = nprocs)
+        elif (app_name == "histo-opt"):
+            shrc = "exec -p 0 /bin/histo-op -n%(nproc)d /etc/histo_s.bmp\n" % dict(nproc = nprocs)
+        elif (app_name == "kmeans"):
+            shrc = "exec -p 0 /bin/kmeans -n %(nproc)d -p %(npoints)d\n" % dict(nproc = nprocs, npoints = 1000)
+        elif (app_name == "kmeans-opt"):
+            shrc = "exec -p 0 /bin/kmeans-o -n %(nproc)d -p %(npoints)d\n" % dict(nproc = nprocs, npoints = 1000)
+        elif (app_name == "linear_regression"):
+            shrc = "exec -p 0 /bin/linear_r -n%(nproc)d /etc/key_1MB.txt\n" % dict(nproc = nprocs)
+        elif (app_name == "lu"):
+            shrc = "exec -p 0 /bin/lu -n%(nproc)d -m16\n" % dict(nproc = nprocs)
+        elif (app_name == "mandel"):
+            shrc = "exec -p 0 /bin/mandel -n%(nproc)d -x 30 -y 20\n" % dict(nproc = nprocs)
+        elif (app_name == "mat_mult"):
+            shrc = "exec -p 0 /bin/mat_mult -n%(nproc)d -s 10\n" % dict(nproc = nprocs) # s = matrix size
+        elif (app_name == "mat_mult-opt"):
+            shrc = "exec -p 0 /bin/mat_mult -n%(nproc)d -s 10\n" % dict(nproc = nprocs)
+        elif (app_name == "pca"):
+            shrc = "exec -p 0 /bin/pca -n%(nproc)d -r 16 -c 8\n" % dict(nproc = nprocs) # r = num rows, c = num cols
+        elif (app_name == "pca-opt"):
+            shrc = "exec -p 0 /bin/pca-opt -n%(nproc)d -r 16 -c 8\n" % dict(nproc = nprocs)
+        elif (app_name == "radix"):
+            shrc = "exec -p 0 /bin/radix -n%(nproc)d -k1024\n" % dict(nproc = nprocs)
+        elif (app_name == "radix_ga"):
+            shrc = "exec -p 0 /bin/radix_ga -n%(nproc)d -k1024\n" % dict(nproc = nprocs) # n = num_keys
+        elif (app_name == "string_match"):
+            shrc = "exec -p 0 /bin/string_m -n%(nproc)d /etc/key_1MB.txt\n" % dict(nproc = nprocs)
+        elif (app_name == "swaptions"):
+            shrc = "exec -p 0 /bin/swaption -n%(nproc)d -s 16 -t 1000\n" % dict(nproc = nprocs) # s = num swaptions (default 16), t = num simus (default 10000)
+        else:
+            print "*** Error: The application %s is not available in test mode", app_name
+            sys.exit()
+    else:
+        if (app_name == "barnes"):
+            shrc = "exec -p 0 /bin/barnes -n%(nproc)d -b%(nbody)d\n" % dict(nproc = nprocs, nbody = 1024)
+        elif (app_name == "blackscholes"):
+            shrc = "exec -p 0 /bin/blacksch -n %(nproc)d /etc/black_4K.txt\n" % dict(nproc = nprocs)
+        elif (app_name == "boot_only"):
+            shrc = "exec -p 0 /bin/boot_onl\n"
+        elif (app_name == "cholesky"):
+            shrc = "exec -p 0 /bin/cholesky -n%(nproc)d /etc/tk14.O\n" % dict(nproc = nprocs)
+        elif (app_name == "fft"):
+            shrc = "exec -p 0 /bin/fft -n%(nproc)d -m18\n" % dict(nproc = nprocs)
+        elif (app_name == "fft_ga"):
+            shrc = "exec -p 0 /bin/fft_ga -n%(nproc)d -m18\n" % dict(nproc = nprocs)
+        elif (app_name == "fluidanimate"):
+            shrc = "exec -p 0 /bin/fluidani -n%(nproc)d -i /etc/flui_35K.flu\n" % dict(nproc = nprocs)
+        elif (app_name == "filter"):
+            shrc = "exec -p 0 /bin/filter -l 1024 -c 1024 -n %(nproc)d -i /etc/img1024.raw\n" % dict(nproc = nprocs)
+        elif (app_name == "filt_ga"):
+            shrc = "exec -p 0 /bin/filt_ga -l 1024 -c 1024 -n %(nproc)d -i /etc/img1024.raw\n" % dict(nproc = nprocs)
+        elif (app_name == "histogram"):
+            shrc = "exec -p 0 /bin/histogra -n%(nproc)d /etc/histo.bmp\n" % dict(nproc = nprocs)
+        elif (app_name == "histo-opt"):
+            shrc = "exec -p 0 /bin/histo-op -n%(nproc)d /etc/histo.bmp\n" % dict(nproc = nprocs)
+        elif (app_name == "kmeans"):
+            shrc = "exec -p 0 /bin/kmeans -n %(nproc)d -p %(npoints)d\n" % dict(nproc = nprocs, npoints = 10000) # default npoints = 100000
+        elif (app_name == "kmeans-opt"):
+            shrc = "exec -p 0 /bin/kmeans-o -n %(nproc)d -p %(npoints)d\n" % dict(nproc = nprocs, npoints = 10000) # default npoints = 100000
+        elif (app_name == "linear_regression"):
+            shrc = "exec -p 0 /bin/linear_r -n%(nproc)d /etc/key_50MB.txt\n" % dict(nproc = nprocs)
+        elif (app_name == "lu"):
+            shrc = "exec -p 0 /bin/lu -n%(nproc)d -m512\n" % dict(nproc = nprocs)
+        elif (app_name == "mandel"):
+            shrc = "exec -p 0 /bin/mandel -n%(nproc)d\n" % dict(nproc = nprocs)
+        elif (app_name == "mat_mult"):
+            shrc = "exec -p 0 /bin/mat_mult -n%(nproc)d\n" % dict(nproc = nprocs)
+        elif (app_name == "mat_mult-opt"):
+            shrc = "exec -p 0 /bin/mat_mult -n%(nproc)d\n" % dict(nproc = nprocs)
+        elif (app_name == "pca"):
+            shrc = "exec -p 0 /bin/pca -n%(nproc)d\n" % dict(nproc = nprocs)
+        elif (app_name == "pca-opt"):
+            shrc = "exec -p 0 /bin/pca-opt -n%(nproc)d\n" % dict(nproc = nprocs)
+        elif (app_name == "fmm"):
+            shrc = "exec -p 0 /bin/fmm -n%(nproc)d -p%(nparticles)d\n" % dict(nproc = nprocs, nparticles = 1024)
+        elif (app_name == "ocean"):
+            shrc = "exec -p 0 /bin/ocean -n%(nproc)d -m%(gridsize)d\n" % dict(nproc = nprocs, gridsize = 66)
+        elif (app_name == "radiosity"):
+            shrc = "exec -p 0 /bin/radiosit -n %(nproc)d -batch\n" % dict(nproc = nprocs)
+        elif (app_name == "radix"):
+            shrc = "exec -p 0 /bin/radix -n%(nproc)d -k2097152\n" % dict(nproc = nprocs)
+        elif (app_name == "radix_ga"):
+            shrc = "exec -p 0 /bin/radix_ga -n%(nproc)d -k2097152\n" % dict(nproc = nprocs) # k = num_keys
+        elif (app_name == "string_match"):
+            shrc = "exec -p 0 /bin/string_m -n%(nproc)d /etc/key_50MB.txt\n" % dict(nproc = nprocs)
+        elif (app_name == "raytrace"):
+            shrc = "exec -p 0 /bin/raytrace -n%(nproc)d /etc/tea.env\n" % dict(nproc = nprocs)
+        elif (app_name == "showimg"):
+            shrc = "exec -p 0 /bin/showimg -i /etc/lena.sgi\n"
+        elif (app_name == "swaptions"):
+            shrc = "exec -p 0 /bin/swaption -n%(nproc)d -s 256 -t 1000\n" % dict(nproc = nprocs) # s = num swaptions (default 16), t = num simus (default 10000)
+        elif (app_name == "watern"):
+            shrc = "exec -p 0 /bin/watern -n%(nproc)d -m512\n" % dict(nproc = nprocs)
+        elif (app_name == "waters"):
+            shrc = "exec -p 0 /bin/waters -n%(nproc)d -m512\n" % dict(nproc = nprocs)
+        else:
+            assert(False)
+    
+    file = open(shrc_file_name, 'w')
+    file.write(shrc)
+    file.close()
+
+    # Copie du shrc dans la future image disque
+    cmd = ['cp', shrc_file_name, os.path.join(partition_root_path, "etc", "shrc")]
+    print_and_call(cmd)
+# end of gen_shrc
+
+
+
+cmd = ['mkdir', '-p', os.path.join(scripts_path, data_dir)]
+print_and_call(cmd)
 
 gen_sym_links()
 gen_soclib_conf()
+compile_preloader()
+compile_almos()
+# Compile application once at the beginning not to intererfere with
+# other simulations
+for app in apps:
+    compile_app(app)
+    full_app_name = os.path.join(apps_dir, app, app)
+    cmd = ['cp', full_app_name, os.path.join(partition_root_path, "bin", app)]
+    print_and_call(cmd)
+
+ 
+print "cd", top_path
+os.chdir(top_path)
 
 for i in nb_procs:
-   x, y = get_x_y(i)
-   nthreads = min(4, x * y)
-   gen_hard_config(x, y, hard_config_name)
-   gen_arch_info(x, y, arch_info_name, arch_info_bib_name)
-
-   print "cd", top_path
-   os.chdir(top_path)
-   print "touch", topcell_name
-   subprocess.call([ 'touch', topcell_name ])
-   print "make"
-   retval = subprocess.call([ 'make' ])
-   if retval != 0:
-       sys.exit()
-
-   for app in apps:
-      print "cd", top_path
-      os.chdir(top_path)
-
-      compile_app(app, i)
-
-      # Launch simulation
-      if use_omp:
-         print "./simul.x -THREADS", nthreads, ">", os.path.join(scripts_path, data_dir, app + '_' + log_init_name + str(i))
-         output = subprocess.Popen([ './simul.x', '-THREADS', str(nthreads) ], stdout = subprocess.PIPE).communicate()[0]
-      else:
-         print "./simul.x >", os.path.join(scripts_path, data_dir, app + '_' + log_init_name + str(i))
-         output = subprocess.Popen([ './simul.x' ], stdout = subprocess.PIPE).communicate()[0]
-
-
-      # Write simulation results to data directory
-      print "cd", scripts_path
-      os.chdir(scripts_path)
-      filename = os.path.join(data_dir, app + '_' + log_init_name + str(i))
-      file = open(filename, 'w')
-      file.write(output)
-      file.close()
-
-      filename = os.path.join(scripts_path, data_dir, app + '_' + log_term_name + str(i))
-      print "mv", os.path.join(top_path, 'term1'), filename
-      subprocess.call([ 'mv', os.path.join(top_path, 'term1'), filename ])
-
-      if rerun_stats:
-         start2_found = False
-         end_found = False
-         for line in open(filename):
-            if "[THREAD_COMPUTE_START]" in line:
-               start2 = line.split()[-1]
-               start2_found = True
-            if "[THREAD_COMPUTE_END]" in line:
-               end = line.split()[-1]
-               end_found = True
-         assert(start2_found and end_found)
-         
-         print "cd", top_path
-         os.chdir(top_path)
-
-         # Relauching simulation with reset and dump of counters
-         if use_omp:
-            print "./simul.x -THREADS", nthreads, "--reset-counters %s --dump-counters %s >" % (start2, end), os.path.join(scripts_path, data_dir, app + '_' + log_init_name + str(i))
-            output = subprocess.Popen([ './simul.x', '-THREADS', str(nthreads), '--reset-counters', start2, '--dump-counters', end ], stdout = subprocess.PIPE).communicate()[0]
-         else:
-            print "./simul.x --reset-counters %s --dump-counters %s >" % (start2, end), os.path.join(scripts_path, data_dir, app + '_' + log_init_name + str(i))
-            output = subprocess.Popen([ './simul.x', '--reset-counters', start2, '--dump-counters', end ], stdout = subprocess.PIPE).communicate()[0]
-         
-         # Write simulation results (counters) to data directory
-         print "cd", scripts_path
-         os.chdir(scripts_path)
-         filename = os.path.join(data_dir, app + '_' + log_init_name + str(i))
-         file = open(filename, 'w')
-         file.write(output)
-         file.close()
+    x, y = get_x_y(i, cpu_per_cluster)
+    x_width = get_nb_bits(x)
+    y_width = get_nb_bits(y)
+    nthreads = min(4, x * y)
+    hard_config(x, y, x_width, y_width, cpu_per_cluster, hard_config_name, protocol)
+    gen_arch_info_bib(x, y, arch_info_name, arch_info_bib_name)
+
+    cmd = ['touch', topcell_name]
+    print_and_call(cmd)
+
+    cmd = ['make']
+    retval = print_and_call(cmd)
+    if retval != 0:
+        sys.exit()
+ 
+    for app in apps:
+        # Generate shrc
+        gen_shrc(app, i)
+
+        # Remove current disk image
+        print "rm", hdd_img_file_name
+        os.remove(hdd_img_file_name)
+
+        # Regenerate disk image
+        hdd_img(partition_root_path, hdd_img_file_name, "fat32", bootloader_link_name)
+
+        # Launch simulation
+        if use_omp:
+            cmd = ['./simul.x', '-THREADS', str(nthreads)]
+        else:
+            cmd = ['./simul.x']
+        filename = os.path.join(scripts_path, data_dir, app + '_' + log_init_name + str(i))
+        output = print_and_popen(cmd, filename)
+ 
+        # Write simulation results to data directory
+        file = open(filename, 'w')
+        file.write(output)
+        file.close()
+ 
+        filename = os.path.join(scripts_path, data_dir, app + '_' + log_term_name + str(i))
+        
+        cmd = ['mv', os.path.join(top_path, 'term1'), filename]
+        print_and_call(cmd)
+ 
+        if rerun_stats:
+            start2_found = False
+            end_found = False
+            for line in open(filename):
+                if "[THREAD_COMPUTE_START]" in line:
+                    start2 = line.split()[-1]
+                    start2_found = True
+                if "[THREAD_COMPUTE_END]" in line:
+                    end = line.split()[-1]
+                    end_found = True
+            assert(start2_found and end_found)
+          
+            # Regenerate shrc and hdd to ensure having the same hdd image
+            gen_shrc(app, i)
+ 
+            # Relauching simulation with reset and dump of counters
+            if use_omp:
+                cmd = ['./simul.x', '-THREADS', str(nthreads), '--reset-counters', start2, '--dump-counters', end]
+            else:
+                cmd = ['./simul.x', '--reset-counters', start2, '--dump-counters', end]
+            filename = os.path.join(scripts_path, data_dir, app + '_' + log_init_name + str(i))
+            output = print_and_popen(cmd, filename)
+           
+            # Checking that the two terms obtained are identical
+            import filecmp
+            term_orig_file = os.path.join(scripts_path, data_dir, app + '_' + log_term_name + str(i))
+            term_new_file = os.path.join(top_path, 'term1')
+            assert(filecmp.cmp(term_orig_file, term_new_file))
+ 
+            # Write simulation results (counters) to data directory
+            file = open(filename, 'w')
+            file.write(output)
+            file.close()
  
 
Index: trunk/platforms/tsar_generic_xbar/scripts/templates/coherence_template.gp
===================================================================
--- trunk/platforms/tsar_generic_xbar/scripts/templates/coherence_template.gp	(revision 836)
+++ trunk/platforms/tsar_generic_xbar/scripts/templates/coherence_template.gp	(revision 1012)
@@ -15,5 +15,5 @@
 #set logscale y 2
 set xrange [8:256]
-#set yrange [0:30]
+set yrange [0:300]
 
 set key inside left top Left reverse
Index: trunk/platforms/tsar_generic_xbar/scripts/templates/metric_template.gp
===================================================================
--- trunk/platforms/tsar_generic_xbar/scripts/templates/metric_template.gp	(revision 836)
+++ trunk/platforms/tsar_generic_xbar/scripts/templates/metric_template.gp	(revision 1012)
@@ -1,4 +1,4 @@
 
-set terminal svg size 1000 400 fixed
+set terminal svg size 1000 300 fixed
 set output "%(svg_name)s.svg"
 
Index: trunk/platforms/tsar_generic_xbar/scripts/templates/speedup_template.gp
===================================================================
--- trunk/platforms/tsar_generic_xbar/scripts/templates/speedup_template.gp	(revision 836)
+++ trunk/platforms/tsar_generic_xbar/scripts/templates/speedup_template.gp	(revision 1012)
@@ -1,4 +1,4 @@
 
-set terminal svg size 1000 800 fixed
+set terminal svg size 500 400 fixed
 set output "%(svg_name)s.svg"
 
