Index: soft/giet_vm/applications/rosenfeld/include/clock.h
===================================================================
--- soft/giet_vm/applications/rosenfeld/include/clock.h	(revision 823)
+++ soft/giet_vm/applications/rosenfeld/include/clock.h	(revision 826)
@@ -9,4 +9,10 @@
     #include <x86intrin.h>
     #include <sys/time.h>
+
+    typedef uint64_t cl_size_t;
+    #define MAX_CLOCK_VAL 0xFFFFFFFFFFFFFFFFLU
+#elif TARGET_OS == GIETVM
+    typedef uint32_t cl_size_t;
+    #define MAX_CLOCK_VAL 0xFFFFFFFF
 #endif
 
@@ -37,9 +43,9 @@
 
 
-static void local_sort_asc(uint64_t tab[], int32_t size) {
-    uint64_t tmp;
+static void local_sort_asc(cl_size_t tab[], int32_t size) {
+    cl_size_t tmp;
     int32_t i, j;
     for (i = 0; i < size; i++) {
-        uint64_t min = tab[i];
+        cl_size_t min = tab[i];
         int32_t jmin = i;
         for (j = i + 1; j < size; j++) {
@@ -57,25 +63,25 @@
 
 
-#define CLOCK_DEC uint64_t app_start;                   \
-                  uint64_t app_end;                     \
-                  uint64_t app_create;                  \
-                  uint64_t app_join;                    \
-                  uint64_t * thread_start;              \
-                  uint64_t * thread_end;                \
-                  uint64_t * thread_compute_start;      \
-                  uint64_t * thread_compute_end;        \
+#define CLOCK_DEC cl_size_t app_start;                   \
+                  cl_size_t app_end;                     \
+                  cl_size_t app_create;                  \
+                  cl_size_t app_join;                    \
+                  cl_size_t * thread_start;              \
+                  cl_size_t * thread_end;                \
+                  cl_size_t * thread_compute_start;      \
+                  cl_size_t * thread_compute_end;        \
                   int32_t step_number;                  \
                   int32_t clock_thread_num;             \
                   int32_t clock_num_runs;               \
-                  uint64_t ** thread_start_step;        \
-                  uint64_t ** thread_end_step;          \
-                  uint64_t global_thread_start;         \
-                  uint64_t global_thread_end;           \
-                  uint64_t global_thread_compute_start; \
-                  uint64_t global_thread_compute_end;   \
-                  uint64_t accumulated_thread_compute;  \
-                  uint64_t * global_thread_start_step;  \
-                  uint64_t * global_thread_end_step;    \
-                  uint64_t * accumulated_thread_step;
+                  cl_size_t ** thread_start_step;        \
+                  cl_size_t ** thread_end_step;          \
+                  cl_size_t global_thread_start;         \
+                  cl_size_t global_thread_end;           \
+                  cl_size_t global_thread_compute_start; \
+                  cl_size_t global_thread_compute_end;   \
+                  cl_size_t accumulated_thread_compute;  \
+                  cl_size_t * global_thread_start_step;  \
+                  cl_size_t * global_thread_end_step;    \
+                  cl_size_t * accumulated_thread_step;
 
 #if TARGET_OS == GIETVM
@@ -85,5 +91,5 @@
             struct timeval full_time;         \
             gettimeofday(&full_time, NULL);   \
-            x = (uint64_t) ((full_time.tv_usec + full_time.tv_sec * 1000000)); \
+            x = (cl_size_t) ((full_time.tv_usec + full_time.tv_sec * 1000000)); \
             }) */
     #define CLOCK(x) ({ x = __rdtsc(); })
@@ -91,33 +97,33 @@
 
 // x = number of threads, y = number of steps
-#define CLOCK_INIT(x, y) ({                                                         \
-    clock_thread_num = (x);                                                         \
-    step_number = (y);                                                              \
-    clock_num_runs = 0;                                                             \
-    global_thread_start = 0xFFFFFFFFFFFFFFFFLLU;                                    \
-    global_thread_end = 0;                                                          \
-    global_thread_compute_start = 0xFFFFFFFFFFFFFFFFLLU;                            \
-    global_thread_compute_end = 0;                                                  \
-    accumulated_thread_compute = 0;                                                 \
-    if ((x) > 0) {                                                                  \
-        thread_start = (uint64_t *) malloc(sizeof(uint64_t) * (x));                 \
-        thread_end = (uint64_t *) malloc(sizeof(uint64_t) * (x));                   \
-        thread_compute_start = (uint64_t *) malloc(sizeof(uint64_t) * (x));         \
-        thread_compute_end = (uint64_t *) malloc(sizeof(uint64_t) * (x));           \
-        if ((y) > 0) {                                                              \
-            global_thread_start_step = (uint64_t *) malloc(sizeof(uint64_t) * (y)); \
-            global_thread_end_step = (uint64_t *) malloc(sizeof(uint64_t) * (y));   \
-            thread_start_step = (uint64_t **) malloc(sizeof(uint64_t *) * (y));     \
-            thread_end_step = (uint64_t **) malloc(sizeof(uint64_t *) * (y));       \
-            accumulated_thread_step = (uint64_t *) malloc(sizeof(uint64_t) * (y));  \
-            for (int32_t j = 0; j < (y); j++) {                                     \
-                global_thread_start_step[j] = 0xFFFFFFFFFFFFFFFFLLU;                \
-                global_thread_end_step[j] = 0;                                      \
-                accumulated_thread_step[j] = 0;                                     \
-                thread_start_step[j] = (uint64_t *) malloc(sizeof(uint64_t) * (x)); \
-                thread_end_step[j] = (uint64_t *) malloc(sizeof(uint64_t) * (x));   \
-            }                                                                       \
-        }                                                                           \
-    }                                                                               \
+#define CLOCK_INIT(x, y) ({                                                           \
+    clock_thread_num = (x);                                                           \
+    step_number = (y);                                                                \
+    clock_num_runs = 0;                                                               \
+    global_thread_start = MAX_CLOCK_VAL;                                              \
+    global_thread_end = 0;                                                            \
+    global_thread_compute_start = MAX_CLOCK_VAL;                                      \
+    global_thread_compute_end = 0;                                                    \
+    accumulated_thread_compute = 0;                                                   \
+    if ((x) > 0) {                                                                    \
+        thread_start = (cl_size_t *) malloc(sizeof(cl_size_t) * (x));                 \
+        thread_end = (cl_size_t *) malloc(sizeof(cl_size_t) * (x));                   \
+        thread_compute_start = (cl_size_t *) malloc(sizeof(cl_size_t) * (x));         \
+        thread_compute_end = (cl_size_t *) malloc(sizeof(cl_size_t) * (x));           \
+        if ((y) > 0) {                                                                \
+            global_thread_start_step = (cl_size_t *) malloc(sizeof(cl_size_t) * (y)); \
+            global_thread_end_step = (cl_size_t *) malloc(sizeof(cl_size_t) * (y));   \
+            thread_start_step = (cl_size_t **) malloc(sizeof(cl_size_t *) * (y));     \
+            thread_end_step = (cl_size_t **) malloc(sizeof(cl_size_t *) * (y));       \
+            accumulated_thread_step = (cl_size_t *) malloc(sizeof(cl_size_t) * (y));  \
+            for (int32_t j = 0; j < (y); j++) {                                       \
+                global_thread_start_step[j] = MAX_CLOCK_VAL;                          \
+                global_thread_end_step[j] = 0;                                        \
+                accumulated_thread_step[j] = 0;                                       \
+                thread_start_step[j] = (cl_size_t *) malloc(sizeof(cl_size_t) * (x)); \
+                thread_end_step[j] = (cl_size_t *) malloc(sizeof(cl_size_t) * (x));   \
+            }                                                                         \
+        }                                                                             \
+    }                                                                                 \
 })
 
@@ -153,9 +159,9 @@
     for (int32_t j = 0; j < step_number; j++) {                          \
         accumulated_thread_step[j] += (global_thread_end_step[j] - global_thread_start_step[j]); \
-        global_thread_start_step[j] = 0xFFFFFFFFFFFFFFFFLLU;             \
+        global_thread_start_step[j] = MAX_CLOCK_VAL;                     \
         global_thread_end_step[j] = 0;                                   \
     }                                                                    \
     accumulated_thread_compute += (global_thread_compute_end - global_thread_compute_start); \
-    global_thread_compute_start = 0xFFFFFFFFFFFFFFFFLLU;                 \
+    global_thread_compute_start = MAX_CLOCK_VAL;                         \
     global_thread_compute_end = 0;                                       \
     clock_num_runs++;                                                    \
@@ -192,4 +198,6 @@
 
 
+#if TARGET_OS == LINUX
+
 #define PRINT_CLOCK ({                                                                                                        \
     MCA_VERBOSE1(printf("Timestamps:\n"));                                                                                    \
@@ -198,26 +206,26 @@
         MCA_VERBOSE1(printf("(are those of the last run)\n"));                                                                \
     }                                                                                                                         \
-    MCA_VERBOSE1(printf("[APP_START]            : %llu\n", app_start));                                                       \
-    MCA_VERBOSE1(printf("[APP_CREATE]           : %llu\n", app_create));                                                      \
-    MCA_VERBOSE1(printf("[THREAD_START]         : %llu\n", global_thread_start));                                             \
-    MCA_VERBOSE1(printf("[THREAD_COMPUTE_START] : %llu\n", global_thread_compute_start));                                     \
+    MCA_VERBOSE1(printf("[APP_START]            : %llu\n", (long long unsigned int) app_start));                              \
+    MCA_VERBOSE1(printf("[APP_CREATE]           : %llu\n", (long long unsigned int) app_create));                             \
+    MCA_VERBOSE1(printf("[THREAD_START]         : %llu\n", (long long unsigned int) global_thread_start));                    \
+    MCA_VERBOSE1(printf("[THREAD_COMPUTE_START] : %llu\n", (long long unsigned int) global_thread_compute_start));            \
     for (int32_t j = 0; j < step_number; j++) {                                                                               \
-        MCA_VERBOSE1(printf("[THREAD_START_STEP_%d]  : %llu\n", j, global_thread_start_step[j]));                             \
-        MCA_VERBOSE1(printf("[THREAD_END_STEP_%d]    : %llu\n", j, global_thread_end_step[j]));                               \
-    }                                                                                                                         \
-    MCA_VERBOSE1(printf("[THREAD_COMPUTE_END]   : %llu\n", global_thread_compute_end));                                       \
-    MCA_VERBOSE1(printf("[THREAD_END]           : %llu\n", global_thread_end));                                               \
-    MCA_VERBOSE1(printf("[APP_JOIN]             : %llu\n", app_join));                                                        \
-    MCA_VERBOSE1(printf("[APP_END]              : %llu\n", app_end));                                                         \
+        MCA_VERBOSE1(printf("[THREAD_START_STEP_%d]  : %llu\n", j, (long long unsigned int) global_thread_start_step[j]));    \
+        MCA_VERBOSE1(printf("[THREAD_END_STEP_%d]    : %llu\n", j, (long long unsigned int) global_thread_end_step[j]));      \
+    }                                                                                                                         \
+    MCA_VERBOSE1(printf("[THREAD_COMPUTE_END]   : %llu\n", (long long unsigned int) global_thread_compute_end));              \
+    MCA_VERBOSE1(printf("[THREAD_END]           : %llu\n", (long long unsigned int) global_thread_end));                      \
+    MCA_VERBOSE1(printf("[APP_JOIN]             : %llu\n", (long long unsigned int) app_join));                               \
+    MCA_VERBOSE1(printf("[APP_END]              : %llu\n", (long long unsigned int) app_end));                                \
     MCA_VERBOSE1(printf("Durations (in cycles):\n"));                                                                         \
     if (clock_num_runs > 1) {                                                                                                 \
         MCA_VERBOSE1(printf("(PARALLEL_COMPUTE and THREAD_STEPs are averaged over %d runs)\n", clock_num_runs));              \
     }                                                                                                                         \
-    MCA_VERBOSE1(printf("[TOTAL]                : %llu\n", app_end - app_start));                                             \
-    MCA_VERBOSE1(printf("[THREAD]               : %llu\n", app_join - app_create));                                           \
-    MCA_VERBOSE1(printf("[PARALLEL]             : %llu\n", global_thread_end - global_thread_start));                         \
-    MCA_VERBOSE1(printf("[PARALLEL_COMPUTE]     : %llu\n", accumulated_thread_compute / clock_num_runs));                     \
+    MCA_VERBOSE1(printf("[TOTAL]                : %llu\n", (long long unsigned int) app_end - app_start));                    \
+    MCA_VERBOSE1(printf("[THREAD]               : %llu\n", (long long unsigned int) app_join - app_create));                  \
+    MCA_VERBOSE1(printf("[PARALLEL]             : %llu\n", (long long unsigned int) global_thread_end - global_thread_start));\
+    MCA_VERBOSE1(printf("[PARALLEL_COMPUTE]     : %llu\n", (long long unsigned int) accumulated_thread_compute / clock_num_runs)); \
     for (int32_t j = 0; j < step_number; j++) {                                                                               \
-        MCA_VERBOSE1(printf("[THREAD_STEP_%d]        : %llu\n", j, accumulated_thread_step[j] / clock_num_runs));             \
+        MCA_VERBOSE1(printf("[THREAD_STEP_%d]        : %llu\n", j, (long long unsigned int) accumulated_thread_step[j] / clock_num_runs)); \
     }                                                                                                                         \
     MCA_VERBOSE1(printf("\n"));                                                                                               \
@@ -233,16 +241,71 @@
     MCA_VERBOSE1(printf("# cycle     thread_id\n"));                                                                          \
     for (int32_t i = 0; i < clock_thread_num; i++) {                                                                          \
-        MCA_VERBOSE1(printf("%llu\t%d\n", thread_start[i] - app_start, i));                                                   \
-        MCA_VERBOSE1(printf("%llu\t%d\n", thread_compute_start[i] - app_start, i));                                           \
+        MCA_VERBOSE1(printf("%llu\t%d\n", (long long unsigned int) thread_start[i] - app_start, i));                          \
+        MCA_VERBOSE1(printf("%llu\t%d\n", (long long unsigned int) thread_compute_start[i] - app_start, i));                  \
         for (int32_t j = 0; j < step_number; j++) {                                                                           \
-            MCA_VERBOSE1(printf("%llu\t%d\n", thread_start_step[j][i] - app_start, i));                                       \
-            MCA_VERBOSE1(printf("%llu\t%d\n", thread_end_step[j][i] - app_start, i));                                         \
+            MCA_VERBOSE1(printf("%llu\t%d\n", (long long unsigned int) thread_start_step[j][i] - app_start, i));              \
+            MCA_VERBOSE1(printf("%llu\t%d\n", (long long unsigned int) thread_end_step[j][i] - app_start, i));                \
         }                                                                                                                     \
-        MCA_VERBOSE1(printf("%llu\t%d\n", thread_compute_end[i] - app_start, i));                                             \
-        MCA_VERBOSE1(printf("%llu\t%d\n", thread_end[i] - app_start, i));                                                     \
-    }                                                                                                                         \
-})
-
-                
+        MCA_VERBOSE1(printf("%llu\t%d\n", (long long unsigned int) thread_compute_end[i] - app_start, i));                    \
+        MCA_VERBOSE1(printf("%llu\t%d\n", (long long unsigned int) thread_end[i] - app_start, i));                            \
+    }                                                                                                                         \
+})
+
+#elif TARGET_OS == GIETVM
+
+#define PRINT_CLOCK ({                                                                                           \
+    MCA_VERBOSE1(printf("Timestamps:\n"));                                                                       \
+    if (clock_num_runs > 1) {                                                                                    \
+        MCA_VERBOSE1(printf("(THREAD_COMPUTE_START, THREAD_COMPUTE_END, THREAD_START_STEPs and THREAD_END_STEPs)\n")); \
+        MCA_VERBOSE1(printf("(are those of the last run)\n"));                                                   \
+    }                                                                                                            \
+    MCA_VERBOSE1(printf("[APP_START]            : %d\n",  app_start));                                           \
+    MCA_VERBOSE1(printf("[APP_CREATE]           : %d\n", app_create));                                           \
+    MCA_VERBOSE1(printf("[THREAD_START]         : %d\n", global_thread_start));                                  \
+    MCA_VERBOSE1(printf("[THREAD_COMPUTE_START] : %d\n", global_thread_compute_start));                          \
+    for (int32_t j = 0; j < step_number; j++) {                                                                  \
+        MCA_VERBOSE1(printf("[THREAD_START_STEP_%d]  : %d\n", j, global_thread_start_step[j]));                  \
+        MCA_VERBOSE1(printf("[THREAD_END_STEP_%d]    : %d\n", j, global_thread_end_step[j]));                    \
+    }                                                                                                            \
+    MCA_VERBOSE1(printf("[THREAD_COMPUTE_END]   : %d\n", global_thread_compute_end));                            \
+    MCA_VERBOSE1(printf("[THREAD_END]           : %d\n", global_thread_end));                                    \
+    MCA_VERBOSE1(printf("[APP_JOIN]             : %d\n", app_join));                                             \
+    MCA_VERBOSE1(printf("[APP_END]              : %d\n", app_end));                                              \
+    MCA_VERBOSE1(printf("Durations (in cycles):\n"));                                                            \
+    if (clock_num_runs > 1) {                                                                                    \
+        MCA_VERBOSE1(printf("(PARALLEL_COMPUTE and THREAD_STEPs are averaged over %d runs)\n", clock_num_runs)); \
+    }                                                                                                            \
+    MCA_VERBOSE1(printf("[TOTAL]                : %d\n", app_end - app_start));                                  \
+    MCA_VERBOSE1(printf("[THREAD]               : %d\n", app_join - app_create));                                \
+    MCA_VERBOSE1(printf("[PARALLEL]             : %d\n", global_thread_end - global_thread_start));              \
+    MCA_VERBOSE1(printf("[PARALLEL_COMPUTE]     : %d\n", accumulated_thread_compute / clock_num_runs));          \
+    for (int32_t j = 0; j < step_number; j++) {                                                                  \
+        MCA_VERBOSE1(printf("[THREAD_STEP_%d]        : %d\n", j, accumulated_thread_step[j] / clock_num_runs));  \
+    }                                                                                                            \
+    MCA_VERBOSE1(printf("\n"));                                                                                  \
+    MCA_VERBOSE1(printf("*** All threads times output in a gnuplot data-style ***\n"));                          \
+    local_sort_asc(thread_start, clock_thread_num);                                                              \
+    local_sort_asc(thread_compute_start, clock_thread_num);                                                      \
+    local_sort_asc(thread_compute_end, clock_thread_num);                                                        \
+    local_sort_asc(thread_end, clock_thread_num);                                                                \
+    for (int32_t j = 0; j < step_number; j++) {                                                                  \
+        local_sort_asc(thread_start_step[j], clock_thread_num);                                                  \
+        local_sort_asc(thread_end_step[j], clock_thread_num);                                                    \
+    }                                                                                                            \
+    MCA_VERBOSE1(printf("# cycle     thread_id\n"));                                                             \
+    for (int32_t i = 0; i < clock_thread_num; i++) {                                                             \
+        MCA_VERBOSE1(printf("%d\t%d\n", thread_start[i] - app_start, i));                                        \
+        MCA_VERBOSE1(printf("%d\t%d\n", thread_compute_start[i] - app_start, i));                                \
+        for (int32_t j = 0; j < step_number; j++) {                                                              \
+            MCA_VERBOSE1(printf("%d\t%d\n", thread_start_step[j][i] - app_start, i));                            \
+            MCA_VERBOSE1(printf("%d\t%d\n", thread_end_step[j][i] - app_start, i));                              \
+        }                                                                                                        \
+        MCA_VERBOSE1(printf("%d\t%d\n", thread_compute_end[i] - app_start, i));                                  \
+        MCA_VERBOSE1(printf("%d\t%d\n", thread_end[i] - app_start, i));                                          \
+    }                                                                                                            \
+})
+
+
+#endif
 
 
