Index: soft/giet_vm/applications/convol/main.c
===================================================================
--- soft/giet_vm/applications/convol/main.c	(revision 589)
+++ soft/giet_vm/applications/convol/main.c	(revision 669)
@@ -1,4 +1,4 @@
 ///////////////////////////////////////////////////////////////////////////////////////
-// File   : main.c   (for convol application)
+// File   : main.c   (convol application)
 // Date   : june 2014
 // author : Alain Greiner
@@ -22,5 +22,5 @@
 
 #define USE_SQT_BARRIER            1
-#define VERBOSE                    0
+#define VERBOSE                    1
 #define SUPER_VERBOSE              0
 
@@ -49,4 +49,9 @@
 #define max(x,y) ((x) > (y) ? (x) : (y))
 #define min(x,y) ((x) < (y) ? (x) : (y))
+
+// macro to use a shared TTY
+#define printf(...)     lock_acquire( &tty_lock ); \
+                        giet_tty_printf(__VA_ARGS__);  \
+                        lock_release( &tty_lock )
 
 // global instrumentation counters (cluster_id, lpid]
@@ -60,5 +65,5 @@
 unsigned int D_END[CLUSTERS_MAX][PROCS_MAX];
 
-// global synchronization barrier
+// global synchronization barriers
 
 #if USE_SQT_BARRIER
@@ -71,4 +76,7 @@
 volatile unsigned int load_image_ok      = 0;
 volatile unsigned int instrumentation_ok = 0;
+
+// lock protecting access to shared TTY
+user_lock_t         tty_lock;
 
 // global pointers on distributed buffers in all clusters
@@ -138,8 +146,4 @@
     START[cluster_id][lpid] = date;
 
-#if VERBOSE
-giet_shr_printf( "\n[CONVOL] task[%d,%d,%d] starts at cycle %d\n", x,y,lpid, date );
-#endif
-
      // parameters checking 
    
@@ -161,15 +165,26 @@
     
     ///////////////////////////////////////////////////////////////////
-    // task[0][0][0] makes barrier initialisation
+    // task[0][0][0] makes various initialisations
     ///////////////////////////////////////////////////////////////////
     
     if ( (x==0) && (y==0) && (lpid==0) )
     {
-        giet_shr_printf("\n[CONVOL] task[0,0,0] starts barrier init at cycle %d\n" 
-                        "- CLUSTERS   = %d\n"
-                        "- PROCS      = %d\n" 
-                        "- TASKS      = %d\n" 
-                        "- LINES/TASK = %d\n",
-                        giet_proctime(), nclusters, nprocs, ntasks, lines_per_task );
+        // get a shared TTY
+        giet_tty_alloc( 1 );
+
+        // initializes TTY lock
+        lock_init( &tty_lock );
+
+        // initializes the distributed heap[x,y]
+        unsigned int cx;
+        unsigned int cy;
+        for ( cx = 0 ; cx < x_size ; cx++ )
+        {
+            for ( cy = 0 ; cy < y_size ; cy++ )
+            {
+                heap_init( cx , cy );
+            }
+        }
+
 #if USE_SQT_BARRIER
         sqt_barrier_init( &barrier, x_size , y_size , nprocs );
@@ -178,6 +193,10 @@
 #endif
 
-        giet_shr_printf( "\n[CONVOL] task[0,0,0] completes barrier init at cycle %d\n",
-                         giet_proctime() );
+        printf("\n[CONVOL] task[0,0,0] completes initialisation at cycle %d\n" 
+               "- CLUSTERS   = %d\n"
+               "- PROCS      = %d\n" 
+               "- TASKS      = %d\n" 
+               "- LINES/TASK = %d\n",
+               giet_proctime(), nclusters, nprocs, ntasks, lines_per_task );
 
         barrier_init_ok = 1;
@@ -196,5 +215,5 @@
 
 #if VERBOSE
-giet_shr_printf( "\n[CONVOL] task[%d,%d,%d] enters malloc at cycle %d\n", 
+printf( "\n[CONVOL] task[%d,%d,%d] enters malloc at cycle %d\n", 
                  x,y,lpid, date );
 #endif
@@ -207,16 +226,16 @@
         
 #if VERBOSE
-giet_shr_printf( "\n[CONVOL]  Shared Buffer Virtual Addresses in cluster(%d,%d)\n"
-                 "### GA = %x\n"
-                 "### GB = %x\n"               
-                 "### GC = %x\n"               
-                 "### GD = %x\n"               
-                 "### GZ = %x\n",
-                 x, y,
-                 GA[cluster_id],
-                 GB[cluster_id],
-                 GC[cluster_id],
-                 GD[cluster_id],
-                 GZ[cluster_id] );
+printf( "\n[CONVOL]  Shared Buffer Virtual Addresses in cluster(%d,%d)\n"
+        "### GA = %x\n"
+        "### GB = %x\n"               
+        "### GC = %x\n"               
+        "### GD = %x\n"               
+        "### GZ = %x\n",
+        x, y,
+        GA[cluster_id],
+        GB[cluster_id],
+        GC[cluster_id],
+        GD[cluster_id],
+        GZ[cluster_id] );
 #endif
     }
@@ -257,15 +276,15 @@
     {
         // open file
-        file = giet_fat_open( "misc/philips_image.raw" , 0 );
+        file = giet_fat_open( "/misc/philips_1024.raw" , 0 );
         if ( file < 0 ) giet_exit( "[CONVOL ERROR] task[0,0,0] cannot open"
-                                   " file misc/philips_image.raw" );
+                                   " file /misc/philips_1024.raw" );
  
-        giet_shr_printf( "\n[CONVOL] task[0,0,0] open file misc/philips_image.raw"
-                         " at cycle %d\n", giet_proctime() );
+        printf( "\n[CONVOL] task[0,0,0] open file /misc/philips_1024.raw"
+                " at cycle %d\n", giet_proctime() );
 
         for ( c = 0 ; c < nclusters ; c++ )
         {
-            giet_shr_printf( "\n[CONVOL] task[0,0,0] starts load "
-                             "for cluster %d at cycle %d\n", c, giet_proctime() );
+            printf( "\n[CONVOL] task[0,0,0] starts load "
+                    "for cluster %d at cycle %d\n", c, giet_proctime() );
 
             giet_fat_lseek( file,
@@ -277,6 +296,6 @@
                            frame_size/nclusters );
 
-            giet_shr_printf( "\n[CONVOL] task[0,0,0] completes load "
-                             "for cluster %d at cycle %d\n", c, giet_proctime() );
+            printf( "\n[CONVOL] task[0,0,0] completes load "
+                    "for cluster %d at cycle %d\n", c, giet_proctime() );
         }
         load_image_ok = 1;
@@ -296,7 +315,7 @@
 
 #if VERBOSE
-giet_shr_printf( "\n[CONVOL] task[%d,%d,%d] starts initial display"
-                 " at cycle %d\n",
-                 x, y, lpid, giet_proctime() );
+printf( "\n[CONVOL] task[%d,%d,%d] starts initial display"
+        " at cycle %d\n",
+        x, y, lpid, giet_proctime() );
 #endif
 
@@ -319,7 +338,7 @@
 
 #if VERBOSE 
-giet_shr_printf( "\n[CONVOL] task[%d,%d,%d] completes initial display"
-                 " at cycle %d\n",
-                 x, y, lpid, giet_proctime() );
+printf( "\n[CONVOL] task[%d,%d,%d] completes initial display"
+        " at cycle %d\n",
+        x, y, lpid, giet_proctime() );
 #endif
 
@@ -347,11 +366,11 @@
 
 #if VERBOSE 
-giet_shr_printf( "\n[CONVOL] task[%d,%d,%d] starts horizontal filter"
-                 " at cycle %d\n",
-                 x, y, lpid, date );
+printf( "\n[CONVOL] task[%d,%d,%d] starts horizontal filter"
+        " at cycle %d\n",
+        x, y, lpid, date );
 #else
 if ( (x==0) && (y==0) && (lpid==0) ) 
-giet_shr_printf( "\n[CONVOL] task[0,0,0] starts horizontal filter"
-                 " at cycle %d\n", date );
+printf( "\n[CONVOL] task[0,0,0] starts horizontal filter"
+        " at cycle %d\n", date );
 #endif
 
@@ -412,5 +431,5 @@
 
 #if SUPER_VERBOSE
-giet_shr_printf(" - line %d computed at cycle %d\n", l, giet_proctime() );
+printf(" - line %d computed at cycle %d\n", l, giet_proctime() );
 #endif    
 
@@ -421,11 +440,11 @@
 
 #if VERBOSE 
-giet_shr_printf( "\n[CONVOL] task[%d,%d,%d] completes horizontal filter"
-                 " at cycle %d\n",
-                 x, y, lpid, date );
+printf( "\n[CONVOL] task[%d,%d,%d] completes horizontal filter"
+        " at cycle %d\n",
+        x, y, lpid, date );
 #else
 if ( (x==0) && (y==0) && (lpid==0) ) 
-giet_shr_printf( "\n[CONVOL] task[0,0,0] completes horizontal filter"
-                 " at cycle %d\n", date );
+printf( "\n[CONVOL] task[0,0,0] completes horizontal filter"
+        " at cycle %d\n", date );
 #endif
 
@@ -451,11 +470,11 @@
 
 #if VERBOSE 
-giet_shr_printf( "\n[CONVOL] task[%d,%d,%d] starts vertical filter"
-                 " at cycle %d\n",
-                 x, y, lpid, date );
+printf( "\n[CONVOL] task[%d,%d,%d] starts vertical filter"
+        " at cycle %d\n",
+        x, y, lpid, date );
 #else
 if ( (x==0) && (y==0) && (lpid==0) ) 
-giet_shr_printf( "\n[CONVOL] task[0,0,0] starts vertical filter"
-                 " at cycle %d\n", date );
+printf( "\n[CONVOL] task[0,0,0] starts vertical filter"
+        " at cycle %d\n", date );
 #endif
 
@@ -532,5 +551,5 @@
 
 #if SUPER_VERBOSE
-giet_shr_printf(" - column %d computed at cycle %d\n", p, giet_proctime());
+printf(" - column %d computed at cycle %d\n", p, giet_proctime());
 #endif 
 
@@ -541,11 +560,11 @@
 
 #if VERBOSE 
-giet_shr_printf( "\n[CONVOL] task[%d,%d,%d] completes vertical filter"
-                 " at cycle %d\n",
-                 x, y, lpid, date );
+printf( "\n[CONVOL] task[%d,%d,%d] completes vertical filter"
+        " at cycle %d\n",
+        x, y, lpid, date );
 #else
 if ( (x==0) && (y==0) && (lpid==0) ) 
-giet_shr_printf( "\n[CONVOL] task[0,0,0] completes vertical filter"
-                 " at cycle %d\n", date );
+printf( "\n[CONVOL] task[0,0,0] completes vertical filter"
+        " at cycle %d\n", date );
 #endif
 
@@ -568,11 +587,11 @@
 
 #if VERBOSE
-giet_shr_printf( "\n[CONVOL] task[%d,%d,%d] starts final display"
-                 " at cycle %d\n",
-                 x, y, lpid, date);
+printf( "\n[CONVOL] task[%d,%d,%d] starts final display"
+        " at cycle %d\n",
+        x, y, lpid, date);
 #else
 if ( (x==0) && (y==0) && (lpid==0) ) 
-giet_shr_printf( "\n[CONVOL] task[0,0,0] starts final display"
-                 " at cycle %d\n", date );
+printf( "\n[CONVOL] task[0,0,0] starts final display"
+        " at cycle %d\n", date );
 #endif
 
@@ -600,11 +619,11 @@
 
 #if VERBOSE
-giet_shr_printf( "\n[CONVOL] task[%d,%d,%d] completes final display"
-                 " at cycle %d\n",
-                 x, y, lpid, date);
+printf( "\n[CONVOL] task[%d,%d,%d] completes final display"
+        " at cycle %d\n",
+        x, y, lpid, date);
 #else
 if ( (x==0) && (y==0) && (lpid==0) ) 
-giet_shr_printf( "\n[CONVOL] task[0,0,0] completes final display"
-                 " at cycle %d\n", date );
+printf( "\n[CONVOL] task[0,0,0] completes final display"
+        " at cycle %d\n", date );
 #endif
      
@@ -625,6 +644,6 @@
     {
         date  = giet_proctime();
-        giet_shr_printf("\n[CONVOL] task[0,0,0] starts instrumentation"
-                        " at cycle %d\n\n", date );
+        printf("\n[CONVOL] task[0,0,0] starts instrumentation"
+               " at cycle %d\n\n", date );
 
         int cc, pp;
@@ -678,33 +697,33 @@
         }
 
-        giet_shr_printf(" - START : min = %d / max = %d / med = %d / delta = %d\n",
+        printf(" - START : min = %d / max = %d / med = %d / delta = %d\n",
                min_start, max_start, (min_start+max_start)/2, max_start-min_start);
 
-        giet_shr_printf(" - H_BEG : min = %d / max = %d / med = %d / delta = %d\n",
+        printf(" - H_BEG : min = %d / max = %d / med = %d / delta = %d\n",
                min_h_beg, max_h_beg, (min_h_beg+max_h_beg)/2, max_h_beg-min_h_beg);
 
-        giet_shr_printf(" - H_END : min = %d / max = %d / med = %d / delta = %d\n",
+        printf(" - H_END : min = %d / max = %d / med = %d / delta = %d\n",
                min_h_end, max_h_end, (min_h_end+max_h_end)/2, max_h_end-min_h_end);
 
-        giet_shr_printf(" - V_BEG : min = %d / max = %d / med = %d / delta = %d\n",
+        printf(" - V_BEG : min = %d / max = %d / med = %d / delta = %d\n",
                min_v_beg, max_v_beg, (min_v_beg+max_v_beg)/2, max_v_beg-min_v_beg);
 
-        giet_shr_printf(" - V_END : min = %d / max = %d / med = %d / delta = %d\n",
+        printf(" - V_END : min = %d / max = %d / med = %d / delta = %d\n",
                min_v_end, max_v_end, (min_v_end+max_v_end)/2, max_v_end-min_v_end);
 
-        giet_shr_printf(" - D_BEG : min = %d / max = %d / med = %d / delta = %d\n",
+        printf(" - D_BEG : min = %d / max = %d / med = %d / delta = %d\n",
                min_d_beg, max_d_beg, (min_d_beg+max_d_beg)/2, max_d_beg-min_d_beg);
 
-        giet_shr_printf(" - D_END : min = %d / max = %d / med = %d / delta = %d\n",
+        printf(" - D_END : min = %d / max = %d / med = %d / delta = %d\n",
                min_d_end, max_d_end, (min_d_end+max_d_end)/2, max_d_end-min_d_end);
 
-        giet_shr_printf( "\n General Scenario (Kcycles for each step)\n" );
-        giet_shr_printf( " - BOOT OS           = %d\n", (min_start            )/1000 );
-        giet_shr_printf( " - LOAD IMAGE        = %d\n", (min_h_beg - min_start)/1000 );
-        giet_shr_printf( " - H_FILTER          = %d\n", (max_h_end - min_h_beg)/1000 );
-        giet_shr_printf( " - BARRIER HORI/VERT = %d\n", (min_v_beg - max_h_end)/1000 );
-        giet_shr_printf( " - V_FILTER          = %d\n", (max_v_end - min_v_beg)/1000 );
-        giet_shr_printf( " - BARRIER VERT/DISP = %d\n", (min_d_beg - max_v_end)/1000 );
-        giet_shr_printf( " - DISPLAY           = %d\n", (max_d_end - min_d_beg)/1000 );
+        printf( "\n General Scenario (Kcycles for each step)\n" );
+        printf( " - BOOT OS           = %d\n", (min_start            )/1000 );
+        printf( " - LOAD IMAGE        = %d\n", (min_h_beg - min_start)/1000 );
+        printf( " - H_FILTER          = %d\n", (max_h_end - min_h_beg)/1000 );
+        printf( " - BARRIER HORI/VERT = %d\n", (min_v_beg - max_h_end)/1000 );
+        printf( " - V_FILTER          = %d\n", (max_v_end - min_v_beg)/1000 );
+        printf( " - BARRIER VERT/DISP = %d\n", (min_d_beg - max_v_end)/1000 );
+        printf( " - DISPLAY           = %d\n", (max_d_end - min_d_beg)/1000 );
 
         instrumentation_ok = 1;
