Index: /soft/giet_vm/applications/convol/convol.c
===================================================================
--- /soft/giet_vm/applications/convol/convol.c	(revision 717)
+++ /soft/giet_vm/applications/convol/convol.c	(revision 718)
@@ -727,5 +727,16 @@
     unsigned int nthreads   = nclusters * nprocs;     
 
+    // get a shared TTY
+    giet_tty_alloc( 1 );
+    lock_init( &tty_lock );
+
+    // get FBF size
+    unsigned int  width;
+    unsigned int  height;
+    giet_fbf_size( &width , &height );
+
     // parameters checking 
+    if ( (width != NP) || (height != NL) )
+        giet_pthread_exit( "[CONVOL ERROR] FBF size must be NP * NL\n");
     if ((nprocs != 1) && (nprocs != 2) && (nprocs != 4) && (nprocs != 8))
         giet_pthread_exit( "[CONVOL ERROR] NB_PROCS_MAX must be 1, 2, 4 or 8\n");
@@ -743,8 +754,7 @@
         giet_pthread_exit( "[CONVOL ERROR] X_SIZE*Y_SIZE must be a divider of NP");
 
-    // get a shared TTY
-    giet_tty_alloc( 1 );
-    lock_init( &tty_lock );
-
+    // get FBF ownership
+    giet_fbf_alloc();
+ 
     // initializes the distributed heap[x,y]
     for ( cx = 0 ; cx < x_size ; cx++ )
Index: /soft/giet_vm/applications/sort/Makefile
===================================================================
--- /soft/giet_vm/applications/sort/Makefile	(revision 717)
+++ /soft/giet_vm/applications/sort/Makefile	(revision 718)
@@ -2,5 +2,5 @@
 APP_NAME = sort
 
-OBJS = main.o
+OBJS = sort.o
 
 LIBS = -L../../build/libs -luser
Index: ft/giet_vm/applications/sort/main.c
===================================================================
--- /soft/giet_vm/applications/sort/main.c	(revision 717)
+++ 	(revision )
@@ -1,273 +1,0 @@
-///////////////////////////////////////////////////////////////////////////////
-// File   :  main.c
-// Date   :  November 2013
-// Author :  Cesar Fuguet Tortolero <cesar.fuguet-tortolero@lip6.fr>
-///////////////////////////////////////////////////////////////////////////////
-// This multi-threaded application implement a multi-stage sort application.
-// The various stages are separated by synchronisation barriers.
-// There is one thread per physical processors. Computation is organised as
-// a binary tree: All threads contribute to the first stage of parallel sort
-// but, the number of participating threads is divided by 2 at each next stage.
-//       Number_of_stages = number of barriers = log2(Number_of_threads)
-//
-// Constraints :
-// - It supports up to 1024 processors and the number of processors
-//   must be a power of 2.
-// _ The array of values to be sorted (ARRAY_LENGTH) must be power of 2 
-//   larger than the number of processors.
-// - This application uses a private TTY terminal, shared by all threads,
-//   that is protectted by an user-level SQT lock.
-///////////////////////////////////////////////////////////////////////////////
-
-#include "stdio.h"
-#include "mapping_info.h"
-#include "user_barrier.h"
-#include "user_lock.h"
-
-#define ARRAY_LENGTH    0x400
-#define IPT             (ARRAY_LENGTH / threads) // ITEMS PER THREAD
-
-// macro to use a shared TTY
-#define printf(...)     lock_acquire( &tty_lock ); \
-                        giet_tty_printf(__VA_ARGS__);  \
-                        lock_release( &tty_lock )
-
-int              array0[ARRAY_LENGTH];
-int              array1[ARRAY_LENGTH];
-
-volatile int     init_ok = 0;
-giet_barrier_t   barrier[10];
-user_lock_t      tty_lock;   
-
-void bubbleSort(
-        int * array,
-        unsigned int length,
-        unsigned int init_pos);
-
-void merge(
-        int * array,
-        int * result,
-        int length,
-        int init_pos_a,
-        int init_pos_b,
-        int init_pos_result);
-
-//////////////////////////////////////////
-__attribute__ ((constructor)) void main()
-//////////////////////////////////////////
-{
-    int * src_array = NULL;
-    int * dst_array = NULL;
-    int i;
-    unsigned int x_size;
-    unsigned int y_size;
-    unsigned int nprocs;
-    unsigned int threads;
-
-    // each thread gets its thread_id
-    int thread_id = giet_thread_id();
-    
-    unsigned int time_start = giet_proctime();
-    unsigned int time_end;   
-
-    // each thread compute number of threads (one thread per proc)
-    giet_procs_number( &x_size , &y_size , &nprocs );
-    threads = x_size * y_size * nprocs;
-
-    // thread 0 makes TTY and barrier initialisations
-    // other threads wait initialisation completion.
-    if ( thread_id == 0 )
-    {
-        // request a shared TTY used by all threads
-        giet_tty_alloc(1);
-        
-        // TTY lock initialisation
-        lock_init( &tty_lock );
-
-        printf("\n[ SORT T0 ] Starting sort application with %d threads "
-                 "at cycle %d\n", threads, time_start);
-
-        // Barriers Initialization
-        for (i = 0; i < __builtin_ctz( threads ); i++)
-        {
-            barrier_init( &barrier[i], threads >> i );
-        }
-
-        init_ok = 1;
-    }
-    else
-    {
-        while( !init_ok );
-    }
-
-    // each thread checks number of tasks
-    if ( (threads != 1)   && (threads != 2)   && (threads != 4)   && 
-         (threads != 8)   && (threads != 16 ) && (threads != 32)  && 
-         (threads != 64)  && (threads != 128) && (threads != 256) && 
-         (threads != 512) && (threads != 1024) )
-    {
-        giet_exit("error : number of processors must be power of 2");
-    }
-
-
-    // Each thread contribute to Array Initialization
-    for (i = IPT * thread_id; i < IPT * (thread_id + 1); i++)
-    {
-        array0[i] = giet_rand();
-    }
-
-    // all threads contribute to the first stage of parallel sort
-    printf("[ SORT T%d ] Stage 0: Sorting...\n\r", thread_id);
-
-    bubbleSort(array0, IPT, IPT * thread_id);
-
-    printf("[ SORT T%d ] Finishing Stage 0\n\r", thread_id);
-
-    // the number of threads is divided by 2 at each next stage
-    for (i = 0; i < __builtin_ctz( threads ); i++)
-    {
-        barrier_wait( &barrier[i] );
-
-        if((thread_id % (2 << i)) != 0)
-        {
-            printf("[ SORT T%d ] Quit\n\r", thread_id );
-            giet_exit("Completed");
-        }
-
-        printf("[ SORT T%d ] Stage %d: Sorting...\n\r", thread_id, i+1);
-
-        if((i % 2) == 0)
-        {
-            src_array = &array0[0];
-            dst_array = &array1[0];
-        }
-        else
-        {
-            src_array = &array1[0];
-            dst_array = &array0[0];
-        }
-
-        merge(src_array, dst_array
-                , IPT << i
-                , IPT * thread_id
-                , IPT * (thread_id + (1 << i))
-                , IPT * thread_id
-                );
-
-        printf("[ SORT T%d ] Finishing Stage %d\n\r", thread_id, i + 1);
-    }
-
-    int success;
-    int failure_index;
-
-    // Verify the resulting array
-    if(thread_id != 0)
-    {
-        giet_exit("error: only thread 0 should get here");
-    }
-
-    success = 1;
-    for(i=0; i<(ARRAY_LENGTH-1); i++)
-    {
-        if(dst_array[i] > dst_array[i+1])
-        {
-            success = 0;
-            failure_index = i;
-            break;
-        }
-    }
-
-    time_end = giet_proctime();
-
-    printf("[ SORT T0 ] Finishing sort application at cycle %d\n"
-           "[ SORT T0 ] Time elapsed = %d\n",
-            time_end, (time_end - time_start) );
-
-    if (success)
-    {
-        giet_exit("!!! Success !!!");
-    }
-    else
-    {
-        printf("[ SORT T0 ] Failure!! Incorrect element: %d\n\r", 
-               failure_index);
-        for(i=0; i<ARRAY_LENGTH; i++)
-        {
-            printf("array[%d] = %d\n", i, dst_array[i]);
-        }
-        giet_exit("!!!  Failure !!!");
-    }
-
-    giet_exit("Completed");
-}
-
-////////////////////////////////////
-void bubbleSort( int *        array,
-                 unsigned int length,
-                 unsigned int init_pos )
-{
-    int i;
-    int j;
-    int aux;
-
-    for(i = 0; i < length; i++)
-    {
-        for(j = init_pos; j < (init_pos + length - i - 1); j++)
-        {
-            if(array[j] > array[j + 1])
-            {
-                aux          = array[j + 1];
-                array[j + 1] = array[j];
-                array[j]     = aux;
-            }
-        }
-    }
-}
-
-/////////////
-void merge(
-        int * array,
-        int * result,
-        int length,
-        int init_pos_a,
-        int init_pos_b,
-        int init_pos_result)
-{
-    int i;
-    int j;
-    int k;
-
-    i = 0;
-    j = 0;
-    k = init_pos_result;
-
-    while((i < length) || (j < length))
-    {
-        if((i < length) && (j < length))
-        {
-            if(array[init_pos_a + i] < array[init_pos_b + j])
-            {
-                result[k++] = array[init_pos_a + i];
-                i++;
-            }
-            else
-            {
-                result[k++] = array[init_pos_b + j];
-                j++;
-            }
-        }
-        else if(i < length)
-        {
-            result[k++] = array[init_pos_a + i];
-            i++;
-        }
-        else
-        {
-            result[k++] = array[init_pos_b + j];
-            j++;
-        }
-    }
-}
-
-/* vim: tabstop=4 : shiftwidth=4 : expandtab
-*/
Index: /soft/giet_vm/applications/sort/sort.c
===================================================================
--- /soft/giet_vm/applications/sort/sort.c	(revision 718)
+++ /soft/giet_vm/applications/sort/sort.c	(revision 718)
@@ -0,0 +1,292 @@
+///////////////////////////////////////////////////////////////////////////////
+// File   :  sort.c
+// Date   :  November 2013
+// Author :  Cesar Fuguet Tortolero <cesar.fuguet-tortolero@lip6.fr>
+///////////////////////////////////////////////////////////////////////////////
+// This multi-threaded application implement a multi-stage sort application.
+// The various stages are separated by synchronisation barriers.
+// There is one thread per physical processors. Computation is organised as
+// a binary tree: All threads contribute to the first stage of parallel sort
+// but, the number of participating threads is divided by 2 at each next stage.
+//       Number_of_stages = number of barriers = log2(Number_of_threads)
+//
+// Constraints :
+// - It supports up to 1024 processors and the number of processors
+//   must be a power of 2.
+// _ The array of values to be sorted (ARRAY_LENGTH) must be power of 2 
+//   larger than the number of processors.
+// - This application uses a single TTY terminal, shared by all threads,
+//   that is protectted by an user-level SQT lock.
+///////////////////////////////////////////////////////////////////////////////
+
+#include "stdio.h"
+#include "mapping_info.h"
+#include "user_barrier.h"
+#include "user_lock.h"
+
+#define ARRAY_LENGTH    0x400
+#define VERBOSE         0
+
+// macro to use a shared TTY
+#define printf(...);  { lock_acquire( &tty_lock ); \
+                        giet_tty_printf(__VA_ARGS__);  \
+                        lock_release( &tty_lock ); }
+
+// argument for the sort() function
+typedef struct
+{
+    unsigned int threads;     // number of threads (one per core
+    unsigned int index;       // user defined thread index
+}   args_t;
+
+//////////////////////////////////////////
+//  Global variables
+//////////////////////////////////////////
+
+int              array0[ARRAY_LENGTH];
+int              array1[ARRAY_LENGTH];
+
+giet_barrier_t   barrier[10];
+
+user_lock_t      tty_lock;   
+
+
+////////////////////////////////////
+void bubbleSort( int *        array,
+                 unsigned int length,
+                 unsigned int init_pos )
+{
+    int i;
+    int j;
+    int aux;
+
+    for(i = 0; i < length; i++)
+    {
+        for(j = init_pos; j < (init_pos + length - i - 1); j++)
+        {
+            if(array[j] > array[j + 1])
+            {
+                aux          = array[j + 1];
+                array[j + 1] = array[j];
+                array[j]     = aux;
+            }
+        }
+    }
+}  // end bubbleSort()
+
+
+/////////////////////////
+void merge( int * array,
+            int * result,
+            int length,
+            int init_pos_a,
+            int init_pos_b,
+            int init_pos_result )
+{
+    int i;
+    int j;
+    int k;
+
+    i = 0;
+    j = 0;
+    k = init_pos_result;
+
+    while((i < length) || (j < length))
+    {
+        if((i < length) && (j < length))
+        {
+            if(array[init_pos_a + i] < array[init_pos_b + j])
+            {
+                result[k++] = array[init_pos_a + i];
+                i++;
+            }
+            else
+            {
+                result[k++] = array[init_pos_b + j];
+                j++;
+            }
+        }
+        else if(i < length)
+        {
+            result[k++] = array[init_pos_a + i];
+            i++;
+        }
+        else
+        {
+            result[k++] = array[init_pos_b + j];
+            j++;
+        }
+    }
+}  // end merge()
+
+
+///////////////////////////////////////////////////////////////////
+__attribute__ ((constructor)) void sort( args_t* ptr )
+///////////////////////////////////////////////////////////////////
+{
+    int * src_array = NULL;
+    int * dst_array = NULL;
+
+    unsigned int  thread_id = ptr->index;
+    unsigned int  threads   = ptr->threads;
+    unsigned int  items     = ARRAY_LENGTH / threads;
+    unsigned int  stages    = __builtin_ctz( threads );
+    unsigned int  i;
+
+    // all threads contribute to the first stage of parallel sort
+    printf("[SORT] Thread %d / Stage 0: Sorting...\n\r", thread_id );
+
+    bubbleSort( array0, items, items * thread_id );
+
+    printf("[SORT] Thread %d / Stage 0: Completed\n\r", thread_id);
+
+    // the number of threads is divided by 2 at each next stage
+    for ( i = 0 ; i < stages ; i++ )
+    {
+        barrier_wait( &barrier[i] );
+
+        if((thread_id % (2 << i)) != 0)  giet_pthread_exit("Completed");
+
+        printf("[SORT] Thread %d / Stage %d: Sorting...\n\r", thread_id, i+1);
+
+        if((i % 2) == 0)               // even stage 
+        {
+            src_array = &array0[0];
+            dst_array = &array1[0];
+        }
+        else                           // odd stage
+        {
+            src_array = &array1[0];
+            dst_array = &array0[0];
+        }
+
+        merge( src_array, 
+               dst_array,
+               items << i,
+               items * thread_id,
+               items * (thread_id + (1 << i)),
+               items * thread_id );
+
+        printf("[SORT] Thread %d / Stage %d: Completed\n\r", thread_id, i+1);
+    }
+
+
+} // end sort()
+
+
+//////////////////////////////////////////
+__attribute__ ((constructor)) void main()
+//////////////////////////////////////////
+{
+    unsigned int x_size;      // number of rows
+    unsigned int y_size;      // number of columns
+    unsigned int nprocs;      // number of procs per cluster
+    unsigned int threads;     // total number of threads
+    unsigned int n;           // index for loops
+
+    args_t       arg[1024];   // array of arguments for sort() 
+
+    // compute number of threads (one thread per proc)
+    giet_procs_number( &x_size , &y_size , &nprocs );
+    threads = x_size * y_size * nprocs;
+
+    // alloc a shared TTY used by all threads
+    giet_tty_alloc(1);
+    lock_init( &tty_lock );
+
+    // checks number of threads
+    if ( (threads != 1)   && (threads != 2)   && (threads != 4)   && 
+         (threads != 8)   && (threads != 16 ) && (threads != 32)  && 
+         (threads != 64)  && (threads != 128) && (threads != 256) && 
+         (threads != 512) && (threads != 1024) )
+    {
+        giet_pthread_exit("[SORT ERROR] : number of cores must be power of 2\n");
+    }
+
+    // check array size
+    if ( ARRAY_LENGTH % threads) 
+    {
+        giet_pthread_exit("[SORT ERROR] : array size must be multiple of number of cores\n");
+    }
+
+    // Barriers initialization (number of participants divided by 2 at each stage)
+    for (n = 0; n < __builtin_ctz( threads ); n++)
+    {
+        barrier_init( &barrier[n], threads >> n );
+    }
+
+    // Array to sort initialization
+    for ( n = 0 ; n < ARRAY_LENGTH ; n++ )
+    {
+        array0[n] = giet_rand();
+
+#if VERBOSE
+        printf("array[%d] = %d\n", n , array0[n] );
+#endif
+
+    }
+
+    printf("\n[SORT] main completes initialisation at cycle %d / %d threads\n",
+           giet_proctime() , threads );
+
+    // launch other threads to run sort() function
+    pthread_t   trdid;
+    for ( n = 1 ; n < threads ; n++ )
+    {
+        arg[n].index   = n;
+        arg[n].threads = threads;
+        if ( giet_pthread_create( &trdid,        // not used because no join
+                                  NULL,          // no attribute
+                                  &sort,
+                                  &arg[n] ) )    // pointer on sort arguments
+        {
+            printf("\n[SORT ERROR] creating thread %d\n", n );
+            giet_pthread_exit( NULL );
+        }
+    }
+
+    // main run also the sort() function
+    arg[0].index   = 0;
+    arg[0].threads = threads;
+    sort( &arg[0] );
+
+    // Check result
+    int    success = 1;
+    int*   res_array = ( (threads==  2) ||
+                         (threads==  8) || 
+                         (threads== 32) || 
+                         (threads==128) || 
+                         (threads==512) ) ? array1 : array0;
+    
+    for( n=0 ; n<(ARRAY_LENGTH-1) ; n++ )
+    {
+        if ( res_array[n] > res_array[n+1] )
+        {
+            success = 0;
+            break;
+        }
+    }
+
+#if VERBOSE
+    for( n=0; n<ARRAY_LENGTH; n++)
+    {
+        printf("array[%d] = %d\n", n , res_array[n] );
+    }
+#endif
+
+    if ( success )
+    {
+        printf("[SORT] Main completes at cycle %d : success\n", giet_proctime() );
+        giet_pthread_exit("Success");
+    }
+    else
+    {
+        printf("[SORT] Main completes at cycle %d : failure\n", giet_proctime() );
+        giet_pthread_exit("Failure");
+    }
+
+}  // end main()
+
+
+/* vim: tabstop=4 : shiftwidth=4 : expandtab
+*/
Index: /soft/giet_vm/applications/sort/sort.py
===================================================================
--- /soft/giet_vm/applications/sort/sort.py	(revision 717)
+++ /soft/giet_vm/applications/sort/sort.py	(revision 718)
@@ -11,5 +11,5 @@
 #  application on a multi_clusters, multi-processors architecture.
 #  This include both the mapping of virtual segments on the clusters,
-#  and the mapping of tasks on processors.
+#  and the mapping of threads on processors.
 #  This mapping uses 5 platform parameters, (obtained from the "mapping" argument)
 #  - x_size    : number of clusters in a row
@@ -29,5 +29,5 @@
     y_width   = mapping.y_width
 
-    ntasks    = x_size * y_size * nprocs
+    nthreads    = x_size * y_size * nprocs
 
     # define vsegs base & size
@@ -64,5 +64,5 @@
                                  local = True )
 
-    # stacks vsegs : local (one stack per task)
+    # stacks vsegs : local (one stack per thread)
     for x in xrange (x_size):
         for y in xrange (y_size):
@@ -79,5 +79,5 @@
                                      local = True, big = True )
 
-    # heap vsegs : distributed but non local (all tasks can access all heap vsegs)
+    # heap vsegs : distributed but non local (all threads can access all heap vsegs)
     for x in xrange (x_size):
         for y in xrange (y_size):
@@ -91,5 +91,5 @@
                                  local = False, big = True )
 
-    # distributed tasks / one task per processor
+    # distributed threads / one thread per processor
     for x in xrange (x_size):
         for y in xrange (y_size):
@@ -97,10 +97,18 @@
             if ( mapping.clusters[cluster_id].procs ):
                 for p in xrange( nprocs ):
-                    trdid = (((x * y_size) + y) * nprocs) + p
+                    if (x == 0) and (y == 0) and (p == 0) :   # main thread
+                        startid = 1
+                        is_main = True
+                    else :                                    # other threads
+                        startid = 0
+                        is_main = False
 
-                    mapping.addTask( vspace, 'sort_%d_%d_%d' % (x,y,p),
-                                     trdid, x, y, p,
-                                     'sort_stack_%d_%d_%d' % (x,y,p),
-                                     'sort_heap_%d_%d' % (x,y), 0 )
+                    mapping.addThread( vspace, 
+                                       'sort_%d_%d_%d' % (x,y,p),
+                                       is_main,
+                                       x, y, p,
+                                       'sort_stack_%d_%d_%d' % (x,y,p),
+                                       'sort_heap_%d_%d' % (x,y),
+                                       startid )
 
     # extend mapping name
