BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to improve performance of C++ complex template?
Goto page 1, 2  Next
 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Language C++)
View previous topic :: View next topic  
Author Message
Radek
Guest





PostPosted: Sat Dec 17, 2005 7:56 am    Post subject: How to improve performance of C++ complex template? Reply with quote



Hi all,

I wrote the simulation of technique used in UMTS and I am heavily using STL
complex template and I have noticed strange thing. When I am using
complex<float> instead of complex<double> it is almost 60% slower. Are there
any compiler options that my improve thatI? don't know why it is like that
and whether there is a way to improve performance of complex template in
general or not. I need to transmit 10 000 000 bits in my simulation which
takes ages and I am a little bit confused with speed of my simulation.

A little more about my simulation:
I generate bits in a function and bits are stored in INT array. Then there
is channel coding, spreading and some more operations done on bits. Every
single array that stores bits s INT. Then there is QPSK modulation which
converts two bits into one complex symbol. All complex symbols are stored in
dynamically declared complex<double> arrays. Before complex symbols are
transmitted through the channel complex<double> is put into array of
structures, because channel is written in such a way that it takes pointer
to array of structures as an argument. After transmission throug the channel
there are some more functions called that operates on array of structures
and then again it is converted to complex<double> to make use of complex
template which is quite simple and straight forward to use. And then again
complex<double> is converted into bits (each complex symbol into two bits).

I tried to change all int arrays into short without expected result (speed
boost). I tried the same with char (the same result). As for my compiler
settings I have default settings with one change: Data Aligment is Quad Word
not default Double Word.

Any help, hints, remarks will be much appreciated.

Best regards,

Radek


Back to top
Rob
Guest





PostPosted: Sat Dec 17, 2005 10:28 am    Post subject: Re: How to improve performance of C++ complex template? Reply with quote



Radek wrote:

Quote:
Hi all,

I wrote the simulation of technique used in UMTS and I am heavily
using STL complex template and I have noticed strange thing. When I
am using complex<float> instead of complex<double> it is almost 60%
slower. Are there any compiler options that my improve thatI? don't
know why it is like that and whether there is a way to improve
performance of complex template in general or not. I need to transmit
10 000 000 bits in my simulation which takes ages and I am a little
bit confused with speed of my simulation.

I doubt it would be affected by compiler options. One weakness of C++
(which it inherits from C) is that a lot of operations on a float
involve an implicit conversion of the float to a double. Several math
functions also act on double argument(s) and return a double, meaning a
need to convert back the other way. Depending on how it's done, those
conversions can introduce a performance hit.



Quote:

A little more about my simulation:
I generate bits in a function and bits are stored in INT array. Then
there is channel coding, spreading and some more operations done on
bits. Every single array that stores bits s INT. Then there is QPSK
modulation which converts two bits into one complex symbol. All
complex symbols are stored in dynamically declared complex<double
arrays. Before complex symbols are transmitted through the channel
complex written in such a way that it takes pointer to array of structures as
an argument. After transmission throug the channel there are some
more functions called that operates on array of structures and then
again it is converted to complex<double> to make use of complex
template which is quite simple and straight forward to use. And then
again complex<double> is converted into bits (each complex symbol
into two bits).

It is possible that your conversion from complex<double> to and from
bits is introducing a performance hit. Going to complex<float> will
not give you much benefit if it is necessary to convert the real and
imaginary parts of the complex value to double values.

Quote:

I tried to change all int arrays into short without expected result
(speed boost). I tried the same with char (the same result). As for
my compiler settings I have default settings with one change: Data
Aligment is Quad Word not default Double Word.


AS for the double vs float, there is no guarantee that operations on a
short will be implicitly more (or less) efficient than those on a long.
And an int might be either a short or a long, depending on your
compiler (although with BCB, int and long are the same).

I would be surprised if changing data alignment to quad word would give
a performance advantage.

The basic issue is that performance (however you define it) depends as
much on the operating system and hardware as it does on compiler
settings and your code. The only way to be sure is to test .....

Back to top
Zara
Guest





PostPosted: Sat Dec 17, 2005 12:18 pm    Post subject: Re: How to improve performance of C++ complex template? Reply with quote



On Sat, 17 Dec 2005 08:56:20 +0100, "Radek"
<radekkedzior (AT) poczta (DOT) onet.pl> wrote:

Quote:
Hi all,

I wrote the simulation of technique used in UMTS and I am heavily using STL
complex template and I have noticed strange thing. When I am using
complex<float> instead of complex<double> it is almost 60% slower. Are there
any compiler options that my improve thatI? don't know why it is like that
and whether there is a way to improve performance of complex template in
general or not. I need to transmit 10 000 000 bits in my simulation which
takes ages and I am a little bit confused with speed of my simulation.

Try to make all calculations using doubles, and convert to float only
for transmission. The type double is the natural type for C/C++ and a
s such it is faster than float. It should be the type supported by the
FP coprocessor, when there is one available.

Quote:

A little more about my simulation:
I generate bits in a function and bits are stored in INT array. Then there
is channel coding, spreading and some more operations done on bits. Every
single array that stores bits s INT. Then there is QPSK modulation which
converts two bits into one complex symbol. All complex symbols are stored in
dynamically declared complex<double> arrays. Before complex symbols are
transmitted through the channel complex<double> is put into array of
structures, because channel is written in such a way that it takes pointer
to array of structures as an argument. After transmission throug the channel
there are some more functions called that operates on array of structures
and then again it is converted to complex<double> to make use of complex
template which is quite simple and straight forward to use. And then again
complex<double> is converted into bits (each complex symbol into two bits).

I tried to change all int arrays into short without expected result (speed
boost). I tried the same with char (the same result). As for my compiler
settings I have default settings with one change: Data Aligment is Quad Word
not default Double Word.

Again, fast calculations are guaranted for int type. All the others
must be internally converetd to/from int, so the may behave even more
slowly.
Quote:

Any help, hints, remarks will be much appreciated.

Best regards,

Radek


I think your botteleneck lies in all those structure type conversions,
that may need intensive meory copying and type transformation.

My 2 cents: use some profiling sytm to identify what is really slowing
your system, instead of this trial-and error method you seem to be
using

Regards,

Zara

Back to top
Alan Bellingham
Guest





PostPosted: Sat Dec 17, 2005 2:25 pm    Post subject: Re: How to improve performance of C++ complex template? Reply with quote

"Rob" <nospam (AT) nonexistant (DOT) com> wrote:

Quote:
I doubt it would be affected by compiler options. One weakness of C++
(which it inherits from C) is that a lot of operations on a float
involve an implicit conversion of the float to a double. Several math
functions also act on double argument(s) and return a double, meaning a
need to convert back the other way. Depending on how it's done, those
conversions can introduce a performance hit.

The common advice I've encountered is to use double, and only to use
float if you have space problems.

Alan Bellingham
--
Team Thai Kingdom
<url:http://www.borland.com/newsgroups/> Borland newsgroup descriptions
<url:http://www.borland.com/newsgroups/netiquette.html> netiquette

Back to top
Radek
Guest





PostPosted: Sat Dec 17, 2005 3:44 pm    Post subject: Re: How to improve performance of C++ complex template? Reply with quote

Quote:
I would be surprised if changing data alignment to quad word would give
a performance advantage.

The basic issue is that performance (however you define it) depends as
much on the operating system and hardware as it does on compiler
settings and your code. The only way to be sure is to test .....

Thanks for reply. I have already tried different compiler settings and so on
but as I have writtem without any results. I know that it highly depends on
hardware and OS but I hoped there is other way to optimize the code except
modyfing assembler code that I don't feel confident about.

Thanks again.

Radek



Back to top
Radek
Guest





PostPosted: Sat Dec 17, 2005 3:45 pm    Post subject: Re: How to improve performance of C++ complex template? Reply with quote

Quote:
The common advice I've encountered is to use double, and only to use
float if you have space problems.

Ok. I have also noticed that but at first I was really astonished that
double is faster than float. Anyway I will try that out.

Thanks.

Radek



Back to top
Bob Gonder
Guest





PostPosted: Sat Dec 17, 2005 3:59 pm    Post subject: Re: How to improve performance of C++ complex template? Reply with quote

Radek wrote:

Quote:
Thanks for reply. I have already tried different compiler settings and so on
but as I have writtem without any results. I know that it highly depends on
hardware and OS but I hoped there is other way to optimize the code except
modyfing assembler code that I don't feel confident about.

Just a reminder that 80% of all speed improvements come from using
better algorythms.

If you could eliminate the array of complex, and go directly brom
array of bits to array of structs (possably using a complex, but not
an array of them)..

For all of these arrays, do you preallocate the entire array, or
expand them?

I don't know...is complex costly to construct/destruct? Might be
faster to hold onto it rather than be dynamic.
10 million bits, how many complexes? Probably a lot of
constructing/destructing going on.




Back to top
Radek
Guest





PostPosted: Sat Dec 17, 2005 6:54 pm    Post subject: Re: How to improve performance of C++ complex template? Reply with quote

Quote:
Just a reminder that 80% of all speed improvements come from using
better algorythms.

I know that but I think I did my best in this subject.

Quote:
If you could eliminate the array of complex, and go directly brom
array of bits to array of structs (possably using a complex, but not
an array of them)..

It is possible I think. I used complex template because it is simple to use
and I don't have to overload multiplying operator. Do you think it would be
faster to use directly array of structures rather than complex ??

Quote:
For all of these arrays, do you preallocate the entire array, or
expand them?

I am using new, and then delete because all those arrays are dynamically
allocated.

Quote:
I don't know...is complex costly to construct/destruct? Might be
faster to hold onto it rather than be dynamic.
10 million bits, how many complexes? Probably a lot of
constructing/destructing going on.

Many complexes Smile When I transmit 10M bits I must use a lot of memory to
serve it in complex. In worst it is 10M * 3 * 8 = 240 M complexes in one
array...

Br,

Radek



Back to top
Leroy Casterline
Guest





PostPosted: Sat Dec 17, 2005 9:20 pm    Post subject: Re: How to improve performance of C++ complex template? Reply with quote

On Sat, 17 Dec 2005 08:56:20 +0100, "Radek"
<radekkedzior (AT) poczta (DOT) onet.pl> wrote:

Quote:
Any help, hints, remarks will be much appreciated.

Beyond what's been said already, have you tried profiling the
application? AutomatedQA (http://www.automatedqa.com/products/aqtime/)
has a great profiler with, as I recall, a 30 day trial period.

Back to top
Radek
Guest





PostPosted: Sat Dec 17, 2005 10:51 pm    Post subject: Re: How to improve performance of C++ complex template? Reply with quote

Quote:
Beyond what's been said already, have you tried profiling the
application? AutomatedQA (http://www.automatedqa.com/products/aqtime/)
has a great profiler with, as I recall, a 30 day trial period.

Thanks for a link. I will also try that out :-)

Radek



Back to top
Bob Gonder
Guest





PostPosted: Sun Dec 18, 2005 3:54 am    Post subject: Re: How to improve performance of C++ complex template? Reply with quote

Radek wrote:

Quote:
Just a reminder that 80% of all speed improvements come from using
better algorythms.

I know that but I think I did my best in this subject.

Eliminating "240 M complexes in one array"...comes under the heading
of "better algorythm"


Quote:
It is possible I think. I used complex template because it is simple to use
and I don't have to overload multiplying operator. Do you think it would be
faster to use directly array of structures rather than complex ??

Well, it eliminates a step, and new complex<double>[240million] can't
be very fast. And, it probably causes slow page swaps, using that much
memory (about 2GB?) just for intermediary values.


Quote:
For all of these arrays, do you preallocate the entire array, or
expand them?

I am using new, and then delete because all those arrays are dynamically
allocated.

Yes, that was understood from "dynamic", but the question was... do
you allocate a few for the array, and add new complexes to the array
(expand it), or do you new[] the entire array in one shot?
But, it sounds like you aren't using the array template, but instead
using the C-type array.



Back to top
Radek
Guest





PostPosted: Sun Dec 18, 2005 8:56 am    Post subject: Re: How to improve performance of C++ complex template? Reply with quote

Quote:
Eliminating "240 M complexes in one array"...comes under the heading
of "better algorythm"

I tried splitting this array into smaller ones but it appeared to be slower.

Quote:
Yes, that was understood from "dynamic", but the question was... do
you allocate a few for the array, and add new complexes to the array
(expand it), or do you new[] the entire array in one shot?
But, it sounds like you aren't using the array template, but instead
using the C-type array.

Actually I don't know what's an array template if you could explain me in a
few words...
I "new[]" the array in one shot. I don't expand them.

Radek



Back to top
Bob Gonder
Guest





PostPosted: Sun Dec 18, 2005 7:02 pm    Post subject: Re: How to improve performance of C++ complex template? Reply with quote

Radek wrote:

Quote:
Actually I don't know what's an array template if you could explain me in a
few words...

Well. this _is_ the C++ group, so one never knows if you are going
full-blown C++ or partial.
I was thinking of the STL container classes (which I don't use, I'm a
C guy). Perhaps I meant vector, though I remember reading recently
array types being mentioned.
There is also the BCB template DynamicArray

Perhaps closer to your needs might be valarray.

The BCB5.hlp has several pages on it.

Also MSDN:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcstdlib/html/vclrf_valarray_header.asp?frame=true
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclang98/html/VALARRAY_valarray.asp?frame=true




Back to top
Radek
Guest





PostPosted: Sun Dec 18, 2005 7:24 pm    Post subject: Re: How to improve performance of C++ complex template? Reply with quote


Quote:
Well. this _is_ the C++ group, so one never knows if you are going
full-blown C++ or partial.
I was thinking of the STL container classes (which I don't use, I'm a
C guy). Perhaps I meant vector, though I remember reading recently
array types being mentioned.
There is also the BCB template DynamicArray

Perhaps closer to your needs might be valarray.

The BCB5.hlp has several pages on it.

Also MSDN:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcstdlib/ht

ml/vclrf_valarray_header.asp?frame=true
Quote:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclang98/ht

ml/VALARRAY_valarray.asp?frame=true

I have let's say average knowledge on C++ and quite good on C. I read today
about template arrays and syntax is not so complicated but isn't it slowet
than new, delete or alloc, malloc, calloc from C syntax?
My code maybe is not efficient it could be but taking conditions of my
simulation into account it is not so bad Smile When I am transmiting 1 000 000
bits in my simulation it takes about 1,5 hour running on 2 GHz Pentium M,
with 1 GB RAM memory. With 10 000 000 bits it is much worse...

I will read sth about valarray maybe, as you said, it will be closer to my
needs.

Thanks again for your help.

Br,

Radek




Back to top
Leroy Casterline
Guest





PostPosted: Sun Dec 18, 2005 8:04 pm    Post subject: Re: How to improve performance of C++ complex template? Reply with quote

On Sun, 18 Dec 2005 20:24:06 +0100, "Radek"
<radekkedzior (AT) poczta (DOT) onet.pl> wrote:

Quote:
I will read sth about valarray maybe, as you said, it will be closer to my
needs.

Have you given the profiler a try? In my experience what's causing a
bottleneck isn't always obvious. It might save you time and effort to
know exactly where the problem is before you spend time optimizing the
wrong thing (I know - been there, done that!).

Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Language C++) All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.