tuguldur.s If you are looking for high performance, then it is important to keep in mind how things are laid out in memory. The best memory layout is unfortunately described by a different type -- as you suggest, you would create Vectors for each piece of information separately. This is e.g. important to allow SIMD vectorization:
const D=3
type Packets{T}
IDs::Vector{T}
positions::NTuple{D, Vector{T}}
directions::NTuple{D, Vector{T}}
energies::Vector{T}
times::Vector{T}
end
If you want to keep these pieces of information closer together (likely at a
significant cost), then you would use "immutable" instead of "type", and
"NTuple" (as above) instead of "Vector" to ensure that you don't need to
allocate memory for each packet separately. (I'm not sure how tuples are
currently allocated, but from what I gather, the plan is at least to make them
efficient in this way in the near future.)
-erik
> On Jan 13, 2015, at 23:34 , [email protected] wrote:
>
> I am writing a monte carlo radiation transport code (for applications in
> astrophysics), where I follow the temporal and spacial evolution of millions
> of whats called "monte-carlo packets". And I am wondering whether if I should
> use the Julia's type system, if so how should I implement it and also if
> there is any performance loss/gain.
>
> Let's say I define a type like following (based on this example tutorial):
>
> type Packet{T}
> ID::{T}
> position::Vector{T}
> direction::Vector{T}
> energy::{T}
> time::{T}
> end
>
> obviously this could make the code much more easier to read than a version
> with all information represented in separate arrays. But beside this
> elegance, is there anything else I should know about types? when I apply this
> to millions of objects will there be any effect to the performance?
>
> thanks,
--
Erik Schnetter <[email protected]>
http://www.perimeterinstitute.ca/personal/eschnetter/
My email is as private as my paper mail. I therefore support encrypting
and signing email messages. Get my PGP key from http://pgp.mit.edu/.
signature.asc
Description: Message signed with OpenPGP using GPGMail
