472,351 Members | 1,473 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,351 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 1524
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...
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...
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()...
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...
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...
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...
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...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...

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.