Index: soft/giet_vm/applications/gameoflife/main.c
===================================================================
--- soft/giet_vm/applications/gameoflife/main.c	(revision 515)
+++ soft/giet_vm/applications/gameoflife/main.c	(revision 669)
@@ -5,10 +5,10 @@
 //            Alain Greiner <alain.greiner@lip6.fr> february 2015
 //
-// This application is an emulation of the Game of Life automaton.
+// This multi-threaded application is an emulation of the Game of Life automaton.
 // The world size is defined by the HEIGHT and WIDTH parameters.
 // There is one task per processor.
 // Each task compute HEIGHT/nbprocs lines.
-// Task running on processor P(0,0,0) initialises the barrier, and
-// the chained buffer DMA controler.
+// Task running on processor P(0,0,0) initialises the barrier, the TTY terminal,
+// and the chained buffer DMA controler.
 //
 // The number of processors must be a power of 2 not larger than HEIGHT.
@@ -19,4 +19,5 @@
 #include "user_barrier.h"
 #include "mapping_info.h"
+#include "hard_config.h"
 
 #define WIDTH           128
@@ -24,5 +25,5 @@
 #define NB_ITERATION    1000000000
 
-#define PRINTF(...) ({ if ( proc_id==0) { giet_shr_printf(__VA_ARGS__); } })
+#define PRINTF(...) ({ if ( proc_id==0) { giet_tty_printf(__VA_ARGS__); } })
 
 typedef unsigned char uint8_t;
@@ -31,4 +32,7 @@
 
 uint8_t DISPLAY[2][HEIGHT][WIDTH] __attribute__((aligned(64)));
+
+unsigned int status0[16];
+unsigned int status1[16];
 
 giet_sqt_barrier_t barrier;
@@ -121,4 +125,5 @@
 ////////////////////////////////////////
 __attribute__((constructor)) void main()
+////////////////////////////////////////
 {
    // get processor identifier
@@ -131,39 +136,69 @@
    unsigned int x_size;
    unsigned int y_size;
-   unsigned int n_local_procs;
-   giet_procs_number( &x_size, &y_size, &n_local_procs );
+   unsigned int nprocs;
+   giet_procs_number( &x_size, &y_size, &nprocs );
 
    // compute continuous processor index & number of procs
-   unsigned int proc_id = (((x * y_size) + y) * n_local_procs) + p;  
-   unsigned int n_global_procs = x_size * y_size * n_local_procs; 
+   unsigned int proc_id = (((x * y_size) + y) * nprocs) + p;  
+   unsigned int n_global_procs = x_size * y_size * nprocs; 
 
    unsigned int i;
-
-   if ( n_global_procs > HEIGHT )
-   {
-       PRINTF("[GAMEOFLIFE ERROR] Number or processors too large :"
-              " nb_procs = %d / image heigth = %d\n", n_global_procs, HEIGHT );
-       giet_exit("error");
-   }
 
    unsigned int nb_line       = HEIGHT / n_global_procs;
    unsigned int base_line     = nb_line * proc_id; 
    
-   PRINTF("\n*** Starting barrier and CMA initialisation at cycle %d ***\n"
-          " nprocs = %d / nlines = %d\n", 
-          giet_proctime() , n_global_procs, HEIGHT );
-
-   //////////// barrier & CMA initialization ( P(0,0,0) )
-
+   // parameters checking
+   giet_assert( (n_global_procs <= HEIGHT),
+                " Number or processors larger than world height" );
+
+   giet_assert( ((WIDTH == FBUF_X_SIZE) && (HEIGHT == FBUF_Y_SIZE)),
+                "Frame Buffer size does not fit the world size" );
+   
+   giet_assert( ((x_size == 1) || (x_size == 2) || (x_size == 4) ||
+                 (x_size == 8) || (x_size == 16)),
+                "x_size must be a power of 2 no larger than 16" );
+
+   giet_assert( ((y_size == 1) || (y_size == 2) || (y_size == 4) ||
+                 (y_size == 8) || (y_size == 16)),
+                "y_size must be a power of 2 no larger than 16" );
+
+   giet_assert( ((nprocs == 1) || (nprocs == 2) || (nprocs == 4)), 
+                "nprocs must be a power of 2 no larger than 4" );
+
+   // P[0,0,0] makes initialisation
    if ( proc_id == 0 )
    {
-      // initialises CMA component
+      // get a private TTY for P[0,0,0]
+      giet_tty_alloc( 0 );
+
+      // get a Chained Buffer DMA channel
       giet_fbf_cma_alloc();
-      giet_fbf_cma_start( &DISPLAY[0][0][0] , 
-                          &DISPLAY[1][0][0] , 
-                          HEIGHT * WIDTH );
+
+      // initializes the source and destination buffers
+      giet_fbf_cma_init_buf( &DISPLAY[0][0][0] , 
+                             &DISPLAY[1][0][0] , 
+                             status0 ,
+                             status1 );
+
+      // activates CMA channel
+      giet_fbf_cma_start( HEIGHT * WIDTH );
+
+      // initializes distributed heap
+      unsigned int cx;
+      unsigned int cy;
+      for ( cx = 0 ; cx < x_size ; cx++ )
+      {
+         for ( cx = 0 ; cx < x_size ; cx++ )
+         {
+            heap_init( cx , cy );
+         }
+      }
 
       // initialises barrier
-      sqt_barrier_init( &barrier , x_size , y_size , n_local_procs );
+      sqt_barrier_init( &barrier , x_size , y_size , nprocs );
+
+      PRINTF("\n[GAMEOFLIFE] P[0,0,0] completes initialisation at cycle %d\n"
+             " nprocs = %d / nlines = %d\n", 
+             giet_proctime() , n_global_procs, HEIGHT );
 
       // activates all other processors
@@ -175,10 +210,7 @@
    }
 
-   PRINTF("\n*** Starting world initialisation at cycle %d ***\n",
-          giet_proctime() );
-
    ///////////// world  initialization ( All processors )
 
-   // initialises WORLD[0]
+   // All processors initialize WORLD[0]
    init_world( 0 , base_line , nb_line );
 
@@ -192,5 +224,5 @@
    if ( proc_id == 0 ) giet_fbf_cma_display ( 0 );
 
-   PRINTF("\n*** Starting evolution at cycle %d ***\n", giet_proctime() );
+   PRINTF("\n[GAMEOFLIFE] starts evolution at cycle %d\n", giet_proctime() );
    
    //////////// evolution : 2 steps per iteration 
