Re: [julia-users] Re: FDTD 2D acoustic

2015-10-12 Thread Alain Clo
Thanks Steven. It is far more elegant than the trunc function.


Another question is the way that I use to produce image/bitmap using Gadfly.
Is there a more efficient way to produce those bitmaps and to display them ?



2015-10-12 6:14 GMT+03:00 Steven G. Johnson :

>
>
> On Sunday, October 11, 2015 at 4:48:55 PM UTC-4, Kristoffer Carlsson wrote:
>>
>> Some unsolicited comments on the code.
>>
>> You probably want to change line 118 and 119 to
>>
>> sxloc = trunc(Int, mxnx / 2)
>> szloc = trunc(Int, mxnz / 2)
>>
>> so that they really are ints, Without the "Int" it will still be a float.
>>
>
> Probably it is cleaner to use div, via div(mxnx, 2) or simply mxnx÷2, if
> you want truncated integer division (similar to / in C).
>


[julia-users] Re: FDTD 2D acoustic

2015-10-12 Thread Páll Haraldsson
On Sunday, October 11, 2015 at 10:07:30 PM UTC, Kristoffer Carlsson wrote:
>
> The reason for the improvements when you fixed the truncations is that 
> indexing with a float is deprecated
>

Good to know.. But I would think indexing with a float per se is slow (even 
in 0.3.11).. One of the strange things in JavaScript, is there are only 
floats (double) and no integers, and I'm looking into how Julia can support 
compilation to JavaScript.. Seems the depecation may complicate things.
 

> and calling deprecated methods is very slow.
>

I guess only in 0.4.0 you get warning printed (repeatedly) just adding to 
the slowness.

For good performance it is therefore important not to repeatedly call any 
> deprecated method.
>

-- 
Palli.



Re: [julia-users] Re: FDTD 2D acoustic

2015-10-12 Thread Tim Holy
For displaying bitmaps, consider ImageView.

--Tim

On Monday, October 12, 2015 12:28:45 PM Alain Clo wrote:
> Thanks Steven. It is far more elegant than the trunc function.
> 
> 
> Another question is the way that I use to produce image/bitmap using Gadfly.
> Is there a more efficient way to produce those bitmaps and to display them
> ?
> 2015-10-12 6:14 GMT+03:00 Steven G. Johnson :
> > On Sunday, October 11, 2015 at 4:48:55 PM UTC-4, Kristoffer Carlsson wrote:
> >> Some unsolicited comments on the code.
> >> 
> >> You probably want to change line 118 and 119 to
> >> 
> >> sxloc = trunc(Int, mxnx / 2)
> >> szloc = trunc(Int, mxnz / 2)
> >> 
> >> so that they really are ints, Without the "Int" it will still be a float.
> > 
> > Probably it is cleaner to use div, via div(mxnx, 2) or simply mxnx÷2, if
> > you want truncated integer division (similar to / in C).



[julia-users] Re: FDTD 2D acoustic

2015-10-11 Thread Kristoffer Carlsson
Maybe you can give a link to the updated code?

[julia-users] Re: FDTD 2D acoustic

2015-10-11 Thread Alain Clo
See attached the updated code ( slight modifications, code embedded into a 
function acoustic(), and some loops interchanged).
To see some images, uncomment at the end of the code.
Enjoy !
Alain
Le dimanche 11 octobre 2015 21:30:43 UTC+3, Kristoffer Carlsson a écrit :
>
> Maybe you can give a link to the updated code?



array-acoustic.jl
Description: Binary data


Re: [julia-users] Re: FDTD 2D acoustic

2015-10-11 Thread Alain Clo
Yes, I will take a look at shared arrays. The halo ( overlap of arrays
resulting from the poisson's part of the wave equation) might be easier to
program with a shared array.
I will make an MPI version from the fortran as well. Is there an MPI for
Julia available somewhere ?
Thanks for your valuable inputs. I made tremendous progress recently
-Alain

2015-10-12 1:07 GMT+03:00 Kristoffer Carlsson :

> The reason for the improvements when you fixed the truncations is that
> indexing with a float is deprecated and calling deprecated methods is very
> slow. For good performance it is therefore important not to repeatedly call
> any deprecated method.
>
> @inbounds is good if you have a very tight loop with many vector loads
> (like in your example). Remember that @inbounds turns off bounds checking
> so if you mess up you can segfault or get garbage data.
>
> For parallellization I would look at shared arrays:
> http://julia.readthedocs.org/en/latest/manual/parallel-computing/#shared-arrays
>
> On Sunday, October 11, 2015 at 11:28:08 PM UTC+2, Alain Clo wrote:
>>
>> Pretty good improvements Thanks to you Kristoffer.
>> I am puzzled why the changes on the truncations for sxloc and szloc
>> brings a factor of 3 to the whole program,
>> to the loop underneath. Maybe the truncation changed the indexing type to
>> the whole array, right ?
>> How did you figure out this affect ?
>>
>> Regarding @inbounds and @fastmath. I have the same question, but I see
>> them now in the performance tips.
>> Maybe as a generic rule, those options have to be checked.
>>
>> Would you have any suggestions for parallelisation ?
>>
>> Thanks for the feedback
>> Alain
>>
>>
>>
>>
>> Le dimanche 11 octobre 2015 23:48:55 UTC+3, Kristoffer Carlsson a écrit :
>>>
>>> Some unsolicited comments on the code.
>>>
>>> You probably want to change line 118 and 119 to
>>>
>>> sxloc = trunc(Int, mxnx / 2)
>>> szloc = trunc(Int, mxnz / 2)
>>>
>>> so that they really are ints, Without the "Int" it will still be a float.
>>>
>>> As a base line, your code for me ran in 1.239 seconds.
>>>
>>> Adding "@inbounds" on line 127 takes this down to 0.75 seconds.
>>>
>>> Adding "@fastmath" on the same line reduces it further down to 0.52
>>> seconds. Normal caveats for fastmath of course applies.
>>>
>>> // Kristoffer
>>>
>>>
>>>
>>> On Sunday, October 11, 2015 at 9:32:04 PM UTC+2, Alain Clo wrote:

 See attached the updated code ( slight modifications, code embedded
 into a function acoustic(), and some loops interchanged).
 To see some images, uncomment at the end of the code.
 Enjoy !
 Alain
 Le dimanche 11 octobre 2015 21:30:43 UTC+3, Kristoffer Carlsson a
 écrit :
>
> Maybe you can give a link to the updated code?




[julia-users] Re: FDTD 2D acoustic

2015-10-11 Thread Alain Clo
Pretty good improvements Thanks to you Kristoffer.
I am puzzled why the changes on the truncations for sxloc and szloc brings 
a factor of 3 to the whole program,
to the loop underneath. Maybe the truncation changed the indexing type to 
the whole array, right ?
How did you figure out this affect ?

Regarding @inbounds and @fastmath. I have the same question, but I see them 
now in the performance tips.
Maybe as a generic rule, those options have to be checked. 

Would you have any suggestions for parallelisation ?

Thanks for the feedback
Alain




Le dimanche 11 octobre 2015 23:48:55 UTC+3, Kristoffer Carlsson a écrit :
>
> Some unsolicited comments on the code.
>
> You probably want to change line 118 and 119 to
>
> sxloc = trunc(Int, mxnx / 2)   
> szloc = trunc(Int, mxnz / 2)   
>
> so that they really are ints, Without the "Int" it will still be a float.
>
> As a base line, your code for me ran in 1.239 seconds.
>
> Adding "@inbounds" on line 127 takes this down to 0.75 seconds.
>
> Adding "@fastmath" on the same line reduces it further down to 0.52 
> seconds. Normal caveats for fastmath of course applies.
>
> // Kristoffer
>
>
>
> On Sunday, October 11, 2015 at 9:32:04 PM UTC+2, Alain Clo wrote:
>>
>> See attached the updated code ( slight modifications, code embedded into 
>> a function acoustic(), and some loops interchanged).
>> To see some images, uncomment at the end of the code.
>> Enjoy !
>> Alain
>> Le dimanche 11 octobre 2015 21:30:43 UTC+3, Kristoffer Carlsson a écrit :
>>>
>>> Maybe you can give a link to the updated code?
>>
>>

[julia-users] Re: FDTD 2D acoustic

2015-10-11 Thread Kristoffer Carlsson
The reason for the improvements when you fixed the truncations is that 
indexing with a float is deprecated and calling deprecated methods is very 
slow. For good performance it is therefore important not to repeatedly call 
any deprecated method.

@inbounds is good if you have a very tight loop with many vector loads 
(like in your example). Remember that @inbounds turns off bounds checking 
so if you mess up you can segfault or get garbage data.

For parallellization I would look at shared 
arrays: 
http://julia.readthedocs.org/en/latest/manual/parallel-computing/#shared-arrays

On Sunday, October 11, 2015 at 11:28:08 PM UTC+2, Alain Clo wrote:
>
> Pretty good improvements Thanks to you Kristoffer.
> I am puzzled why the changes on the truncations for sxloc and szloc brings 
> a factor of 3 to the whole program,
> to the loop underneath. Maybe the truncation changed the indexing type to 
> the whole array, right ?
> How did you figure out this affect ?
>
> Regarding @inbounds and @fastmath. I have the same question, but I see 
> them now in the performance tips.
> Maybe as a generic rule, those options have to be checked. 
>
> Would you have any suggestions for parallelisation ?
>
> Thanks for the feedback
> Alain
>
>
>
>
> Le dimanche 11 octobre 2015 23:48:55 UTC+3, Kristoffer Carlsson a écrit :
>>
>> Some unsolicited comments on the code.
>>
>> You probably want to change line 118 and 119 to
>>
>> sxloc = trunc(Int, mxnx / 2)   
>> szloc = trunc(Int, mxnz / 2)   
>>
>> so that they really are ints, Without the "Int" it will still be a float.
>>
>> As a base line, your code for me ran in 1.239 seconds.
>>
>> Adding "@inbounds" on line 127 takes this down to 0.75 seconds.
>>
>> Adding "@fastmath" on the same line reduces it further down to 0.52 
>> seconds. Normal caveats for fastmath of course applies.
>>
>> // Kristoffer
>>
>>
>>
>> On Sunday, October 11, 2015 at 9:32:04 PM UTC+2, Alain Clo wrote:
>>>
>>> See attached the updated code ( slight modifications, code embedded into 
>>> a function acoustic(), and some loops interchanged).
>>> To see some images, uncomment at the end of the code.
>>> Enjoy !
>>> Alain
>>> Le dimanche 11 octobre 2015 21:30:43 UTC+3, Kristoffer Carlsson a écrit :

 Maybe you can give a link to the updated code?
>>>
>>>

[julia-users] Re: FDTD 2D acoustic

2015-10-11 Thread Steven G. Johnson


On Sunday, October 11, 2015 at 4:48:55 PM UTC-4, Kristoffer Carlsson wrote:
>
> Some unsolicited comments on the code.
>
> You probably want to change line 118 and 119 to
>
> sxloc = trunc(Int, mxnx / 2)   
> szloc = trunc(Int, mxnz / 2)   
>
> so that they really are ints, Without the "Int" it will still be a float.
>

Probably it is cleaner to use div, via div(mxnx, 2) or simply mxnx÷2, if 
you want truncated integer division (similar to / in C). 


[julia-users] Re: FDTD 2D acoustic

2015-10-06 Thread Alain Clo
I just found out the reason why it is so slow. Most of the variables were 
global, allocated on the heap.
So I put the program into a function. Now it runs 40 times faster.

Le mercredi 7 octobre 2015 00:40:10 UTC+3, Alain Clo a écrit :
>
> Hello, 
> I am a new user of Julia and I would like to introduce Julia to 
> researchers and students
> in the university.
>
> As to give a try, I translated a fortran code to Julia.
> This code implements the propagation of a 2D acoustic wave using finite 
> differences.
> The code produces good numerical results, 
> and I am using gadfly to display the results (currently commented)
>
> The not so good news is that it is very slow, 100 times slower than 
> fortran.
> It spends most the time in the loops at line 121. I do not know why it is 
> so slow.
> I guess that I must be doing something really wrong. (maybe in the array 
> allocations !)
>
> Can someone take a look at the code and give me some hints.
> Thanks
> Alain
>
>