Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Re: Code optimisation

Reply
Thread Tools

Re: Code optimisation

 
 
mjm
Guest
Posts: n/a
 
      08-29-2003
If these arrays are really big memory bandwidth will be the constraint.
So I would check if I can get by with floats instead of doubles.

To improve the locality of reference I would not have separate arrays
in, out, test since for each i the locations of in[i], out[i] and test[i]
won't be anywhere near each other in main memory so that three different cache
lines will have to be written into the L2 cache from memory.

Instead I would have a vector vec of structs

struct {

int test;
float in, out;

};

where vec[i] contains test[i], in[i], out[i].
 
Reply With Quote
 
 
 
 
Pete
Guest
Posts: n/a
 
      08-29-2003

"mjm" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> If these arrays are really big memory bandwidth will be the constraint.
> So I would check if I can get by with floats instead of doubles.
>
> To improve the locality of reference I would not have separate arrays
> in, out, test since for each i the locations of in[i], out[i] and test[i]
> won't be anywhere near each other in main memory so that three different

cache
> lines will have to be written into the L2 cache from memory.
>
> Instead I would have a vector vec of structs
>
> struct {
>
> int test;
> float in, out;
>
> };
>
> where vec[i] contains test[i], in[i], out[i].


Thanks for that advice.

Unfortunately I can't fully implement this approach since the vector out
actually corresponds to 3 sepatate vectors which arise as part of the
iterative solution scheme. So whilst test[[] and in[] can always be paired
in this way, out [] cannot.

I take your point about localising thing in memory though and I'm applying
this in a few other places.

One problem that this does cause is the lack of const control - I've raised
this in a separate thread.

Thanks again
Pete.


 
Reply With Quote
 
 
 
 
Peter van Merkerk
Guest
Posts: n/a
 
      08-29-2003
> Unfortunately I can't fully implement this approach since the vector
out
> actually corresponds to 3 sepatate vectors which arise as part of the
> iterative solution scheme. So whilst test[[] and in[] can always be

paired
> in this way, out [] cannot.
>
> I take your point about localising thing in memory though and I'm

applying
> this in a few other places.
>
> One problem that this does cause is the lack of const control - I've

raised
> this in a separate thread.


Another thing that might be problematic for the optimizer is aliasing.
Since the out, in and test pointers might point to the same memory block
(you might know that this is never the case but the compiler doesn't),
the compiler must assume that writing to out[] may change in[] and/or
test[] as well which prevents some optimizations. Using const for in[]
and test[] doesn't help the optimizer, as it only tells that memory
should not be changed trough the in and test vectors, not that the
memory cannot change (via out[]).

Some compilers have an option "assume no aliasing", which tells the
optimizer that it may assume that writing to out[] won't affect in[] and
test[]. Other compilers may support the restrict keyword (borrowed from
C99), which essentially does the same thing.

--
Peter van Merkerk
peter.van.merkerk(at)dse.nl


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
please help with optimisation of this code - update of given table according to another table Farraige Python 4 11-08-2006 07:58 PM
Re: Code optimisation Rob Williscroft C++ 2 08-28-2003 07:39 AM
Re: Code optimisation Peter van Merkerk C++ 1 08-27-2003 09:26 PM
Re: Code optimisation Rob Williscroft C++ 1 08-27-2003 07:49 PM
Re: Code optimisation Agent Mulder C++ 1 08-27-2003 01:18 PM



Advertisments