Re: Code optimisation

Discussion in 'C++' started by mjm, Aug 29, 2003.

  1. mjm

    mjm Guest

    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, out and test
    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 contains test, in, out.
     
    mjm, Aug 29, 2003
    #1
    1. Advertising

  2. mjm

    Pete Guest

    "mjm" <> wrote in message
    news:...
    > 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, out and test
    > 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 contains test, in, out.


    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.
     
    Pete, Aug 29, 2003
    #2
    1. Advertising

  3. > 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
     
    Peter van Merkerk, Aug 29, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Agent Mulder

    Re: Code optimisation

    Agent Mulder, Aug 27, 2003, in forum: C++
    Replies:
    1
    Views:
    309
    Peter van Merkerk
    Aug 27, 2003
  2. Rob Williscroft

    Re: Code optimisation

    Rob Williscroft, Aug 27, 2003, in forum: C++
    Replies:
    2
    Views:
    359
    Peter van Merkerk
    Aug 28, 2003
  3. Rob Williscroft

    Re: Code optimisation

    Rob Williscroft, Aug 27, 2003, in forum: C++
    Replies:
    1
    Views:
    348
    Peter van Merkerk
    Aug 27, 2003
  4. Peter van Merkerk

    Re: Code optimisation

    Peter van Merkerk, Aug 27, 2003, in forum: C++
    Replies:
    1
    Views:
    356
    Alan Sung
    Aug 27, 2003
  5. Farraige
    Replies:
    4
    Views:
    287
    Farraige
    Nov 8, 2006
Loading...

Share This Page