Re: How to initialize an immutable array

2013-03-01 Thread FG
On 2013-03-01 22:05, Sparsh Mittal wrote: On Friday, 1 March 2013 at 20:28:19 UTC, FG wrote: I suppose this: immutable long DIM = 1024L*1024L *128L; immutable(double)[] signal = new double[DIM+1]; static this() { for (long i=0L; i< DIM+1; i++) { signal[i] = (i+DIM)%7 + (i+DIM+1)%5;

Re: How to initialize an immutable array

2013-03-01 Thread bearophile
Sparsh Mittal: Thanks. However, rdmd gives error on this line: temp1.d(12): Error: no identifier for declarator immutable(i) Probably v.2.062 of the D compiler is enough to not see that error. Bye, bearophile

Re: How to initialize an immutable array

2013-03-01 Thread Sparsh Mittal
I realized that access to "temp" causes bottleneck. On defining it inside for loop, it become local and then there is speedup. Defining it outside makes it shared, which slows the program.

Re: How to initialize an immutable array

2013-03-01 Thread Sparsh Mittal
Removing immutable word solves the problem. Thanks.

Re: How to initialize an immutable array

2013-03-01 Thread Sparsh Mittal
On Friday, 1 March 2013 at 20:28:19 UTC, FG wrote: I suppose this: immutable long DIM = 1024L*1024L *128L; immutable(double)[] signal = new double[DIM+1]; static this() { for (long i=0L; i< DIM+1; i++) { signal[i] = (i+DIM)%7 + (i+DIM+1)%5; } } void main() { ... } Thanks. This

Re: How to initialize an immutable array

2013-03-01 Thread Sparsh Mittal
foreach (immutable i; 0 .. DIM + 1) { Thanks. However, rdmd gives error on this line: temp1.d(12): Error: no identifier for declarator immutable(i)

Re: How to initialize an immutable array

2013-03-01 Thread bearophile
Sparsh Mittal: So, is there a way, an array can be made immutable and still initialized? Thanks a lot for your time. There are various ways to do it. One of the safest way to do it is to create a mutable array inside a strongly pure function, and then when you return it assign it to immutabl

Re: How to initialize an immutable array

2013-03-01 Thread FG
I suppose this: immutable long DIM = 1024L*1024L *128L; immutable(double)[] signal = new double[DIM+1]; static this() { for (long i=0L; i< DIM+1; i++) { signal[i] = (i+DIM)%7 + (i+DIM+1)%5; } } void main() { ... }

Re: How to initialize an immutable array

2013-03-01 Thread Sparsh Mittal
Array is really big! import std.stdio; import std.datetime; import std.parallelism; import std.range; //int numberOfWorkers = 2; //for parallel; double my_abs(double n) { return n > 0 ? n : -n; } immutable long DIM = 1024L*1024L *128L; void main() { double[] signal = new double[DIM+1]; d

Re: How to initialize an immutable array

2013-03-01 Thread Dicebot
On Friday, 1 March 2013 at 20:05:41 UTC, Sparsh Mittal wrote: I am making a program which accesses 1D array using for loop and then I am parallelizing this with foreach, TaskPool and parallel. The array does not need to change, once initialized. However, the parallel version takes more time t

How to initialize an immutable array

2013-03-01 Thread Sparsh Mittal
I am making a program which accesses 1D array using for loop and then I am parallelizing this with foreach, TaskPool and parallel. The array does not need to change, once initialized. However, the parallel version takes more time than serial version, which I think may be because compiler is tr