|
I would probably write the GUI in .NET and if you need any high performance calculation, then implement this in a standard unmanaged dll.
|
|
|
|
|
Hi,
I am currently digging through heaps of articles about various mechanisms for parallel programming, such as OpenMP, OpenCL, and the new Parallels library in Visual Studio 2010. In the short run, I intend to modify our application to take advantage of multicore systems, and it seems the VS libraries will make this really easy to implement.
But I am looking further, and would like to draw on the power of GPU processing as well, so I'd like to make my changes in a way that are not limited to just one method. What I'm thinking of is an interface that can be adapted through settings to use multiple cores, GPU power, or whatever other method I might think of in the future (cloud computing maybe?).
I have no idea where to start though. I've found some very helpful articles (with examples) for using the VS integrated libraries, so I'm good for these. I am pretty much dangling in thin air with respect to GPU processing though: the Wiki articles on OpenMP or OpenCL are pretty much academic, and provide very little in the way of examples or 'how-to' advice.
Can anyone point me to a good article or two to get me started?
P.S.: The application this is all about is a product sold to individual customers with varying hardware, so information about specific GPU programming such as CUDA (I've already found a good article about this on CP) doesn't really help all that much, as it's limited to just one family of graphic cards.
|
|
|
|
|
This is not easy to answer. It's like if you asked: 'Oh, I like the idea of quantum physics, I tried to read a book but it was too academic, please help...'
Parallel computing is a very wide field, divided into many distinct disciplines. I suggest you first try to clarify what you go into first: Utilizing multicore CPU systems is mostly about 'task parallelism' (= pieces of your program code are running concurrently, possibly sharing same data), GPU computing is mainly about 'data parallelism' (= data is processed by several independent units performing the same step on different data). Often, these two kinds of parallelism overlap. Technically, however, programming GPU parallelism versus concurrent programming on a (multicore) CPU system are two different worlds...
Wikipedia articles are not a bad point to start with. I also suggest to have a look at the MSDN magazine articles and the tutorials on msdn.com. You also mentioned OpenCL and OpenMP - there is a vast amount of introductory material available in printed and online format. With regard to concurrent programing I'd recommend to have a look at frameworks which abstract concurrency, like Microsofts TPL or CCR. With regard to general purpose GPU computing, I liked http://www.mathematik.uni-dortmund.de/~goeddeke/gpgpu/index.html[^]
modified on Sunday, September 19, 2010 5:15 AM
|
|
|
|
|
Thank you for your response.
To clarify, I am actually not exactly new to programming, I already dabbled a bit into it in the 80s, then using the OCCAM programming language. However, what we did was largely academic because we never managed to lay our hands on actual parallel hardware, we just simulated it to see how it works.
The problem I have is that since then I never really had a need to care about multithreading or any other form of parallelism until, some 5 years ago, I joined a team that had a master-slave pattern implemented for remote data base queries. This was the first time I've seen the problem of parallelism molded into an object-oriented pattern, and it was completely different from my first experiences with OCCAM.
What I am trying to accomplish now is two things:
First, get a mechanism into place to deal with massive data paralellism: we have multiple time-consuming numerical algorithms that work on dozens, hundreds, or sometimes thousands of sets of independent data at the same time. Multicore paralleliism like what is supported by the VS parallel libraries would be a first step, but I'd like to be sufficiently abstract to be able to use GPUs instead, if the graphics card supports it.
Second, add 'task-parallelism', as you named it. I'm currently not clear how much this would help, but fear it will take a lot of work for little gain. The areas that I've determined so far which could benefit from this are also in a way data-parallel, although on a much more complex level, and possibly would require some work to prevent race conditions.
From what I've read - confirmed by you're saying - my first goal might be tough to fit into one framework. Anyway, the link you posted looks like it might give me a better idea of that. I'll be content if I can at the very least design an interface that I don't have to completely rewrite once I add in GPU programmming. It's just too much work that depends on this interface, i. e. too much code I need to adapt, to do it twice over. I just want to do that once, and then concentrate on the crunchy bits.
|
|
|
|
|
I see what you're up to. Currently, I do not know of any framework (planned or existing) which would sufficiently abstract 'parallelisms' (huch, this plural sounds strange) of both kinds.
Well, there is something which comes close: the deferred expression/query technique from microsoft's .net framework, also known as LINQ. You define an expression which is basically converted into AST. This expression can be 'compiled' into executable code in an application specific manner. The expression is compiled on demand yielding a 'callable' entity which can be executed with various parameters. What the expression is actually compiled into is an implementation detail.
For example, there is a framwork called 'brahma' (go google 'brahma' = 'gpu computing'). Brahma takes as input an algebraic expression consisting of matrix or other vector operations and compiles it into a program which can execute on a GPU. Equally well, you could compile the expression into a program which uses TPL (Task Parallel Library) or something else...
|
|
|
|
|
What constitutes a good programmer?
Do you know any links which say something about this matter? e.g. skills etc.
best regards.
|
|
|
|
|
Flying_Dutchman wrote: What constitutes a good programmer?
That's almost an impossible question to answer (compounded by it being asked in the wrong forum). What constitutes good?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
thanks david. do u know a forum where to ask it??
let's try, good - highly paid? ...
best regards.
|
|
|
|
|
Strong programming skills.
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
[My articles]
|
|
|
|
|
very funny
not saying anything about the post below etc....
best regards.
|
|
|
|
|
One who is kind to animals and helps old ladies across the street.
It's time for a new signature.
|
|
|
|
|
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
[My articles]
|
|
|
|
|
I believe u r right...when we help someone, we feel mental/internal satisfaction which is mendatory for good programmer(in my humble opinion)
|
|
|
|
|
His capability in finding a boss who believes that.
2 bugs found.
> recompile ...
65534 bugs found.
|
|
|
|
|
How to use the c++ to resolved Load Balance problem just as Emule server, but I donot know how to get the emule server source.
Is there anyone can tell me how to make the Load Balance using C++?
|
|
|
|
|
I think you are trying to bite off waaaay more than you can chew by posing such a general question here - and I doubt people will know or care know emule enough to help you
yu-jian wrote: but I donot know how to get the emule server source.
see here http://www.emule-project.net/home/perl/general.cgi?l=1&rm=download[^]
there's a download link under 'Sourcecode v0.50a'
As for the rest of your issue, I suspect you would be better of studying c++ tcp/ip socket servers etc and then asking a more specific question
'g'
|
|
|
|
|
The problem:
I am using an accessor to INSERT into a table but this does return a value so I am using two commands to find out the ID of what was just inserted or at least that is the idea. I get DB_E_ERRORSINCOMMAND so if anyone can point me to where I am going wrong then you can save both my sanity and my hair...
This is the accessor class from the test application I have been troubleshooting against.
class CDBEvtRawInsert
{
public:
int f_Direction;
int f_HubID;
TCHAR f_RawEvent[1400];
LARGE_INTEGER f_RawEventID;
BEGIN_COLUMN_MAP(CDBEvtRawInsert)
COLUMN_ENTRY(1, f_RawEventID)
END_COLUMN_MAP()
BEGIN_PARAM_MAP(CDBEvtRawInsert)
SET_PARAM_TYPE(DBPARAMIO_INPUT)
COLUMN_ENTRY(1, f_Direction)
COLUMN_ENTRY(2, f_HubID)
COLUMN_ENTRY(3, f_RawEvent)
END_PARAM_MAP()
DEFINE_COMMAND_EX(CDBEvtRawInsert, L" \
INSERT INTO [RawEvent] ([TimeStamp],[Direction],[Hub],[RawEvent]) \
VALUES (GETDATE(),?,?,?);SELECT @@IDENTITY AS RawEventID")
};
This is an extract from the function
CString szValue = _T("test");
HRESULT hr = E_FAIL;
CCommand<CAccessor<CDBEvtRawInsert >,CRowset, CMultipleResults > rsEvtRawInsert;
wcscpy_s(rsEvtRawInsert.f_RawEvent, szValue.GetLength()*2, szValue);
rsEvtRawInsert.f_Direction = 1;
rsEvtRawInsert.f_HubID = 0;
hr = rsEvtRawInsert.Open(theApp.m_oDB.session);
if(S_OK == hr)
{
DBROWCOUNT out;
hr = rsEvtRawInsert.GetNextResult(&out);
I know the SQL is ok as I have tested it in SQL Management Studio on the same DB this code is using. Also if I make it a single recordset by removing the SELECT @@IDENTITY that works too.
If you have an alternative suggestion which would achieve the same result then I am all ears.
Thank you for reading this far.
Alan
|
|
|
|
|
hello guys...how do I get the names of the available devices in a TAPI app?? thnx
|
|
|
|
|
overloaded Name wrote: how do I get the names of the available devices in a TAPI app??
Wouldn't that be up to the app to provide you with that information?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
I have an MFC MDI app in which I have included a docking control bar (Cristi Posea - CSizingControlBar - a resizable control bar) The controlbar has a dialog associated with it which, amongst other things, continuously grabs data from a PCI A/D card using a worker thread.
I have the following code,
first initialise the control bar and associated dialog:-
in MainFrm.h:-
class CMainFrame : public CMDIFrameWnd
{
DECLARE_DYNAMIC(CMainFrame)
public:
CMainFrame();
CMainControlBar m_MCB;
CDataControls m_GrabDataDialog;
.
.
.
}
then in MainFrm.cpp:-
int CMainFrame::EnableControlBar()
{
if (!m_MCB.Create(_T("Data Window"), this, 50))
{
TRACE0("Failed to create Data Window\n");
return -1;
}
m_MCB.SetBarStyle(m_MCB.GetBarStyle() | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC );
m_MCB.EnableDocking(CBRS_ALIGN_ANY);
#ifdef _SCB_REPLACE_MINIFRAME
m_pFloatingFrameClass = RUNTIME_CLASS(CSCBMiniDockFrameWnd);
#endif
DockControlBar(&m_MCB, AFX_IDW_DOCKBAR_LEFT);
if (!m_DataDialog.Create(IDD_MAINCONTROLS,&m_MCB))
{
TRACE0("Failed to create instant bar child\n");
return -1;
}
m_DataDialog.ShowWindow(SW_SHOW);
return 0;
}
Next, set up the thread:-
class CDataControls : public CDialog
{
public:
virtual ~CDataControls();
CDataControls(CWnd* pParent = NULL);
CGraphDraw m_Graph;
void DoDataDraw();
void DoDataGrab();
BOOL m_TerminateThreads;
CWinThread *pDataGrabThread;
double Sig[1024];
.
.
.
};
and:-
BOOL CDataControls::OnInitDialog()
{
CDialog::OnInitDialog();
m_Graph.Initialise();
pDataGrabThread = AfxBeginThread(DataGrabThread,this,THREAD_PRIORITY_NORMAL, 0, CREATE_SUSPENDED);
if(pDataGrabThread==NULL)
AfxMessageBox(L"Crap Thread");
pDataGrabThread->m_bAutoDelete=FALSE;
pDataGrabThread->ResumeThread();
return TRUE;
}
Now the actual thread:-
UINT DataGrabThread(LPVOID me)
{
CDataControls *self = (CDataControls *)me;
while(self->m_TerminateThreads!=0)
{
self->DoDataGrab();
Sleep(100);
}
return 0;
}
To close the thread when the controlbar closes I have:-
void CDataControls::OnClose()
{
m_TerminateThreads=FALSE;
WaitForSingleObject(pDataGrabThread->m_hThread,10000);
delete pDataGrabThread;
CDialog::OnClose();
}
Now I assumed that when I close the main application that it would take care of closing the controlbar sensibly via CDataControls::OnClose() but it doesn't - CDataControls::OnClose() isn't called at all, and I get 'MFC Application has encountered a problem...' error.
So now I have the following in the MainFrm.cpp:-
void CMainFrame::OnClose()
{
::SendMessage(m_ControlsDialog,WM_CLOSE,0,0);
CMDIFrameWnd::OnClose();
}
This now works perfectly! No errors, no memory leaks just apparently a nice clean finish. My question then, is this the correct way to go about this? I haven't had much experience with threads and although this seems to work well and I'm fairly happy with it I would like to know if it is the right way to do it and if not how else might I go about closing a thread running in a non-modal dialog when the main application is closed?
modified on Thursday, September 16, 2010 11:02 AM
|
|
|
|
|
i think its not a safe practice to access the m_TerminateThread variable in main UI thread from another thread, without using any locking mechanisms. Better to use an Event object, which is initially non-signalled, set it to signaled in CDataControls::OnClose(), and wait on thread handle. And in Thread function,
while(WAIT_OBJECT_0 != WaitForSingleObject(self->m_hEvent,0))
{
self->DoDataGrab();
Sleep(100);
}
or,
while(WAIT_OBJECT_0 != WaitForSingleObjectself->m_hEvent,100))
{
self->DoDataGrab();
}
|
|
|
|
|
Actually it is safe in this particular case. As the worker thread only ever reads the state of the variable, but he has to make sure it is reading the changes on each loop, i.e. it must be declared [code]mutable[/code] elase a compiler optimisation step may remove the follow on reads.
As long as multiple threads are not read/writing it should be fine.
If you vote me down, my score will only get lower
|
|
|
|
|
IMO it needs to be no wider than what can be handled atomically (hence 32-bit) AND declared volatile. Then it does not matter how many readers there are, as long as there is only one writer all is fine. With several writers, it most often needs a lock of some kind.
|
|
|
|
|
Cool_Dev wrote: Better to use an Event object,
Thanks, I tried this - it works ok but I still need the WaitForSingleObject() in the CDataControls::OnClose() (see below) Why is this?
void CDataControls::OnClose()
{
SetEvent(g_Event);
WaitForSingleObject(pDataGrabThread>m_hThread,1000);
CDialog::OnClose();
}
|
|
|
|
|
because you need to give the thread a chance to see the event and react to it.
|
|
|
|
|