Index: trunk/user/sort/sort.c
===================================================================
--- trunk/user/sort/sort.c	(revision 436)
+++ trunk/user/sort/sort.c	(revision 440)
@@ -27,9 +27,14 @@
 #include <pthread.h>
 
-#define ARRAY_LENGTH    0x100    // 256 values
-#define VERBOSE         0
+#define ARRAY_LENGTH        0x100    // 256 values
+
+#define MAX_THREADS         1024     // 16 * 16 * 4
+
+#define DISPLAY_ARRAY       0
+#define DISPLAY_THREADS     1
 
 ///////////////////////////////////////////////////////
 // macros for fixed format cxy <=> (x,y) translation
+// TODO these macros are only for TSAR architecture... 
 ///////////////////////////////////////////////////////
 
@@ -61,4 +66,6 @@
 pthread_barrier_t   barrier;                 // synchronisation variables
 
+pthread_attr_t      attr[MAX_THREADS];       // thread attributes (one per thread)
+args_t              arg[MAX_THREADS];        // sort function arguments (one per thread)
 
 ////////////////////////////////////
@@ -135,7 +142,13 @@
     unsigned int       i;
     unsigned long long cycle;
+    unsigned int       cxy;
+    unsigned int       lid;
 
     int         * src_array  = NULL;
     int         * dst_array  = NULL;
+
+    // get core coordinates an date
+    get_core( &cxy , &lid );
+    get_cycle( &cycle );
 
     unsigned int  thread_uid = ptr->thread_uid;
@@ -143,11 +156,11 @@
     unsigned int  main_uid   = ptr->main_uid;
 
+printf("\n### core[%x,%d] enter sort : threads %d / thread_uid %x / main_uid %x / cycle %d\n",
+cxy, lid, threads, thread_uid, main_uid, (int)cycle );
+
+    while( 1 ) { asm volatile("nop"); }
+
     unsigned int  items      = ARRAY_LENGTH / threads;
     unsigned int  stages     = __builtin_ctz( threads ) + 1;
-    
-    get_cycle( &cycle );
-    printf("\n[SORT] thread[%d] enter at cycle %d\n", thread_uid , (unsigned int)cycle );
-
-    printf("\n[SORT] thread[%d] / stage 0 start\n", thread_uid );
 
     bubbleSort( array0, items, items * thread_uid );
@@ -157,4 +170,6 @@
     /////////////////////////////////
     pthread_barrier_wait( &barrier ); 
+
+    printf("\n[SORT] thread[%d] exit barrier\n", thread_uid );
 
     // the number of threads contributing to sort
@@ -220,6 +235,4 @@
     pthread_t              trdid;              // kernel allocated thread index (unused)
     pthread_barrierattr_t  barrier_attr;       // barrier attributes
-    pthread_attr_t         attr[1024];         // thread attributes (one per thread)
-    args_t                 arg[1024];          // sort function arguments (one per thread)
 
     // compute number of threads (one thread per proc)
@@ -251,6 +264,6 @@
 
     get_cycle( &cycle );
-    printf("\n[SORT] starts : %d threads / %d values / cycle %d\n",
-    threads, ARRAY_LENGTH , (unsigned int)cycle );
+    printf("\n\n[SORT] main starts on core[%x,%d] / %d threads / %d values / cycle %d\n",
+    main_cxy, main_lid, threads, ARRAY_LENGTH, (unsigned int)cycle );
 
     // Barrier initialization
@@ -265,5 +278,5 @@
 
     get_cycle( &cycle );
-    printf("\n[SORT] completes barrier init at cycle %d\n", (unsigned int)cycle );
+    printf("\n[SORT] main completes barrier init at cycle %d\n", (unsigned int)cycle );
 
     // Array to sort initialization
@@ -273,5 +286,5 @@
     }
 
-#if VERBOSE
+#if DISPLAY_ARRAY
 printf("\n*** array before sort\n");
 for( n=0; n<ARRAY_LENGTH; n++) printf("array[%d] = %d\n", n , array0[n] );
@@ -279,5 +292,5 @@
 
     get_cycle( &cycle );
-    printf("\n[SORT] completes array init at cycle %d\n", (unsigned int)cycle );
+    printf("\n[SORT] main completes array init at cycle %d\n", (unsigned int)cycle );
 
     // launch other threads to execute sort() function
@@ -303,4 +316,9 @@
                 if( thread_uid != main_uid )
                 {
+
+get_cycle( &cycle );
+printf("\n### main creates thread_uid %d / &sort_arg %x / cycle %d\n",
+thread_uid, &arg[thread_uid], (unsigned int)cycle );
+
                     if ( pthread_create( &trdid,              // not used because no join
                                          &attr[thread_uid],   // thread attributes 
@@ -308,17 +326,20 @@
                                          &arg[thread_uid] ) ) // sort arguments
                     {
-                        printf("\n[SORT ERROR] creating thread %x\n", thread_uid );
+                        printf("\n[SORT ERROR] main created thread %x \n", thread_uid );
                         exit( 0 );
                     }
+                }
          
-                }
-            }
-        }
-    }
-
-    get_cycle( &cycle );
-    printf("\n[SORT] completes threads create at cycle %d\n", (unsigned int)cycle );
-
-   // main run also the sort() function
+#if DISPLAY_THREADS
+display_sched( CXY_FROM_XY(x,y) , lid );
+#endif
+            }
+        }
+    }
+
+    get_cycle( &cycle );
+    printf("\n[SORT] main completes threads create at cycle %d\n", (unsigned int)cycle );
+
+    // main run also the sort() function
     sort( &arg[main_uid] );
 
@@ -335,4 +356,6 @@
         if ( res_array[n] > res_array[n+1] )
         {
+            printf("\n[SORT] array[%d] = %d > array[%d] = %d\n",
+            n , res_array[n] , n+1 , res_array[n+1] );
             success = 0;
             break;
@@ -340,5 +363,5 @@
     }
 
-#if VERBOSE
+#if DISPLAY_ARRAY
 printf("\n*** array after sort\n");
 for( n=0; n<ARRAY_LENGTH; n++) printf("array[%d] = %d\n", n , res_array[n] );
