OMPT Callbacks not being called

OMPT Callbacks not being called

Hi Intel OpenMP team!

    I am trying to get a simple "Hello, World!" application up and running with OMPT. I downloaded the 20160808 version of the OpenMP runtime and built it with both gcc and clang on Ubuntu 14.04. I manually ran some "expand-vars.pl" scripts to create the needed header files because the build system didn't do it for some reason. I have an Intel i5 CPU. If it is helpful, my Cmake invocation strings for each configuration were: 

cmake -DCMAKE_C_COMPILER=/home/stone_cold_hughes/llvm_dir/build/bin/clang -DLIBOMP_ARCH=32e -DLIBOMP_OMPT_SUPPORT=on -G "Unix Makefiles
and:
cmake -DCMAKE_C_COMPILER=gcc -DLIBOMP_ARCH=32e -DLIBOMP_OMPT_SUPPORT=on -G "Unix Makefiles"

Once libiomp5.so was created, I examined the symbols within with "nm" and found all of my callback functions as well as what appeared to be all OMPT functions. I compiled my program, "main.c" with the following compiler strings with clang and gcc:

clang -I/home/stone_cold_hughes/libomp_oss/src -L/home/stone_cold_hughes/libomp_oss/src -liomp5 main.c -o main
gcc -I/home/stone_cold_hughes/libomp_oss/src -L/home/stone_cold_hughes/libomp_oss/src -fopenmp main.c -o main

and it compiled with no warnings or errors in both cases. My program is:

#include "omp.h"
#include "ompt.h"
#include "stdio.h"
#include "stdlib.h"

/*A useful typecast*/
typedef int (*callback_typecast)(ompt_event_t, ompt_callback_t);

void thread_begin_cb(ompt_thread_id_t thread_id)
{
  printf("Hello, World! It's thread %lu\n", thread_id);

  return;
}

/*This function registers a "Hello World" callback for the thread_begin event*/
void ompt_initialize
  (
   ompt_function_lookup_t lookup
  ,const char *runtime_version
  ,unsigned int ompt_version
  )
{
  /*set the event I am registering for*/
  ompt_event_t ompt_event = ompt_event_thread_begin;

  /*Get a handle to the "set_callback" function*/
  ompt_interface_fn_t ompt_set_callback_ptr = lookup("ompt_set_callback");

  /*Use the handle to register the "Hello World" callback with the thread_begin event*/
  ((callback_typecast)(*ompt_set_callback_ptr))(ompt_event, ((ompt_callback_t)thread_begin_cb));

  return;
}

/*This function returns the initializer function above*/
ompt_initialize_t ompt_tool(void)
{
  return &ompt_initialize;
}

int main (int argc, char *argv[])
{
  int tid;

  /*As a sanity check, have each thread print it's ID*/
#pragma omp parallel private(tid)
  {
    tid = omp_get_thread_num();

    printf("Thread %d\n", tid);

  }

}

I expect to see a lot of "Hello, World!" printouts, but I get nothing, even when I flush stdout. All I get is the sanity check printf() in main:

Thread 0
Thread 2
Thread 3
Thread 1

In some random order. Can anyone help me figure out why my callback isn't being invoked?? I have spend many days on this and am my wit's end. Any help is greatly appreciated.

AttachmentSize
Downloadtext/x-csrc main.c1.22 KB

Thread Topic: 

Help Me
3 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.
Best Reply

Hi Harry H.

You most likely don't have your newly built library accessible at run-time.  Try to set LD_LIBRARY_PATH, e.g.:

  export LD_LIBRARY_PATH=/home/stone_cold_hughes/libomp_oss/src:$LD_LIBRARY_PATH

if your library was built in this directory.

I tried your test and get the following output (though I also enabled -DLIBOMP_OMPT_DEBUG=on for the library build to see more OMPT output, and copied the built library, links and include files in the current directory):

$ gcc -fopenmp test.c -I. -L.

$ LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH OMP_NUM_THREADS=4 ./a.out
ompt_pre_init(): tool_setting = 1
ompt_pre_init(): ompt_enabled = 1
Hello, World! It's thread 1
Thread 0
Hello, World! It's thread 2
Thread 3
Hello, World! It's thread 2
Thread 2
Hello, World! It's thread 2
Thread 1

Regards,
Andrey
 

Andrey,

    That was my issue, I changed my LD_LIBRARY_PATH and got the same output as you. Thank you!

Sincerely,

Harry Hughes

Leave a Comment

Please sign in to add a comment. Not a member? Join today