Segmentation fault on FFI call containing OpenMP clause

  • From: Ciprian Tomoiaga <ciprian.tomoiaga@xxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Tue, 9 Dec 2014 20:51:58 +0100

Hi all,

I am writing to ask for methods of debugging the following scenario.
I have a C function containing OpenMP clause which I call with ffi. On my
machine, the program terminates with a segmentation fault. However, it
works without a problem on a Mac and on another machine. Here is my small
example:

//---- test.c -------------
#include <stdio.h>
#include <omp.h>

// gcc -std=c99 -Wall -pedantic -fopenmp -shared -fPIC test.c -o libtest.so

void parallel_test() {
  #pragma omp parallel num_threads(2)
  {
    printf("In Parallel\n");
  }
}
--------------------------------
--- test.lua --------
local ffi = require "ffi"
local testLib = ffi.load("./libtest.so")
ffi.cdef[[
  void parallel_test();
]]
testLib.parallel_test()
-----------------------
Now call
​:​
luajit test.lua

My machine, Linux Mint 17, based on Ubuntu 14.04, compiled with gcc (v4.7,
v4.8, v4.9) results in Segmentation fault when num_threads is greater than
1.
A Mac machine, compiled with gcc v4.9 works fine.
Another Linux machine, SLC 6.6, based on RHEL6, compiled with gcc v4.4
works fine. Moreover, I did a crazy (stupid?) thing and ran it with the .so
compiled for my machine, and still worked fine (intel CPUs both, different
versions).

Can anyone please point me towards what tools I can use to debug this
problem? I expect valgrind would be the choice, but I'm not sure how to use
it with LuaJIT.

Many thanks everyone!

Regards,
Ciprian

Other related posts: