Index: soft/giet_vm/applications/convol/main.c
===================================================================
--- soft/giet_vm/applications/convol/main.c	(revision 488)
+++ soft/giet_vm/applications/convol/main.c	(revision 502)
@@ -1,39 +1,36 @@
-////////////////////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////////////
 // File   : main.c   (for convol application)
 // Date   : june 2014
 // author : Alain Greiner
-////////////////////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////////////
 // This multi-threaded application application implements a 2D convolution product.  
 // The convolution kernel is [201]*[35] pixels, but it can be factored in two
 // independant line and column convolution products.
 // It can run on a multi-processors, multi-clusters architecture, with one thread
-// per processor. It uses the he following hardware parameters, that must be defined 
-// in the hard_config.h file:
-// - X_SIZE       : number of clusters in a row
-// - Y_SIZE       : number of clusters in a column
-// - NB_PROCS_MAX : number of processors per cluster
-// - FBUF_X_SIZE  : number of pixels per line in frame buffer
-// - FBUF_Y_SIZE  : number of lines  in frame buffer
+// per processor. 
 // 
 // The (1024 * 1024) pixels image is read from a file (2 bytes per pixel).
 //
-// - The number of clusters containing processors must be a power of 2.
-// - The number of processors per cluster must be a power of 2.
-////////////////////////////////////////////////////////////////////////////////////////////
-
-#include "hard_config.h"
+// - number of clusters containing processors must be power of 2 no larger than 256.
+// - number of processors per cluster must be power of 2 no larger than 8.
+///////////////////////////////////////////////////////////////////////////////////////
+
 #include "stdio.h"
 #include "stdlib.h"
-#include "barrier.h"
+#include "user_barrier.h"
 #include "malloc.h"
 
-#define USE_SBT_BARRIER            1
+#define USE_SQT_BARRIER            1
 #define VERBOSE                    0
 #define SUPER_VERBOSE              0
 
+#define X_SIZE_MAX                 16
+#define Y_SIZE_MAX                 16
+#define PROCS_MAX                  8
+#define CLUSTERS_MAX               (X_SIZE_MAX * Y_SIZE_MAX)
+
 #define INITIAL_DISPLAY_ENABLE     0
 #define FINAL_DISPLAY_ENABLE       1
 
-#define NB_CLUSTERS                (X_SIZE * Y_SIZE)
 #define PIXEL_SIZE                 2
 #define NL                         1024
@@ -53,16 +50,16 @@
 // global instrumentation counters (cluster_id, lpid]
 
-unsigned int START[NB_CLUSTERS][NB_PROCS_MAX];
-unsigned int H_BEG[NB_CLUSTERS][NB_PROCS_MAX];
-unsigned int H_END[NB_CLUSTERS][NB_PROCS_MAX];
-unsigned int V_BEG[NB_CLUSTERS][NB_PROCS_MAX];
-unsigned int V_END[NB_CLUSTERS][NB_PROCS_MAX];
-unsigned int D_BEG[NB_CLUSTERS][NB_PROCS_MAX];
-unsigned int D_END[NB_CLUSTERS][NB_PROCS_MAX];
+unsigned int START[CLUSTERS_MAX][PROCS_MAX];
+unsigned int H_BEG[CLUSTERS_MAX][PROCS_MAX];
+unsigned int H_END[CLUSTERS_MAX][PROCS_MAX];
+unsigned int V_BEG[CLUSTERS_MAX][PROCS_MAX];
+unsigned int V_END[CLUSTERS_MAX][PROCS_MAX];
+unsigned int D_BEG[CLUSTERS_MAX][PROCS_MAX];
+unsigned int D_END[CLUSTERS_MAX][PROCS_MAX];
 
 // global synchronization barrier
 
-#if USE_SBT_BARRIER
-giet_sbt_barrier_t  barrier;
+#if USE_SQT_BARRIER
+giet_sqt_barrier_t  barrier;
 #else
 giet_barrier_t      barrier;
@@ -74,9 +71,9 @@
 
 // global pointers on distributed buffers in all clusters
-unsigned short * GA[NB_CLUSTERS];
-int *            GB[NB_CLUSTERS];
-int *            GC[NB_CLUSTERS];
-int *            GD[NB_CLUSTERS];
-unsigned char *  GZ[NB_CLUSTERS];
+unsigned short * GA[CLUSTERS_MAX];
+int *            GB[CLUSTERS_MAX];
+int *            GC[CLUSTERS_MAX];
+int *            GD[CLUSTERS_MAX];
+unsigned char *  GZ[CLUSTERS_MAX];
 
 ///////////////////////////////////////////
@@ -109,23 +106,29 @@
     int z; // vertical filter index for loops
 
+    // plat-form parameters
+    unsigned int x_size;             // number of clusters in a row
+    unsigned int y_size;             // number of clusters in a column
+    unsigned int nprocs;             // number of processors per cluster
+    
+    giet_procs_number( &x_size , &y_size , &nprocs );
+
     // processor identifiers
-    unsigned int x;                                           // x coordinate
-    unsigned int y;                                           // y coordinate
-    unsigned int lpid;                                        // local proc/task id
+    unsigned int x;                                         // x coordinate
+    unsigned int y;                                         // y coordinate
+    unsigned int lpid;                                      // local proc/task id
     giet_proc_xyp( &x, &y, &lpid );
 
-    int          file        = 0;                             // file descriptor
-    unsigned int nprocs      = NB_PROCS_MAX;                  // procs per cluster
-    unsigned int nclusters   = NB_CLUSTERS;                   // number of clusters
-    unsigned int cluster_id  = (x * Y_SIZE) + y;              // continuous cluster index
-    unsigned int task_id     = (cluster_id * nprocs) + lpid;  // continuous task index
-    unsigned int ntasks      = nclusters * nprocs;            // number of tasks
-    unsigned int frame_size  = FRAME_SIZE;                    // total size (bytes)
-    unsigned int nblocks     = frame_size / 512;              // number of blocks per frame
-
-    unsigned int lines_per_task     = NL / ntasks;            // lines per task
-    unsigned int lines_per_cluster  = NL / nclusters;         // lines per cluster
-    unsigned int pixels_per_task    = NP / ntasks;            // columns per task
-    unsigned int pixels_per_cluster = NP / nclusters;         // columns per cluster
+    int          file       = 0;                            // file descriptor
+    unsigned int nclusters  = x_size * y_size;              // number of clusters
+    unsigned int cluster_id = (x * y_size) + y;             // continuous cluster index
+    unsigned int task_id    = (cluster_id * nprocs) + lpid; // continuous task index
+    unsigned int ntasks     = nclusters * nprocs;           // number of tasks
+    unsigned int frame_size = FRAME_SIZE;                   // total size (bytes)
+    unsigned int nblocks    = frame_size / 512;             // number of blocks/frame
+
+    unsigned int lines_per_task     = NL / ntasks;          // lines per task
+    unsigned int lines_per_cluster  = NL / nclusters;       // lines per cluster
+    unsigned int pixels_per_task    = NP / ntasks;          // columns per task
+    unsigned int pixels_per_cluster = NP / nclusters;       // columns per cluster
 
     int first, last;
@@ -140,22 +143,18 @@
      // parameters checking 
    
-    if ( (NP != FBUF_X_SIZE) || (NL != FBUF_Y_SIZE) )
-    {
-        giet_exit("[TRANSPOSE ERROR] Frame buffer size does not fit image size");
-    }
-    if ((nprocs != 1) && (nprocs != 2) && (nprocs != 4))
-        giet_exit( "[CONVOL ERROR] NB_PROCS_MAX must be 1, 2 or 4\n");
-
-    if ((X_SIZE!=1) && (X_SIZE!=2) && (X_SIZE!=4) && (X_SIZE!=8) && (X_SIZE!=16))
-        giet_exit( "[CONVOL ERROR] X_SIZE must be 1, 2, 4, 8, 16\n");
+    if ((nprocs != 1) && (nprocs != 2) && (nprocs != 4) && (nprocs != 8))
+        giet_exit( "[CONVOL ERROR] NB_PROCS_MAX must be 1, 2, 4 or 8\n");
+
+    if ((x_size!=1) && (x_size!=2) && (x_size!=4) && (x_size!=8) && (x_size!=16))
+        giet_exit( "[CONVOL ERROR] x_size must be 1, 2, 4, 8, 16\n");
         
-    if ((Y_SIZE!=1) && (Y_SIZE!=2) && (Y_SIZE!=4) && (Y_SIZE!=8) && (Y_SIZE!=16))
-        giet_exit( "[CONVOL ERROR] Y_SIZE must be 1, 2, 4, 8, 16\n");
+    if ((y_size!=1) && (y_size!=2) && (y_size!=4) && (y_size!=8) && (y_size!=16))
+        giet_exit( "[CONVOL ERROR] y_size must be 1, 2, 4, 8, 16\n");
 
     if ( NL % nclusters != 0 )
-        giet_exit( "[CONVOL ERROR] NB_CLUSTERS must be a divider of NL");
+        giet_exit( "[CONVOL ERROR] CLUSTERS_MAX must be a divider of NL");
 
     if ( NP % nclusters != 0 )
-        giet_exit( "[CONVOL ERROR] NB_CLUSTERS must be a divider of NP");
+        giet_exit( "[CONVOL ERROR] CLUSTERS_MAX must be a divider of NP");
 
     
@@ -166,32 +165,12 @@
     if ( (x==0) && (y==0) && (lpid==0) )
     {
-        // parameters checking 
-        if ( (NP != FBUF_X_SIZE) || (NL != FBUF_Y_SIZE) )
-            giet_exit("[TRANSPOSE ERROR] Frame buffer size does not fit image size");
-        
-        if ((nprocs != 1) && (nprocs != 2) && (nprocs != 4))
-            giet_exit( "[CONVOL ERROR] NB_PROCS_MAX must be 1, 2 or 4\n");
-
-        if ((X_SIZE!=1) && (X_SIZE!=2) && (X_SIZE!=4) && (X_SIZE!=8) && (X_SIZE!=16))
-            giet_exit( "[CONVOL ERROR] X_SIZE must be 1, 2, 4, 8, 16\n");
-        
-        if ((Y_SIZE!=1) && (Y_SIZE!=2) && (Y_SIZE!=4) && (Y_SIZE!=8) && (Y_SIZE!=16))
-            giet_exit( "[CONVOL ERROR] Y_SIZE must be 1, 2, 4, 8, 16\n");
-
-        if ( NL % nclusters != 0 )
-            giet_exit( "[CONVOL ERROR] NB_CLUSTERS must be a divider of NL");
-
-        if ( NP % nclusters != 0 )
-            giet_exit( "[CONVOL ERROR] NB_CLUSTERS must be a divider of NP");
-
-    
         giet_shr_printf("\n[CONVOL] task[0,0,0] starts barrier init at cycle %d\n" 
-                        "- NB_CLUSTERS     = %d\n"
-                        "- NB_PROCS_MAX    = %d\n" 
-                        "- NB_TASKS        = %d\n" 
-                        "- NB_BLOCKS       = %x\n",
+                        "- CLUSTERS  = %d\n"
+                        "- PROCS     = %d\n" 
+                        "- TASKS     = %d\n" 
+                        "- BLOCKS    = %d\n",
                         giet_proctime(), nclusters, nprocs, ntasks, nblocks );
-#if USE_SBT_BARRIER
-        sbt_barrier_init( &barrier, nclusters , nprocs );
+#if USE_SQT_BARRIER
+        sqt_barrier_init( &barrier, x_size , y_size , nprocs );
 #else
         barrier_init( &barrier, ntasks );
@@ -216,5 +195,6 @@
 
 #if VERBOSE
-giet_shr_printf( "\n[CONVOL] task[%d,%d,%d] enters malloc at cycle %d\n", x,y,lpid, date );
+giet_shr_printf( "\n[CONVOL] task[%d,%d,%d] enters malloc at cycle %d\n", 
+                 x,y,lpid, date );
 #endif
 
@@ -242,6 +222,6 @@
 
     ///////////////////////////////
-    #if USE_SBT_BARRIER
-    sbt_barrier_wait( &barrier );
+    #if USE_SQT_BARRIER
+    sqt_barrier_wait( &barrier );
     #else
     barrier_wait( &barrier );
@@ -253,9 +233,9 @@
     ///////////////////////////////////////////////////////////////////
 
-    unsigned short * A[NB_CLUSTERS];
-    int *            B[NB_CLUSTERS];
-    int *            C[NB_CLUSTERS];
-    int *            D[NB_CLUSTERS];
-    unsigned char *  Z[NB_CLUSTERS];
+    unsigned short * A[CLUSTERS_MAX];
+    int            * B[CLUSTERS_MAX];
+    int            * C[CLUSTERS_MAX];
+    int            * D[CLUSTERS_MAX];
+    unsigned char  * Z[CLUSTERS_MAX];
 
     for (c = 0; c < nclusters; c++)
@@ -283,5 +263,5 @@
                          " at cycle %d\n", giet_proctime() );
 
-        for ( c = 0 ; c < NB_CLUSTERS ; c++ )
+        for ( c = 0 ; c < nclusters ; c++ )
         {
             giet_shr_printf( "\n[CONVOL] task[0,0,0] starts load "
@@ -341,6 +321,6 @@
 
         ////////////////////////////
-        #if USE_SBT_BARRIER
-        sbt_barrier_wait( &barrier );
+        #if USE_SQT_BARRIER
+        sqt_barrier_wait( &barrier );
         #else
         barrier_wait( &barrier );
@@ -447,6 +427,6 @@
 
     /////////////////////////////
-    #if USE_SBT_BARRIER
-    sbt_barrier_wait( &barrier );
+    #if USE_SQT_BARRIER
+    sqt_barrier_wait( &barrier );
     #else
     barrier_wait( &barrier );
@@ -567,6 +547,6 @@
 
     ////////////////////////////
-    #if USE_SBT_BARRIER
-    sbt_barrier_wait( &barrier );
+    #if USE_SQT_BARRIER
+    sqt_barrier_wait( &barrier );
     #else
     barrier_wait( &barrier );
@@ -626,6 +606,6 @@
      
     //////////////////////////////
-    #if USE_SBT_BARRIER
-    sbt_barrier_wait( &barrier );
+    #if USE_SQT_BARRIER
+    sqt_barrier_wait( &barrier );
     #else
     barrier_wait( &barrier );
