Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 什么是快速或正确的并行分析数组的方法_C#_Arrays_Multithreading_Parallel.for - Fatal编程技术网

C# 什么是快速或正确的并行分析数组的方法

C# 什么是快速或正确的并行分析数组的方法,c#,arrays,multithreading,parallel.for,C#,Arrays,Multithreading,Parallel.for,我有一个大的一维数组,里面装满了Zmap数据(ea高度数据) 这个阵列相当大,它由一个面积像素的100个测量样本组成。我需要以几种方式处理它,以便可以更正另一个锁定的位图。为了加快这个大型阵列的处理速度,我使用parallel.for ea: public void MarkErrorSamples(int[]Depthdata,int下限) { Parallel.For(0,depthData.Length,sampleN=> { if(深度数据[sampleN]

我有一个大的一维数组,里面装满了Zmap数据(ea高度数据) 这个阵列相当大,它由一个面积像素的100个测量样本组成。我需要以几种方式处理它,以便可以更正另一个锁定的位图。为了加快这个大型阵列的处理速度,我使用parallel.for

ea:

public void MarkErrorSamples(int[]Depthdata,int下限)
{ 
Parallel.For(0,depthData.Length,sampleN=>
{
if(深度数据[sampleN]
上面的代码可以工作,但我对访问
depthdata[sampleN]有一些疑问
我现在的做法。我在这里担心的是,每次启动线程从数组中检索数据时,线程都可能会锁定数组。因此,我想知道并行处理“外部块”数组数据的正确方法是什么。例如


请注意,在上述空白中,不需要更改depthdata本身,只需对位图执行操作(使用lockbits位图).

我在这里担心的是,每次启动线程从中检索数据时,线程可能会锁定数组。不确定我是否正确理解了您的句子,但如果数组被锁定,那么这将不再是并行的。普遍的共识似乎是从不同的thr访问数组的不同部分eads不是问题。,@M.kazem是的,我想知道,当调用此函数时,没有其他东西在声明数组。但是数组的元素位于Parallel.Fro范围之外。因此我想知道是否可以在每个线程中放入depthData[sampleN]的值注意,由于强制重新加载处理器缓存,这可能会严重影响并行算法。嗯,是的,我担心访问锁定,根据@Heinz的说法,这不是一个问题,而其他人对此进行了描述。我甚至可能将整个数据集“批处理”成更小的部分,让简单的操作在更小的阵列上运行……但是我仍然在想:内存锁、数组和线程。我不知道如何将数组解析为并行for,以便每个线程都知道从零开始使用哪个数组元素。
public void MarkErrorSamples(int[]Depthdata,int lowbound)
{ 
    Parallel.For (0, depthData.Length, sampleN => 
    {
        if(depthData[sampleN] < lowbount) 
        {
            // update redchannel Red value by 20
            int x= xfromLockedmemPos(sampleN); // x value based upon sampleN
            int y =yfromLockedmemPos(sampleN); 
            setpixel(x,y,AddRed((getpixelRed(x,y),20);
        }
    });
}