Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Exploring Inline::C (Generating primes)

by wazoox (Prior)
on Oct 25, 2011 at 15:30 UTC ( [id://933638]=note: print w/replies, xml ) Need Help??


in reply to Exploring Inline::C (Generating primes)

Funnily, this doesn't work at all on my machine. The first test works fine, the second one ends with "Out of memory" after a long, painful swap to disk (obviously Test::More must be doing something wrong). Maybe it's a 5.14.0 bug?

Replies are listed 'Best First'.
Re^2: Exploring Inline::C (Generating primes)
by davido (Cardinal) on Oct 25, 2011 at 16:28 UTC

    Well that's strange. I've tested on the following Perls:

    • Windows Vista Home Premium 64 bit / Strawberry Perl version 5.12.3
    • Ubuntu Linux 32 bit version 11.10 / System Perl version 5.12.4
    • Ubuntu Linux 32 bit version 11.10 / Perlbrew-managed Perl version 5.14.2

    Is it possible that your Inline::C is installed using a different compiler from the one used to compile Perl? That can make a difference. When I installed using cpan Inline::C, I was prompted for which compiler to use, but the default had already detected the compiler used to compile Perl, so I just accepted the default.

    Test::More is used by just about every module you install, so I would be more inclined to put the blame on Inline::C than on Test::More.


    Dave

      Is it possible that your Inline::C is installed using a different compiler from the one used to compile Perl?

      No, I've compiled 5.14 myself on this same machine, so the same compiler was used to build the whole setup. But that maybe indeed the problem : maybe I'm running the original system perl? I'll double check and retry.

Re^2: Exploring Inline::C (Generating primes)
by davido (Cardinal) on Oct 26, 2011 at 21:43 UTC

    The first test works fine, the second one ends with "Out of memory" after a long, painful swap to disk

    Actually now that I re-read the description of your problem I have to conclude it probably has nothing at all to do with Inline::C. The second test is comparing the results of the pure Perl sub to the results of the sub that invokes an external program. That external program is the C++ program whos source I provided in my example.

    That program is not seen or touched by Inline::C. Inline::C doesn't know or care about it.

    The C++ program has to be saved in its own C++ source file, compiled, and linked to a filename that makes sense for your operating system. In fact whether it's Win32 or Linux, there's no harm in having an .exe suffix in this simple test case. Just compile the C++ source into an executable named 'primes.exe', and put it wherever the script will be able to find it (or specify a fully qualified path within the Perl script's call to primes.exe).

    Maybe you've already done all this. If you haven't, go ahead and do it now.

    The next step in sleuthing what's going wrong would be to invoke primes.exe (the executable built from the C++ source I provided). Invoke it with some smallish integer, like primes.exe 100. Then try it as primes.exe 100000, and again as primes.exe 1000000.

    If it runs properly in all those cases, there's no sane reason it shouldn't work from within your Perl script. If it doesn't run properly, perhaps you have a C++ compiler and library that lacks the Standard Template Library, which is a necessary component of the C++ program.

    If all else fails, you ought to be able to just remove the 2nd test, and remove all mention of the external_cpp() sub within the Perl script (remove the function's declaration/definition, and its use within the cmpthese() benchmark). Then you'll only be comparing the Inline::C function with the pure Perl one; you're taking the C++ program out of the equation.

    Hope this helps...


    Dave

      I've recompiled everything from the start, and it works somewhat better, though not very well in the end :) The c++ code goes well enough, but the Inline::C fails miserably:

      perl test.pl 1..3 /usr/local/bin/perl /usr/local/lib/perl5/5.14.0/ExtUtils/xsubpp -type +map /usr/local/lib/perl5/5.14.0/ExtUtils/typemap test_pl_97a8.xs > +test_pl_97a8.xsc && mv test_pl_97a8.xsc test_pl_97a8.c cc -c -I/home/emmanuel -D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasin +g -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D +_FILE_OFFSET_BITS=64 -O2 -DVERSION=\"0.00\" -DXS_VERSION=\"0.00\" - +fPIC "-I/usr/local/lib/perl5/5.14.0/i686-linux-thread-multi/CORE" t +est_pl_97a8.c test_pl_97a8.xs:6:3: erreur: directive de pré-traitement #Here invalid +e test_pl_97a8.xs:33:3: erreur: directive de pré-traitement #Cross inval +ide make: *** [test_pl_97a8.o] Erreur 1 A problem was encountered while attempting to compile and install your + Inline C code. The command that failed was: make > out.make 2>&1 The build directory was: /home/emmanuel/_Inline/build/test_pl_97a8 To debug the problem, cd to the build directory, and inspect the outpu +t files. at test.pl line 0 INIT failed--call queue aborted. # Looks like your test exited with 2 before it could output anything.

        That's not so miserable. ;) In fact, it's pretty much how any error message looks with Inline::C.

        Open the .xs file in the directory pointed to in the error message. Find the line mentioned in the error message (lines 6 and 33, I think). There is a problem somewhere nearby. Don't edit the XS file, edit the same line (but different line number) in your Perl/C source file.


        Dave

Re^2: Exploring Inline::C (Generating primes)
by syphilis (Archbishop) on Oct 26, 2011 at 07:44 UTC
    Maybe it's a 5.14.0 bug?

    No problem for me with 5.14.0 on Windows.
    The second test runs 'primes.exe' - perhaps there's a problem with the way that file is being executed (or built) on your system.

    Cheers,
    Rob
      Nope, the primes binary compiles and executes as expected by itself. It's only that the perl script goes awry...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://933638]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2024-03-29 10:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found