|
Is there a way to write an application to take advantage of multi-core procesors so that all availble processors (be-it dual-core, quad-core, etc) get equal duty??
Thanks!
|
|
|
|
|
Threads.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
97C5ENVY wrote: Is there a way
yes, be multithreaded.
but that also means that you'll probably have to be very careful about data synchronization and such problems...
|
|
|
|
|
The OS usually assigns the workload to the various cores (or processors). If, for example, you have an application with just a single thread running on a dual core processor, it's quite likely that Windows will spread the work evenly to both cores. In this case, each core would be loaded to approx. 50%.
So, to answer your question, Windows will try to "equalize" the workload for all cores/processors (unless you mess around with affinity settings). However, In order to load the cores to more than 50% (or 25% for a quad), you'll have to create multiple threads in your application (as CPallini pointed out so short and sweet ).
|
|
|
|
|
Michael Schubert wrote: If, for example, you have an application with just a single thread running on a dual core processor, it's quite likely that Windows will spread the work evenly to both cores.
How can a single thread be run simultaneously on multiple cores?
Just curious,
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Not simultaneously. It's called context switching. The OS manages the thread pool and distributes the workload from all threads among the available cores (be it 1, 2, 4 or 16 cores) in small time intervals.
|
|
|
|
|
Michael Schubert wrote: distributes the workload from all threads among the available cores (
Right, but you stated "If, for example, you have an application with
just a single thread running on a dual core processor, it's quite likely
that Windows will spread the work evenly to both cores. In this case, each
core would be loaded to approx. 50%.".
So again, how does one thread get split between cores? IME, if you have a thread
that is busy (e.g. in a loop) then one core gets pegged to 100%.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote: So again, how does one thread get split between cores? IME, if you have a thread
that is busy (e.g. in a loop) then one core gets pegged to 100%.
The OS splits, even a single thread, into "time slices".
If you have a dual core CPU, try it yourself with a single threaded application that puts a heavy load on the CPU and watch how the workload is distributed in Task Manager. It may favour one core but you will see that both are used (unless you set the affinity in Task Manager to use just one core).
|
|
|
|
|
Gotcha. The key part I missed in your previous reply was "Not simultaneously"
Thanks!
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
So basicly the OS manages the processor loads and not the application correct?
|
|
|
|
|
I am trying to use CopyFileEx to copy files like this:
CopyFileEx(m_strSrc,m_strDst,(LPPROGRESS_ROUTINE)CopyProgressRoutine,NULL,false,COPY_FILE_FAIL_IF_EXISTS)
DWORD CALLBACK CopyProgressRoutine(
LARGE_INTEGER TotalFileSize, LARGE_INTEGER TotalBytesTransferred,LARGE_INTEGER StreamSize, LARGE_INTEGER StreamBytesTransferred,
DWORD dwStreamNumber, DWORD dwCallbackReason,
HANDLE hSourceFile, HANDLE hDestinationFile, LPVOID lpData)
{
return PROGRESS_CONTINUE;
}
I want to have a progress indicator to display the copying progress. What would be the best way to have somthing like this?
I think this should be in CopyProgressRoutine. Is IProgressDialog an option for me? If I use this, I can update the progress using IProgressDialog::SetProgress but this function seems to accept the following DWORD parameters:
DWORD dwCompleted,
DWORD dwTotal
But in my CopyProgressRoutine I have LARGE_INTEGER parameters
TotalFileSize, TotalBytesTransferred. Please advice. Thanks
modified on Thursday, May 8, 2008 8:55 PM
|
|
|
|
|
Have CopyProgressRoutine() post a message to the primasry thread indicating the percent done. The handler for that message will call the progress bar's "update" methods.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I'm stress testing a server that utilizes IO Completion Ports. For my test client, I'm just creating threads that perform many connect() calls to the server and leaving the socket connected so I can test my timeout mechanism on the server.
One thing of interest on the test client is a limit I hit on a per thread basis. If one thread loops with a call to connect() inside, just shy of connection number 3956, connect() fails and the system error reads "An operation on a socket could not be performed because the system lacked sufficient buffer space or because a queue was full."
I can drop the thread and start a new one from the same application and the cycle will repeat just fine. I tried increasing the threads stack size, etc... but it doesn't change it.
This is just a test client meant to beat up on my server, but I'm at a loss to explain why connect() always fails at roughly the same spot. I'm using the loopback address to test them on the same box.
Any guidance would be greatly appreciated.
|
|
|
|
|
There is a limit of 10,000 handles per process on Windows XP. I have no idea what the limit is on Vista. My guess is that you are reaching this limit.
Maximum NT User Handles Per Process Is 10,000 in Windows XP[^]
CreateIoCompletionPort consumes 1 handle as does each socket.
3956 * 2 = 7912
Not counting GDI/window and other types of handles.
You can try changing the registry key HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows\USERProcessHandleQuota to check if my theory is correct. I may be wrong.
Best Wishes,
-David Delaune
|
|
|
|
|
I've seen that limit in action with too many windows, gdi related handles etc...
However, my IOCP server which is on the same box is handling more than 30,000 sockets.
Thanks for the idea.
Any other suggestions?
|
|
|
|
|
Just for kicks, since I found a few references to locked page limits and references that talked about increasing the working set, I gave this a try but no change in behavior...
HANDLE hProcess=GetCurrentProcess();
if (hProcess) {
DWORD dwMin, dwMax;
if (GetProcessWorkingSetSize(hProcess, &dwMin, &dwMax)) {
TRACE("Before\n");
TRACE("Minimum working set: %lu Kbytes\n", dwMin/1024);
TRACE("Maximum working set: %lu Kbytes\n", dwMax/1024);
}
SetProcessWorkingSetSize(hProcess, 204800, 1413120*4);
if (GetProcessWorkingSetSize(hProcess, &dwMin, &dwMax)) {
TRACE("After\n");
TRACE("Minimum working set: %lu Kbytes\n", dwMin/1024);
TRACE("Maximum working set: %lu Kbytes\n", dwMax/1024);
}
}
|
|
|
|
|
I don't think increasing the working set will have any effect. Based on what I have read you can implement zero-byte read operations to prevent exceeding the locked pages limit. I believe you should focus your attention to two areas:
1.) Non-Paged pool limit.
2.) Locked pages limit.
Here is a sample chapter from Network Programming for Microsoft® Windows®, Second Edition[^] which addresses the issue.
Best Wishes,
-David Delaune
|
|
|
|
|
Funny, thats the same article I've been digging through.
I agree. I've been trying to reduce my usage to see if that allows the connection limit to vary.
Thanks again for taking the time out to post your comments.
|
|
|
|
|
Randor wrote: you can implement zero-byte read operations
Do you think he means put the socket in non-blocking mode, read, then put it back into blocking mode?
DWORD dwArg=1;
ioctlsocket(socketClient,FIONBIO,&dwArg); // Non-blocking mode
recv(socketClient,NULL,0,0);
dwArg=0;
ioctlsocket(socketClient,FIONBIO,&dwArg); // Blocking mode
|
|
|
|
|
I believe the best thing for you to do is take a look at the implementation by Len Holgate[^]. I have used his code in the past and was very impressed with the performance. It is available here:
http://www.lenholgate.com/archives/000637.html[^]
In SocketServer.cpp there is a function ZeroByteRead() which you should probably take a look at.
Best Wishes,
-David Delaune
|
|
|
|
|
Hello.
I have been working on an XPCOM component project in Visual C++ 2008 Express and have been trying to create a GNU Make-compatible Makefile to build the component with CL. Compiling within the IDE works fine, but I have a strange header error when using the same command line options with CL in my Makefile. I have to address this before adding the Link step.
I have this in my Makefile:
COMPONENT = MoonshineLua
GECKOSDK = C:\gecko-sdk
SOURCES = MoonshineLua.cpp MoonshineLuaModule.cpp
PPDEFS = WIN32 _DEBUG _WINDOWS _USRDLL LUAINTERPRETER_EXPORTS _UNICODE UNICODE
LIBS = nspr4.lib xpcom.lib xpcomglue_s.lib lua.lib
FIREFOX = C:\Program Files\Mozilla Firefox 3 Beta 5
# create the XPCOM component
make:
cl /Od /I "$(GECKOSDK)\include" /D "$(PPDEFS)" /Gm /EHsc /RTC1 /MDd /Fo"Debug\\" \
/Fd"Debug\vc90.pdb" /W3 /nologo /c /ZI /TP $(SOURCES)
I get this output when I run Make:
cl /Od /I "C:\gecko-sdk\include" /D "WIN32 _DEBUG _WINDOWS _USRDLL LUAINTERPRETER_EXPORTS _UNICODE UNICODE" /Gm /EHsc /RTC1 /MDd /Fo"Debug\\" \
/Fd"Debug\vc90.pdb" /W3 /nologo /c /ZI /TP MoonshineLua.cpp MoonshineLuaModule.cpp
MoonshineLuaModule.cpp
c:\gecko-sdk\include\prtypes.h(61) : fatal error C1083: Cannot open include file: 'stddef.h': No such file or directory
MoonshineLua.cpp
c:\gecko-sdk\include\prtypes.h(61) : fatal error C1083: Cannot open include file: 'stddef.h': No such file or directory
Generating Code...
make: *** [make] Error 2
I checked prtypes.h and sure enough it includes stddef.h. This is a standard C header, so what is the problem? I know it must not be a problem, since I can build the component within the IDE wrong. So how can I solve this for use in the Makefile or the command line in general?
Thanks for any help.
|
|
|
|
|
Probably you have to add an option similar to
/I "C:\gecko-sdk\include" for the folder containing stddef.h .
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
"make" cannot find the path for stddef.h, standard VS includes
You may go for trying make file project,
Or try setting the environment variables for Visual Studio Tools,
I don't know its path, in vs2005 it is vsvar32.bat, execute it before make in the command line
see this, [Building a C/C++ Program on the Command Line^]
modified on Thursday, May 8, 2008 10:39 AM
|
|
|
|
|
|
Thanks for your help.
I got it working with this:
# build the XPCOM component
make:
cl /Od /c /I "$(GECKOSDK)\include" /I "$(MSVC)\include" /D "$(PPDEFS)" \
/Gm /ZI /EHsc /MDd /Fo"Debug\\" /W3 /nologo /TP $(SOURCES)
link /OUT:"Debug\$(COMPONENT).dll" /NOLOGO \
/LIBPATH:"$(GECKOSDK)\lib" /LIBPATH:"$(MSVC)\lib" /LIBPATH:"$(WINSDK)\Lib" \
/DLL /MANIFEST /DEBUG /SUBSYSTEM:WINDOWS /MACHINE:X86 \
Debug\$(COMPONENT).obj Debug\$(COMPONENT)Module.obj $(LIBS)
|
|
|
|