Quantcast
Channel: Intel® Software - Intel® C++ Compiler
Viewing all articles
Browse latest Browse all 1175

Cannot call OpenMP functions from libiomp after calling from libomp

$
0
0

Hi,

when a program loads both libiomp and libomp with dlopen, calling an OpenMP function from one then from the other one can cause the program to terminate, depending on the order of the calls.

calling from libiomp first, then from libomp is fine. The issue is when calling from libomp first and then from libiomp.

Here is a reproducible example: test.c

#include <stdlib.h>
#include <dlfcn.h>

int main(int argc, char **argv){
    // load libomp and libiomp
    void *libomp_handle = dlopen("path/to/libomp.so", RTLD_NOW);
    void *libiomp_handle = dlopen("path/to/libiomp5.so", RTLD_NOW);
   
    // get "omp_get_max_threads" from each library
    int (*libiomp_get_max_threads)() = (int (*)()) dlsym(libiomp_handle, "omp_get_num_threads");
    int (*libomp_get_max_threads)() = (int (*)()) dlsym(libomp_handle, "omp_get_max_threads");

    // switch order of calls causes SIGABRT
    libomp_get_max_threads();
    libiomp_get_max_threads();

    return 0;
}

Compile and run:

    icc test.c -o test -ldl && ./test

Error Message:

OMP: Error #13: Assertion failure at z_Linux_util.cpp(2338). OMP: Hint Please submit a bug report with this message, compile and run commands used, and machine configuration info including native compiler and operating system versions. Faster response will be obtained by including all program sources. For information on submitting this issue, please see http://www.intel.com/software/products/support/.

Backtrace:

#0 0x00007ffff783e428 in raise () from /lib/x86_64-linux-gnu/libc.so.6

#1 0x00007ffff784002a in abort () from /lib/x86_64-linux-gnu/libc.so.6

#2 0x00007ffff6f7b2c3 in __kmp_abort_process () at ../../src/kmp_runtime.cpp:481

#3 0x00007ffff6f66237 in __kmp_fatal (message=...) at ../../src/kmp_i18n.cpp:894

#4 0x00007ffff6f3a82c in __kmp_debug_assert (msg=0x76c5 <error: Cannot access memory at address 0x76c5>, file=0x76c5 <error: Cannot access memory at address 0x76c5>, line=6) at ../../src/kmp_debug.cpp:100

#5 0x00007ffff6fb57ee in __kmp_is_address_mapped (addr=0x76c5) at ../../src/z_Linux_util.cpp:2337

#6 0x00007ffff6f78f87 in __kmp_register_library_startup () at ../../src/kmp_runtime.cpp:6684

#7 0x00007ffff6f7a49b in _INTERNAL_25_______src_kmp_runtime_cpp_ddfed41b::__kmp_do_serial_initialize () at ../../src/kmp_runtime.cpp:6834

#8 _INTERNAL_25_______src_kmp_runtime_cpp_ddfed41b::__kmp_do_middle_initialize () at ../../src/kmp_runtime.cpp:7146

#9 __kmp_middle_initialize () at ../../src/kmp_runtime.cpp:7255

#10 0x00007ffff6f5ad75 in __kmp_api_omp_get_max_threads () at ../../src/kmp_ftn_entry.h:366

#11 0x00000000004006ab in main ()

 

Some remarks:

- Loading libgomp instead of libomp does not raise the error

- Link libraries instead of dlopen does not raise the error

- I know it's bad practice to load different OpenMP runtimes simultaneously. And in fact I have to set KMP_DUPLICATE_LIB_OK=TRUE otherwise it does not work at all. But in the python ecosystem, you can easily install packages from pre-built binaries and we don't know in advance which compiler has been used. For instance if one package uses MKL and another one uses OpenMP and is built with clang.

 

Thanks for your help


Viewing all articles
Browse latest Browse all 1175

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>