473,732 Members | 2,207 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

problem with microsoft speed optimization

Hello.

I'm having a problem with the Visual Studio .net (2003) C++ speed
optimization, and hope someone can suggest a workaround.

My project includes many C++ files, most of which work fine with speed
optimization turned on. At least one does not however, though it does
work with size optimization turned on. I don't know specifically what
the optimizer is doing wrong, just that the output is incorrect. And I
know within about 10 lines where the problem is. I've tried
rearranging the offending lines (which are straight C code). I've
tried using 'volitle' data types in hopes of avoiding optimization.
I've looked for missing variable initializations , but everything looks
correct and straightforward .

One solution would be to have a precompiler directive which would
enable (or disable) the optimization only on specific files. Of course
I can manually turn the optimization on and off while recompiling
specific files, but I need something automated.

I can't post the code, but will try to follow up with a test case that
exhibits the same behavior.

Presumably the program would compile fine with g++, but unfortunately
that's not an option for this project.

Thanks very much.

Mark

Dec 29 '05 #1
21 2572

mjbackues at yahoo wrote:
Hello.

I'm having a problem with the Visual Studio .net (2003) C++ speed
optimization, and hope someone can suggest a workaround.

My project includes many C++ files, most of which work fine with speed
optimization turned on. At least one does not however, though it does
work with size optimization turned on. I don't know specifically what
the optimizer is doing wrong, just that the output is incorrect. And I
know within about 10 lines where the problem is. I've tried
rearranging the offending lines (which are straight C code). I've
tried using 'volitle' data types in hopes of avoiding optimization.
I've looked for missing variable initializations , but everything looks
correct and straightforward .

One solution would be to have a precompiler directive which would
enable (or disable) the optimization only on specific files. Of course
I can manually turn the optimization on and off while recompiling
specific files, but I need something automated.

I can't post the code, but will try to follow up with a test case that
exhibits the same behavior.

Presumably the program would compile fine with g++, but unfortunately
that's not an option for this project.


It sounds like you're asking about the particular behaviour of your
compiler's optimiser. If so, then you are asking the wrong group. There
is a VC++ .Net group suggested here.

http://www.parashift.com/c++-faq-lit...t.html#faq-5.9

Gavin Deane

Dec 29 '05 #2
OK, thanks.

Dec 29 '05 #3
mjbackues at yahoo wrote:
Hello.

I'm having a problem with the Visual Studio .net (2003) C++ speed
optimization, and hope someone can suggest a workaround.
This subject matter is off-topic in this group, which is solely
concerned with *standard* C++. See the FAQ for what is on-topic and for
some suggestions of better places to post:

http://www.parashift.com/c++-faq-lit...t.html#faq-5.9
My project includes many C++ files, most of which work fine with speed
optimization turned on. At least one does not however, though it does
work with size optimization turned on. I don't know specifically what
the optimizer is doing wrong, just that the output is incorrect. And I
know within about 10 lines where the problem is. I've tried
rearranging the offending lines (which are straight C code). I've
tried using 'volitle' data types in hopes of avoiding optimization.
I've looked for missing variable initializations , but everything looks
correct and straightforward .
People often blame the compiler for strange errors, but it usually
turns out to be user error, perhaps in an apparently unrelated part of
the program. Have you tried looking at the generated assembly code?
One solution would be to have a precompiler directive which would
enable (or disable) the optimization only on specific files. Of course
I can manually turn the optimization on and off while recompiling
specific files, but I need something automated.
Look up #pragma in your compiler documentation. Better yet, turn off
the optimizer altogether (except for inlining and such). See this
article, "Optimizati on: Your Worst Enemy":

http://www.codeproject.com/tips/optimizationenemy.asp

See also "Surviving the Release Version":

http://www.codeproject.com/debug/survivereleasever.asp
I can't post the code, but will try to follow up with a test case that
exhibits the same behavior.
You should have done this before posting. See the FAQ:

http://www.parashift.com/c++-faq-lit...t.html#faq-5.8

But, of course, if you had read the FAQ in advance, you would have
posted to a different newsgroup to begin with. ;-)
Presumably the program would compile fine with g++, but unfortunately
that's not an option for this project.


Such warantless speculation is entirely unhelpful. If possible, you
should try at least the problem spot in your code on that and any other
compiler you have at your disposal. You could use the same distilled
code that you'll be posting shortly, and that might generate some
helpful results.

Cheers! --M

Dec 29 '05 #4
Wow. Since you fancy yourself clever and obviously have time on your
hands....follow ing is a test program that works with gcc but not with
visual studio (either with or without optimization). The output using
'fprintf' is correct, whereas the output with 'fwrite' is not, and the
resulting file doesn't even have the right size. The 'fwrite' does
work however if the '3.14' in the preceeding calculation is replaced
with another pi approximation with more digits.

Useful responses from other people are also welcome.

#include <stdio.h>
#include <math.h>
#include <malloc.h>
#define PI 3.1415926535897 9

main(){
float* ph;
int i;
FILE *fid;

ph = (float*)malloc( sizeof(float)*1 28*1024*2);

for(i=0;i<128*1 024*2;i+=2){
ph[i]=(float)cos(3.1 4*(double)i*0.2 );
ph[i+1]=1.0;
}

fid=fopen("out1 ","w");
for(i=0;i<128*1 024*2;i++)
fprintf(fid,"%l f\n",ph[i]);
fclose(fid);

fid = fopen("out2","w ");
fwrite(ph,sizeo f(float),128*10 24*2,fid);
fclose(fid);

free(ph);
}

Dec 29 '05 #5
mjbackues at yahoo wrote:
fid = fopen("out2","w ");
fwrite(ph,sizeo f(float),128*10 24*2,fid);


When you're writing binary data you must open the file with "wb" rather
than "w".

--

Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)
Dec 29 '05 #6
mjbackues at yahoo wrote:
Wow. Since you fancy yourself clever and obviously have time on your
hands....follow ing is a test program that works with gcc but not with
visual studio (either with or without optimization). The output using
'fprintf' is correct, whereas the output with 'fwrite' is not, and the
resulting file doesn't even have the right size. The 'fwrite' does
work however if the '3.14' in the preceeding calculation is replaced
with another pi approximation with more digits.

Useful responses from other people are also welcome.

#include <stdio.h>
#include <math.h>
#include <malloc.h>
#define PI 3.1415926535897 9

main(){
float* ph;
int i;
FILE *fid;

ph = (float*)malloc( sizeof(float)*1 28*1024*2);

for(i=0;i<128*1 024*2;i+=2){
ph[i]=(float)cos(3.1 4*(double)i*0.2 );
ph[i+1]=1.0;
}

fid=fopen("out1 ","w");
for(i=0;i<128*1 024*2;i++)
fprintf(fid,"%l f\n",ph[i]);
fclose(fid);

fid = fopen("out2","w ");
fwrite(ph,sizeo f(float),128*10 24*2,fid);
fclose(fid);

free(ph);
}


In what way is the output incorrect?

BTW, a more C++-style way to do it might look something like:

#include <vector>
#include <cmath>
#include <fstream>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

#define PI 3.1415926535897 9

int main()
{
vector<double> v( 128*1024*2 );

for(unsigned int i=0; i < v.size(); i+=2 )
{
v[i]=cos(PI*i*0.2);
v[i+1]=1.0;
}

ofstream f1("out1");
if( !f1 )
{
cerr << "error!" << endl;
return -1;
}
copy( v.begin(), v.end(),
ostream_iterato r<double>( f1, "\n" ) );

ofstream f2( "out2", ios_base::binar y );
if( !f2
|| !f2.write( reinterpret_cas t<const char*>( &v[0] ),
v.size()*sizeof (double) ) )
{
cerr << "error!" << endl;
return -1;
}

return 0;
}

Dec 29 '05 #7
yeah, that's it, thanks very much.

Dec 29 '05 #8
Thanks. This was a problem a coworker had, and he wound up using
ofstream and write to get around it.

Dec 29 '05 #9
>yeah, that's it, thanks very much.

oops, intended as reply to Pete Becker

Dec 29 '05 #10

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

Similar topics

11
1849
by: Jonny | last post by:
Netscape 7.02 is giving me a headache with a downloaded snow script. Starting with a blank page, I inserted the script and checked it in IE 6 and Netscape 7.02. Everything worked and looked fine. A check on CPU usage (Windows Task Manager>Performance) gave a 0% to 2% reading for both browsers on a Pentium 4, 3.06GHz running XP. As I added text, images, tiled background and so on. I noticed the mouse was becoming jerky in Netscape 7....
23
2637
by: Mark Dickinson | last post by:
I have a simple 192-line Python script that begins with the line: dummy0 = 47 The script runs in less than 2.5 seconds. The variable dummy0 is never referenced again, directly or indirectly, by the rest of the script. Here's the surprise: if I remove or comment out this first line, the script takes more than 15 seconds to run. So it appears that adding a redundant line produces a spectacular six-fold increase in speed!
23
3496
by: Rudolf Bargholz | last post by:
Hi, I have a ralatively simple SQL: select FK from TABLE where upper(A) like 'B%' and upper(C) like 'D%' We have DB2 UDB v7.1 FP 12 installed on Linux and on Windows 2003 On Linux using optimization level 5 as well as 9 and 0 the SQL uses 3'100'000'000 timerons !
57
4289
by: Xarky | last post by:
Hi, I am writing a linked list in the following way. struct list { struct list *next; char *mybuff; };
5
2345
by: Hari | last post by:
Guys please help me to solve this strange problem what Iam getting as follows.. Trying to instantiate a global instance of a template class as follows :- when i build this code with debug and run this works fine. but if build in unicode release or release this does't work. IS THERE ANY PROBLEM OF INSTANTIATING TEMPLATE CLASSES
7
3046
by: YAZ | last post by:
Hello, I have a dll which do some number crunching. Performances (execution speed) are very important in my application. I use VC6 to compile the DLL. A friend of mine told me that in Visual studio 2003 .net optimization were enhanced and that i must gain in performance if I switch to VS 2003 or intel compiler. So I send him the project and he returned a compiled DLL with VS 2003. Result : the VS 2003 compiled Dll is slower than the VC6...
4
1658
by: Renato | last post by:
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++);
13
2260
by: Snis Pilbor | last post by:
Hello, Here is an idea I've been toying with to speed up programs but still keep them portable. It's just a very handwavey rough description right now since I haven't worked out details. The program would contain lots of little utility functions which do small amounts of work. None of these would actually be run. Rather, they would be typecast as strings and those strings would be examined by the program. In otherwords, the...
2
2088
by: pavanip | last post by:
Hi, I have an application like Optimize System Performance by using Memory speed, cpu speed and Disk speed. How to optimize memory speed,disk optimization and CPU optimization. Please provide me some sample source code to optimize system performance. Thanks pavani
0
8946
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9447
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9307
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9235
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9181
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6735
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6031
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.