Historical Data
Which site is good to find up to 3 years of historical data through CSV?
Parallel example fron documentation does not compile
This code snippet is from: http://dlang.org/phobos/std_parallelism.html --- import std.algorithm, std.parallelism, std.range; void main() { // Parallel reduce can be combined with // std.algorithm.map to interesting effect. // The following example (thanks to Russel Winder) // calculates pi by quadrature using // std.algorithm.map and TaskPool.reduce. // getTerm is evaluated in parallel as needed by // TaskPool.reduce. // // Timings on an Athlon 64 X2 dual core machine: // // TaskPool.reduce: 12.170 s // std.algorithm.reduce: 24.065 s immutable n = 1_000_000_000; immutable delta = 1.0 / n; real getTerm(int i) { immutable x = ( i - 0.5 ) * delta; return delta / ( 1.0 + x * x ) ; } immutable pi = 4.0 * taskPool.reduce!"a + b"( std.algorithm.map!getTerm(iota(n)) ); } dmd compiler gives error: /usr/include/dmd/phobos/std/parallelism.d(2624): Error: function std.parallelism.TaskPool.reduce!"a + b".reduce!(MapResult!(getTerm, Result)).reduce cannot get frame pointer to D main Is there way to compile it? -Ish
gdc-4.4 on sparc64 debian linux?
Where can I find help on this? -ish
mutex usage problem?
The following code does core dump (compiled with gdc). Pointers will be appreciated. import std.stdio; import std.conv; import std.math; import std.concurrency; import core.thread; import core.sync.mutex; enum count = 5; __gshared double rslt = 0.0; __gshared Mutex mutex; void term(immutable(int)* nterm) { double r; auto n = to!double(*nterm); r = 4.0*pow(-1.0, *nterm)/(2.0*n + 1); writefln("%s: %6.6f.", *nterm, r); mutex.lock(); rslt = rslt + r; mutex.unlock(); } void main() { foreach (i; 0 .. count) { int* jm = new int; *jm = i; immutable int *j = cast(immutable) jm; Tid tid = spawn(, j); } thread_joinAll(); writefln("Result: %6.9f.", rslt); } -ish
taskPool.reduce() help
The following code does not compile (with gdc) but if the line containing taskPool.reduce is reduce it does compile. Any pointers will be appreciated. import std.stdio; import std.math; import std.algorithm; import std.parallelism; // does not work!! import core.thread; double aCalculation(double result, int element) { double r = 4.0*(pow(-1.0, element)/(2.0*cast(double)element + 1.0)); result += r; return result; } void main() { writefln("Result: %7.2f.", taskPool.reduce!aCalculation(0.0, [0, 1, 2, 3, 4])); } -ish
Re: Thread in detached state?
On Thursday, 19 November 2015 at 22:07:19 UTC, ZombineDev wrote: On Friday, 13 November 2015 at 15:35:11 UTC, Ish wrote: [...] If you're more familiar with pthreads, you can just use them from core.sys.posix.pthread [1]. After all this what core.thread uses on Posix [2]. In general you can use any OS functionality by importing the declarations you need from core.sys.[OS].[header] [3]. However you need to make sure to register your thread if you are going to use features of D that need runtime support (such as the GC). [...] Well I was trying to see how many threads could be created by a process. Linux has limit of 380 joinable threads (POSIX) per process. OS runs out of resources at this point. To increase the limit one has to recover the resources right away when a thread terminates. I will look into the links that you posted. Thanks for answering my query.
Re: Thread in detached state?
On Friday, 13 November 2015 at 19:45:58 UTC, Ali Çehreli wrote: On 11/13/2015 07:35 AM, Ish wrote: [...] I think the following is the idea: import std.stdio; import core.thread; extern(C) void rt_moduleTlsDtor(); void threadFunc() { writeln("Worker thread started"); thread_detachThis(); scope(exit) rt_moduleTlsDtor(); foreach (i; 0 .. 3) { Thread.sleep(1.seconds); writeln("Working..."); } writeln("Worker terminating"); } void main() { writeln("Creating thread in main"); auto worker = new Thread(); writeln("Starting thread in main"); worker.start(); writeln("main terminating"); } The output: Creating thread in main Starting thread in main main terminating Worker thread started Working... Working... Working... Worker terminating Ali Does not produce the desired effect. For 380 threads (Linux limit) it works, for 381 threads it dies. The program termination is exactly same as in 381 threads created using spawn().
A new instance of a variable?
foreach (i; 0..5) { immutable int j = i; etc. } I want each j to be assigned separate memory so that it can be passed to a calle function and not overwritten by next value of i in foreach()??
Thread in detached state?
I was directed here from General list, so be patient with me. I am looking for syntax for creating a detached-state thread in the spirit of POSIX thread attribute PTHREAD_CREATE_DETACHED (the thread resources are released on termination and not when the main thread terminates - allows for a very large number of threads). Sample code with call will be helpful.
Re: A new instance of a variable?
On Friday, 13 November 2015 at 18:10:38 UTC, Marc Schütz wrote: On Friday, 13 November 2015 at 17:44:31 UTC, Ish wrote: On Friday, 13 November 2015 at 16:06:51 UTC, Alex Parrill wrote: [...] immutable int* j = new immutable int(i); gives error: locks1.d:27: error: no constructor for immutable(int); I need to allocate separate objects as the value is passed to a separate thread as: void incrementer(immutable int* nterm, shared(Lock) lock) { etc. } This compiles for me with 2.068, 2.069 and latest Git (Linux x86_64): void main() { foreach(i; 0 .. 1) { immutable int* j = new immutable int(i); } } Can you post more of your actual code? I am using gdc w/gcc.4.9.2 (backend). So, I should have mentioned it before making so much noise. Code provided also does not compile.
Re: A new instance of a variable?
On Friday, 13 November 2015 at 16:06:51 UTC, Alex Parrill wrote: On Friday, 13 November 2015 at 15:49:01 UTC, Ish wrote: foreach (i; 0..5) { immutable int j = i; etc. } I want each j to be assigned separate memory so that it can be passed to a calle function and not overwritten by next value of i in foreach()?? Just like in C, you'll have to allocate storage for each object you create. immutable int* j = new immutable int(i); Though if you use `new`, you can let the GC free them. But if the data is immutable, then there's no point in allocating separate objects for each number, since they can't be changed. immutable int* j = new immutable int(i); gives error: locks1.d:27: error: no constructor for immutable(int); I need to allocate separate objects as the value is passed to a separate thread as: void incrementer(immutable int* nterm, shared(Lock) lock) { etc. }