Calling D from Python. I have two functions in D, compiled to a shared
object on Linux using LDC (but I get same problem using DMD).

The sequential code:

    extern(C)
    double sequential(const int n, const double delta) {
      Runtime.initialize();
      const pi = 4.0 * delta * reduce!(
            (double t, int i){ immutable x = (i - 0.5) * delta; return t + 1.0 
/ (1.0 + x * x); })(
            0.0, iota(1, n + 1));
      Runtime.terminate();
      return pi;
    }

works entirely fine. However the "parallel" code:

    extern(C)
    double parallel(const int n, const double delta) {
      Runtime.initialize();
      const pi = 4.0 * delta * taskPool.reduce!"a + b"(
          map!((int i){ immutable x = (i - 0.5) * delta; return 1.0 / (1.0 + x 
* x); })(iota(1, n + 1)));
      Runtime.terminate();
      return pi;
    }

causes an immediate segfault (with LDC and DMD.  I am assuming that the
problem is the lack of initialization of the std.parallelism module and
hence the use of taskPool is causing a problem. I am betting I am
missing something very simple about module initialization, and that
this is not actually a bug.

Anyone any proposals?

-- 
Russel.
=============================================================================
Dr Russel Winder      t: +44 20 7585 2200   voip: sip:russel.win...@ekiga.net
41 Buckmaster Road    m: +44 7770 465 077   xmpp: rus...@winder.org.uk
London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to