multithreading program

multithreading program

Hi,I want to run a program on a set of threads but Iobserve that the program appears toconsume all the resources of all the processors in the system, even when there is no parallel work to perform.I follewed the exampleQuickDemoandI create a computation thread using operating-system facilities (_beginthreadex) ...

but also there is no performanceCan you tell me wat's wrong please ,thanks ,this is my source code#define Second (1000)int qmain (void *ArgList){ FPgrowth *fpgrowth = new FPgrowth(); char *file = "retail.dat" ; fpgrowth->setData(file,3); fpgrowth->setMinsup(500); cilk::cilkview cv; cv.start(); ::SendMessage (HWND_BROADCAST, WMU_PARALLEL_STARTING, (WPARAM)file, 0); int added = fpgrowth->mine(file); cv.stop(); ::SendMessage (HWND_BROADCAST, WMU_PARALLEL_DONE, (WPARAM)cv.accumulated_milliseconds() / 1000.f, 0); FILE *fp_sum; fp_sum = fopen("resultFPgrowth.txt", "a+"); fprintf(fp_sum, "Total running time = [%.3f s]\\n", cv.accumulated_milliseconds() / 1000.f); fprintf(fp_sum, "\\t--------------------------------------------------------\\n"); fprintf(fp_sum, "\\t\\t\\t\\t\\t\\t\\t\\n"); fclose(fp_sum); cout << added << "\\t[" << cv.accumulated_milliseconds() / 1000.f << "s]" << endl; delete fpgrowth; return 1; }#define NUM_THREADS 4unsigned __stdcall ParallelQSort (void *ArgList){ ::SendMessage (NULL, WMU_PARALLEL_INITIALIZING, 0, 0); cilk::context ctx; cout << " cilk::context::get_worker_count() " << ctx.get_worker_count() << endl; ctx.set_worker_count (NUM_THREADS); ctx.run (qmain,ArgList); return 1;}// User Defines Messages#define THRD_MESSAGE_SOMEWORK WM_USER + 1#define THRD_MESSAGE_EXIT WM_USER + 2int main(int argc, char *argv[]){ int ErrorNumber, DOSErrorNumber; unsigned ThreadId; HANDLE hThread, hEvent ; hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); // Spawn a thread to run the parallel quicksort hThread = (HANDLE)_beginthreadex(NULL, 0, ParallelQSort, &hEvent, 0, &ThreadId); WaitForSingleObject(hThread, INFINITE); if (hThread == 0) { cout << " Failed to create thread! " << endl; ErrorNumber = errno; DOSErrorNumber = _doserrno; cerr << "Begin thread error: " << strerror(ErrorNumber) << '\\n'; cerr << "Begin thread DOS error code: " << DOSErrorNumber << '\\n'; return 16; } Sleep(Second<<4); SetEvent(hEvent); // signal thread to end int rv = WaitForSingleObject(hThread, Second<<3); // wait up to 8 seconds cout << "Thread wait rv " << rv << '\\n'; CloseHandle(hEvent); CloseHandle(hThread); return 0;}

6 posts / 0 nouveau(x)
Dernière contribution
Reportez-vous à notre Notice d'optimisation pour plus d'informations sur les choix et l'optimisation des performances dans les produits logiciels Intel.

While the system will show you that the Cilk application is consuming all of the CPU, it's not really true.

Cilk workersrun in a loop, attempting to steal work. If the steal attempt succeeds, it will go off and execute that work, as you'd expect. This will consume whatever CPU resources it needs, again as you'd expect.

If a steal attempt fails, the worker gives up it's quantum (by calling Sleep(0) on Windows) so if other threads are available, they will be given the processor. However, if no other threads are ready, the OS will reschedule the thread immediately, giving the appearance that the Cilk workers are consumming the CPU without constraint.

- Barry

I understand this butwhile runing the same code on 2 threads and 4 threads, I got the same excution timeand I don't know how can I resolve this problemI read in the Cilk++ programmer guide thatan Intel Cilk++ strand is not guaranteed to run on any specific OS thread, parallel code using Intel Cilk++ cannot safely call MFC functions

First, I highly recommend you upgrade to Intel Cilk Plus. The old Cilk++ kit is unsupported.

Second, I can't find any cilk_spawn statements in your code, so there's no parallelism. Perhaps they're in the FPgrowth class? I didn't see any source for it.

- Barry

the cilk_spawn statments are in the FPgrowth classi used the intel cilk plus, but I found a problem with it: that the threads run sequentially while the same code run in parallel with Cilk++. I couldn't understand why, and that's why I prefered to keep using Cilk++My problem now is to run the same code on 4 and 8 threads with a Dual core machine : while increasing the number of threads, the excution time increasein the true case, the excution time should decrease while increasing the number of threads but not in my caseand this is my problemThanks,

If you can give me an example of a program which runs in parallel with Cilk++ and doesn't with Cilk Plus, I can try to figure out what the problem is. But without code I can execute here, I can only guess.

- Barry

Laisser un commentaire

Veuillez ouvrir une session pour ajouter un commentaire. Pas encore membre ? Rejoignez-nous dès aujourd’hui