请帮助...平行执行.时间比顺序的要多. [英] Please help...Parallel exec. time is coming more than sequential one.

查看:77
本文介绍了请帮助...平行执行.时间比顺序的要多.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在c#.net 4.0中为我的并行性项目编写代码.
编码后,我遇到了一个并行执行程序的问题.时间比顺序的要多.

``x''和``y''是全局数组变量.

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.

推荐答案

并行并不意味着事情会同时发生.这意味着操作 可以 发生在单独的线程中,这些线程可以(也可以不)在单独的内核上运行.假设有可用的内核来运行线程,或者所有发生的事情是建立线程和管理线程的额外开销,意味着整个操作将花费更长的时间.它还取决于所涉及的处理以及数据之间的相互关系.

仅通过尝试加快速度就可以很慢地放慢速度...
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...


这篇关于请帮助...平行执行.时间比顺序的要多.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆