Re: Error running concurrent process and storing results in array

2020-05-06 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 6 May 2020 at 10:23:17 UTC, data pulverizer wrote: D: ~ 1.5 seconds This is going to sound absurd but can we do even better? If none of the optimizations we have so far is using simd maybe we can get even better performance by using it. I think I need to go and read a

Re: Thread to watch keyboard during main's infinite loop

2020-05-06 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 7 May 2020 at 01:33:12 UTC, Daren Scot Wilson wrote: import core.thread: sleep; It sould be import core.thread : Thread; Thread.sleep(1.secs); // or whatever sleep is a static method on the Thread class.

Re: Thread to watch keyboard during main's infinite loop

2020-05-06 Thread Daren Scot Wilson via Digitalmars-d-learn
On Thursday, 7 May 2020 at 01:02:57 UTC, ag0aep6g wrote: Thank you, this is 110% helpful. Actually, I'd like to return the excess 10%. My dmd compiler does not like: import core.thread: sleep; so I put the code back the way I had, just to get on with work. Use `shared` so that all

Re: Thread to watch keyboard during main's infinite loop

2020-05-06 Thread ag0aep6g via Digitalmars-d-learn
On 07.05.20 02:13, Daren Scot Wilson wrote: import std.stdio; import core.stdc.stdio;  // for getchar().  There's nothing similar in D std libs? import std.concurrency; import core.thread; // just for sleep() Instead of the comment you can write: import core.thread: sleep; bool

Re: Error running concurrent process and storing results in array

2020-05-06 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 6 May 2020 at 23:10:05 UTC, data pulverizer wrote: The -O3 -O5 optimization on the ldc compiler is instrumental in bringing the times down, going with -02 based optimization even with the other flags gives us ~ 13 seconds for the 10,000 dataset rather than the very nice 1.5

Thread to watch keyboard during main's infinite loop

2020-05-06 Thread Daren Scot Wilson via Digitalmars-d-learn
I'm writing a simple command line tool to send data by UDP once per second forever, to test some software on another machine. Not actually forever, of course, but until ^C or I hit 'Q'. I want to tap keys to make other things happen, like change the data or rate of sending. Not sure of the

Re: Error running concurrent process and storing results in array

2020-05-06 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 6 May 2020 at 17:31:39 UTC, Jacob Carlborg wrote: On 2020-05-06 12:23, data pulverizer wrote: Yes, I'll do a blog or something on GitHub and link it. It would be nice if you could get it published on the Dlang blog [1]. One usually get paid for that. Contact Mike Parker. [1]

Re: Get months / years between two dates.

2020-05-06 Thread bauss via Digitalmars-d-learn
On Wednesday, 6 May 2020 at 19:58:59 UTC, Adam D. Ruppe wrote: On Wednesday, 6 May 2020 at 19:51:01 UTC, bauss wrote: How will I get the months or years between the two dates? What's the length of a month or a year? That's the tricky part - they have variable lengths. So a difference of one

Re: Get months / years between two dates.

2020-05-06 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 6 May 2020 at 19:51:01 UTC, bauss wrote: How will I get the months or years between the two dates? What's the length of a month or a year? That's the tricky part - they have variable lengths. So a difference of one month is not super precise. You could probably just do days /

Get months / years between two dates.

2020-05-06 Thread bauss via Digitalmars-d-learn
How do you exactly do that? Like if I have two dates as std.datetime.DateTime How will I get the months or years between the two dates? I was surprised to learn that Duration does not support them and only has weeks, days etc. but not months or years. I can't seem to find any standard way

Re: Beginner's Comparison Benchmark

2020-05-06 Thread p.shkadzko via Digitalmars-d-learn
On Tuesday, 5 May 2020 at 20:07:54 UTC, RegeleIONESCU wrote: [...] Python should be ruled out, this is not its war :) I have done benchmarks against NumPy if you are interested: https://github.com/tastyminerals/mir_benchmarks

Re: Error running concurrent process and storing results in array

2020-05-06 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/6/20 2:29 PM, drug wrote: 06.05.2020 16:57, Steven Schveighoffer пишет: ``` foreach(i; 0..n) // instead of for(long i = 0; i < n;) ``` I guess that `proc` delegate cant capture `i` var of `foreach` loop so the range violation doesn't happen. foreach over a range of integers is lowered

Re: Error running concurrent process and storing results in array

2020-05-06 Thread drug via Digitalmars-d-learn
06.05.2020 13:23, data pulverizer пишет: On Wednesday, 6 May 2020 at 08:28:41 UTC, drug wrote: What is current D time? ... Current Times: D:  ~ 1.5 seconds Chapel: ~ 9 seconds Julia:  ~ 35 seconds Oh, I'm impressed. I thought that D time has been decreased by 1.5 seconds but it is

Re: Error running concurrent process and storing results in array

2020-05-06 Thread drug via Digitalmars-d-learn
06.05.2020 16:57, Steven Schveighoffer пишет: ``` foreach(i; 0..n) // instead of for(long i = 0; i < n;) ``` I guess that `proc` delegate cant capture `i` var of `foreach` loop so the range violation doesn't happen. foreach over a range of integers is lowered to an equivalent for loop, so

Re: How to port C++ std::is_reference to D ?

2020-05-06 Thread Q. Schroll via Digitalmars-d-learn
On Wednesday, 6 May 2020 at 09:07:22 UTC, wjoe wrote: Hello, I'm choking on a piece of C++ I have no idea about how to translate to D. std::is_reference In general, you can't. In D, `ref` is not part of the type, it's a "storage class", and as such it is a property that a function

Re: Error running concurrent process and storing results in array

2020-05-06 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-05-06 12:23, data pulverizer wrote: Yes, I'll do a blog or something on GitHub and link it. It would be nice if you could get it published on the Dlang blog [1]. One usually get paid for that. Contact Mike Parker. [1] https://blog.dlang.org -- /Jacob Carlborg

Re: Beginner's Comparison Benchmark

2020-05-06 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, May 06, 2020 at 09:59:48AM +, welkam via Digitalmars-d-learn wrote: > On Tuesday, 5 May 2020 at 20:29:13 UTC, Steven Schveighoffer wrote: > > the optimizer recognizes what you are doing and changes your code > > to: > > > > writeln(1_000_000_001); > > > Oh yes a classic constant

Re: How to port C++ std::is_reference to D ?

2020-05-06 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 6 May 2020 at 09:40:47 UTC, wjoe wrote: yes, I did read the spec. I read the language spec on traits as well as std.traits docs as well as searching the internet for a solution since day before yesterday. But I couldn't bring it together because } else static if

Re: Error running concurrent process and storing results in array

2020-05-06 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/6/20 2:49 AM, drug wrote: 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 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

Re: Retrieve the return type of the current function

2020-05-06 Thread learner via Digitalmars-d-learn
On Wednesday, 6 May 2020 at 08:04:16 UTC, Jacob Carlborg wrote: On 2020-05-05 19:11, 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: Yes,

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

2020-05-06 Thread WebFreak001 via Digitalmars-d-learn
On Wednesday, 6 May 2020 at 10:57:59 UTC, learner wrote: On Tuesday, 5 May 2020 at 19:24:41 UTC, WebFreak001 wrote: 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

Re: Beginner's Comparison Benchmark

2020-05-06 Thread welkam via Digitalmars-d-learn
On Tuesday, 5 May 2020 at 20:29:13 UTC, Steven Schveighoffer wrote: the optimizer recognizes what you are doing and changes your code to: writeln(1_000_000_001); Oh yes a classic constant folding. The other thing to worry about is dead code elimination. Walter has a nice story where he sent

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

2020-05-06 Thread learner via Digitalmars-d-learn
On Tuesday, 5 May 2020 at 19:24:41 UTC, WebFreak001 wrote: 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

Re: How to port C++ std::is_reference to D ?

2020-05-06 Thread drug via Digitalmars-d-learn
06.05.2020 12:07, wjoe пишет: Hello, I'm choking on a piece of C++ I have no idea about how to translate to D.   template     typename std::enable_if< std::is_const::value == true, void>::type* = nullptr>     constexpr const char *modifier() const {     return "[in] ";     }  

Re: Error running concurrent process and storing results in array

2020-05-06 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 6 May 2020 at 08:28:41 UTC, drug wrote: What is current D time? ... Current Times: D: ~ 1.5 seconds Chapel: ~ 9 seconds Julia: ~ 35 seconds That would be really nice if you make the resume of your research. Yes, I'll do a blog or something on GitHub and link it.

How to port C++ std::is_reference to D ?

2020-05-06 Thread wjoe via Digitalmars-d-learn
Hello, I'm choking on a piece of C++ I have no idea about how to translate to D. template typename std::enable_if< std::is_const::value == true, void>::type* = nullptr> constexpr const char *modifier() const { return "[in] "; } template typename

Re: How to port C++ std::is_reference to D ?

2020-05-06 Thread wjoe via Digitalmars-d-learn
On Wednesday, 6 May 2020 at 09:19:10 UTC, drug wrote: 06.05.2020 12:07, wjoe пишет: Hello, I'm choking on a piece of C++ I have no idea about how to translate to D.   template     typename std::enable_if< std::is_const::value == true, void>::type* = nullptr>     constexpr const

Re: Error running concurrent process and storing results in array

2020-05-06 Thread drug via Digitalmars-d-learn
06.05.2020 11:18, data pulverizer пишет: CPU usage now revs up almost has time to touch 100% before the process is finished! Interestingly using `--boundscheck=off` without `--ffast-math` gives a timing of around 4 seconds and, whereas using `--ffast-math` without `--boundscheck=off` made no

Re: Error running concurrent process and storing results in array

2020-05-06 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 6 May 2020 at 07:57:46 UTC, WebFreak001 wrote: On Wednesday, 6 May 2020 at 07:42:44 UTC, data pulverizer wrote: On Wednesday, 6 May 2020 at 07:27:19 UTC, data pulverizer wrote: Just tried removing the boundscheck and got 1.5 seconds in D! Cool! But before getting too excited I

Re: Error running concurrent process and storing results in array

2020-05-06 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 6 May 2020 at 07:47:59 UTC, drug wrote: 06.05.2020 10:42, data pulverizer пишет: On Wednesday, 6 May 2020 at 07:27:19 UTC, data pulverizer wrote: On Wednesday, 6 May 2020 at 06:54:07 UTC, drug wrote: Thing are really interesting. So there is a space to improve performance in 2.5

Re: Retrieve the return type of the current function

2020-05-06 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-05-05 19:11, 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: Yes, kind of: void foo(string caller = __FUNCTION__)() { import

Re: Error running concurrent process and storing results in array

2020-05-06 Thread WebFreak001 via Digitalmars-d-learn
On Wednesday, 6 May 2020 at 07:42:44 UTC, data pulverizer wrote: On Wednesday, 6 May 2020 at 07:27:19 UTC, data pulverizer wrote: On Wednesday, 6 May 2020 at 06:54:07 UTC, drug wrote: Thing are really interesting. So there is a space to improve performance in 2.5 times :-) Yes, `array` is

Re: Error running concurrent process and storing results in array

2020-05-06 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-05-06 06:04, Mathias LANG wrote: In general, if you want to parallelize something, you should aim to have as many threads as you have cores. That should be _logical_ cores. If the CPU supports hyper threading it can run two threads per core. -- /Jacob Carlborg

Re: Error running concurrent process and storing results in array

2020-05-06 Thread drug via Digitalmars-d-learn
06.05.2020 10:42, data pulverizer пишет: On Wednesday, 6 May 2020 at 07:27:19 UTC, data pulverizer wrote: On Wednesday, 6 May 2020 at 06:54:07 UTC, drug wrote: Thing are really interesting. So there is a space to improve performance in 2.5 times :-) Yes, `array` is smart enough and if you call

Re: Error running concurrent process and storing results in array

2020-05-06 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-05-06 08:54, drug wrote: Do you try `--fast-math` in ldc? Don't know if 05 use this flag Try the following flags as well: `-mcpu=native -flto=full -defaultlib=phobos2-ldc-lto,druntime-ldc-lto` -- /Jacob Carlborg

Re: Error running concurrent process and storing results in array

2020-05-06 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 6 May 2020 at 07:27:19 UTC, data pulverizer wrote: On Wednesday, 6 May 2020 at 06:54:07 UTC, drug wrote: Thing are really interesting. So there is a space to improve performance in 2.5 times :-) Yes, `array` is smart enough and if you call it on another array it is no op. What

Re: Error running concurrent process and storing results in array

2020-05-06 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 6 May 2020 at 07:27:19 UTC, data pulverizer wrote: On Wednesday, 6 May 2020 at 06:54:07 UTC, drug wrote: Thing are really interesting. So there is a space to improve performance in 2.5 times :-) Yes, `array` is smart enough and if you call it on another array it is no op. What

Re: Error running concurrent process and storing results in array

2020-05-06 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-05-06 05:25, data pulverizer wrote: 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 If you happen to be using macOS, I know that when std.parallelism checks how many cores the computer has, it

Re: Error running concurrent process and storing results in array

2020-05-06 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 6 May 2020 at 06:49:13 UTC, drug wrote: ... Then you can pass the arguments in ctor of the derived class like: ``` foreach(long i; 0..n) new DerivedThread(double)(i), cast(double)(i + 1), i, z).start(); thread_joinAll(); ``` not tested example of derived thread ``` class

Re: Error running concurrent process and storing results in array

2020-05-06 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 6 May 2020 at 06:54:07 UTC, drug wrote: Thing are really interesting. So there is a space to improve performance in 2.5 times :-) Yes, `array` is smart enough and if you call it on another array it is no op. What means `--fast` in Chapel? Do you try `--fast-math` in ldc? Don't

Re: Error running concurrent process and storing results in array

2020-05-06 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

Re: Error running concurrent process and storing results in array

2020-05-06 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 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. ```

Re: Error running concurrent process and storing results in array

2020-05-06 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

Re: Error running concurrent process and storing results in array

2020-05-06 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 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