ompt-general.c

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * system include files
00003  ****************************************************************************/
00004 
00005 #include <assert.h>
00006 
00007 #include <stdint.h>
00008 #include <stdio.h>
00009 #include <stdlib.h>
00010 #include <string.h>
00011 
00012 
00013 
00014 /*****************************************************************************
00015  * ompt include files
00016  ****************************************************************************/
00017 
00018 #include "ompt-internal.h"
00019 #include "ompt-specific.c"
00020 
00021 
00022 
00023 /*****************************************************************************
00024  * macros
00025  ****************************************************************************/
00026 
00027 // these return codes and the event macros still need some work
00028 //
00029 #define set_success 3
00030 #define set_failure 0
00031 
00032 #define get_success 1
00033 #define get_failure 0
00034 
00035 #define no_tool_present 0
00036 
00037 
00038 
00039 /*****************************************************************************
00040  * types
00041  ****************************************************************************/
00042 
00043 typedef struct {
00044   char *state_name;
00045   ompt_state_t  state_id;
00046 } ompt_state_info_t;
00047 
00048 
00049 
00050 /*****************************************************************************
00051  * global variables
00052  ****************************************************************************/
00053 
00054 ompt_status_t ompt_status = ompt_status_ready;
00055 
00056 
00057 ompt_state_info_t ompt_state_info[] = {
00058 #define ompt_state(state, code) { # state, state },
00059 #include "ompt-state.h"
00060 };
00061 
00062 
00063 ompt_callbacks_t ompt_callbacks;
00064 
00065 _OMP_EXTERN char **ompd_dll_locations;
00066 
00067 
00068 
00069 /*****************************************************************************
00070  * state
00071  ****************************************************************************/
00072 
00073 
00074 
00075 _OMP_EXTERN int ompt_enumerate_state(int current_state, int *next_state, 
00076                                      const char **next_state_name)
00077 {
00078   const static int len = sizeof(ompt_state_info) / sizeof(ompt_state_info_t);
00079   int i = 0;
00080 
00081   for (i = 0; i < len - 1; i++) {
00082     if (ompt_state_info[i].state_id == current_state) {
00083       *next_state = ompt_state_info[i+1].state_id;
00084       *next_state_name = ompt_state_info[i+1].state_name;
00085       return 1;
00086     }
00087   }
00088 
00089   return 0;
00090 }
00091 
00092 
00093 
00094 /*****************************************************************************
00095  * callbacks 
00096  ****************************************************************************/
00097 
00098 _OMP_EXTERN int ompt_set_callback(ompt_event_t evid, ompt_callback_t cb)
00099 {
00100   switch (evid) {
00101 
00102 #define ompt_event(event_name, callback_type, event_id, is_impl) \
00103   case event_name: \
00104     if (is_impl) { \
00105       ompt_callbacks.ompt_callback(event_name) = (callback_type) cb; \
00106       return set_success; \
00107     } \
00108     return set_failure; 
00109 
00110 #include "ompt-event.h"
00111 
00112   default: return set_failure;
00113   }
00114 }
00115 
00116 
00117 _OMP_EXTERN int ompt_get_callback(ompt_event_t evid, ompt_callback_t *cb)
00118 {
00119   switch (evid) {
00120 
00121 #define ompt_event(event_name, callback_type, event_id, is_impl) \
00122   case event_name:  \
00123     if (is_impl) { \
00124       ompt_callback_t mycb = \
00125         (ompt_callback_t) ompt_callbacks.ompt_callback(event_name); \
00126       if (mycb) { \
00127         *cb = mycb; \
00128          return get_success; \
00129       } \
00130     } \
00131     return get_failure; 
00132 
00133 #include "ompt-event.h"
00134 
00135   default: return get_failure;
00136   }
00137 }
00138 
00139 
00140 
00141 /*****************************************************************************
00142  * intialization/finalization
00143  ****************************************************************************/
00144 
00145 _OMP_EXTERN __attribute__ (( weak )) int ompt_initialize()
00146 {
00147   return no_tool_present;
00148 }
00149 
00150 
00151 void ompt_init()
00152 {
00153    char *ompt_env_var = getenv("OMPT_INITIALIZE");
00154 
00155    int ompt_env_var_is_true = ompt_env_var && !strcmp(ompt_env_var, "true");
00156    int ompt_env_var_is_disabled = ompt_env_var && !strcmp(ompt_env_var, "disabled");
00157    int ompt_env_var_is_false = ompt_env_var && !strcmp(ompt_env_var, "false");
00158    int ompt_env_var_is_null = ompt_env_var && !strcmp(ompt_env_var, "");
00159 
00160    ompd_dll_locations = (char **) malloc(sizeof(char **));
00161    ompd_dll_locations[0] = NULL;
00162 
00163    if (!ompt_env_var || ompt_env_var_is_null) {
00164       int ompt_init_val = ompt_initialize();
00165       if (ompt_init_val) ompt_status = ompt_status_track_callback;
00166       // else remain in ready
00167    } else if (ompt_env_var_is_true) {
00168       int ompt_init_val = ompt_initialize();
00169       ompt_status = (ompt_init_val ? ompt_status_track_callback : ompt_status_track);
00170    } else if (ompt_env_var_is_false) {
00171       // no-op: remain in ready
00172    } else if (ompt_env_var_is_disabled) {
00173       ompt_status = ompt_status_disabled;
00174    } else {
00175       fprintf(stderr,"OMPT: warning: OMPT_INITIALIZE has invalid value.\n"
00176                      "      legal values are (NULL,\"\",\"true\",\"false\",\"disabled\").\n");
00177    }
00178 }
00179 
00180 
00181 void ompt_fini()
00182 {
00183    if (ompt_status == ompt_status_track_callback) {
00184      if (ompt_callbacks.ompt_callback(ompt_event_runtime_shutdown)) {
00185        ompt_callbacks.ompt_callback(ompt_event_runtime_shutdown)();
00186      }
00187    }
00188 
00189    ompt_status = ompt_status_disabled;
00190 }
00191 
00192 
00193 
00194 /*****************************************************************************
00195  * parallel regions
00196  ****************************************************************************/
00197 
00198 _OMP_EXTERN ompt_parallel_id_t ompt_get_parallel_id(int ancestor_level)
00199 {
00200    return __ompt_get_parallel_id_internal(ancestor_level);
00201 }
00202 
00203 
00204 _OMP_EXTERN void *ompt_get_parallel_function(int ancestor_level) 
00205 {
00206    return __ompt_get_parallel_function_internal(ancestor_level);
00207 }
00208 
00209 
00210 _OMP_EXTERN ompt_state_t ompt_get_state(ompt_wait_id_t *ompt_wait_id)
00211 {
00212    ompt_state_t thread_state = __ompt_get_state_internal(ompt_wait_id);
00213 
00214    if (thread_state == ompt_state_undefined) {
00215      thread_state = ompt_state_work_serial;
00216    }
00217 
00218    return thread_state;
00219 }
00220 
00221 
00222 
00223 /*****************************************************************************
00224  * threads
00225  ****************************************************************************/
00226 
00227 
00228 _OMP_EXTERN void *ompt_get_idle_frame()
00229 {
00230    return __ompt_get_idle_frame_internal();
00231 }
00232 
00233 
00234 
00235 /*****************************************************************************
00236  * tasks
00237  ****************************************************************************/
00238 
00239 _OMP_EXTERN ompt_task_id_t ompt_get_task_id(int ancestor_level)
00240 {
00241   return __ompt_get_task_id_internal(ancestor_level); 
00242 }
00243 
00244 
00245 _OMP_EXTERN ompt_frame_t *ompt_get_task_frame(int ancestor_level)
00246 {
00247   return __ompt_get_task_frame_internal(ancestor_level); 
00248 }
00249 
00250 
00251 _OMP_EXTERN void *ompt_get_task_function(int ancestor_level)
00252 {
00253   return __ompt_get_task_function_internal(ancestor_level); 
00254 }
00255 
00256 
00257 
00258 /*****************************************************************************
00259  * compatability
00260  ****************************************************************************/
00261 
00262 _OMP_EXTERN int ompt_get_ompt_version()
00263 {
00264   return OMPT_VERSION;
00265 }
00266 
00267 
00268 
00269 /*****************************************************************************
00270  * application-facing API
00271  ****************************************************************************/
00272 
00273 
00274 /*----------------------------------------------------------------------------
00275  | control
00276  ---------------------------------------------------------------------------*/
00277 
00278 _OMP_EXTERN void ompt_control(uint64_t command, uint64_t modifier)
00279 {
00280    if (ompt_status == ompt_status_track_callback) {
00281      if (ompt_callbacks.ompt_callback(ompt_event_control)) {
00282        ompt_callbacks.ompt_callback(ompt_event_control)(command, modifier);
00283      }
00284    }
00285 }
00286 
00287 /*----------------------------------------------------------------------------
00288  | runtime version
00289  ---------------------------------------------------------------------------*/
00290 
00291 _OMP_EXTERN int ompt_get_runtime_version(char *buffer, int length)
00292 {
00293   return __ompt_get_runtime_version_internal(buffer,length);
00294 }
00295 

Generated on 25 Aug 2013 for libomp_oss by  doxygen 1.6.1