0

I'm writing a C# windows form application that provide end-to-end image processing system. The system consists of many image processing blocks (i.e, scaler, noise reduction,...), each block is a algorithm that is written in C, and I've built the each of them into DLLs and call them from my C# application.

My system is something like this:

(main) input1 -> block1 -> block2

(ig) input2 -> block3 -> block4  -> MUX -> output

(pg) input3 -> block5 -> block6

At the moment, the code I'm using is look like this:

   Task.Factory.StartNew(() => Parallel.For(0, loop_num, i =>
            {
                Parallel.Invoke(
                () =>
                {
                    main(i);
                },
                () =>
                {
                    ig(i);
                },
                () =>
                {
                    pg(i);
                }
                );
                mux(i);
            }), TaskCreationOptions.LongRunning);

But I see that the application is taking very long time to complete just few images. Actually I'm not good at C# and just self study about parallel and task via some examples.

I don't know if my code is good enough on handle multiple processing, or is there a better way? So I start this thread to look for help/suggest.

svick
  • 236,525
  • 50
  • 385
  • 514
Nghiep Ly
  • 11
  • 2
  • Isn't the input for scaling, noise reduction etc. depended on the output of the previous operation? – Stefan Apr 01 '15 at 08:55
  • yes you're correct. on each block (dll), I've use IntPtr to store the image struct pointer, and call free_image dll function to free up the image after used. I wonder way to manage the memory using by the parallel tasks too. – Nghiep Ly Apr 01 '15 at 09:30
  • But the way I see it in your code, you are trying to perform the operations parallel and hence simultaneously. I think parallelization won't help you in this case. – Stefan Apr 01 '15 at 09:42
  • You need to profile your code to find out why is it slow. I don't think we can help you with that. – svick Apr 01 '15 at 11:45
  • Because there's 3 input images, so I think parallel is fine here on 3 way processing seperately and after all 3 images is done, call mux function. Looking for anyone has experience on this case can suggest me on the way i used parallel. More info, I just realize my application is memory bound, not cpu bound, and I found out because of the memory leak in dll and fix it. the app is slow or sometime hangs because of the out of ram memory. – Nghiep Ly Apr 02 '15 at 04:34

0 Answers0