Thread overview | |||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
September 19, 2015 Debugging D shared libraries | ||||
---|---|---|---|---|
| ||||
Attachments:
| 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.winder@ekiga.net 41 Buckmaster Road m: +44 7770 465 077 xmpp: russel@winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder
|
September 19, 2015 Re: Debugging D shared libraries | ||||
---|---|---|---|---|
| ||||
Posted in reply to Russel Winder | On Saturday, 19 September 2015 at 10:45:22 UTC, Russel Winder wrote:
> 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).
>
> [...]
I heard it crashed during the talk. Bummer. I should really be there, seeing as I live about 15 mins away. If you get a chance to talk to Alex Bishop, don't be too harsh on D to him, I'm trying to convince him to make the switch :)
|
September 19, 2015 Re: Debugging D shared libraries | ||||
---|---|---|---|---|
| ||||
Posted in reply to Russel Winder | On Saturday, 19 September 2015 at 10:45:22 UTC, Russel Winder wrote: > 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? Try using an explicit TaskPool and destroying it with scope(exit). Also if using LDC, you can use global ctor/dtor to deal with the runtime. ----------------------->8--------------------- extern (C) { pragma(LDC_global_crt_ctor, 0) void initRuntime() { import core.runtime; Runtime.initialize(); } pragma(LDC_global_crt_dtor, 0) void deinitRuntime() { import core.runtime; Runtime.terminate(); } } ----------------------->8--------------------- |
September 19, 2015 Re: Debugging D shared libraries | ||||
---|---|---|---|---|
| ||||
Posted in reply to ponce Attachments:
| On Sat, 2015-09-19 at 12:21 +0000, ponce via Digitalmars-d-learn wrote: > […] > > Try using an explicit TaskPool and destroying it with scope(exit). > > > Also if using LDC, you can use global ctor/dtor to deal with the runtime. > > > ----------------------->8--------------------- > > extern (C) { > pragma(LDC_global_crt_ctor, 0) > void initRuntime() > { > import core.runtime; > Runtime.initialize(); > } > pragma(LDC_global_crt_dtor, 0) > void deinitRuntime() > { > import core.runtime; > Runtime.terminate(); > } > } > > ----------------------->8--------------------- > Hummm… I now do not get a segfault, and the code runs as expected : -))))) but the program never terminates. :-( Also, what would I need to cover the DMD and the GDC situations? -- Russel. ============================================================================= Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.winder@ekiga.net 41 Buckmaster Road m: +44 7770 465 077 xmpp: russel@winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder |
September 19, 2015 Re: Debugging D shared libraries | ||||
---|---|---|---|---|
| ||||
Posted in reply to Russel Winder | On Saturday, 19 September 2015 at 15:42:15 UTC, Russel Winder wrote: > > Hummm… I now do not get a segfault, and the code runs as expected : > -))))) but the program never terminates. :-( Where is it stuck? > > Also, what would I need to cover the DMD and the GDC situations? I don't know. :( |
September 19, 2015 Re: Debugging D shared libraries | ||||
---|---|---|---|---|
| ||||
Posted in reply to ponce Attachments:
| On Sat, 2015-09-19 at 15:58 +0000, ponce via Digitalmars-d-learn wrote: > On Saturday, 19 September 2015 at 15:42:15 UTC, Russel Winder wrote: > > > > Hummm… I now do not get a segfault, and the code runs as > > expected : > > -))))) but the program never terminates. :-( > > Where is it stuck? I commented out the : //pragma(LDC_global_crt_dtor, 0) //void deinitRuntime() { //import core.runtime: Runtime; //Runtime.terminate(); //} and it now works fine :-))))) > > > > Also, what would I need to cover the DMD and the GDC situations? > > I don't know. :( Let's hope DMD and GDC folk chip in :-) Sadly the: pragma(LDC_global_crt_ctor, 0) void initRuntime() { import core.runtime: Runtime; Runtime.initialize(); } will not compile under DMD :-( -- Russel. ============================================================================= Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.winder@ekiga.net 41 Buckmaster Road m: +44 7770 465 077 xmpp: russel@winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder |
September 19, 2015 Re: Debugging D shared libraries | ||||
---|---|---|---|---|
| ||||
Posted in reply to ponce | On Saturday, 19 September 2015 at 12:21:02 UTC, ponce wrote:
> On Saturday, 19 September 2015 at 10:45:22 UTC, Russel Winder wrote:
>> 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?
>
> Try using an explicit TaskPool and destroying it with scope(exit).
>
>
> Also if using LDC, you can use global ctor/dtor to deal with the runtime.
>
>
> ----------------------->8---------------------
>
> extern (C) {
> pragma(LDC_global_crt_ctor, 0)
> void initRuntime()
> {
> import core.runtime;
> Runtime.initialize();
> }
> pragma(LDC_global_crt_dtor, 0)
> void deinitRuntime()
> {
> import core.runtime;
> Runtime.terminate();
> }
> }
>
> ----------------------->8---------------------
What is the difference between shared static this and the global constructor ? Russell, if you use shared static this for dmd does it work ? Laeeth.
|
September 19, 2015 Re: Debugging D shared libraries | ||||
---|---|---|---|---|
| ||||
Posted in reply to Laeeth Isharc | On Saturday, 19 September 2015 at 16:25:28 UTC, Laeeth Isharc wrote:
>
> What is the difference between shared static this and the global constructor ? Russell, if you use shared static this for dmd does it work ? Laeeth.
Would like to know too. On OSX I've found that shared static this() was called by Runtime.initialize(), maybe it's different on Linux.
|
September 19, 2015 Re: Debugging D shared libraries | ||||
---|---|---|---|---|
| ||||
Posted in reply to John Colvin Attachments:
| On Sat, 2015-09-19 at 11:07 +0000, John Colvin via Digitalmars-d-learn wrote: > […] > I heard it crashed during the talk. Bummer. I should really be there, seeing as I live about 15 mins away. If you get a chance to talk to Alex Bishop, don't be too harsh on D to him, I'm trying to convince him to make the switch :) With the input from ponce (*) I now have the code working. Now all is need is a time machine so as to redo the demo successfully. Doctor, where are you? Oh you are committed to be on BBC1 in two hours time. Get Alex to have a chat with me and I can show the demonstration working. (*) ponce is arguably not the most positive or constructive name to go by. -- Russel. ============================================================================= Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.winder@ekiga.net 41 Buckmaster Road m: +44 7770 465 077 xmpp: russel@winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder |
September 19, 2015 Re: Debugging D shared libraries | ||||
---|---|---|---|---|
| ||||
Posted in reply to Russel Winder | On Saturday, 19 September 2015 at 16:15:45 UTC, Russel Winder wrote:
> Sadly the:
>
> pragma(LDC_global_crt_ctor, 0)
> void initRuntime() {
> import core.runtime: Runtime;
> Runtime.initialize();
> }
>
> will not compile under DMD :-(
version(LDC){ /* ... */ }
not that it helps make things work correctly, but at least they'll compile :)
|
Copyright © 1999-2021 by the D Language Foundation