Index: soft/giet_vm/sort/sort.py
===================================================================
--- soft/giet_vm/sort/sort.py	(revision 407)
+++ soft/giet_vm/sort/sort.py	(revision 416)
@@ -17,5 +17,5 @@
 #  - x_width   : number of bits coding x coordinate
 #  - y_width   : number of bits coding y coordinate
-#  - procs_max : number of processors per cluster
+#  - nprocs    : number of processors per cluster
 ####################################################################################
 
@@ -25,71 +25,78 @@
     x_size    = mapping.x_size
     y_size    = mapping.y_size
-    procs_max = mapping.procs_max
+    nprocs    = mapping.nprocs
     x_width   = mapping.x_width
     y_width   = mapping.y_width
 
-    ntasks    = x_size * y_size * procs_max
+    ntasks    = x_size * y_size * nprocs
 
     # define vsegs base & size
     code_base  = 0x10000000
-    code_size  = 0x00010000     # 64 Kbytes
+    code_size  = 0x00010000     # 64 Kbytes (replicated in each cluster)
 
     data_base  = 0x20000000
-    data_size  = 0x00010000     # 64 Kbytes
+    data_size  = 0x00010000     # 64 Kbytes (non replicated)
 
-    ptab_base  = 0x30000000
-    ptab_size  = 0x00040000     # 256 Kbytes
+    args_base  = 0x20010000
+    args_size  = 0x00000004     # 4 bytes (non replicated)
 
     stack_base = 0x40000000
-    stack_size = 0x00010000     # 64 Kbytes
+    stack_size = 0x00200000     # 2 Mbytes (per cluster)
 
-    heap_base  = 0x50000000
-    heap_size  = 0x00010000     # 64 Kbytes
-
-    args_base  = 0x60000000
-    args_size  = 0x00000004     # 4 bytes
+    heap_base  = 0x60000000
+    heap_size  = 0x00200000     # 2 Mbytes (per cluster)
 
     # create Vspace
     vspace = mapping.addVspace( name = 'sort', startname = 'sort_data' )
 
-    # non replicated vsegs in cluster[0,0]
-    mapping.addVseg( vspace, 'sort_code', code_base , code_size, 'CXWU', vtype = 'ELF',
-                     x = 0, y = 0, pseg = 'RAM', binpath = 'build/sort/sort.elf' )
+    # data vseg : non local (only in cluster[0,0])
+    mapping.addVseg( vspace, 'sort_data', data_base , data_size,
+                     'C_WU', vtype = 'ELF', x = 0, y = 0, pseg = 'RAM',
+                     binpath = 'build/sort/sort.elf',
+                     local = False )
 
-    mapping.addVseg( vspace, 'sort_data', data_base , data_size, 'C_WU', vtype = 'ELF',
-                     x = 0, y = 0, pseg = 'RAM', binpath = 'build/sort/sort.elf' )
+    # args vseg : non local (only in cluster[0,0])
+    mapping.addVseg( vspace, 'sort_args', args_base , args_size, 
+                     'C_WU', vtype = 'CONST', x = 0, y = 0, pseg = 'RAM', 
+                     init = ntasks,
+                     local = False )
 
-    mapping.addVseg( vspace, 'sort_args', args_base , args_size, 'C_WU', vtype = 'CONST',
-                     x = 0, y = 0, pseg = 'RAM', init = ntasks )
+    # code vsegs : local (one copy per cluster)
+    for x in xrange (x_size):
+        for y in xrange (y_size):
+            mapping.addVseg( vspace, 'sort_code', code_base , code_size, 
+                             'CXWU', vtype = 'ELF', x = 0, y = 0, pseg = 'RAM', 
+                             binpath = 'build/sort/sort.elf',
+                             local = True )
 
-    # distributed vsegs: one stack per task, one ptab and heap per cluster
-    for c in mapping.clusters:
-        x, y = c.x, c.y
-        cluster_offset = ((x << y_width) + y) << 20  # 1 Mbytes per cluster
-        mapping.addVseg( vspace, 'sort_heap_%d_%d' % (x, y),
-                         heap_base + cluster_offset, heap_size, 'C_WU',
-                         vtype = 'BUFFER', x = x, y = y, pseg = 'RAM' )
+    # stacks vsegs : local (one stack per task)
+    for x in xrange (x_size):
+        for y in xrange (y_size):
+            for p in xrange (nprocs)
+                proc_id = (((x * y_size) + y) * nprocs) + p
+                size    = stack_size / nprocs
+                base    = stack_base + (proc_id * size)
+                mapping.addVseg( vspace, 'sort_stack_%d_%d_%d' % (x,y,p), base, size
+                                 'C_WU', vtype = 'BUFFER', x = x, y = y, pseg = 'RAM',
+                                 local = True, big = True )
 
-        mapping.addVseg( vspace, 'sort_ptab_%d_%d' % (x, y),
-                         ptab_base + cluster_offset, ptab_size, 'C_WU',
-                         vtype = 'PTAB', x = x, y = y, pseg = 'RAM', align = 13 )
-
-        for p in c.procs:
-            l = p.lpid
-            proc_offset = cluster_offset + (l << 18) # 256 Kbytes per proc
-            mapping.addVseg( vspace, 'sort_stack_%d_%d_%d' % (x, y, l),
-                             stack_base + proc_offset, stack_size, 'C_WU',
-                             vtype = 'BUFFER', x = x, y = y, pseg = 'RAM' )
+    # heap vsegs : distributed but non local (all tasks can access all heap vsegs)
+    for x in xrange (x_size):
+        for y in xrange (y_size):
+            cluster_id = (x * y_size) + y
+            size       = heap_size
+            base       = heap_base + (cluster_id * size)
+            mapping.addVseg( vspace, 'sort_heap_%d_%d' % (x,y), base, size,
+                             'C_WU', vtype = 'BUFFER', x = x, y = y, pseg = 'RAM',
+                             local = False, big = True )
 
     # distributed tasks / one task per processor
-    trdid = 0
-    for c in mapping.clusters:
-        x, y = c.x, c.y
-        for p in c.procs:
-            l = p.lpid
-            mapping.addTask( vspace, 'sort_%d_%d_%d' % (x, y, l), trdid, x, y, l,
-                             'sort_stack_%d_%d_%d' % (x, y, l),
-                             'sort_heap_%d_%d' % (x, y), 0 )
-            trdid += 1
+    for x in xrange (x_size):
+        for y in xrange (y_size):
+            for p in xrange( nprocs ):
+                trdid = (((x * y_size) + y) * nprocs) + p
+                mapping.addTask( vspace, 'sort_%d_%d_%d' % (x,y,p), trdid, x, y, p,
+                                 'trsp_stack_%d_%d_%d' % (x,y,p),
+                                 'trsp_heap_%d_%d' % (x,y), 0 )
 
     # extend mapping name
