Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inline::C and openmp #47

Closed
jmricher70 opened this issue Aug 16, 2015 · 8 comments
Closed

Inline::C and openmp #47

jmricher70 opened this issue Aug 16, 2015 · 8 comments

Comments

@jmricher70
Copy link

Hi everybody,
I am new to perl and inline::C, anyway I could write some program to compute Mandelbrot set using a C function called from perl.
I would like to know if it is possible to compile this code with OpenMP ? I have tried to add this to the config section like
use Inline C => config => CCFLAGSEX => '-fopenmp';

but it does not seem to be taken into account when compiling.
So my question : is it possible and how to do it ?

Thank you for your help.

@mohawk2
Copy link
Collaborator

mohawk2 commented Aug 16, 2015

Normally you'd use (I think) CFLAGS - why do you want to use CCFLAGSEX?

@jmricher70
Copy link
Author

I didn't use CFLAGS because it reports some error : 'CFLAGS' is not a valid config option for Inline::C
So I used CCFLAGS.

use Inline C => Config => CCFLAGS => '-fopenmp', BUILD_NOISY => 1, LIBS => '-lgomp';
use Inline C =><<'END_OF_C_CODE';
.... C code ....
END_OF_C_CODE

mandel(-2.0, 1.0, 256, -1.0, 1.0, 256, 100000);

Now when I am testing the program (time ./perl mandelbrot_inline.pl) and I print the threads or use top to see how many threads are used I get only one thread. I tried to do
" export OMP_NUM_THREADS=2"
but still I have one thread

@mohawk2
Copy link
Collaborator

mohawk2 commented Aug 16, 2015

Could you try going into the build directory and modifying the Makefile such that it does work, and report here the changes you made?

@jmricher70
Copy link
Author

There is nothing in the _Inline/build directory, here is nevertheless the output of the compilation stage:

Starting Build Compile Stage
Starting "perl Makefile.PL" Stage
Generating a Unix-style Makefile
Writing Makefile for mandelbrot_inline_pl_8320
Writing MYMETA.yml and MYMETA.json
Finished "perl Makefile.PL" Stage

Starting "make" Stage
Running Mkbootstrap for mandelbrot_inline_pl_8320 ()
chmod 644 "mandelbrot_inline_pl_8320.bs"
"/usr/bin/perl" "/usr/share/perl/5.18/ExtUtils/xsubpp" -typemap "/usr/share/perl/5.18/ExtUtils/typemap" mandelbrot_inline_pl_8320.xs > mandelbrot_inline_pl_8320.xsc && mv mandelbrot_inline_pl_8320.xsc mandelbrot_inline_pl_8320.c
cc -c -I"/home/richer/dev/cpp/perl/inline" -fopenmp -O2 -g -DVERSION="0.00" -DXS_VERSION="0.00" -fPIC "-I/usr/lib/perl/5.18/CORE" mandelbrot_inline_pl_8320.c
rm -f blib/arch/auto/mandelbrot_inline_pl_8320/mandelbrot_inline_pl_8320.so
LD_RUN_PATH="/usr/lib/x86_64-linux-gnu" cc -shared -L/usr/local/lib -fstack-protector mandelbrot_inline_pl_8320.o -o blib/arch/auto/mandelbrot_inline_pl_8320/mandelbrot_inline_pl_8320.so
-lgomp \

chmod 755 blib/arch/auto/mandelbrot_inline_pl_8320/mandelbrot_inline_pl_8320.so
"/usr/bin/perl" -MExtUtils::Command::MM -e 'cp_nonempty' -- mandelbrot_inline_pl_8320.bs blib/arch/auto/mandelbrot_inline_pl_8320/mandelbrot_inline_pl_8320.bs 644
Finished "make" Stage

Starting "make install" Stage
Running Mkbootstrap for mandelbrot_inline_pl_8320 ()
chmod 644 "mandelbrot_inline_pl_8320.bs"
Files found in blib/arch: installing files in blib/lib into architecture dependent library tree
Installing /home/richer/dev/cpp/perl/inline/_Inline/lib/auto/mandelbrot_inline_pl_8320/mandelbrot_inline_pl_8320.so
Finished "make install" Stage

Starting Cleaning Up Stage
Finished Cleaning Up Stage

Finished Build Compile Stage

@mohawk2
Copy link
Collaborator

mohawk2 commented Aug 16, 2015

Thanks. You'll need to specify clean_after_build => 0 to not zap the build files.

This:

cc -c -I"/home/richer/dev/cpp/perl/inline" -fopenmp -O2 -g -DVERSION=\"0.00\" -DXS_VERSION=\"0.00\" -fPIC "-I/usr/lib/perl/5.18/CORE" mandelbrot_inline_pl_8320.c

shows that ccflagsex is working correctly, so there isn't obviously a problem with Inline::C. However, I'm still interested in learning how the problem is happening.

@jmricher70
Copy link
Author

Thank you very much for your help, I will continue to search for a solution ;-) I will post it here if I can find

@jmricher70
Copy link
Author

So I have tried the following solutions with OpenMP :

  • inline::C : not working, just one thread used
  • XS : not working, just one thread used
  • SWIG : working !!!!!
    does someone have any idea about why it is not working with XS or inline::C ?

@jmricher70
Copy link
Author

It seems I finally found the reason it is not working. I have by default a clang compiler installed and Inline::C is using it instead of gcc. So I have added in the configuration :

use Inline C => Config => CC => '/usr/bin/gcc', ...

and it works now !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants