commit 023e6482d98f8e62a9496f3fd1c11e72e88bad55
Author: François Trahay <francois.trahay@telecom-sudparis.eu>
Date:   Tue Aug 23 11:38:50 2022 +0200

    fix header compatibility issues when linking against opari2

diff --git a/src/modules/omp/gomp.c b/src/modules/omp/gomp.c
index 2c1fd517..6ef52892 100644
--- a/src/modules/omp/gomp.c
+++ b/src/modules/omp/gomp.c
@@ -67,14 +67,20 @@ static void openmp_register_functions();
 
 struct ezt_hashtable lock_map;
 
+typedef int EZT_Region_handle;
+typedef struct {
+  int creating_thread; // the thread who created the task
+  int generation_number; // thread-private generation number of task's creating thread
+} EZT_Task_handle;
+
 /* TODO: does it work with nested parallelism ? */
 /* each thread has its own counter */
-static __thread POMP2_Region_handle _next_section_id = -1;
+static __thread EZT_Region_handle _next_section_id = -1;
 
-static POMP2_Region_handle _get_next_section_id() {
+static EZT_Region_handle _get_next_section_id() {
 //  /* make sure that the counters of each thread do not collide */
 //  if (_next_section_id < 0) {
-//    /* POMP2_Region_handle is an int, this will work for:
+//    /* EZT_Region_handle is an int, this will work for:
 //     * - ~ 2^11 threads
 //     * - ~ 2^20 parallel region created by a thread
 //     */
@@ -112,7 +118,8 @@ static POMP2_Region_handle _get_next_section_id() {
 /* event issued by the master thread before #pragma omp parallel  */
 void openmp_parallel_fork_generic(POMP2_Region_handle* pomp2_handle,
 				 int num_threads) {
-  *pomp2_handle = ezt_otf2_register_thread_team("OpenMP Thread Team", num_threads);
+  EZT_Region_handle *ezt_handle = (EZT_Region_handle*)pomp2_handle;
+  *ezt_handle = ezt_otf2_register_thread_team("OpenMP Thread Team", num_threads);
   if(EZTRACE_SAFE) {
     OTF2_ErrorCode err =  OTF2_EvtWriter_ThreadFork( evt_writer,
 						     NULL,
@@ -143,7 +150,9 @@ void openmp_parallel_begin_generic(POMP2_Region_handle* pomp2_handle) {
 
   int nb_threads = omp_get_num_threads();
   int my_id = omp_get_thread_num();
-  int thread_team = *pomp2_handle;
+  EZT_Region_handle *ezt_handle = (EZT_Region_handle*)pomp2_handle;
+
+  int thread_team = *ezt_handle;
   ezt_otf2_register_thread_team_member(thread_team, my_id, nb_threads);
 
   if(EZTRACE_SAFE) {
@@ -159,7 +168,8 @@ void openmp_parallel_begin_generic(POMP2_Region_handle* pomp2_handle) {
 
 /* event issued by each thread of an OpenMP team at the end of a #pragma omp parallel block */
 void openmp_parallel_end_generic(POMP2_Region_handle* pomp2_handle) {
-  int thread_team = *pomp2_handle;
+  EZT_Region_handle *ezt_handle = (EZT_Region_handle*)pomp2_handle;
+  int thread_team = *ezt_handle;
   if(EZTRACE_SAFE) {
     OTF2_ErrorCode err = OTF2_EvtWriter_ThreadTeamEnd(evt_writer,
 						      NULL,
@@ -191,7 +201,7 @@ void (*libGOMP_parallel_loop_runtime)(void (*)(void*), void*, unsigned, long, lo
 struct gomp_arg_t {
   void (*func)(void*);
   void* data;
-  POMP2_Region_handle id;
+  EZT_Region_handle id;
 };
 
 /* Function called by GOMP_parallel_start for each thread */
@@ -200,12 +210,13 @@ void gomp_new_thread(void* arg) {
   struct gomp_arg_t* _arg = (struct gomp_arg_t*)arg;
   void (*func)(void*) = _arg->func;
   void* data = _arg->data;
-  POMP2_Region_handle section_id = _arg->id;
+  EZT_Region_handle section_id = _arg->id;
+  POMP2_Region_handle *pomp2_section_id = (POMP2_Region_handle *)&section_id;
   if(!pomp2_found)
-    openmp_parallel_begin_generic(&section_id);
+    openmp_parallel_begin_generic(pomp2_section_id);
   func(data);
   if(!pomp2_found)
-    openmp_parallel_end_generic(&section_id);
+    openmp_parallel_end_generic(pomp2_section_id);
   return;
 }
 
@@ -226,10 +237,11 @@ void gomp_new_thread(void* arg) {
 
 #define GOMP4_PARALLEL_LOOP_GENERIC(fn, data, num_threads, varname, gomp_func) \
   {									\
-    POMP2_Region_handle section_id = -1;				\
+    EZT_Region_handle section_id = -1;					\
+    POMP2_Region_handle *pomp2_section_id = (POMP2_Region_handle *)&section_id;	\
     if(!pomp2_found) {							\
       /* the application was not instrumented, so we need to record events when intercepting the libGOMP API */ \
-      openmp_parallel_fork_generic(&section_id, num_threads);		\
+      openmp_parallel_fork_generic(pomp2_section_id, num_threads);	\
     }									\
     GOMP_PARALLEL_LOOP_GENERIC(fn, data, varname, gomp_func, section_id); \
   }
@@ -240,7 +252,7 @@ void gomp_new_thread(void* arg) {
 #define GOMP3_PARALLEL_LOOP_GENERIC(fn, data, varname, gomp_func)	\
   {									\
     OMP_ENTER(openmp_parallel_id);					\
-    POMP2_Region_handle section_id = _get_next_section_id();		\
+    EZT_Region_handle section_id = _get_next_section_id();		\
     GOMP_PARALLEL_LOOP_GENERIC(fn, data, varname, gomp_func, section_id); \
     return;								\
   }
@@ -640,11 +652,11 @@ void POMP2_Ordered_exit(
   OMP_LEAVE(openmp_ordered_id);
 }
 
-static _Thread_local POMP2_Task_handle task_handle = {.creating_thread = -1,
+static _Thread_local EZT_Task_handle task_handle = {.creating_thread = -1,
 						      .generation_number = -1};
 #define DEFAULT_STACK_SIZE 1024
 struct _ezt_task_stack {
-  POMP2_Task_handle *stack;
+  EZT_Task_handle *stack;
   int alloc_size; // number of allocated spots
   int index; // index of the next empty spot in the stack
 };
@@ -654,11 +666,11 @@ _task_stack = {
 	       .alloc_size = 0,
 	       .index = 0};
 
-void task_stack_push(POMP2_Task_handle *t) {
+void task_stack_push(EZT_Task_handle *t) {
   while(_task_stack.index >= _task_stack.alloc_size) {
     /* stack is full. Allocate more spots */
     int new_size = _task_stack.alloc_size ? _task_stack.alloc_size * 2 : DEFAULT_STACK_SIZE;
-    void* ptr = realloc(_task_stack.stack, new_size * sizeof(POMP2_Task_handle));
+    void* ptr = realloc(_task_stack.stack, new_size * sizeof(EZT_Task_handle));
     if(!ptr) {
       eztrace_error("Cannot allocated memory\n");
     }
@@ -666,7 +678,7 @@ void task_stack_push(POMP2_Task_handle *t) {
     _task_stack.alloc_size = new_size;
   }
 
-  memcpy(&_task_stack.stack[_task_stack.index], t, sizeof(POMP2_Task_handle));
+  memcpy(&_task_stack.stack[_task_stack.index], t, sizeof(EZT_Task_handle));
   _task_stack.index++;
 }
 
@@ -674,14 +686,14 @@ void task_stack_pop() {
   eztrace_assert(_task_stack.index > 0);
   //#if DEBUG
 #if 1
-  memset(&_task_stack.stack[_task_stack.index-1], -1, sizeof(POMP2_Task_handle));
+  memset(&_task_stack.stack[_task_stack.index-1], -1, sizeof(EZT_Task_handle));
 #endif
   _task_stack.index--;
 }
 
 int task_stack_size() { return _task_stack.index; }
 
-POMP2_Task_handle * task_stack_top() {
+EZT_Task_handle * task_stack_top() {
   if(task_stack_size() > 0)
     return &_task_stack.stack[_task_stack.index-1];
   return NULL;
@@ -697,47 +709,52 @@ void _ezt_task_create(POMP2_Region_handle* pomp2_handle,
    * In order to keep the overhead as low as possible, let's only record the event.
    */
   if(EZTRACE_SAFE) {
+    EZT_Region_handle *ezt_handle = (EZT_Region_handle*)pomp2_handle;
+    int thread_team = *ezt_handle;
 
-    int thread_team = *pomp2_handle;
+    EZT_Task_handle *ezt_new_task = (EZT_Task_handle *) pomp2_new_task;
 
     if(task_handle.generation_number < 0) {
       task_handle.creating_thread = otf2_thread_id;
       task_handle.generation_number = 0;
     }
 
-    memcpy(pomp2_new_task, &task_handle, sizeof(task_handle));
+    memcpy(ezt_new_task, &task_handle, sizeof(task_handle));
     task_handle.generation_number++;
     OTF2_ErrorCode err = OTF2_EvtWriter_ThreadTaskCreate(evt_writer,
 							 NULL,
 							 ezt_get_timestamp(),
 							 thread_team,
 							 otf2_thread_id,
-							 pomp2_new_task->generation_number);
+							 ezt_new_task->generation_number);
     eztrace_assert(err == OTF2_SUCCESS);
   }
 }
 
 void _ezt_task_begin(POMP2_Region_handle* pomp2_handle,
                       POMP2_Task_handle pomp2_task) {
-  int thread_team = *pomp2_handle;
+  EZT_Region_handle *ezt_handle = (EZT_Region_handle*)pomp2_handle;
+  int thread_team = *ezt_handle;
   if(EZTRACE_SAFE) {
 
-    task_stack_push(&pomp2_task);
+    EZT_Task_handle *task_handle = (EZT_Task_handle *)&pomp2_task;
+    task_stack_push(task_handle);
     OTF2_ErrorCode err = OTF2_EvtWriter_ThreadTaskSwitch(evt_writer,
 							 NULL,
 							 ezt_get_timestamp(),
 							 thread_team,
-							 pomp2_task.creating_thread,
-							 pomp2_task.generation_number);
+							 task_handle->creating_thread,
+							 task_handle->generation_number);
     eztrace_assert(err == OTF2_SUCCESS);
   }
 }
 void ezt_task_end(POMP2_Region_handle* pomp2_handle) {
 
-  int thread_team = *pomp2_handle;
+  EZT_Region_handle *ezt_handle = (EZT_Region_handle*)pomp2_handle;
+  int thread_team = *ezt_handle;
 
   if(EZTRACE_SAFE) {
-    POMP2_Task_handle *current_omp_task = task_stack_top();
+    EZT_Task_handle *current_omp_task = task_stack_top();
     eztrace_assert(current_omp_task);
     eztrace_assert(current_omp_task->creating_thread >= 0);
     eztrace_assert(current_omp_task->generation_number >= 0);
