|
Intelligence and Experience.
Kuphryn
|
|
|
|
|
|
but that's true, experience is one of the major factor in optimization.
One other thing, is good source level analysis, how can you restructure your source code to remove as much as possible useless computation, for example, loop unfolding, pre-computation of values.
Maximilien Lincourt
For success one must aquire one's self
|
|
|
|
|
Hi Maximilien
I've got an old program that makes 20.000.000.000 calculations in few minutes due to a precalculated tables, etc... I'm relaly happy with speed and clients too. But I was thinking about compiler switches about p4 optimizations.
The program was done before p4 and in my old msdn I haven't found switches about p4 optimization.
I was thinking in MMX optimization for comparisons. Maybe in the future 'cos now it's a lot of work.
Best Regards
|
|
|
|
|
Geesh, you give somebody 20 billion CPM and they want more! What's the world coming to?
|
|
|
|
|
20bilions in some minutes not just in one.
Well The program do the following:
It's about football bets.
I have 15 matches and 3 possible results 1 X 2 (1 local wins X tie 2 visitor wins)
Then you have 3^15 possible combinations = 14.348.907 dif. bets
The program gets these combinations and generate what we call a reduction
that is less bets with a certain garantee.
Ex: how many bets do you need to garantee 14 hits of 15? Because the winner could be anyone.
Then you can generate these bets and you have to check the guarantee that consist to compare 1 by 1 the file 1 (14.348.9079 with the second one (depends if you want just 1 mistake or 2 or 3...)
Then as you can see it's really a lot of comparisons.
Using precalculated tables I could let this in an amount of time really nice, but if could be possible fast calculations it would be nice.
Best regards
Dr.Pi
|
|
|
|
|
Seems to me the problem isn't in the speed of the program, but in the speed (and design) of the algorithm(s). This is often the case with algorithms like this.
At first glance it seems you don't know about combinations and permutations, which I believe could reduce your search set by quite a few order of magnitudes in this case.
You might want to visit at least Google and this place.
|
|
|
|
|
The problem is more complex that it seems. Is not a simple combination problem.
When you have the complete serie of 3^n (n=15) combinations is just a mathematical problem, but when do you have an incomplete set and not regular (not predectable), what combinations do you have to get to have the minimum number of combinations that guarantees n-1 hits? and n-2? and n-3? and all this in the minimum time.
Anyway the program do the reduction of 4.782.969 combinations to 314.569 in 52 secs.
Try to find and save in a file the minimum number of combinations that guarantees n-1 hits from a 3^14 combination file in less time.
The only thing that you have at the beggining is a file like this
1X211X2X12X12X1 .....row 1
X1112X12X12X12X
X212X121X212X12
1111X212XX212XX
.
.
.
.
X22X12X2X12X12X .....row 4.782.969 (and are not sorted)
If you have a better solution, sincerely I'll be really pleased to learn it.
Best Regards
Dr. Pi
|
|
|
|
|
Think of using the INTEL C++-compiler instead of the MSVC++.
I have read a test where the Intel compiler achived a major improve just by recompiling. It can use Hyperthreading, SSE2 and so on. But it is no drop-in replacement, and you need to adapt your program to it.
My opinions may have changed, but not the fact that I am right.
|
|
|
|
|
If possible, you should run your code inside a profiler. The design of your program (and the algorithm choices made for how to process data) will affect how fast the program runs, but you shouldn't unnecessarily make changes to code that is already debugged and running correctly.
What you want to do is identify what areas of the code are using the most cpu time, and concentrate any effort in optimizing to those areas that actually make a difference. Even with a lot of experience with what code sequences are slow versus fast, it is a waste of effort to fix parts that only take a small amount of the total time (even if they are written using a slow algorithm). This is where the profiler will help. Use it to find the areas of your program which are taking the largest amount of time to execute, and concentrate any effort on speedups to those areas. (If one part of the program is taking 90% of the time, any effort spent on improving other parts of the program can only get you at most a 10% improvement).
As far as using tricks - I would avoid any "tricky" sequence of code. You are more likely to get it wrong, and even if you get it right, it makes future maintenance more difficult.
For compiler options, I would just choose whatever optimizations match the most likely target machine for the program.
Best regards,
John
|
|
|
|
|
Thank you a lot.
You're right, the calculation part is the only part that I must optimize 'cos do it in the others is just a waste of time.
What profiler do you use?
Best Regards
Dr.Pi
|
|
|
|
|
Recently, I have been using the Intel VTune performance analyzer. The version that I use supports Visual C++ 6.0. I typically use it to do time-based sampling, where the program collects samples of where the program is executing at a regular time interval.
It works Ok for my usage, but I find that sometimes I need to make calls into the profiler API so that I can isolate just the sections of code that I want to profile. I mostly work on a CAD application where most of the CPU time is spent idling (waiting for user input), so I only turn on the profiling once the user is done with whatever selections they need to make. These calls aren't necessary, but make it easier to figure out the sections that actually need improvements (by removing clock ticks for user idle from the profile data).
If most of the time spent in your program is doing calculations, you probably won't need to do these API calls, as the user input time will still be just a small percentage of the total time. If you don't add these calls, you can profile your program without needing to make any changes. If you add these calls, it only requires minor changes to your program.
Best regards,
John
|
|
|
|
|
Short of experience and program design, the only guidelines would be to not use float/double (use int/long) instead, avoid division wherever possible, and attempt to precompute values into tables at the start of your program, and doing simple calculations of the individual items against the precomputed values, rather than making complex calculations 20000000000 times.
|
|
|
|
|
I've been struggling with an error message that prevents me from initializing the CPoint member (adk) of my structure. As a test, I discovered that my own Point structure worked fine.
What am I doing wrong...surely one can conveniently initialize a CPoint structure???
Excerpt of my Code:
typedef struct {
int x;
int y;
} MyCPoint;
struct s_Door{
MyCPoint InsertionPt;
int iPline;
int iEach_Pline[1];
int iVert;
MyCPoint Vert[5];
CPoint adk;
}
Door =
{
{0,0},
1,
{5},
5,
{-15,0, -14,2, 13,15, 15,13, -15,0},
4
};
Error message:
'Door' : non-aggregates cannot be initialized with initializer list
|
|
|
|
|
Add brackets.
Door = {{0,0}, 1, 5, 5, {{-15,0}, {-14,2}, {13,15}, {15,13}, {-15,0}}, 4};
Kuphryn
|
|
|
|
|
Thanks for your help, but this still gives the same error message. In fact, this very simple code results in the same error message???
struct s_Desk{
CPoint adk;
} Desk = { 0,0 }; //I tried { {0,0} } as well.
error C2552: 'Desk' : non-aggregates cannot be initialized with initializer list
|
|
|
|
|
CPoint cannot be initialized with an initializer list probably because it has one or more constructors, and has a base class.
|
|
|
|
|
OR:
typedef struct {
int x;
int y;
} MyCPoint;
struct s_Door{
s_Door();
MyCPoint InsertionPt;
int iPline;
int iEach_Pline[1];
int iVert;
MyCPoint Vert[5];
CPoint adk;
}
s_Door::s_Door() : InsertionPt( 0, 0), iPline( 1 ), ... adk( 0, 0 )
{
// anything you want to addd....
}
|
|
|
|
|
I want to small project so I can share some data, printer, ...etc. But I don't know VC++ support fuction or ActiveX object for parallel port. please help me.
Thank and Best regards!
The child learn to program
|
|
|
|
|
Here is one solution from MSDN.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnfiles/html/msdn_serial.asp
Kuphryn
|
|
|
|
|
Hi,
I have implemented an FTP application, which will schedule itself to run daily by using SetTimer, once it’s started. Everyday it will FTP-get a plain text file from a remote server using MFC classes CInternetSession and CFtpConnection.
The plain text file’s name will be the same, but the content is updated daily. The problem I’m having is the first time I start the application, it gets the text file of that day, but then it will get the same file, even though the content of the remote file has already been updated. It seems like the file is cached somewhere. If I stop the application and re-start it, again it will be fine the first time.
The code is below:
CInternetSession session(_T("DBAdmin"));
CFtpConnection* ftp;
session.SetOption (INTERNET_OPTION_CONNECT_TIMEOUT, 30000);
session.SetOption (INTERNET_OPTION_CONTROL_SEND_TIMEOUT, 30000);
session.SetOption (INTERNET_OPTION_CONTROL_RECEIVE_TIMEOUT, 30000);
session.SetOption (INTERNET_OPTION_DATA_SEND_TIMEOUT, 30000);
session.SetOption (INTERNET_OPTION_DATA_RECEIVE_TIMEOUT, 30000);
try
{
ftp = session.GetFtpConnection (strIP, strLogin, strPwd, iPort);
if (ftp)
{
if (!ftp->GetFile (strSrc + strFileName, strDest + strFileName))
}
}
Is this a setting problem or a programming one?
Thanks in advance.
Tony
|
|
|
|
|
I suspect there is a problem on the server side. The server may not be updating its data relative to the actual file. In other words, the server is no aware that the file has changed.
Kuphryn
|
|
|
|
|
When you construct the CInternetSession object, pass the flag INTERNET_FLAG_DONT_CACHE as the Flags parameter:
CInternetSession session(_T("DBAdmin"), 1, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, INTERNET_FLAG_DONT_CACHE);
|
|
|
|
|
I just downloaded SP5 from msdn and I choose the multi-part download. So I have 11 files numbered 1 to 11 this is the SP5 core, no problem with those.
There are aslo 3 files called vs6sp5s1.exe, vs6sp5s2.exe and vs6sp5s3.exe. When I unpack them they are full of headers, .lib and so. I don't know how to install those files, should I unzip them in the same folder as the SP5 core. It seems odd to me as SP5 is mainly composed of CAB files when the 3 others are a bit messy.
Any info someone ?
Thnak in advance
Yarp
http://www.senosoft.com/
|
|
|
|
|
Just for yor information, you need to unzip all files into one folder and then run the Setup.exe that came with the 1st cab file.
|
|
|
|
|