Re: Error running concurrent process and storing results in array

2020-05-05 Thread drug via Digitalmars-d-learn
06.05.2020 09:43, data pulverizer пишет: On Wednesday, 6 May 2020 at 05:50:23 UTC, drug wrote: General advice - try to avoid using `array` and `new` in hot code. Memory allocating is slow in general, except if you use carefully crafted custom memory allocators. And that can easily be the reason

Re: Error running concurrent process and storing results in array

2020-05-05 Thread drug via Digitalmars-d-learn
06.05.2020 09:24, data pulverizer пишет: On Wednesday, 6 May 2020 at 05:44:47 UTC, drug wrote: proc is already a delegate, so &proc is a pointer to the delegate, just pass a `proc` itself Thanks done that but getting a range violation on z which was not there before. ``` core.exception.Ra

Re: Error running concurrent process and storing results in array

2020-05-05 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 6 May 2020 at 05:50:23 UTC, drug wrote: General advice - try to avoid using `array` and `new` in hot code. Memory allocating is slow in general, except if you use carefully crafted custom memory allocators. And that can easily be the reason of 40% cpu usage because the cores are w

Re: Error running concurrent process and storing results in array

2020-05-05 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 6 May 2020 at 05:44:47 UTC, drug wrote: proc is already a delegate, so &proc is a pointer to the delegate, just pass a `proc` itself Thanks done that but getting a range violation on z which was not there before. ``` core.exception.RangeError@onlineapp.d(3): Range violation -

Re: Error running concurrent process and storing results in array

2020-05-05 Thread drug via Digitalmars-d-learn
06.05.2020 07:52, data pulverizer пишет: On Wednesday, 6 May 2020 at 04:04:14 UTC, Mathias LANG wrote: On Wednesday, 6 May 2020 at 03:41:11 UTC, data pulverizer wrote: Yes, that's exactly what I want the actual computation I'm running is much more expensive and much larger. It shouldn't matter

Re: Error running concurrent process and storing results in array

2020-05-05 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 6 May 2020 at 04:52:30 UTC, data pulverizer wrote: myData is referencing elements [5..10] of data and not creating a new array with elements data[5..10] copied? Just checked this and can confirm that the data is not being copied so that is not the source of cpu idling: https://d

Re: Error running concurrent process and storing results in array

2020-05-05 Thread drug via Digitalmars-d-learn
06.05.2020 07:25, data pulverizer пишет: On Wednesday, 6 May 2020 at 03:56:04 UTC, Ali Çehreli wrote: On 5/5/20 8:41 PM, data pulverizer wrote:> On Wednesday, 6 May 2020 at 03:33:12 UTC, Mathias LANG wrote: >> On Wednesday, 6 May 2020 at 03:25:41 UTC, data pulverizer wrote: > Is there somethin

Re: Error running concurrent process and storing results in array

2020-05-05 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 6 May 2020 at 04:04:14 UTC, Mathias LANG wrote: On Wednesday, 6 May 2020 at 03:41:11 UTC, data pulverizer wrote: Yes, that's exactly what I want the actual computation I'm running is much more expensive and much larger. It shouldn't matter if I have like 100_000_000 threads should

Re: Error running concurrent process and storing results in array

2020-05-05 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 6 May 2020 at 03:56:04 UTC, Ali Çehreli wrote: On 5/5/20 8:41 PM, data pulverizer wrote:> On Wednesday, 6 May 2020 at 03:33:12 UTC, Mathias LANG wrote: >> On Wednesday, 6 May 2020 at 03:25:41 UTC, data pulverizer wrote: > Is there something I need to do to wait for each thread to

Re: Error running concurrent process and storing results in array

2020-05-05 Thread Mathias LANG via Digitalmars-d-learn
On Wednesday, 6 May 2020 at 03:41:11 UTC, data pulverizer wrote: Is there something I need to do to wait for each thread to finish computation? Yeah, you need to synchronize so that your main thread wait on all the other threads to finish. Look up `Thread.join`. Yes, that's exactly what I

Re: Error running concurrent process and storing results in array

2020-05-05 Thread Ali Çehreli via Digitalmars-d-learn
On 5/5/20 8:41 PM, data pulverizer wrote:> On Wednesday, 6 May 2020 at 03:33:12 UTC, Mathias LANG wrote: >> On Wednesday, 6 May 2020 at 03:25:41 UTC, data pulverizer wrote: > Is there something I need to do to wait for each thread to finish > computation? thread_joinAll(). I have an example her

Re: Error running concurrent process and storing results in array

2020-05-05 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 6 May 2020 at 03:33:12 UTC, Mathias LANG wrote: On Wednesday, 6 May 2020 at 03:25:41 UTC, data pulverizer wrote: [...] The problem here is that `process` is a delegate, not a function. The compiler *should* know it's a function, but for some reason it does not. Making the funct

Re: Error running concurrent process and storing results in array

2020-05-05 Thread drug via Digitalmars-d-learn
06.05.2020 06:25, data pulverizer пишет: ``` onlineapp.d(14): Error: template std.concurrency.spawn cannot deduce function from argument types !()(void delegate(double x, double y, long i, shared(double[]) z) pure nothrow @nogc @safe, double, double, long, shared(double[])), candidates are: /

Re: Error running concurrent process and storing results in array

2020-05-05 Thread Mathias LANG via Digitalmars-d-learn
On Wednesday, 6 May 2020 at 03:25:41 UTC, data pulverizer wrote: [...] The problem here is that `process` is a delegate, not a function. The compiler *should* know it's a function, but for some reason it does not. Making the function static, or moving it outside of the scope of main, will fi

Error running concurrent process and storing results in array

2020-05-05 Thread data pulverizer via Digitalmars-d-learn
I have been using std.parallelism and that has worked quite nicely but it is not fully utilising all the cpu resources in my computation so I though it could be good to run it concurrently to see if I can get better performance. However I am very new to std.concurrency and the baby version of t

Re: Beginner's Comparison Benchmark

2020-05-05 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/5/20 4:07 PM, RegeleIONESCU wrote: Hello! I made a little test(counting to 1 billion by adding 1)to compare execution speed of a small counting for loop in C, D, Julia and Python. = The C version:

Beginner's Comparison Benchmark

2020-05-05 Thread RegeleIONESCU via Digitalmars-d-learn
Hello! I made a little test(counting to 1 billion by adding 1)to compare execution speed of a small counting for loop in C, D, Julia and Python. = The C version: |The D version: |The Julia versio

Re: std.uni, std.ascii, std.encoding, std.utf ugh!

2020-05-05 Thread WebFreak001 via Digitalmars-d-learn
On Tuesday, 5 May 2020 at 18:41:50 UTC, learner wrote: Good morning, Trying to do this: ``` bool foo(string s) nothrow { return s.all!isDigit; } ``` I realised that the conversion from char to dchar could throw. I need to validate and operate over ascii strings and utf8 strings, possibly in

Re: real operations imprecise?

2020-05-05 Thread WebFreak001 via Digitalmars-d-learn
On Tuesday, 5 May 2020 at 14:15:03 UTC, H. S. Teoh wrote: On Tue, May 05, 2020 at 01:44:18PM +, WebFreak001 via Digitalmars-d-learn wrote: [...] Whoa, hold your horses right there! What does `pragma(msg, real.dig);` output on your machine? [...] You are right, probably should have do

std.uni, std.ascii, std.encoding, std.utf ugh!

2020-05-05 Thread learner via Digitalmars-d-learn
Good morning, Trying to do this: ``` bool foo(string s) nothrow { return s.all!isDigit; } ``` I realised that the conversion from char to dchar could throw. I need to validate and operate over ascii strings and utf8 strings, possibly in separate functions, what's the best way to transition b

Re: Retrieve the return type of the current function

2020-05-05 Thread Meta via Digitalmars-d-learn
On Tuesday, 5 May 2020 at 18:19:00 UTC, Meta wrote: mixin template magic() { alias CallerRet = typeof(return); CallerRet magic() { return CallerRet.init; } } Small edit: you can remove the "CallerRet" alias by doing the following: mixin template magic() { typeof(r

Re: Retrieve the return type of the current function

2020-05-05 Thread Meta via Digitalmars-d-learn
On Tuesday, 5 May 2020 at 17:11:53 UTC, learner wrote: On Tuesday, 5 May 2020 at 16:41:06 UTC, Adam D. Ruppe wrote: typeof(return) Thank you, that was indeed easy! Is it possible to retrieve also the caller return type? Something like: ``` int foo() { return magic(); } auto magic(may

Re: Retrieve the return type of the current function

2020-05-05 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, May 5, 2020 11:11:53 AM MDT learner via Digitalmars-d-learn wrote: > On Tuesday, 5 May 2020 at 16:41:06 UTC, Adam D. Ruppe wrote: > > typeof(return) > > Thank you, that was indeed easy! > > Is it possible to retrieve also the caller return type? Something > like: > > ``` > int foo() {

Re: Retrieve the return type of the current function

2020-05-05 Thread learner via Digitalmars-d-learn
On Tuesday, 5 May 2020 at 16:41:06 UTC, Adam D. Ruppe wrote: typeof(return) Thank you, that was indeed easy! Is it possible to retrieve also the caller return type? Something like: ``` int foo() { return magic(); } auto magic(maybesomedefaulttemplateargs = ??)() { alias R = __trai

Re: Retrieve the return type of the current function

2020-05-05 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 5 May 2020 at 16:36:48 UTC, learner wrote: I mean, without using the function name in the body, like ReturnType!foo ? even easier: typeof(return)

Retrieve the return type of the current function

2020-05-05 Thread learner via Digitalmars-d-learn
Good morning, Is it possible something like this? ``` int foo() { __traits(some_trait, some_generic_this) theInt = 0; ``` I mean, without using the function name in the body, like ReturnType!foo ?

Re: real operations imprecise?

2020-05-05 Thread kinke via Digitalmars-d-learn
I can't even reproduce the 'missing' digits. On run.dlang.io, i.e., on Linux x64 (and so x87 real), I get an identical output for both DMD and LDC: void main() { import core.stdc.stdio, std.math; printf("%.70Lf\n", PI); printf("%.70Lf\n", PI_2); printf("%La\n", PI); printf("

Re: real operations imprecise?

2020-05-05 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, May 05, 2020 at 01:44:18PM +, WebFreak001 via Digitalmars-d-learn wrote: > I was dumping the full PI value on my machine with the highest > precision it could get and got: > > $ rdmd --eval='printf("%.70llf\n", PI)' > 3.14159265358979323851280895940618620443274267017841339111328125000

real operations imprecise?

2020-05-05 Thread WebFreak001 via Digitalmars-d-learn
I was dumping the full PI value on my machine with the highest precision it could get and got: $ rdmd --eval='printf("%.70llf\n", PI)' 3.14159265358979323851280895940618620443274267017841339111328125 now this all looks good, but when I tried to print PI_2 I got $ rdmd --eval='printf("%

Re: Compilation memory use

2020-05-05 Thread Patrick Schluter via Digitalmars-d-learn
On Monday, 4 May 2020 at 17:00:21 UTC, Anonymouse wrote: TL;DR: Is there a way to tell what module or other section of a codebase is eating memory when compiling? [...] maybe with the massif tool of valgrind?

Re: Bug?

2020-05-05 Thread RazvanN via Digitalmars-d-learn
On Tuesday, 5 May 2020 at 05:37:08 UTC, Simen Kjærås wrote: On Tuesday, 5 May 2020 at 04:02:06 UTC, RazvanN wrote: [...] Surely the above code, which silently discards the exception, does not print "hello"? Regardless, I ran your code with writeln inside the catch(), and without the try-ca