Click here to Skip to main content
15,891,943 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.

C#
	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
Updated 18-Mar-12 22:16pm
v3

1 solution

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...
 
Share this answer
 
Comments
Ratika Agarwal 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 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 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900