multithreading - Parallel, but slower -


I am using Monte Carlo method to calculate PE and make a basic experience with parallel programming and OpenMP I want to

The problem is that when I use 1 thread, x iterations always run faster than n thread, x iterations. Can anyone tell me?

For example the code runs like "a.out 1 1000000", where there are 1 thread and 1000000 iterations

  include  using namespace std; Int main (int argc, char * argv []) {double arrow_area_circle, pi; Float xp, yp; Int i, n; Double Pitting = Ethan (1.0) * 4.0; // pi for error cout & lt; & Lt; "Number Processor:" & lt; & Lt; Omp_get_num_procs () & lt; & Lt; Endl; // Number of divisions Iersarions = atoi (argv [2]); Arrow_area_circle = 0.0; #pragma omp parallel number_read (eto (argv [1])) {srandom (omp_get_thread_num ()); To reduce personal (XP, YP) ​​#pragma omp (+: arrow_area_circle) for // *, /, -, + (i = 0; i  

If you do more work then a CPU intensive task will be slow in this way Threads in comparison to the CPU in the system If you are running it on a CPU system, you can of course see slowdown with more than one thread. This is due to the OS to switch between different threads - it's a pure overhead. Ideally this kind of thread should work as a core.

Another issue is that arrow_area_circle has been shared between Threads. If you have a thread running on each core, then increasing the arrow arrow_area_circle will cancel the copy in the other core's cache, which will refresh them. Arrow_area_circle ++ Whatever cycle you should take, take dozens or hundreds of cycles.

EDIT: Joe Duffy posted at the cost of sharing data between threads.


Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -