Re: Are files in dub's "copyFiles" copied every time dub is run?
On Monday, March 05, 2018 21:26:48 Marc via Digitalmars-d-learn wrote: > if so, can I somehow make it copy only if newest? It actually would have been my guess that it would copy too infrequently - e.g. only on a fresh build - but I don't know. IIRC, it does have that problem when running pre-build steps, but I'd have to check to be 100% sure. And if you're worried about what it's doing with copy, I'd suggest that you test to see what it's doing by having huge files or something (so that the time difference can be seen). dub generally isn't configurable for stuff like this though. In general, it has the problem that it's trying to do all of the build stuff for you in a standard way and thus configurability seems to have been tacked on to it over time where it's had to be added or where enough people have complained about it. It's really not a general purpose build system like make. Part of that is the price of making dub easy to use for the simple stuff, and part of it stems from the fact that the dub devs don't want to have to worry about whether a dependency requires installing a bunch of extra software to be built. If everything builds in a completely standard way, then that's not a problem - but it also makes it much less flexible, which is a good part of why some folks really don't like using dub. If dub's copyFiles isn't working how you'd like, I'd suggest looking at adding pre or post-build scripts to do the copying for you, though depending on when dub runs them and when it skips them, that may or may not do what you want. - Jonathan M Davis
Re: Speed of math function atan: comparison D and C++
On 2018-03-05 20:11:06 +, H. S. Teoh said: Walter has been adamant that we should always compute std.math.* functions with the `real` type, which on x86 maps to the non-IEEE 80-bit floats. However, 80-bit floats have been deprecated for a while now, Hi, do you have a reference for this? I can't believe this, as the 80-bit are pretty important for a lot of optimization algorithms. We use it all the time and it's absolutly necessary. and pretty much nobody cares to improve their performance on newer CPUs, Really? focusing instead on SSE/MMX performance with 64-bit doubles. People have been clamoring for using 64-bit doubles by default rather than 80-bit floats, but so far Walter has refused to budge. IMO this is all driven by the GPU/AI hype that just (seems) to be happy with rough precision. -- Robert M. Münch http://www.saphirion.com smarter | better | faster
Re: Validity of cast(void*)size_t.max
On Monday, 5 March 2018 at 18:28:43 UTC, Steven Schveighoffer wrote: Note, I think the error is bogus, you should be able to create hard-coded addresses of data at compile time -- I'm not sure how you would do hardware registers otherwise. I'd do them as extern variables, it wouldn't be nice to have them as pointers. extern int reg1; And use linker option to define address: --defsym reg1=0x
Re: Speed of math function atan: comparison D and C++
On Monday, 5 March 2018 at 06:01:27 UTC, J-S Caux wrote: So the codes are trivial, simply some check of raw speed: double x = 0.0; for (int a = 0; a < 10; ++a) x += atan(1.0/(1.0 + sqrt(1.0 + a))); for C++ and double x = 0.0; for (int a = 0; a < 1_000_000_000; ++a) x += atan(1.0/(1.0 + sqrt(1.0 + a))); for D. C++ exec takes 40 seconds, D exec takes 68 seconds. should a be an int? make it a double ;-)
Re: Speed of math function atan: comparison D and C++
On Monday, 5 March 2018 at 21:05:19 UTC, bachmeier wrote: I wonder if Ilya has worked on any of this for Mir. Mir has sin and cos, but that's it. It looks like they use llvm intrinsics on LDC and then fall back to phobos' implementation.
Re: string object won't compile
On Monday, 5 March 2018 at 23:42:59 UTC, Adam D. Ruppe wrote: On Monday, 5 March 2018 at 23:34:50 UTC, askjfbd wrote: string.d The problem is you named the file string.d and didn't give a `module x;` statement in the code, so the compiler assumed the module is named after the file and thus introduced a local name `string` referring to the module, overriding the built in one. You can still refer to the built in one by saying `.string foo = "bar";` - yes, the leading dot, which tells it to use the global instead of local name. Or by putting `module mytest.string;` at the top, so the module has a two-part name (I recommend this in all cases anyway btw, it is the best way to avoid conflicts as you import more modules). Or just renaming the file from string.d to almost_anything_else.d, which will also avoid the local name override. Thanks for the precise advice. How foolish I was and how quickly you gave me the answer! I'll have to learn a lot more about D and more about modules. Since C and common lisp, which I have learned so far, have almost nothing to do with name conflicts, I couldn't imagine that I was still wrong. :) Thank you.
Re: string object won't compile
On Tuesday, 6 March 2018 at 00:18:14 UTC, psychoticRabbit wrote: On Monday, 5 March 2018 at 23:34:50 UTC, askjfbd wrote: Someone please tell me how, for I am a newbie and don't know any solutions even to this very simple problem. As I learned dlang using the Dlang tour page, I stuck at the alias & Strings page. I have tried to compile the following simple code many times but still get the same error both from dmd and gdc. They both say that... This is mistake I made too, when i began using D. I quickly got into the habit of putting module test; at the beginning of every file I create, unless I determine a better module name. Actually, I wrote my own IDE, so it does that for me whenever I select a new D file. Personally, I think that is one of the first things newcomers need to learn about - modules. - "Modules have a one-to-one correspondence with source files. The module name is, by default, the file name with the path and extension stripped off, and can be set explicitly with the module declaration." "Modules automatically provide a namespace scope for their contents." https://dlang.org/spec/module.html Thank you. I will learn about modules from now on. I thought I was right until you two replied to me. ;) Can you make your own IDE? That's great! If it were OpenSource, I would gladly download it for myself to avoid this sort of annoying experience. Thanks.
Re: string object won't compile
On Monday, 5 March 2018 at 23:34:50 UTC, askjfbd wrote: Someone please tell me how, for I am a newbie and don't know any solutions even to this very simple problem. As I learned dlang using the Dlang tour page, I stuck at the alias & Strings page. I have tried to compile the following simple code many times but still get the same error both from dmd and gdc. They both say that... This is mistake I made too, when i began using D. I quickly got into the habit of putting module test; at the beginning of every file I create, unless I determine a better module name. Actually, I wrote my own IDE, so it does that for me whenever I select a new D file. Personally, I think that is one of the first things newcomers need to learn about - modules. - "Modules have a one-to-one correspondence with source files. The module name is, by default, the file name with the path and extension stripped off, and can be set explicitly with the module declaration." "Modules automatically provide a namespace scope for their contents." https://dlang.org/spec/module.html
Re: string object won't compile
On Monday, 5 March 2018 at 23:34:50 UTC, askjfbd wrote: string.d The problem is you named the file string.d and didn't give a `module x;` statement in the code, so the compiler assumed the module is named after the file and thus introduced a local name `string` referring to the module, overriding the built in one. You can still refer to the built in one by saying `.string foo = "bar";` - yes, the leading dot, which tells it to use the global instead of local name. Or by putting `module mytest.string;` at the top, so the module has a two-part name (I recommend this in all cases anyway btw, it is the best way to avoid conflicts as you import more modules). Or just renaming the file from string.d to almost_anything_else.d, which will also avoid the local name override.
Are files in dub's "copyFiles" copied every time dub is run?
if so, can I somehow make it copy only if newest?
Re: Speed of math function atan: comparison D and C++
On Monday, 5 March 2018 at 20:11:06 UTC, H. S. Teoh wrote: Walter has been adamant that we should always compute std.math.* functions with the `real` type, which on x86 maps to the non-IEEE 80-bit floats. However, 80-bit floats have been deprecated for a while now, and pretty much nobody cares to improve their performance on newer CPUs, focusing instead on SSE/MMX performance with 64-bit doubles. People have been clamoring for using 64-bit doubles by default rather than 80-bit floats, but so far Walter has refused to budge. I wonder if Ilya has worked on any of this for Mir.
Re: Speed of math function atan: comparison D and C++
On Mon, Mar 05, 2018 at 06:39:21PM +, J-S Caux via Digitalmars-d-learn wrote: [...] > I've tested these two very basic representative codes: > https://www.dropbox.com/s/b5o4i8h43qh1saf/test.cc?dl=0 > https://www.dropbox.com/s/zsaikhdoyun3olk/test.d?dl=0 > > Results: > > C++: > g++ (Apple LLVM version 7.3.0): 9.5 secs > g++ (GCC 7.1.0): 10.7 secs > > D: > dmd : 35.5 secs > dmd -release -inline -O : 29.5 secs > ldc2 : 34.4 secs > ldc2 -release -O : 31.5 secs > > But now: using the core.stdc.math atan as per Uknown's suggestion: > D: > dmd: 9 secs > dmd -release -inline -O : 6.8 secs > ldc2 : 10 secs > ldc2 -release -O : 6.5 secs <- best > > So indeed the difference is between the `std.math atan` versus the > `core.stdc.math atan`. Thanks Uknown! Just knowing this trick could > make the difference between me and other scientists switching over to > D... > > But now comes the question: can the D fundamental maths functions be > propped up to be as fast as the C ones? Walter has been adamant that we should always compute std.math.* functions with the `real` type, which on x86 maps to the non-IEEE 80-bit floats. However, 80-bit floats have been deprecated for a while now, and pretty much nobody cares to improve their performance on newer CPUs, focusing instead on SSE/MMX performance with 64-bit doubles. People have been clamoring for using 64-bit doubles by default rather than 80-bit floats, but so far Walter has refused to budge. But perhaps this time, we might have a strong case for pushing this into D. IMO, it has been long overdue. I filed an issue for this: https://issues.dlang.org/show_bug.cgi?id=18559 If you have any additional relevant information, please post it there so that we can build a strong case to convince Walter about this issue. T -- Heuristics are bug-ridden by definition. If they didn't have bugs, they'd be algorithms.
Re: Speed of math function atan: comparison D and C++
On Monday, 5 March 2018 at 18:39:21 UTC, J-S Caux wrote: But now comes the question: can the D fundamental maths functions be propped up to be as fast as the C ones? Probably, if someone takes the time to look at the bottlenecks.
Re: How to use globals correctly?
On 3/5/18 2:25 PM, Marc wrote: Can __gshared be used instead of static in the singleton pattern? I, comming from C++, ignorantly, have never used _gshared so I went to static instead of (being static also means thread-safe, as far I know)... static in D is thread safe, because it's thread-local. __gshared is shared between threads, so it's not thread safe, but has the exact same type as just static data. Can you use it for singleton? Sure, classic singleton is shared between threads. But using thread-local data, you can solve the singleton problem in a better way: https://wiki.dlang.org/Low-Lock_Singleton_Pattern Note, it still uses __gshared, which means it doesn't protect you from race conditions when you actually USE the singleton object. This means you need some synchronization inside the methods. -Steve
Re: How to use globals correctly?
On Monday, 5 March 2018 at 19:39:35 UTC, Robert M. Münch wrote: On 2018-03-05 18:57:01 +, Steven Schveighoffer said: If you want to have methods, shared kind of sucks. But this at least tells the type system that it's shared between threads. Why does it suck? Because your code will become very verbose and you'll end up casting shared away to do stuff. Basically you won't be able to do anything that isn't in a synchronized context and such your code will either have synchronized everywhere or you'll cast away shared. Personally I never use shared, because it's just such a bother.
Re: How to use globals correctly?
On 3/5/18 2:39 PM, Robert M. Münch wrote: On 2018-03-05 18:57:01 +, Steven Schveighoffer said: On 3/5/18 1:35 PM, Robert M. Münch wrote: 1. Are myMemb1..N TLS or __gshared as well? No, they are on the heap. Only the reference is __gshared. But effectively it is __gshared, since you can reach those items via the global `myObj`. Ok, that was my idea. And am I right, that I don't need any special syntax, just: myObj.myMemb Yes. Like I said, __gshared means it's global, but it's not typed as shared. So the compiler will let you do anything you want. If you want to have methods, shared kind of sucks. But this at least tells the type system that it's shared between threads. Why does it suck? Because you can't call shared methods on a non-shared object, and vice versa. Once you start putting more complex data types inside a class/struct that is shared, you start not being able to use them. If you're just storing strings and integers, it's probably ok. __gshared does not, it just sticks it in global space, but pretends it's not shared data. Ok, so this is the really hackish solution... __gshared is for those who "know what they are doing". There is more exposure to race conditions, and there is a LOT of code that assumes if something isn't typed as shared, it's not shared. __gshared is kind of a lie in that case, and you can potentially run into problems. If you're doing simple things, it can possibly be OK, especially if it's just for debugging. -Steve
Re: Fastest way to zero a slice of memory
On Sunday, 4 March 2018 at 15:23:41 UTC, Nordlöw wrote: When zeroing a slice of memory (either stack or heap) such as enum n = 100; ubyte[n] chunk; should I use `memset` such as memset(chunk.ptr, 0, n/2); // zero first half or an array assignment such as chunk[0 .. n/2] = 0; // zero first half or are they equivalent in release mode? Further, does it depend on whether the slice length is known at compile-time or not? I'd recommend not concerning yourself with such low-level optimizations and let the compiler do that for you, and only jump in yourself if profiling/benchmarking shows that there's a bottleneck, and prefer nice readable code otherwise. E.g., LDC will lower `chunk[0 .. n/2] = 0` to a memset() call if the length is unknown at compile-time, and otherwise replace it with good-looking assembly code (xor vector register and store it consecutively to memory): https://run.dlang.io/is/I6Fq9G (click on ASM and check the assembly for the two functions).
Re: How to use globals correctly?
On 2018-03-05 18:57:01 +, Steven Schveighoffer said: On 3/5/18 1:35 PM, Robert M. Münch wrote: 1. Are myMemb1..N TLS or __gshared as well? No, they are on the heap. Only the reference is __gshared. But effectively it is __gshared, since you can reach those items via the global `myObj`. Ok, that was my idea. And am I right, that I don't need any special syntax, just: myObj.myMemb 2. How to best implement a simple global to keep track of values (with support for threads)? Shared is the best mechanism, and you don't have to make it a class, it can be a struct. This is only if you are using it as POD (plain old data). Ok, in my case I have some methods as well (but maybe can be avoided). If you want to have methods, shared kind of sucks. But this at least tells the type system that it's shared between threads. Why does it suck? __gshared does not, it just sticks it in global space, but pretends it's not shared data. Ok, so this is the really hackish solution... -- Robert M. Münch http://www.saphirion.com smarter | better | faster
Re: How to use globals correctly?
On Monday, 5 March 2018 at 18:57:01 UTC, Steven Schveighoffer wrote: On 3/5/18 1:35 PM, Robert M. Münch wrote: If I use VisualD and add a watch on myObj, I don't see anything just a "identifier myObj is undefined". Not sure if this is because of some threads running (using the D RX framework). Can't answer your visual D questions... So, some questions: 1. Are myMemb1..N TLS or __gshared as well? No, they are on the heap. Only the reference is __gshared. But effectively it is __gshared, since you can reach those items via the global `myObj`. 2. How to best implement a simple global to keep track of values (with support for threads)? shared is the best mechanism, and you don't have to make it a class, it can be a struct. This is only if you are using it as POD (plain old data). If you want to have methods, shared kind of sucks. But this at least tells the type system that it's shared between threads. __gshared does not, it just sticks it in global space, but pretends it's not shared data. -Steve Can __gshared be used instead of static in the singleton pattern? I, comming from C++, ignorantly, have never used _gshared so I went to static instead of (being static also means thread-safe, as far I know)...
Re: How to use globals correctly?
On 3/5/18 1:35 PM, Robert M. Münch wrote: If I use VisualD and add a watch on myObj, I don't see anything just a "identifier myObj is undefined". Not sure if this is because of some threads running (using the D RX framework). Can't answer your visual D questions... So, some questions: 1. Are myMemb1..N TLS or __gshared as well? No, they are on the heap. Only the reference is __gshared. But effectively it is __gshared, since you can reach those items via the global `myObj`. 2. How to best implement a simple global to keep track of values (with support for threads)? shared is the best mechanism, and you don't have to make it a class, it can be a struct. This is only if you are using it as POD (plain old data). If you want to have methods, shared kind of sucks. But this at least tells the type system that it's shared between threads. __gshared does not, it just sticks it in global space, but pretends it's not shared data. -Steve
Re: Speed of math function atan: comparison D and C++
On Monday, 5 March 2018 at 09:48:49 UTC, Uknown wrote: Depending on your platform, the size of `double` could be different between C++ and D. Could you check that the size and precision are indeed the same? Also, benchmark method is just as important as benchmark code. Did you use DMD or LDC as the D compiler? In this case it shouldn't matter, but try with LDC if you haven't. Also ensure that you've used the right flags: `-release -inline -O`. If the D version is still slower, you could try using the C version of the function Simply change `import std.math: atan;` to `core.stdc.math: atan;` [0] [0]: https://dlang.org/phobos/core_stdc_math.html#.atan Thanks all for the info. I've tested these two very basic representative codes: https://www.dropbox.com/s/b5o4i8h43qh1saf/test.cc?dl=0 https://www.dropbox.com/s/zsaikhdoyun3olk/test.d?dl=0 Results: C++: g++ (Apple LLVM version 7.3.0): 9.5 secs g++ (GCC 7.1.0): 10.7 secs D: dmd : 35.5 secs dmd -release -inline -O : 29.5 secs ldc2 : 34.4 secs ldc2 -release -O : 31.5 secs But now: using the core.stdc.math atan as per Uknown's suggestion: D: dmd: 9 secs dmd -release -inline -O : 6.8 secs ldc2 : 10 secs ldc2 -release -O : 6.5 secs <- best So indeed the difference is between the `std.math atan` versus the `core.stdc.math atan`. Thanks Uknown! Just knowing this trick could make the difference between me and other scientists switching over to D... But now comes the question: can the D fundamental maths functions be propped up to be as fast as the C ones?
How to use globals correctly?
Hi, I'm feeling a bit dumb but anway... For hacking prototypes I mostly create a class to store all kind of values. Then I create one global instance of this class and use it everywhere. Pseudocode looks like this: class myClass { myMemb1; myMembN; this(){...} } __gshared myClass myObj; main() { myObj = new myClass(); func1(); ... } func1(){ myObj.myMemb1 = ... } If I use VisualD and add a watch on myObj, I don't see anything just a "identifier myObj is undefined". Not sure if this is because of some threads running (using the D RX framework). So, some questions: 1. Are myMemb1..N TLS or __gshared as well? 2. How to best implement a simple global to keep track of values (with support for threads)? -- Robert M. Münch http://www.saphirion.com smarter | better | faster
Re: Validity of cast(void*)size_t.max
On 3/5/18 1:08 PM, Stefan Koch wrote: On Monday, 5 March 2018 at 18:04:20 UTC, Nordlöw wrote: On Monday, 5 March 2018 at 16:07:49 UTC, Steven Schveighoffer wrote: No, I mean you call holeKey at *runtime*. Inlined, it's just returning a constant, so it should reduce to a constant. A compile-time constant visible to the optimizer? Yes indeed. For gdc and ldc the optimisation is guranteed and I am quite dmd can do this as well. As long as you don't have too many statements. Note, I think the error is bogus, you should be able to create hard-coded addresses of data at compile time -- I'm not sure how you would do hardware registers otherwise. Another possibility I thought of: struct Dummy { size_t nullValue; void *holeKey; } enum holeKey = &(cast(Dummy *)null).holeKey; But this fails as well Error: dereference of null pointer null -Steve
Re: Speed of math function atan: comparison D and C++
On Monday, 5 March 2018 at 06:01:27 UTC, J-S Caux wrote: On Monday, 5 March 2018 at 05:40:09 UTC, rikki cattermole wrote: On 05/03/2018 6:35 PM, J-S Caux wrote: I'm considering shifting a large existing C++ codebase into D (it's a scientific code making much use of functions like atan, log etc). I've compared the raw speed of atan between C++ (Apple LLVM version 7.3.0 (clang-703.0.29)) and D (dmd v2.079.0, also ldc2 1.7.0) by doing long loops of such functions. I can't get the D to run faster than about half the speed of C++. double x = 0.0; for (int a = 0; a < 10; ++a) x += atan(1.0/(1.0 + sqrt(1.0 + a))); for C++ and double x = 0.0; for (int a = 0; a < 1_000_000_000; ++a) x += atan(1.0/(1.0 + sqrt(1.0 + a))); for D. C++ exec takes 40 seconds, D exec takes 68 seconds. The performance problem with this code is that LDC does not yet do cross-module inlining by default. GDC does. If you pass `-enable-cross-module-inlining` to LDC, things should be faster. In particular, std.sqrt is not inlined although it is profitable to do so (it becomes one machine instruction). Things become worse when using core.stdc.math.sqrt, because no implementation source available: no inlining possible. Another problem is that std.math.atan(double) just calls std.math.atan(real). Calculations are more expensive on platforms where real==80bits (i.e. x86), and that's not solvable with a compile flag. What it takes is someone to write the double and float versions of atan (and other math functions), but it requires someone with the right knowledge to do it. Your tests (and reporting about them) are much appreciated. Please do file bug reports for these things. Perhaps you can take a stab at implementing double-versions of the functions you need? cheers, Johan
Re: Validity of cast(void*)size_t.max
On Monday, 5 March 2018 at 18:04:20 UTC, Nordlöw wrote: On Monday, 5 March 2018 at 16:07:49 UTC, Steven Schveighoffer wrote: No, I mean you call holeKey at *runtime*. Inlined, it's just returning a constant, so it should reduce to a constant. A compile-time constant visible to the optimizer? Yes indeed. For gdc and ldc the optimisation is guranteed and I am quite dmd can do this as well. As long as you don't have too many statements.
Re: Validity of cast(void*)size_t.max
On Monday, 5 March 2018 at 16:07:49 UTC, Steven Schveighoffer wrote: No, I mean you call holeKey at *runtime*. Inlined, it's just returning a constant, so it should reduce to a constant. A compile-time constant visible to the optimizer?
Re: is it possible to put some DDOC after auto generated blocks like unittest examples?
On Monday, 5 March 2018 at 14:50:54 UTC, Adam D. Ruppe wrote: No, ddoc does not support that. You might be able to hack it with javascript though. thanks, yeah eigther that or a d script to do some postprocessing, so it can work without javascript.
Re: howto run unittest of a single module in dub driven project?
On Monday, 5 March 2018 at 11:26:37 UTC, Atila Neves wrote: On Sunday, 4 March 2018 at 10:43:06 UTC, Arjan wrote: Is it somehow possible to only run the unittests of a single d file within a dub project? Of course without resorting to typing the complete commandline with all versions includes switches etc. You could use unit-threaded: http://code.dlang.org/packages/unit-threaded You'd still need to build everything, but `dub test` would take care of that. I started working on, and need to get back to, a way of only building one module and needed dependencies. Atila Thanx will take a look at it and yes that would be exactly what I was after!
Re: Validity of cast(void*)size_t.max
On 3/5/18 9:01 AM, Nordlöw wrote: On Monday, 5 March 2018 at 12:41:06 UTC, Steven Schveighoffer wrote: pragma(inline, true) C lazyDeleted() pure nothrow @trusted { return cast(C)((cast(size_t*)null) + 1); } I still can't evaluate at compile-though... enum holeKeyOffset = 0x1; pragma(inline, true) static K holeKey() @trusted pure nothrow @nogc { return cast(K)((cast(size_t*)null) + holeKeyOffset); } enum _ = holeKey; fails as Error: cannot perform pointer arithmetic on non-arrays at compile time No, I mean you call holeKey at *runtime*. Inlined, it's just returning a constant, so it should reduce to a constant. -Steve
Re: is it possible to put some DDOC after auto generated blocks like unittest examples?
No, ddoc does not support that. You might be able to hack it with javascript though.
Re: Validity of cast(void*)size_t.max
On Monday, 5 March 2018 at 12:41:06 UTC, Steven Schveighoffer wrote: pragma(inline, true) C lazyDeleted() pure nothrow @trusted { return cast(C)((cast(size_t*)null) + 1); } I still can't evaluate at compile-though... enum holeKeyOffset = 0x1; pragma(inline, true) static K holeKey() @trusted pure nothrow @nogc { return cast(K)((cast(size_t*)null) + holeKeyOffset); } enum _ = holeKey; fails as Error: cannot perform pointer arithmetic on non-arrays at compile time
Thread Function does not executes
Hi All, Request your help, I have 3 functions such as below, I am calling these function using another function ptManage which executes these function's in parallel as each of the below 3 function run's on 10 - 12 different file systems, The issue is as below Issue: Most of the time the program executes perfectly, some time the function 2 is skipped, after analysis further I was able to find that if the 1st and 3rd functions(deleteFile, SizeDir) completes before the 2nd function(deleteAgedDir) then it skips, meaning the program is not waiting for all the thread to be completed before exiting the main. so any help on this would be much appreciated. Ti does not throw any exception or error the program exits' smoothly. Function: deleteFile : Delete file after a certain date deleteAgedDir : Delete folder after a certain date SizeDir : Finde Size of folder after a certain date Ex: auto deleteFile (string FFs, int AgeSize) { } auto deleteAgedDir (string FFs, int AgeSize) { } auto SizeDir (string FFs, int AgeSize) { auto TP = new TaskPool(TL); foreach (d; TP.parallel(dFiles[],1)) { Thread.sleep(5.seconds); TP.finish; } } void ptManage(T)(T function(string, string, int) coRoutine, Array!string Dirlst, int AgeSize) { alias scRType = typeof(coRoutine(string.init, string.init, int.init)); auto PFresult = taskPool.workerLocalStorage!scRType(); ReturnType!coRoutine rData; foreach (string FFs; parallel(Dirlst[0 .. $],1)) { PFresult.get ~= coRoutine(FFs.strip, Step, AgeSize); } foreach(i; PFresult.toRange) { rData ~= i[][]; } writeln(rData[]); } Void main() { ptManage(, CleanDirlst, AgeSize1); ptManage(, AgedDirlst, AgeSize2); ptManage(, AgeSize3); } From, Vino.B
Re: Speed of math function atan: comparison D and C++
On Monday, 5 March 2018 at 05:35:28 UTC, J-S Caux wrote: I'm considering shifting a large existing C++ codebase into D (it's a scientific code making much use of functions like atan, log etc). I've compared the raw speed of atan between C++ (Apple LLVM version 7.3.0 (clang-703.0.29)) and D (dmd v2.079.0, also ldc2 1.7.0) by doing long loops of such functions. I can't get the D to run faster than about half the speed of C++. Are there benchmarks for such scientific functions published somewhere? What compiled flags did you used to compile both C++ and D versions?
Re: Validity of cast(void*)size_t.max
On 3/5/18 6:41 AM, Nordlöw wrote: On Wednesday, 28 February 2018 at 20:07:50 UTC, Steven Schveighoffer wrote: auto x = cast(Object)((cast(size_t *)null) + 1); Thanks, how do I store it as enum or static immutable struct member? In @trusted pure unittest { class C { int value; } C x; C y = cast(C)((cast(size_t*)null) + 1); // indicates a lazily deleted key struct S { enum C hole1 = cast(C)((cast(size_t*)null) + 1); // TODO make work static immutable C hole2 = cast(C)((cast(size_t*)null) + 1); // TODO make work } } both `enum` and static` immutable` member declarations fail to compile with the same errors: Error: cannot perform pointer arithmetic on non-arrays at compile time Error: cannot perform pointer arithmetic on non-arrays at compile time My only possible solution so far is to return the expression from an inline member function which I guess cannot be optimized as good as comparing to a compile-time value. Weird, I would have expected to be able to map addresses at compile time, I suppose the way you could work it is: pragma(inline, true) C lazyDeleted() pure nothrow @trusted { return cast(C)((cast(size_t*)null) + 1); } Then you can simply use this like it was an enum or immutable. It should go away in terms of a function call. -Steve
Re: Validity of cast(void*)size_t.max
On Wednesday, 28 February 2018 at 20:07:50 UTC, Steven Schveighoffer wrote: auto x = cast(Object)((cast(size_t *)null) + 1); Thanks, how do I store it as enum or static immutable struct member? In @trusted pure unittest { class C { int value; } C x; C y = cast(C)((cast(size_t*)null) + 1); // indicates a lazily deleted key struct S { enum C hole1 = cast(C)((cast(size_t*)null) + 1); // TODO make work static immutable C hole2 = cast(C)((cast(size_t*)null) + 1); // TODO make work } } both `enum` and static` immutable` member declarations fail to compile with the same errors: Error: cannot perform pointer arithmetic on non-arrays at compile time Error: cannot perform pointer arithmetic on non-arrays at compile time My only possible solution so far is to return the expression from an inline member function which I guess cannot be optimized as good as comparing to a compile-time value.
Re: howto run unittest of a single module in dub driven project?
On Sunday, 4 March 2018 at 10:43:06 UTC, Arjan wrote: Is it somehow possible to only run the unittests of a single d file within a dub project? Of course without resorting to typing the complete commandline with all versions includes switches etc. You could use unit-threaded: http://code.dlang.org/packages/unit-threaded You'd still need to build everything, but `dub test` would take care of that. I started working on, and need to get back to, a way of only building one module and needed dependencies. Atila
Re: howto run unittest of a single module in dub driven project?
On Monday, 5 March 2018 at 09:19:52 UTC, Arjan wrote: On Sunday, 4 March 2018 at 16:51:06 UTC, Basile B. wrote: [1] https://github.com/BBasile/Coedit/commit/f8c5e686c8c6aaa7dc2c770121767e3e59806a0e Thanks for givin me the idea original poster. Guess I will have to give coedit another try then.. ;-) So you do use dub behind the scenes so it seems? Care to elaborate a little on how you achieved this? No this feature is based on dmd / ldmd or gdmd. It's a kind of rdmd. Basically the current source for the editor which has the focused: - is auto saved or saved to a temp file if it's a new module - its shebang is parsed to detect custom options (such as "-release" or "-g") - is optionally scanned to detect if the option "-main" has to be passed or not. - is optionally scanned to detect all "import ...;". The results are used to detect what are the deps in a database based on the "library manager". From the deps -I and *.a or *.lib or *.d are detected. - if the option for autodetection is not checked then the whole libman is passed as import path, additional source or libs to link. - everything is compiled - result is run. The same happens when using the action "run file unittest", just -unittest is added to the compiler arguments. Beside Coedit also support DUB single file package but nothing is done by the IDE, just DUB is called and the IDE let him doing his job ;)
Re: Speed of math function atan: comparison D and C++
On Monday, 5 March 2018 at 06:01:27 UTC, J-S Caux wrote: On Monday, 5 March 2018 at 05:40:09 UTC, rikki cattermole wrote: On 05/03/2018 6:35 PM, J-S Caux wrote: I'm considering shifting a large existing C++ codebase into D (it's a scientific code making much use of functions like atan, log etc). I've compared the raw speed of atan between C++ (Apple LLVM version 7.3.0 (clang-703.0.29)) and D (dmd v2.079.0, also ldc2 1.7.0) by doing long loops of such functions. I can't get the D to run faster than about half the speed of C++. Are there benchmarks for such scientific functions published somewhere Gonna need to disassemble and compare them. atan should work out to only be a few instructions (inline assembly) from what I've looked at in the source. Also you should post the code you used for each. So the codes are trivial, simply some check of raw speed: double x = 0.0; for (int a = 0; a < 10; ++a) x += atan(1.0/(1.0 + sqrt(1.0 + a))); for C++ and double x = 0.0; for (int a = 0; a < 1_000_000_000; ++a) x += atan(1.0/(1.0 + sqrt(1.0 + a))); for D. C++ exec takes 40 seconds, D exec takes 68 seconds. Depending on your platform, the size of `double` could be different between C++ and D. Could you check that the size and precision are indeed the same? Also, benchmark method is just as important as benchmark code. Did you use DMD or LDC as the D compiler? In this case it shouldn't matter, but try with LDC if you haven't. Also ensure that you've used the right flags: `-release -inline -O`. If the D version is still slower, you could try using the C version of the function Simply change `import std.math: atan;` to `core.stdc.math: atan;` [0] [0]: https://dlang.org/phobos/core_stdc_math.html#.atan
Re: howto run unittest of a single module in dub driven project?
On Sunday, 4 March 2018 at 16:51:06 UTC, Basile B. wrote: [1] https://github.com/BBasile/Coedit/commit/f8c5e686c8c6aaa7dc2c770121767e3e59806a0e Thanks for givin me the idea original poster. Guess I will have to give coedit another try then.. ;-) So you do use dub behind the scenes so it seems? Care to elaborate a little on how you achieved this?