Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
I am coding in c#.net 4.0 for my project on parallelism.
After coding I came across a problem that parallel exec. time is coming more than sequential one.
 
'x' and 'y' are global arrays variables.
 
	Program object1= new Program();
	Program object2= new Program();
 
/****SEQUENTIAL*****/
	object1.func1(x);
	object1.func2(x);
	object1.func3(x);
	object1.func4(x);
 
	object2.func1(y);
	object2.func2(y);
	object2.func3(y);
	object2.func4(y);
/****SEQUENTIAL*****/
 
/****PARALLEL******/
            Parallel.Invoke(
                () =>
                {
	object1.func1(x);
	object1.func2(x);
	object1.func3(x);
	object1.func4(x);
                },
                () =>
                {
	object2.func1(y);
	object2.func2(y);
	object2.func3(y);
	object2.func4(y);
                });
/****PARALLEL******/
 
The problem may be of false sharing, but I if two different copies of variables through objects are being used, then there should not be a problem of false sharing..! I don't know exactly what is the problem actually. Please help.
Posted 18-Mar-12 8:45am
Edited 18-Mar-12 23:16pm
v3

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Parallel does not mean that things happen at the same time. All it means is that operations can occur in separate threads, which may (or may not) run on separate cores. This assumes that there are free cores to run the threads, or all that happens is that the extra overhead of establishing the thread and managing the threads, means that the total operation takes longer. It also depends on the processing involved, and how inter-related the data is.
 
It is very easy to slow things down, just by trying to speed them up...
  Permalink  
Comments
Ratika Agarwal at 19-Mar-12 0:31am
   
My system is dual core. And I am invoking operations for exactly two cores, as given in the code. Also there is no communication overhead. Then what is the problem.
OriginalGriff at 19-Mar-12 4:33am
   
Just because you have two cores, does not mean that they are both free to run your threads - There are lo=ads of things going on at the same time. There is always overhead - just the work involved in creating the thread means memory allocation, priority allocation, list insertion, etc., etc., etc. There is yet more work involved in scheduling, starting, stoping, switching, and so forth the various threads that are running, including yours!
Ratika Agarwal at 19-Mar-12 9:01am
   
thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Mathew Soji 334
1 Maciej Los 295
2 BillWoodruff 290
3 Afzaal Ahmad Zeeshan 257
4 DamithSL 225
0 OriginalGriff 6,369
1 Sergey Alexandrovich Kryukov 5,973
2 DamithSL 5,183
3 Manas Bhardwaj 4,673
4 Maciej Los 4,045


Advertise | Privacy | Mobile
Web02 | 2.8.1411019.1 | Last Updated 19 Mar 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100