Index: soft/giet_vm/applications/transpose/main.c
===================================================================
--- soft/giet_vm/applications/transpose/main.c	(revision 661)
+++ soft/giet_vm/applications/transpose/main.c	(revision 669)
@@ -33,8 +33,13 @@
 #define CLUSTER_MAX           (X_MAX * Y_MAX)             // max number of clusters
 #define NN                    256                         // image size : nlines = npixels
-#define INITIAL_FILE_PATH     "misc/lena.raw"             // pathname on virtual disk
+#define INITIAL_FILE_PATH     "/misc/lena_256.raw"        // pathname on virtual disk
 #define TRANSPOSED_FILE_PATH  "/home/lena_transposed.raw" // pathname on virtual disk
 #define RESTORED_FILE_PATH    "/home/lena_restored.raw"   // pathname on virtual disk
 #define INSTRUMENTATION_OK    1                           // display statistics on TTY 
+
+// macro to use a shared TTY
+#define printf(...)     lock_acquire( &tty_lock ); \
+                        giet_tty_printf(__VA_ARGS__);  \
+                        lock_release( &tty_lock )
 
 ///////////////////////////////////////////////////////
@@ -61,5 +66,8 @@
 unsigned check_line_after[NN];
 
-// global synchronisation barrier
+// lock protecting shared TTY
+user_lock_t  tty_lock;
+
+// global & local synchronisation variables
 giet_sqt_barrier_t barrier;
 
@@ -98,4 +106,18 @@
     unsigned int task_id       = (cluster_id * nprocs) + lpid;  // "continuous" task index
 
+    // checking parameters
+    giet_assert( ((nprocs == 1) || (nprocs == 2) || (nprocs == 4)),
+                 "[TRANSPOSE ERROR] number of procs per cluster must be 1, 2 or 4");
+
+    giet_assert( ((x_size == 1) || (x_size == 2) || (x_size == 4) || 
+                  (x_size == 8) || (x_size == 16)),
+                 "[TRANSPOSE ERROR] x_size must be 1,2,4,8,16");
+
+    giet_assert( ((y_size == 1) || (y_size == 2) || (y_size == 4) || 
+                  (y_size == 8) || (y_size == 16)),
+                 "[TRANSPOSE ERROR] y_size must be 1,2,4,8,16");
+
+    giet_assert( (ntasks <= NN ),
+                 "[TRANSPOSE ERROR] number of tasks larger than number of lines");
 
     ///////////////////////////////////////////////////////////////////////
@@ -107,18 +129,10 @@
     if ( (x==0) && (y==0) && (lpid==0) )
     {
-        if ((nprocs != 1) && (nprocs != 2) && (nprocs != 4))
-        { 
-            giet_exit("[TRANSPOSE ERROR] number of procs per cluster must be 1, 2 or 4");
-        }
-        if ((nclusters != 1) && (nclusters != 2) && (nclusters != 4) && 
-            (nclusters != 8) && (nclusters != 16) && (nclusters != 32) && (nclusters != 64) )
-        {
-            giet_exit("[TRANSPOSE ERROR] number of clusters must be 1,2,4,8,16,32,64");
-        }
-        if ( ntasks > NN )
-        {
-            giet_exit("[TRANSPOSE ERROR] number of tasks larger than number of lines");
-        }
-
+        // shared TTY allocation
+        giet_tty_alloc( 1 );
+
+        // TTY lock initialisation
+        lock_init( &tty_lock);
+      
         // distributed heap initialisation
         unsigned int cx , cy;
@@ -134,6 +148,6 @@
         sqt_barrier_init( &barrier, x_size , y_size , nprocs );
 
-        giet_shr_printf("\n[TRANSPOSE] Proc [0,0,0] completes heap & barrier init at cycle %d\n",
-                        giet_proctime() );
+        printf("\n[TRANSPOSE] Proc [0,0,0] completes initialisation at cycle %d\n",
+               giet_proctime() );
 
         global_init_ok = 1;
@@ -157,10 +171,10 @@
 
         if ( (x==0) && (y==0) )
-        giet_shr_printf("\n[TRANSPOSE] Proc [%d,%d,%d] completes buffer allocation"
-                        " for cluster[%d,%d] at cycle %d\n"
-                        " - buf_in  = %x\n"
-                        " - buf_out = %x\n",
-                        x, y, lpid, x, y, giet_proctime(), 
-                        (unsigned int)buf_in[cluster_id], (unsigned int)buf_out[cluster_id] );
+        printf("\n[TRANSPOSE] Proc [%d,%d,%d] completes buffer allocation"
+               " for cluster[%d,%d] at cycle %d\n"
+               " - buf_in  = %x\n"
+               " - buf_out = %x\n",
+               x, y, lpid, x, y, giet_proctime(), 
+               (unsigned int)buf_in[cluster_id], (unsigned int)buf_out[cluster_id] );
 
         ///////////////////////////////////////////////////////////////////////
@@ -173,12 +187,12 @@
         if ( fd_initial < 0 ) 
         { 
-            giet_shr_printf("\n[TRANSPOSE ERROR] Proc [%d,%d,%d] cannot open file %s\n",
-                            x , y , lpid , INITIAL_FILE_PATH );
+            printf("\n[TRANSPOSE ERROR] Proc [%d,%d,%d] cannot open file %s\n",
+                   x , y , lpid , INITIAL_FILE_PATH );
             giet_exit(" open() failure");
         }
         else if ( (x==0) && (y==0) && (lpid==0) )
         {
-            giet_shr_printf("\n[TRANSPOSE] Proc [0,0,0] open file %s / fd = %d\n",
-                            INITIAL_FILE_PATH , fd_initial );
+            printf("\n[TRANSPOSE] Proc [0,0,0] open file %s / fd = %d\n",
+                   INITIAL_FILE_PATH , fd_initial );
         }
 
@@ -187,5 +201,5 @@
         if ( fd_transposed < 0 ) 
         { 
-            giet_shr_printf("\n[TRANSPOSE ERROR] Proc [%d,%d,%d] cannot open file %s\n",
+            printf("\n[TRANSPOSE ERROR] Proc [%d,%d,%d] cannot open file %s\n",
                             x , y , lpid , TRANSPOSED_FILE_PATH );
             giet_exit(" open() failure");
@@ -193,6 +207,6 @@
         else if ( (x==0) && (y==0) && (lpid==0) )
         {
-            giet_shr_printf("\n[TRANSPOSE] Proc [0,0,0] open file %s / fd = %d\n",
-                            TRANSPOSED_FILE_PATH , fd_transposed );
+            printf("\n[TRANSPOSE] Proc [0,0,0] open file %s / fd = %d\n",
+                   TRANSPOSED_FILE_PATH , fd_transposed );
         }
 
@@ -201,12 +215,12 @@
         if ( fd_restored < 0 ) 
         { 
-            giet_shr_printf("\n[TRANSPOSE ERROR] Proc [%d,%d,%d] cannot open file %s\n",
-                            x , y , lpid , RESTORED_FILE_PATH );
+            printf("\n[TRANSPOSE ERROR] Proc [%d,%d,%d] cannot open file %s\n",
+                   x , y , lpid , RESTORED_FILE_PATH );
             giet_exit(" open() failure");
         }
         else if ( (x==0) && (y==0) && (lpid==0) )
         {
-            giet_shr_printf("\n[TRANSPOSE] Proc [0,0,0] open file %s / fd = %d\n",
-                            RESTORED_FILE_PATH , fd_restored );
+            printf("\n[TRANSPOSE] Proc [0,0,0] open file %s / fd = %d\n",
+                   RESTORED_FILE_PATH , fd_restored );
         }
 
@@ -244,6 +258,6 @@
                                  SEEK_SET ) != offset )
             {
-                giet_shr_printf("\n[TRANSPOSE ERROR] Proc [%d,%d,%d] cannot seek fd = %d\n",
-                                x , y , lpid , fd_in );
+                printf("\n[TRANSPOSE ERROR] Proc [%d,%d,%d] cannot seek fd = %d\n",
+                       x , y , lpid , fd_in );
                 giet_exit(" seek() failure");
             }
@@ -254,13 +268,13 @@
                                 pixels ) != pixels )
             {
-                giet_shr_printf("\n[TRANSPOSE ERROR] Proc [%d,%d,%d] cannot read fd = %d\n",
-                                x , y , lpid , fd_in );
+                printf("\n[TRANSPOSE ERROR] Proc [%d,%d,%d] cannot read fd = %d\n",
+                       x , y , lpid , fd_in );
                 giet_exit(" read() failure");
             }
 
             if ( (x==0) && (y==0) )
-            giet_shr_printf("\n[TRANSPOSE] Proc [%d,%d,%d] completes load"
-                            "  for iteration %d at cycle %d\n",
-                            x, y, lpid, iteration, giet_proctime() );
+            printf("\n[TRANSPOSE] Proc [%d,%d,%d] completes load"
+                   "  for iteration %d at cycle %d\n",
+                   x, y, lpid, iteration, giet_proctime() );
         }
 
@@ -314,10 +328,10 @@
         }
 
-        if ( lpid == 0 )
-        {
-            if ( (x==0) && (y==0) )
-            giet_shr_printf("\n[TRANSPOSE] proc [%d,%d,0] completes transpose"
-                            " for iteration %d at cycle %d\n", 
-                            x, y, iteration, giet_proctime() );
+//        if ( lpid == 0 )
+        {
+//            if ( (x==0) && (y==0) )
+            printf("\n[TRANSPOSE] proc [%d,%d,0] completes transpose"
+                   " for iteration %d at cycle %d\n", 
+                   x, y, iteration, giet_proctime() );
 
         }
@@ -340,8 +354,8 @@
                              npt );
 
-        if ( (x==0) && (y==0) && (lpid==0) )
-        giet_shr_printf("\n[TRANSPOSE] Proc [%d,%d,%d] completes display"
-                        " for iteration %d at cycle %d\n",
-                        x, y, lpid, iteration, giet_proctime() );
+//        if ( (x==0) && (y==0) && (lpid==0) )
+        printf("\n[TRANSPOSE] Proc [%d,%d,%d] completes display"
+               " for iteration %d at cycle %d\n",
+               x, y, lpid, iteration, giet_proctime() );
 
         DISP_END[x][y][lpid] = giet_proctime();
@@ -364,6 +378,6 @@
                                  SEEK_SET ) != offset )
             {
-                giet_shr_printf("\n[TRANSPOSE ERROR] Proc [%d,%d,%d] cannot seek fr = %d\n",
-                                x , y , lpid , fd_out );
+                printf("\n[TRANSPOSE ERROR] Proc [%d,%d,%d] cannot seek fr = %d\n",
+                       x , y , lpid , fd_out );
                 giet_exit(" seek() failure");
             }
@@ -374,13 +388,13 @@
                                  pixels ) != pixels )
             {
-                giet_shr_printf("\n[TRANSPOSE ERROR] Proc [%d,%d,%d] cannot write fd = %d\n",
-                                x , y , lpid , fd_out );
+                printf("\n[TRANSPOSE ERROR] Proc [%d,%d,%d] cannot write fd = %d\n",
+                       x , y , lpid , fd_out );
                 giet_exit(" write() failure");
             }
 
             if ( (x==0) && (y==0) )
-            giet_shr_printf("\n[TRANSPOSE] Proc [%d,%d,%d] completes store"
-                            "  for iteration %d at cycle %d\n",
-                            x, y, lpid, iteration, giet_proctime() );
+            printf("\n[TRANSPOSE] Proc [%d,%d,%d] completes store"
+                   "  for iteration %d at cycle %d\n",
+                   x, y, lpid, iteration, giet_proctime() );
         }
 
@@ -437,37 +451,37 @@
             }
 
-            giet_shr_printf("\n   ---------------- Instrumentation Results ---------------------\n");
-
-            giet_shr_printf(" - LOAD_START : min = %d / max = %d / med = %d / delta = %d\n",
-                            min_load_start, max_load_start, (min_load_start+max_load_start)/2, 
-                            max_load_start-min_load_start); 
-
-            giet_shr_printf(" - LOAD_END   : min = %d / max = %d / med = %d / delta = %d\n",
-                            min_load_ended, max_load_ended, (min_load_ended+max_load_ended)/2, 
-                            max_load_ended-min_load_ended); 
-
-            giet_shr_printf(" - TRSP_START : min = %d / max = %d / med = %d / delta = %d\n",
-                            min_trsp_start, max_trsp_start, (min_trsp_start+max_trsp_start)/2, 
-                            max_trsp_start-min_trsp_start); 
-
-            giet_shr_printf(" - TRSP_END   : min = %d / max = %d / med = %d / delta = %d\n",
-                            min_trsp_ended, max_trsp_ended, (min_trsp_ended+max_trsp_ended)/2, 
-                            max_trsp_ended-min_trsp_ended); 
-
-            giet_shr_printf(" - DISP_START : min = %d / max = %d / med = %d / delta = %d\n",
-                            min_disp_start, max_disp_start, (min_disp_start+max_disp_start)/2, 
-                            max_disp_start-min_disp_start); 
-
-            giet_shr_printf(" - DISP_END   : min = %d / max = %d / med = %d / delta = %d\n",
-                            min_disp_ended, max_disp_ended, (min_disp_ended+max_disp_ended)/2, 
-                            max_disp_ended-min_disp_ended); 
-
-            giet_shr_printf(" - STOR_START : min = %d / max = %d / med = %d / delta = %d\n",
-                            min_stor_start, max_stor_start, (min_stor_start+max_stor_start)/2, 
-                            max_stor_start-min_stor_start); 
-
-            giet_shr_printf(" - STOR_END   : min = %d / max = %d / med = %d / delta = %d\n",
-                            min_stor_ended, max_stor_ended, (min_stor_ended+max_stor_ended)/2, 
-                            max_stor_ended-min_stor_ended); 
+            printf("\n   ---------------- Instrumentation Results ---------------------\n");
+
+            printf(" - LOAD_START : min = %d / max = %d / med = %d / delta = %d\n",
+                   min_load_start, max_load_start, (min_load_start+max_load_start)/2, 
+                   max_load_start-min_load_start); 
+
+            printf(" - LOAD_END   : min = %d / max = %d / med = %d / delta = %d\n",
+                   min_load_ended, max_load_ended, (min_load_ended+max_load_ended)/2, 
+                   max_load_ended-min_load_ended); 
+
+            printf(" - TRSP_START : min = %d / max = %d / med = %d / delta = %d\n",
+                   min_trsp_start, max_trsp_start, (min_trsp_start+max_trsp_start)/2, 
+                   max_trsp_start-min_trsp_start); 
+
+            printf(" - TRSP_END   : min = %d / max = %d / med = %d / delta = %d\n",
+                   min_trsp_ended, max_trsp_ended, (min_trsp_ended+max_trsp_ended)/2, 
+                   max_trsp_ended-min_trsp_ended); 
+
+            printf(" - DISP_START : min = %d / max = %d / med = %d / delta = %d\n",
+                   min_disp_start, max_disp_start, (min_disp_start+max_disp_start)/2, 
+                   max_disp_start-min_disp_start); 
+
+            printf(" - DISP_END   : min = %d / max = %d / med = %d / delta = %d\n",
+                   min_disp_ended, max_disp_ended, (min_disp_ended+max_disp_ended)/2, 
+                   max_disp_ended-min_disp_ended); 
+
+            printf(" - STOR_START : min = %d / max = %d / med = %d / delta = %d\n",
+                   min_stor_start, max_stor_start, (min_stor_start+max_stor_start)/2, 
+                   max_stor_start-min_stor_start); 
+
+            printf(" - STOR_END   : min = %d / max = %d / med = %d / delta = %d\n",
+                   min_stor_ended, max_stor_ended, (min_stor_ended+max_stor_ended)/2, 
+                   max_stor_ended-min_stor_ended); 
         }
 
@@ -497,13 +511,4 @@
     }
 
-    // clean up
-    if ( (x==0) && (y == 0) && (lpid == 0) )
-    { 
-        giet_fat_remove( "/home/lena_transposed" , 0 );
-        giet_fat_remove( "/home/lena_restored" , 0 );
-
-        giet_fat_remove( "/home" , 1 );
-    }
-    
     giet_exit("Completed");
 
