Hello everyone,

For this week, I wanted to complete the OMPD library-wide functions, namely
the ompd_initialize and ompd_finalize.  I took notes from:
- https://www.openmp.org/wp-content/uploads/OpenMP-API-Specification-5.0.pdf
,
-
https://github.com/OpenMPToolsInterface/LLVM-openmp/blob/ompd-tests/libompd/src/omp-debug.cpp
,
and
-
https://github.com/OpenMPToolsInterface/OMPD-Technical-Report/blob/master/ompd-tr.pdf
.

It currently has some small changes (see attached) and wanted to get some
feedback on it and what more I should do for these functions.

In particular, I declared a non-static, non-const variable called
gompd_callbacks that would store an independent copy of ompd_callbacks_t.
This is different from how OpenMPToolsInterface's LLVM team has done it:
they have a static const variable that simply stores the pointer value that
was passed in.  The reason for my approach was because the
OpenMPToolsInterface's document repo stated that the argument passed in
cannot be assumed to be unchanged after the function call is completed.

My hesitation is because this is not specified in the OpenMP 5.0 API
specification document.

I would appreciate any feedback.

Cheers,

Tony Sim
From cef95b0d0c63eb364faa3d510f439bbf36a82999 Mon Sep 17 00:00:00 2001
From: y2s1982 <y2s1...@gmail.com>
Date: Tue, 30 Jun 2020 18:46:34 -0400
Subject: [PATCH] libompd: added more OMPD library-wide functions


2020-06-30  Tony Sim  <y2s1...@gmail.com>

libgomp/ChangeLog:

	* libgompd.h : Add gompd_callbacks variable.
	* ompd-lib.c (ompd_finalize): Add new function.

---
 libgomp/libgompd.h |  4 ++++
 libgomp/ompd-lib.c | 15 ++++++++++++++-
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/libgomp/libgompd.h b/libgomp/libgompd.h
index 9782828bff5..2aedeecaa38 100644
--- a/libgomp/libgompd.h
+++ b/libgomp/libgompd.h
@@ -29,9 +29,13 @@
 #ifndef LIBGOMPD_H
 #define LIBGOMPD_H 1
 
+#include "omp-tools.h"
+
 #define ompd_stringify(x) ompd_str2(x)
 #define ompd_str2(x) #x
 
 #define OMPD_VERSION 201811
 
+ompd_callbacks_t* gompd_callbacks;
+
 #endif /* LIBGOMPD_H */
diff --git a/libgomp/ompd-lib.c b/libgomp/ompd-lib.c
index f0ae9e85a7e..4513dadc070 100644
--- a/libgomp/ompd-lib.c
+++ b/libgomp/ompd-lib.c
@@ -28,6 +28,7 @@
 
 #include "omp-tools.h"
 #include "libgompd.h"
+#include <stdlib.h>
 
 ompd_rc_t
 ompd_get_api_version (ompd_word_t *version)
@@ -49,13 +50,25 @@ ompd_initialize (ompd_word_t api_version, const ompd_callbacks_t *callbacks)
 {
   static int ompd_initialized = 0;
 
+  if (!callbacks)
+    return ompd_rc_bad_input;
+
   if (ompd_initialized)
     return ompd_rc_error;
 
+  gompd_callbacks = malloc(sizeof(ompd_callbacks_t));
+  *gompd_callbacks  = *callbacks;
+
   (void) api_version;
-  (void) callbacks;
 
   ompd_initialized = 1;
 
   return ompd_rc_ok;
 }
+
+ompd_rc_t
+ompd_finalize(void)
+{
+  free (gompd_callbacks);
+  return ompd_rc_ok;
+}
-- 
2.27.0

Reply via email to