|
int main(int argc, char* argv[])
{
DWORD beg = GetTickCount();
int i,j,k;
for (j=0;j<N;++j)
{
for (i=0;i<N;++i)
{
for (k=0;k<N;++k)
{
M3[1] = M1[1] * M2[1]; // no indexing just 1
}
}
}
DWORD end = GetTickCount();
printf("%d\n", end - beg);
beg = GetTickCount();
int* pjk = &M1[1000];
int* pik = &M2[1000];
int* pkk = &M3[1000];
for (int* pj = &M1[0]; pj < pjk ; ++pj)
{
for (int* pi = &M2[0]; pi < pik ; ++pi)
{
for (int* pk = &M3[0]; pk < pkk ; ++pk)
{
M3[1] = M1[1] * M2[1];
}
}
}
end = GetTickCount();
printf("%d\n", end - beg);
}
The first one takes 1.594s on my system, the second one 1.438s.
That is on A64 3500+, 1GB DDR 400.
What system do you have??
-- modified at 9:58 Sunday 9th October, 2005
|
|
|
|
|
Try this. This is matrix product.
int M1[1000*1000];
int M2[1000*1000];
int M3[1000*1000];
for(j=0;j<N;j++)
for(i=0;i<N;i++)
for(k=0;k<N;k++)
M1[j*N+i]=M1[j*N+i]+M2[j*N+k]*M3[i+k*N];
I got AMD 800Mhz 256RAM :DD
-- modified at 12:03 Sunday 9th October, 2005
|
|
|
|
|
Use "Ignore HTML tags in this message" when posting becouse half of your code is missing
|
|
|
|
|
Frist: Not enought information.
Second: Do not use i++, unless your are using built in types. Use ++i by default, unless you have a good reason not to. If it is not a built in type, that alone will slow every thing down.
Third: You need to rewrite the question with a little more detail. It does not matter what the results where in the 6 seconcd test, because according to what you gave us (j,i,k) are ignored.
INTP
Every thing is relative...
|
|
|
|
|
I added some information.
|
|
|
|
|
Ok! You added more information that adds nothing to solving the problem. a, b, and c are naturley faster, becuase they are not arrays that have to be indexed; matter of fact, they are just hanging in space with no defined value (they're global so they're probaly 0).
An index of 1 is still an index.
If it takes 6 seconds to process arrays of a mere 1000 elements, then there is something else going on.
Still not enough information!
P.S. It's 6:55 AM sunday mourning here, good night (or good morning).
INTP
Every thing is relative...
|
|
|
|
|
So, what else information do you want to know ?
Because I want to know, how to write code with fast access to array's elements.
I've got simple linear array of integers.
Matrix product is n^3 problem.
Can I handle array memory faster then array[i] ? Or some compiler switches for pointers ...
The aim of my programme is matrix inversion and part which is consumes the most of time, is matrix product.
... right now we have 3:00 pm, so good afternoon;
-- modified at 9:14 Sunday 9th October, 2005
|
|
|
|
|
Sorry! It was way passed my bed time, you did provide enough imformation.
The order in which the calculation are done matters:
(VC6.0, optimizations: maximum speed, Compiled for release)
#define MATRIX_SIZE 1000
int M1[MATRIX_SIZE];
int M2[MATRIX_SIZE];
int M3[MATRIX_SIZE];
void matrix_speed_test()
{
int j, i, k;
for( j=0;j<MATRIX_SIZE;++j )
for( i=0;i<MATRIX_SIZE;++i )
for( k=0;k<MATRIX_SIZE;++k )
M3[j] = M1[i] * M2[k];
}
void matrix_speed_test2()
{
int j, i, k;
int m1,m2;
for( j=0;j<MATRIX_SIZE;++j )
{
m1 = M1[j];
for( i=0;i<MATRIX_SIZE;++i )
{
m2 = M2[i];
for( k=0;k<MATRIX_SIZE;++k )
M3[k] = m1 * m2;
}
}
}
void matrix_speed_test3()
{
int j, i, k;
int m1;
for( j=0;j<MATRIX_SIZE;++j )
{
for( i=0;i<MATRIX_SIZE;++i )
{
m1 = M1[i];
for( k=0;k<MATRIX_SIZE;++k )
M3[j] = m1 * M2[k];
}
}
}
As you can see, rearanging the code to change where the indexing occurs can greatly increase the speed.
I tried a few other ways, but they still avaraged 2.17 seconds.
I hope that helps!
P.S. Sorry for the delay, I am usualy only online when reasearching.
INTP
Every thing is relative...
|
|
|
|
|
Does anyone here have any experience using the Free .Net C++ command line tools?
Is it possible to build programs that are built using the Multi-threaded DLL code generation options if you use STL? The site says that it only comes with static libs for trhe CRT and STL. Does this mean that /MD won't work?
I have a series of DLL's some of which depend on each other. All use the STL, and my understanding is that to allow them to work I *have* to build in /MD or /MDd (Multi-Threaded Debug) mode. Is this possible to do with the Free tools? If not, is there a work around?
¡El diablo está en mis pantalones! ¡Mire, mire!
Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!
SELECT * FROM User WHERE Clue > 0
0 rows returned
Save an Orange - Use the VCF!
|
|
|
|
|
1st: Kudos on the "Dune" reference.
Jim Crafton wrote:
Is it possible to build programs that are built using the Multi-threaded DLL code generation options if you use STL?
Yes!
You have to understand that the STL does not care about multi-threading, it is irrelevant. The code that uses those template classes are the ones who have to care.
INTP
Every thing is relative...
|
|
|
|
|
OK, thanks!
However when I tried to build with it, I get link errors saying it can't find msvcrtd71.lib (or something like that).
I tried a simple test with the following:
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
extern "C" {
__declspec(dllexport) void doit();
}
void doit()
{
int f = 90;
f += 345;
}
When I build this with /MDd (or /MD) I note that despite the fact that NO CRT code is used (as far as I can tell), it automatically links and uses the MS CRT DLL anyways!!!
My understanding is that you cannot use STL in DLL's that are NOT built with "Multi-threaded DLL" code generation options. So if you have DLL A and it uses STL (and has functions that use std::string) and have DLL B, that also uses DLL A, and both use std::string, then you must generate them using the "Multi-threaded DLL" code gen option.
What I remember is that if you just use the "Multi-threaded" option (i.e. static linkage to the CRT) then the strings will become corrupted.
¡El diablo está en mis pantalones! ¡Mire, mire!
Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!
SELECT * FROM User WHERE Clue > 0
0 rows returned
Save an Orange - Use the VCF!
|
|
|
|
|
Good day,
I have a parent dialog instatialing a modeless dialog. My modeless dialog has a public function that updates the progress bar. Everytime I call tmpmodeless->UpdateProgressBar(step) where step is a number to increase, the progress bar show increase on display. I have also a public function in modeless dialog that updates the text for displaying the status tmpmodeless->UpdateMessageStatus(CString mymsg) but I doesnt update the display..
Here is my code:
// Variables of modeless dialog
CProgressCtrl m_ctrlProgress; // Created using MFC Class wizard so it sure points to the
// control id of progress bar.
CStatic m_statusdone; // Created using MFC Class wizard so it sure points to the
// control id CStatic control id. Also sure that Visible property is checked.
CMyParentDialog::MyInitialize()
{
CMyModelessDialog* tmpmodeless=new CMyModelessDialog(this);
tmpmodeless->Create(CMyModelessDialog::IDD);
tmpmodeless->ShowWindow(SW_SHOW);
tmpmodeless->UpdateProgressBar(10); //OK is reflects on screen
tmpmodeless->UpdateMessageStatus("Help me step 10"); doesnt change display..
tmpmodeless->UpdateProgressBar(20); //OK is reflects on screen
tmpmodeless->UpdateMessageStatus("Help me step 20"); still doesnt change display..
}
void CMyModelessDialog::UpdateProgressBar(int pStep)
{
m_ctrlProgress.SetPos(pStep);
}
void CMyModelessDialog::UpdateMessageStatus(CString mymsg) //Doesnt work.. why???????????????
{
m_statusdone.SetWindowText(mymsg);
UpdateData(TRUE);
}
Still Doesnt appear even if I manually put m_statusdone.SetWindowText("Test") under UpdateProgressBar because UpdateProgressBar sure does works on setting progressbar.
Is there something Wrong with CStatic control????
Thanks.
|
|
|
|
|
fjlv2005 wrote:
void CMyModelessDialog::UpdateMessageStatus(CString mymsg) //Doesnt work.. why???????????????
{
m_statusdone.SetWindowText(mymsg);
UpdateData(TRUE);
}
Why are you calling UpdateData(TRUE) at that point? Was it just for testing purposes?
Make sure your static control uses an identifier different than IDC_STATIC (i.e, -1)
--
jlr
http://jlamas.blogspot.com/[^]
|
|
|
|
|
Good day,
Yes Im sure im using ID which is not IDC_STATIC. UpdateData is just for testing...
Why does it doesnt update the display for my modesless dialog??
|
|
|
|
|
How in CEdit to install the cursor in anchor point?
C++ MFC
SetSel installs the cursor in an active end and scrolls the text, I should place(install) the cursor in anchor point, for auto replacement.
|
|
|
|
|
Could you go a little bit more ... in detail ?
SkyWalker
|
|
|
|
|
SetSel(...);
Just make the starting position and ending position the same (anchor point).
The carat (anchor) position is the starting position.
Note: You can reverse the positions passed to SetSel(...) by reversing the starting and ending points..
Under Windows the cursor position is the mouse arrow position and not the position of the text cursor (that's called a caret).
INTP
Every thing is relative...
|
|
|
|
|
Hello,
I have a CButton created dynamically with bitmap:
CButton
m_mybutton.Create(NULL,WS_CHILD|WS_VISIBLE|BS_OWNERDRAW,CRect(1,87,110,107),this, ID_BTNHEADBOOKMARK);
m_mybutton.LoadBitmaps(IDB_LISTHBOOKMARK, IDB_LISTHBOOKMARK, IDB_LISTHBOOKMARK, IDB_LISTHBOOKMARK);
The image have some area with Color RGB(255,0,255).
I wanted those area with that color above to be transparent.
How can I do it?
Hope i could get a response ASAP (if possible )
Also im using EVC, you can try it Visual Studio and if works, i'll try it to EVC3.0.
Thanks you very much.
|
|
|
|
|
My suggestion:
Derive a subclass from CButton, modify its style as owner-draw.
Overwrite the DrawItem() and use TransparentBlt() to paint the bitmap by yourself.
Lane
|
|
|
|
|
Lane,
I understand how to override DrawItem by creating a class derived from CButton, however there no TransparentBlt API in EVC3.0. Anyway to do TransparentBlt?
Thanks Lane
|
|
|
|
|
NewVCbie wrote:
Anyway to do TransparentBlt?
You can use the "True Mask" method. It is the method used by windows to draw icons. It involves creating a black and white mask bitmap that uses white as the transparent part and black as the opaque part. You can have a look at my article at http://www.codeproject.com/bitmap/pjaimage.asp[^] where I use the method to draw transparent bitmaps. Look at the CPJAImage::DrawTransparent() method.
Google[^]
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" - mYkel - 21 Jun '04
"There's not enough blatant self-congratulatory backslapping in the world today..." - HumblePie - 21 Jun '05
Within you lies the power for good - Use it!
|
|
|
|
|
|
Hi!
I am working on MFC SDI application.
can anybody tell me any good example of using extern keyword. can extern be used for passing value of any string variable from one class to another. If it can be used, then how?
thanx
|
|
|
|
|
swaapu says:can extern be used for passing value of any string variable from one class to another?
No it is not possiable using extern.
extern is for different purpose.
if you want to declare later and but if you want to use before itself then use key word extern.
Nice talking to you.
|
|
|
|
|
Hello,
The extern keyword is used to say to the compiler that you are using a variable declared in another translation unit. See the following for example:
You have one translation unit where you define your variable
int g_nSomeInt = 0;
And another one where you want to use the variable
extern int g_nSomeInt;
void DoFoo()
{
g_nSomeInt++;
}
This is how extern can be used. It is adviced though too use accessor functions instead of the extern keyword.
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|