473,322 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Windows/Linux optimization problem

Hi all,
I have a strange optimization problem. I have written a small program,
basically a matrix-vector multiplication at its core, that needs to
run as fast as possible.

The relevant code snippet is:

for (e = start_e; e < end_e; e++)
for (s = start_s; s < end_s;)
*e += (*r++) * (*s++);

where all variables are float pointers, 'r' is the matrix, 's' the
vector and 'e' the result vector. I call the operation on the last
line a MAC (multiply-accumulate), a common measure of performance on
DSPs. The 'r' matrix is very large (about 15 MB) and does not fit into
the cache.

The program does a thousand iterations, each consisting of some setup
and of the matrix mult. above, and prints out the speed.

On Linux, using an Intel Xeon 2.6 Ghz (512Kb cache) I get the
following result:

Done in 0.42 seconds (2398.55 iterations/sec) (487.00 Mmac/sec)

The above result was with the optimizing Intel compiler v9.0, which
auto-vectorize loops using SSE. The non-SSE version was only about 20%
slower.

On Windows, using my Athlon 2700+, I get this:

Done in 1.81 seconds (551.61 iterations/sec) (112.00 Mmac/sec)

I then learned that my non-professional copy of VisualC++ does not
optimize binaries (!), so I downloaded the Microsoft Visual C++
Toolkit 2003, which claims to have the same optimizing compiler
featured by the professional version of Microsoft Visual C++. The
result is even worse:

Done in 1.85 seconds (540.53 iterations/sec) (109.75 Mmac/sec)

The windows version was compiled with this command line:

cl /O2 test2.c

Adding flags for SSE instructions did not help.

Anyone has a clue of what I'm doing wrong? The numbers are very
repeatable. Using a smaller 'r' matrix pushed the speed on the Linux
xeon up to 1.5 GMac (!), while the windows version on the Athlon never
went over 250 Mmac.

Thanks for the answers :-)
Alfio


Feb 10 '06 #1
4 1634
On Fri, 10 Feb 2006 21:17:32 GMT, re***@dodgeit.com (Renato) wrote:
Hi all,
I have a strange optimization problem. I have written a small program,


An interesting problem, but way off topic here, where we discuss the
standard C language, not specific implementations, and not
optimization. Look for a Microsoft newsgroup.

--
Al Balmer
Sun City, AZ
Feb 10 '06 #2
On Fri, 10 Feb 2006 15:09:42 -0700, Al Balmer <al******@att.net>
wrote:
On Fri, 10 Feb 2006 21:17:32 GMT, re***@dodgeit.com (Renato) wrote:
Hi all,
I have a strange optimization problem. I have written a small program,


An interesting problem, but way off topic here, where we discuss the
standard C language, not specific implementations, and not
optimization. Look for a Microsoft newsgroup.


Sorry, I didn't realize that it was offtopic. I'll post it somewhere
else.

Alfio
Feb 10 '06 #3

"Renato" <re***@dodgeit.com> wrote
The relevant code snippet is:

for (e = start_e; e < end_e; e++)
for (s = start_s; s < end_s;)
*e += (*r++) * (*s++);

where all variables are float pointers, 'r' is the matrix, 's' the
vector and 'e' the result vector. I call the operation on the last
line a MAC (multiply-accumulate), a common measure of performance on
DSPs. The 'r' matrix is very large (about 15 MB) and does not fit into
the cache.

[ Windows worse than Linux ]

You want to try to look at the assembly code produced (if you have no tools,
make a minimal program and then hand-dissassemble the binary).

This will tell you whether it is the greedy operating system or the bad
compiler causing your problems on the Windows machine.
Feb 10 '06 #4
Renato wrote:
Hi all, The relevant code snippet is:

for (e = start_e; e < end_e; e++)
for (s = start_s; s < end_s;)
*e += (*r++) * (*s++);
More than this is relevant, including how the pointers are declared.
The windows version was compiled with this command line:

cl /O2 test2.c

Adding flags for SSE instructions did not help.

Anyone has a clue of what I'm doing wrong? The numbers are very
repeatable. Using a smaller 'r' matrix pushed the speed on the Linux
xeon up to 1.5 GMac (!), while the windows version on the Athlon never
went over 250 Mmac.

Most Windows compilers do not default to requiring programs to comply
with the C standard on typed aliasing. In fact, they don't even act as
C compilers by default. Thus, they may assume possible side effects
which prevent scalar reduction (registerization of the sum
accumulation), or unpredictable changes in the pointer values preventing
those from being registerized. You could make it easier on the compiler
by declaring a local scalar for the accumulator, and unambiguously
moving the assignment to +e to the outer loop.
Using pointers to make counted for loops has pitfalls. Purists might
replace the < condition with !=, but that introduces ambiguities in how
to treat the situation where the loop might wrap around in the address
space. So, it's possible that one compiler might choose not to optimize
for such reasons.
Feb 12 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Philip | last post by:
Hi, i'am looking for a db2 driver for windows the DB2 servers runs on as400 if that makes any difference. Thanks, Philip
1
by: Rami Saarinen | last post by:
I have been making a client-server type of software mainly on Linux and now I am trying to get it all work also on windows. However, I am having slight problems running the program in Windows 2000....
1
by: corrado | last post by:
Hello I have an application running several thread to display some financial data; basically I have a thread displaying HTML tables by means of Tkhtml, another implementing a scrolling ticker...
2
by: Read Roberts | last post by:
I have the current Windows binary install of Python 2.3.4 on my Windows XP system. I am pained to discover that tkFileDialog.askdirectory() returns a mangled path when a directory is selected...
2
by: Chris | last post by:
A weird issue...though hopefully not for everyone... I am trying to connect to a 10g database on a Red Hat Linux server from my 9i client on a XP pc. Both are on my local home network, behind...
32
by: cat_dog_ass | last post by:
I am used to programming in DOS mode via Borland C++. I would now like to create programs for the Windows envirinment. Is it absoultely necessary to use Visual C++ to do this? Are there other tools...
17
by: Bruce Jin | last post by:
I wonder how many people are using db2 on Windows? I know db2 is native to AS400 which has about 800,000 installations. Thanks!
2
by: Lev Elbert | last post by:
Hi, all! I have to make a custom email module, based on the standard one. The custom module has to be able to work with extremely large mails (1GB +), having memory "footprint" much smaller....
5
by: yakir22 | last post by:
Hello experts, I am dealing now in porting our server from windows to linux. our client is running only on windows machine. to avoid the wchar_t size problem ( in windows its 2 bytes and linux is...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.