Index: trunk/libs/libalmosmkh/almosmkh.c
===================================================================
--- trunk/libs/libalmosmkh/almosmkh.c	(revision 647)
+++ trunk/libs/libalmosmkh/almosmkh.c	(revision 650)
@@ -616,6 +616,6 @@
 ////////////////////////////////////////////////////////////////////i//////////////////////
 // This static function initialises the store in the cluster identified by the <cxy>
-// arguments. It is called by the malloc() or remote_malloc when a specific store(x,y)
-// is accessed for the first time by a remote() or remote_malloc() request.
+// arguments. It is called by the remote_malloc() function when a specific store(x,y)
+// is accessed for the first time.
 // It uses the mmap( MAP_REMOTE ) syscall to allocate a new vseg mapped in cluster (cxy).
 ////////////////////////////////////////////////////////////////////i//////////////////////
@@ -1099,132 +1099,155 @@
 #define X_MAX                   16              // max number of clusters in a row
 #define Y_MAX                   16              // max number of clusters in a column
-#define CLUSTERS_MAX            X_MAX * Y_MAX
-#define LEVEL_MAX               5
+#define CLUSTERS_MAX            X_MAX * Y_MAX   // max number of clusters 
+#define LEVEL_MAX               5               // max level of DQT
 #define CORES_MAX               4               // max number of cores per cluster
 
-typedef struct build_args_s           
-{
-    unsigned char       cxy;                    // this thread cluster identifier
-    unsigned char       level;                  // this thread level in quad-tree
-    unsigned char       parent_cxy;             // parent thread cluster identifier
-    unsigned char       root_level;             // quad-tree root level 
-    void              * work_func;              // pointer on work function pointer
-    void              * work_args_array;        // pointer on 2D array of pointers
-    pthread_barrier_t * parent_barriers_array;  // pointer on 1D array of barriers
-    unsigned int        error;                  // return value : 0 if success 
-}
-build_args_t;
-
 /////////////////////////////////////////////////////////////////////////////////////////
-//      Global variables used for inter-thread communications
+//      Global variables
+//
+// WARNING :  arguments of the pthread_create() function MUST be global variables.
 /////////////////////////////////////////////////////////////////////////////////////////
 
-pthread_attr_t    build_attr   [CLUSTERS_MAX][LEVEL_MAX];   // POSIX thread attributes
-
-build_args_t      build_args   [CLUSTERS_MAX][LEVEL_MAX];   // build function arguments
-
-pthread_barrier_t build_barrier[CLUSTERS_MAX][LEVEL_MAX];   // parent/child synchro
-
-pthread_attr_t    work_attr    [CLUSTERS_MAX][CORES_MAX];    // POSIX thread attributes
-
-//////////////////////////////////////////////////////////
-static void pthread_recursive_build( build_args_t * args )
-{
-    unsigned int   trdid;         // unused (required by pthread_create()
+// 2D array of <build> threads attributes / indexed by [cid][level]
+__attribute__((aligned(4096)))
+pthread_attr_t                pthread_build_attr[CLUSTERS_MAX][LEVEL_MAX];
+
+// 2D array of <build> threads arguments / indexed by [cid][level]
+__attribute__((aligned(4096)))
+pthread_parallel_build_args_t pthread_build_args[CLUSTERS_MAX][LEVEL_MAX];
+
+// 1D array of <work> threads attributes / indexed by [tid]
+__attribute__((aligned(4096)))
+pthread_attr_t                pthread_work_attr[CLUSTERS_MAX * CORES_MAX];
+
+// 1D array of <work> threads arguments / indexed by [tid]
+__attribute__((aligned(4096)))
+pthread_parallel_work_args_t  pthread_work_args[CLUSTERS_MAX * CORES_MAX];
+
+// kernel thread identifier / unused, but required by pthread_create()
+__attribute__((aligned(4096)))
+pthread_t                     trdid;
+
+///////////////////////////////////////////////////////////////////////////
+static void pthread_recursive_build( pthread_parallel_build_args_t * args )
+{
 
     // get arguments
-    unsigned int        cxy                   = args->cxy;
-    unsigned int        level                 = args->level;
-    unsigned int        parent_cxy            = args->parent_cxy;
-    unsigned int        root_level            = args->root_level;
-    void              * work_func             = args->work_func;
-    void              * work_args_array       = args->work_args_array;
-    pthread_barrier_t * parent_barriers_array = args->parent_barriers_array;
-
-    // set error default value 
-    build_args[cxy][level].error = 0;
+    unsigned int         cid               = args->cid;
+    unsigned int         level             = args->level;
+    unsigned int         parent_cid        = args->parent_cid;
+    pthread_barrier_t  * parent_barrier    = args->parent_barrier;
+    unsigned int         root_level        = args->root_level;
+    void               * work_func         = args->work_func;
+    unsigned int         x_size            = args->x_size;
+    unsigned int         y_size            = args->y_size;
+    unsigned int         ncores            = args->ncores;
+
+#if DEBUG_PTHREAD_PARALLEL
+printf("\n[%s] <build> thread[%d][%d] enters / parent_cid %d / work_func %x\n",
+__FUNCTION__, cid , level , parent_cid , work_func );
+#endif
+
+    // set error default value in pthread_build_args[cid][level] 
+    pthread_build_args[cid][level].error = 0;
+
+    // get cxy from cid
+    unsigned int cxy = HAL_CXY_FROM_XY( cid / y_size , cid % y_size );
+
+    // allocate the parent/child barrier in local cluster
+    pthread_barrier_t * barrier = (pthread_barrier_t *)malloc( sizeof(pthread_barrier_t) );
+
+    if( barrier == NULL )
+    {
+        printf("\n[ERROR] in %s : cannot allocate barrier for <build> thread[%d][%d]\n",
+        __FUNCTION__ , cid , level );
+
+        // report error to parent
+        pthread_build_args[parent_cid][level+1].error = 1;
+    }
 
     ///////////////////////////////////////////////////////////
-    if( level == 0 )             // children are "work" threads
-    {
-        unsigned int   lid;           // core local index
-        unsigned int   ncores;        // number of cores in a cluster
-
-        // get number of cores per cluster
-        get_nb_cores( cxy , &ncores );
-
-        // kill process if no active core in cluster
-        // TODO this "if" should be replaced by an "assert" [AG]
-        if( ncores == 0 )
-        {
-            printf("\n[PANIC] in %s : no active core in cluster %x\n",
-            __FUNCTION__ , cxy );
+    if( level == 0 )             // children are <work> threads
+    {
+
+        // check number of cores in local cluster
+        unsigned int actual_ncores;
+        get_nb_cores( cxy , &actual_ncores );
+
+        if( actual_ncores != ncores )
+        {
+            printf("\n[ERROR] in %s : actual_ncores (%d) in cluster %x\n",
+            __FUNCTION__ , actual_ncores, cxy );
 
             // report error to parent
-            build_args[parent_cxy][level+1].error = 1;
-
-            // kill process
-            exit( EXIT_FAILURE );
-        }
-
-        // initialize the parent_barrier 
-        if( pthread_barrier_init( &parent_barriers_array[cxy] , NULL , ncores + 1 ) )
-        {
-            printf("\n[ERROR] in %s : cannot initialise barrier for build thread[%x][%d]\n",
-            __FUNCTION__ , cxy , level );
+            pthread_build_args[parent_cid][level+1].error = 1;
+        }
+
+        // initializes barrier for (ncores + 1) in flat mode
+        if( pthread_barrier_init( barrier , NULL , ncores + 1 ) )
+        {
+            printf("\n[ERROR] in %s : cannot init barrier for <build> thread[%d][%d]\n",
+            __FUNCTION__ , cid , level );
 
             // report error to parent
-            build_args[parent_cxy][level+1].error = 1;
+            pthread_build_args[parent_cid][level+1].error = 1;
         }
 
 #if DEBUG_PTHREAD_PARALLEL
-printf("\n[%s] <build> thread[%x][%d] created barrier / %d children\n",
-__FUNCTION__, cxy, level, ncores + 1 );
-#endif
-        // create (ncores) "work" threads
+printf("\n[%s] <build> thread[%d][%d] initialized barrier / %d children\n",
+__FUNCTION__, cid, level, ncores );
+#endif
+        unsigned int   lid;     // core local index for <work> thread
+        unsigned int   tid;     // <work> thread continuous index
+
+        // <build> thread creates ncores <work> threads
         for ( lid = 0 ; lid < ncores ; lid++ )
         {
-            // set attributes for thread[cxy][lid]
-            work_attr[cxy][lid].attributes = PT_ATTR_DETACH |
-                                             PT_ATTR_CLUSTER_DEFINED |
-                                             PT_ATTR_CORE_DEFINED;
-            work_attr[cxy][lid].cxy        = cxy;
-            work_attr[cxy][lid].lid        = lid;
-
-            // compute pointer on thread[cxy][lid] arguments
-            void * work_args = *((void **)work_args_array + (cxy * CORES_MAX) + lid);
-
-            // create thread
+            // compute work thread tid
+            tid = (cid * ncores) + lid;
+
+            // set attributes for <work> thread[tid]
+            pthread_work_attr[tid].attributes = PT_ATTR_DETACH |
+                                                PT_ATTR_CLUSTER_DEFINED |
+                                                PT_ATTR_CORE_DEFINED;
+            pthread_work_attr[tid].cxy        = cxy;
+            pthread_work_attr[tid].lid        = lid;
+
+            // set tid and barrier arguments for <work> thread[tid]
+            pthread_work_args[tid].tid     = tid;
+            pthread_work_args[tid].barrier = barrier;
+
+            // create <work> thread
             if ( pthread_create( &trdid,                  // unused
-                                 &work_attr[cxy][lid],
+                                 &pthread_work_attr[tid],
                                  work_func,
-                                 work_args ) ) 
+                                 &pthread_work_args[tid] ) ) 
             {
-                printf("\n[ERROR] in %s : cannot create work thread[%x,%x]\n",
-                __FUNCTION__ , cxy , lid );
+                printf("\n[ERROR] in %s : <build> thread[%d][%d] cannot create <work> thread[%d]\n",
+                __FUNCTION__ , cid , level , tid );
 
                 // report error to parent
-                build_args[parent_cxy][level+1].error = 1;
+                pthread_build_args[parent_cid][level+1].error = 1;
             }
 
 #if DEBUG_PTHREAD_PARALLEL
-printf("\n[%s] <build> thread[%x][%d] created <work> thread[%x][%d]\n",
-__FUNCTION__, cxy, level, cxy, lid );
-#endif
-        }
-
-        // wait on barrier until "work" children threads completed
-        if( pthread_barrier_wait( &parent_barriers_array[cxy] ) )
-        {
-            printf("\n[ERROR] in %s / first barrier for <build> thread[%x][%d]\n",
-            __FUNCTION__ , cxy , level );
+printf("\n[%s] <build> thread[%d][%d] created <work> thread[%d]\n",
+__FUNCTION__, cid, level, tid );
+#endif
+        }
+
+        // wait on barrier until all <work> children threads completed
+        if( pthread_barrier_wait( barrier ) )
+        {
+            printf("\n[ERROR] in %s / barrier for <build> thread[%x][%d]\n",
+            __FUNCTION__ , cid , level );
 
             // report error to parent
-            build_args[parent_cxy][level+1].error = 1;
+            pthread_build_args[parent_cid][level+1].error = 1;
         }
 
 #if DEBUG_PTHREAD_PARALLEL
-printf("\n[%s] <build> thread[%x][%d] resume after children completion\n",
-__FUNCTION__, cxy, level );
+printf("\n[%s] <build> thread[%d][%d] resume after children completion\n",
+__FUNCTION__ , cid , level );
 #endif
 
@@ -1234,6 +1257,6 @@
     else                        // children are "build" threads 
     {
-        // the 4 children threads can be created in any core of each quarters
-        // of the parent macro-cluster
+        // the 4 children threads can be linked to any core in each
+        // sub-macro-cluster[i][j] with [ij] in {00,01,10,11}
 
         unsigned int parent_x;          // X coordinate of parent macro-cluster 
@@ -1241,11 +1264,12 @@
         unsigned int child_x;           // X coordinate of child macro-cluster
         unsigned int child_y;           // Y coordinate of child macro-cluster 
-        unsigned int child_cxy[2][2];   // selected cluster for child thread
-        unsigned int child_lid[2][2];   // selected core index for child thread
-        int          child_sts[2][2];   // -1 if error / 0 if success / +1 if not found
-        unsigned int x;                 // X loop index for children
-        unsigned int y;                 // Y loop index for children
-        
-        unsigned int nb_children = 0;
+        unsigned int child_cid[2][2];   // selected cluster cid for child[i][j]
+        unsigned int child_cxy[2][2];   // selected cluster cxy for child[i][j]
+        unsigned int child_lid[2][2];   // selected core index  for child[i][j]
+        int          child_sts[2][2];   // -1 if error / 0 if success / +1 if no core
+        unsigned int i;                 // loop index for children
+        unsigned int j;                 // loop index for children
+
+        unsigned int nb_children = 0;   // actual number of children (can be < 4)
 
         // get parent macro-cluster mask and half-size from level
@@ -1257,110 +1281,112 @@
         parent_y = HAL_Y_FROM_CXY( cxy ) & ~mask;
 
-        // get child_cxy and child_lid for up to 4 children threads : 00 / 01 / 10 / 11
-        for (x = 0 ; x < 2 ; x++)
+        // First step : select core for each child thread
+        for (i = 0 ; i < 2 ; i++)
         {
             // compute child macro-cluster X coordinate 
-            child_x = (x == 0) ? parent_x : (parent_x + half);
-
-            for (y = 0 ; y < 2 ; y++)
+            child_x = (i == 0) ? parent_x : (parent_x + half);
+
+            for (j = 0 ; j < 2 ; j++)
             {
                 // compute child macro-cluster Y coordinate 
-                child_y = (y == 0) ? parent_y : (parent_y + half);
+                child_y = (j == 0) ? parent_y : (parent_y + half);
 
                 // select the best core in macro-cluster 
-                child_sts[x][y] = get_best_core( HAL_CXY_FROM_XY( child_x , child_y ),
+                unsigned int best_cxy;
+                unsigned int best_lid;
+
+                child_sts[i][j] = get_best_core( HAL_CXY_FROM_XY( child_x , child_y ),
                                                  level-1,
-                                                 &child_cxy[x][y],
-                                                 &child_lid[x][y] );
-
-                if( child_sts[x][y] < 0 )  // failure => report error
+                                                 &best_cxy,
+                                                 &best_lid );
+
+                if( child_sts[i][j] < 0 )  // failure => report error
                 {
-                    printf("\n[ERROR] in %s : illegal arguments for <build> thread[%x,%x]\n",
-                    __FUNCTION__ , cxy , level );
+                    printf("\n[ERROR] in %s select core for child[%d,%d] of <build> thread[%d,%d]\n",
+                    __FUNCTION__ , i , j , cid , level );
 
                     // report error to parent
-                    build_args[parent_cxy][level+1].error = 1;
+                    pthread_build_args[parent_cid][level+1].error = 1;
                 }
-                else if (child_sts[x][y] > 0 )  // macro-cluster undefined => does nothing
+                else if (child_sts[i][j] > 0 )  // macro-cluster empty => does nothing
                 {
                 }
                 else                            // core found
                 {
+                    child_cxy[i][j] = best_cxy;
+                    child_lid[i][j] = best_lid;
+                    child_cid[i][j] = (HAL_X_FROM_CXY(best_cxy) * y_size) + HAL_Y_FROM_CXY( best_cxy);
                     nb_children++;
+
+#if DEBUG_PTHREAD_PARALLEL
+printf("\n[%s] <build> thread[%d][%d] select core[%x][%d] for child[%d][%d]\n",
+__FUNCTION__ , cid , level , best_cxy , best_lid , i , j );
+#endif
+
                 }
-            }  // end for y
-        }  // end for x
-
-        // kill process if no active core in cluster
-        // TODO this "if" should be replaced by an "assert" [AG]
-        if( nb_children == 0 )
-        {
-            printf("\n[PANIC] in %s : no active core in macro cluster [%x,%d]\n",
-            __FUNCTION__ , cxy , level );
+            }  // end for j
+        }  // end for i
+
+        // second step : initialize barrier for (nb_children + 1) in flat mode
+        if( pthread_barrier_init( barrier , NULL , nb_children + 1 ) )
+        {
+            printf("\n[ERROR] in %s : cannot init barrier for <build> thread[%d][%d]\n",
+            __FUNCTION__ , cid , level );
 
             // report error to parent
-            build_args[parent_cxy][level+1].error = 1;
-
-            // kill process
-            exit( EXIT_FAILURE );
-        }
-
-        // initialize the barrier for (nb_children + 1)
-        if( pthread_barrier_init( &build_barrier[cxy][level], NULL , nb_children + 1 ) )
-        {
-            printf("\n[error] in %s : cannot initialise barrier for build thread[%x][%d]\n",
-            __FUNCTION__ , cxy , level );
-
-            // report error to parent
-            build_args[parent_cxy][level+1].error = 1;
+            pthread_build_args[parent_cid][level+1].error = 1;
         }
 
 #if DEBUG_PTHREAD_PARALLEL
-printf("\n[%s] <build> thread[%x][%d] created barrier / %d children\n",
-__FUNCTION__, cxy, level, nb_children + 1 );
-#endif
-        // create 1 to 4 children threads
-        for (x = 0 ; x < 2 ; x++)
-        {
-            for (y = 0 ; y < 2 ; y++)
+printf("\n[%s] <build> thread[%d][%d] initialized barrier / %d children\n",
+__FUNCTION__, cid, level, nb_children );
+#endif
+
+        // Third step : actually create the children threads
+        for (i = 0 ; i < 2 ; i++)
+        {
+            for (j = 0 ; j < 2 ; j++)
             {
                 // thread is created only if macro-cluster is active
-                if( child_sts[x][y] == 0 )
+                if( child_sts[i][j] == 0 )
                 {
-                    unsigned int tgt_cxy = child_cxy[x][y];
-                    unsigned int tgt_lid = child_lid[x][y];
+                    unsigned int tgt_cid = child_cid[i][j];
+                    unsigned int tgt_lid = child_lid[i][j];
+                    unsigned int tgt_cxy = child_cxy[i][j];
 
                     // set child thread attributes
-                    build_attr[tgt_cxy][level-1].attributes = PT_ATTR_DETACH |
-                                                              PT_ATTR_CLUSTER_DEFINED |
-                                                              PT_ATTR_CORE_DEFINED;
-                    build_attr[tgt_cxy][level-1].cxy        = tgt_cxy;
-                    build_attr[tgt_cxy][level-1].lid        = tgt_lid;
-
-                    // propagate build function arguments
-                    build_args[tgt_cxy][level-1].cxy                   = child_cxy[x][y];
-                    build_args[tgt_cxy][level-1].level                 = level-1;
-                    build_args[tgt_cxy][level-1].parent_cxy            = cxy;
-                    build_args[tgt_cxy][level-1].root_level            = root_level;
-                    build_args[tgt_cxy][level-1].work_func             = work_func;
-                    build_args[tgt_cxy][level-1].work_args_array       = work_args_array;
-                    build_args[tgt_cxy][level-1].parent_barriers_array = parent_barriers_array;
+                    pthread_build_attr[tgt_cid][level-1].attributes = PT_ATTR_DETACH |
+                                                                      PT_ATTR_CLUSTER_DEFINED |
+                                                                      PT_ATTR_CORE_DEFINED;
+                    pthread_build_attr[tgt_cid][level-1].cxy        = tgt_cxy;
+                    pthread_build_attr[tgt_cid][level-1].lid        = tgt_lid;
+
+                    // propagate build function arguments from parent to child
+                    pthread_build_args[tgt_cid][level-1].cid            = tgt_cid;
+                    pthread_build_args[tgt_cid][level-1].level          = level-1;
+                    pthread_build_args[tgt_cid][level-1].parent_cid     = cid;
+                    pthread_build_args[tgt_cid][level-1].parent_barrier = barrier;
+                    pthread_build_args[tgt_cid][level-1].root_level     = root_level;
+                    pthread_build_args[tgt_cid][level-1].work_func      = work_func;
+                    pthread_build_args[tgt_cid][level-1].x_size         = x_size;
+                    pthread_build_args[tgt_cid][level-1].y_size         = y_size;
+                    pthread_build_args[tgt_cid][level-1].ncores         = ncores;
                     
                     // create thread
                     if( pthread_create( &trdid,                          
-                                        &build_attr[tgt_cxy][level-1],    
+                                        &pthread_build_attr[tgt_cid][level-1],    
                                         &pthread_recursive_build,                          
-                                        &build_args[tgt_cxy][level-1] ) )
+                                        &pthread_build_args[tgt_cid][level-1] ) )
                     {
-                        printf("\n[ERROR] in %s : cannot create build thread[%x][%d]\n",
-                        __FUNCTION__ , child_cxy , level -1 );
+                        printf("\n[ERROR] in %s : cannot create <build> thread[%x][%d]\n",
+                        __FUNCTION__ , child_cid , level -1 );
 
                         // report error to parent
-                        build_args[parent_cxy][level+1].error = 1;
+                        pthread_build_args[parent_cid][level+1].error = 1;
                     }
 
 #if DEBUG_PTHREAD_PARALLEL
-printf("\n[%s] <build> thread[%x][%d] created <build> thread[%x][%d] on core[%x,%d]\n",
-__FUNCTION__, cxy, level, tgt_cxy, level - 1, tgt_cxy, tgt_lid );
+printf("\n[%s] <build> thread[%d][%d] created <build> thread[%d][%d] on core[%x,%d]\n",
+__FUNCTION__, cid, level, tgt_cid, (level - 1), tgt_cxy, tgt_lid );
 #endif
                 }  //end if sts[x][y]
@@ -1368,17 +1394,17 @@
         }  // end for x
         
-        // wait on barrier until "build" children threads completed
-        if( pthread_barrier_wait( &build_barrier[cxy][level] ) )
-        {
-            printf("\n[ERROR] in %s / first barrier for <build> thread[%x][%d]\n",
-            __FUNCTION__ , cxy , level );
+        // wait on barrier until all <build> children threads completed
+        if( pthread_barrier_wait( barrier ) )
+        {
+            printf("\n[ERROR] in %s / barrier for <build> thread[%d][%d]\n",
+            __FUNCTION__ , cid , level );
 
             // report error to parent
-            build_args[parent_cxy][level+1].error = 1;
+            pthread_build_args[parent_cid][level+1].error = 1;
         }
 
 #if DEBUG_PTHREAD_PARALLEL
 printf("\n[%s] <build> thread[%x][%d] resume after children completion\n",
-__FUNCTION__, cxy, level );
+__FUNCTION__, cid, level );
 #endif
 
@@ -1386,61 +1412,73 @@
 
     // report error to parent when required
-    if( build_args[cxy][level].error )
-    {
-        build_args[parent_cxy][level+1].error = 1;
-    }
-
-    // all <build> threads - but the root - 
-    // signal completion to parent thread and exit 
+    if( pthread_build_args[cid][level].error )
+    {
+        pthread_build_args[parent_cid][level+1].error = 1;
+    }
+
+    // all <build> threads - but the root - signal completion to parent thread and exit 
     if( level < root_level )
     {
-        if( pthread_barrier_wait( &build_barrier[parent_cxy][level+1] ) )
-        {
-            printf("\n[ERROR] in %s / second barrier for <build> thread[%x][%d]\n",
-            __FUNCTION__ , cxy , level );
+        if( pthread_barrier_wait( parent_barrier ) )
+        {
+            printf("\n[ERROR] in %s / parent barrier for <build> thread[%d][%d]\n",
+            __FUNCTION__ , cid , level );
 
             // report error to parent
-            build_args[parent_cxy][level+1].error = 1;
+            pthread_build_args[parent_cid][level+1].error = 1;
         }
    
 #if DEBUG_PTHREAD_PARALLEL
 printf("\n[%s] <build> thread[%x][%d] exit\n",
-__FUNCTION__, cxy , level );
-#endif
-        // "build" thread exit
+__FUNCTION__, cid , level );
+#endif
+        // <build> thread exit
         pthread_exit( NULL );
     }
 }  // end pthread_recursive_build()
 
-///////////////////////////////////////////////////////
-int pthread_parallel_create( unsigned int   root_level,
-                             void         * work_func,
-                             void         * work_args_array,
-                             void         * parent_barriers_array )
-{
+
+//////////////////////////////////////////////////////
+int pthread_parallel_create( unsigned int  root_level,
+                             void        * work_func )
+{
+
+#if DEBUG_PTHREAD_PARALLEL
+printf("\n[%s] enter / root_level %d / func %x\n",
+__FUNCTION__, root_level, work_func );
+#endif
+
+    // get platform parameters
+    unsigned int   x_size;
+    unsigned int   y_size;
+    unsigned int   ncores;
+    get_config( &x_size , &y_size , &ncores );
+
+    // get calling thread cluster identifier
     unsigned int   root_cxy;
     unsigned int   root_lid;    // unused, but required by get_core_id()
+    get_core_id( &root_cxy , &root_lid );
+
+    // get calling thread continuous index
+    unsigned int x        = HAL_X_FROM_CXY( root_cxy );
+    unsigned int y        = HAL_Y_FROM_CXY( root_cxy );
+    unsigned int root_cid = (y_size * x) + y; 
+
+    // set the build function arguments for the root <build> thread
+    pthread_build_args[root_cid][root_level].cid               = root_cid; 
+    pthread_build_args[root_cid][root_level].level             = root_level;
+    pthread_build_args[root_cid][root_level].parent_cid        = -1;
+    pthread_build_args[root_cid][root_level].parent_barrier    = NULL;
+    pthread_build_args[root_cid][root_level].root_level        = root_level;
+    pthread_build_args[root_cid][root_level].work_func         = work_func;
+    pthread_build_args[root_cid][root_level].x_size            = x_size;
+    pthread_build_args[root_cid][root_level].y_size            = y_size;
+    pthread_build_args[root_cid][root_level].ncores            = ncores;
     
-#if DEBUG_PTHREAD_PARALLEL
-printf("\n[%s] enter / root_level %d / func %x / args %x / barriers %x\n",
-__FUNCTION__, root_level, work_func, work_args_array, parent_barriers_array );
-#endif
-
-    // get calling thread cluster
-    get_core_id( &root_cxy , &root_lid );
-
-    // set the build function arguments for the root <build> thread
-    build_args[root_cxy][root_level].cxy                   = root_cxy; 
-    build_args[root_cxy][root_level].level                 = root_level;
-    build_args[root_cxy][root_level].root_level            = root_level;
-    build_args[root_cxy][root_level].work_func             = work_func;
-    build_args[root_cxy][root_level].work_args_array       = work_args_array;
-    build_args[root_cxy][root_level].parent_barriers_array = parent_barriers_array;
-    
-    // call the recursive build function
-    pthread_recursive_build( &build_args[root_cxy][root_level] );
-
-    // check error
-    if( build_args[root_cxy][root_level].error )
+    // call the recursive function
+    pthread_recursive_build( &pthread_build_args[root_cid][root_level] );
+
+    // check error when execution completes
+    if( pthread_build_args[root_cid][root_level].error )
     {
         printf("\n[error] in  %s\n", __FUNCTION__ );
