本文介绍了需要并行的建议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经用c#编写了一个程序,用于并行比较每个像素的图像以使用计算机的所有内核,但是当我在一个内核中然后在两个内核中(我的PC的最大内核)运行它时,它的运行速度更快.这是并行代码的一部分:

I have write a program in c# for comparing images pixel by pixel i parallel form to use all cores of computer but it runs faster when i run it in one core then in two (max core of my PC). This is the part of code in parallel:

//Krahsimi parallel i fotografive piksel për piksel
                    if (opsioni_per_krahasim_sipas_pikselave.Checked == true)
                    {
                        int numri_i_procesorve = Numri_i_berthamave.Value;
                        progressBar1.Visible = true;
                        Color gabim = Color.Red;
                        Color ngjyra_nga_foto_1;
                        Color ngjyra_nga_foto_2;
                        ParallelOptions po = new ParallelOptions();
                        po.MaxDegreeOfParallelism = numri_i_procesorve;
                        koha_e_kaluar.Start();
                        Parallel.For(0, gjersia,po,pikselat_ne_rresht=>
                        {
                            for (int pikselat_ne_kolone = 0; pikselat_ne_kolone < lartesia; pikselat_ne_kolone++)
                            {
                                //Application.DoEvents();
                                  //Color mire = b.GetPixel(pikselat_ne_rresht, pikselat_ne_kolone);
                                lock (a)
                                {
                                    lock (b)
                                    {
                                        ngjyra_nga_foto_1 = a.GetPixel(pikselat_ne_rresht, pikselat_ne_kolone);
                                        ngjyra_nga_foto_2 = b.GetPixel(pikselat_ne_rresht, pikselat_ne_kolone);
                                    }
                                }
                                      if (ngjyra_nga_foto_1 == ngjyra_nga_foto_2)
                                      {
                                              //b.SetPixel(pikselat_ne_rresht, pikselat_ne_kolone, mire);
                                          fillon++;
                                      }
                                      else
                                      {
                                          lock (b)
                                          {
                                              b.SetPixel(pikselat_ne_rresht, pikselat_ne_kolone, gabim);
                                          }
                                              fotot_e_njejta = false;
                                      }
                                 //fillon++;
                            }
                            //double bb = fillon * 100 / (1024 * 768);
                            //Perqindja_e_krahasimit.Text = bb.ToString() + " " + fillon.ToString();

                            //perqinde = (decimal)fillon / (gjersia * lartesia);
                            //Perqindja_e_krahasimit.Text = ((int)(perqinde * 100)).ToString() + "%";
                            //Perqindja_e_krahasimit.Refresh();
                            //progressBar1.Value++;
                        });
                        koha_e_kaluar.Stop();
                        //}
                        }


我有一个跟踪栏,其中包含一些名为Numri_i_berthamave的内核.当我将跟踪栏设置为1个内核并运行程序时,它的运行速度比当我将跟踪条设置为2个内核时要快.我是否正确使用了ParallelOptions的MaxDegreeOfParallelism属性.请提出任何建议.


I have a trackbar that hold numbers of cores named Numri_i_berthamave. When i set the track bar in 1 core and run the program it runs faster then when i set the track bar in 2 cores. Did i use right the MaxDegreeOfParallelism property of ParallelOptions. Any sugestion please.

推荐答案


这篇关于需要并行的建议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 17:44