Jump to content

Benmik

Members
  • Content Count

    10
  • Joined

  • Last visited

Posts posted by Benmik


  1. Thank you so much, Primož. I had read everything but missed out on the fact that Parallel.For is blocking.

    Right now it goes like this:

     var FFor:IOmniParallelSimpleLoop;
     ... 
     Timer.enabled := True;
     FFor := Parallel.For(0,JPGList.Count - 1)
       .NumTasks(Environment.Process.Affinity.Count - 1);
     FFor.Execute(procedure (i:integer)
       begin
         CreateThumbs(JPGList[i]);
       end);
     While not FFor.WaitFor(250) do
       Application.ProcessMessages;
     Timer.enabled := False;
     FFor := nil;

    The timer fires now OK and due to "Application.ProcessMessages" the progress is being displayed in the status bar. It's a bit slower then before, though.

    I'm still experimenting a little.


  2. I read JPG files from disk into a TObjectList and create thumbnails from them that are painted onto a TImage. For creating thumbnails and displaying them I have been using AsyncCalls by Andreas Hausladen for a long time, but now I want to switch to OTL because AsyncCalls isn't maintained any longer.

    Let's say there are 800 JPG in a directory, the first 30 of which fit on the screen. So I force an update of the TImage every time one of these 30 thumbnails has been painted. After that I display a message on a TStatusBar every 50 thumbnails or every second, whichever comes first. I noticed a considerable time lag of a few seconds before the first thumbnail appeared on the screen, so I tried to use a self created thread pool which didn't help much.

     ThumbPool := CreateThreadPool('VSBPool');
     ThumbPool.MaxExecuting := Environment.Process.Affinity.Count - 1;
     ThumbPool.MaxQueued := JPGList.Count - 1;
     Parallel.For(0,JPGList.Count - 1)
       .TaskConfig(Parallel.TaskConfig.ThreadPool(VSBPool))
    //   .TaskConfig(Parallel.TaskConfig.MonitorWith(OmEvMon))
       .NumTasks(Environment.Process.Affinity.Count - 1)
       .Execute(
        procedure (i:integer)
        begin
          CreateThumbs(JPGList[i]);
        end);

    Everything works OK, except for I cannot get the status bar to display the progress. I use a global variable for the count of the produced thumbnails that is incremented (TInterlocked.Increment) in "CreateThumbs". With AsyncCall's "TAsyncCalls.VCLInvoke(procedure begin DisplayProgress end)" in "CreateThumbs" this worked like a charm. But not in OTL. What I have tried so far:

     

    1. A simple timer firing "DisplayProgress" every 500 milliseconds. Timer apparently doesn't get to fire.

    2. Using TOmniEventMonitor. Warning: 'TOmniTaskControl.SetMonitor: Task can be only monitored with a single monitor'

    3. Using Parallel.Async() + "DisplayProgress". Program is slowed down to a creeping pace.

     

    What's the trick, what needs to be  done? Is Parallel.For the right option here? What can I do do get rid of that time lag (singlethreaded the thumbnails appear instantaneously)?


  3. 7 hours ago, David Heffernan said:

    It came across as patronising and gleeful.

    It was by no means meant that way. On the contrary, like everybody else I admire and cherish your capabilities as a programmer, but feel bad every time I witness you treating people badly for minor reasons. I pity this, no more and no less.


  4. 5 minutes ago, Kas Ob. said:

    Then delete it.

    This would be greatly unfair towards Mahdi Safsawi who has put a lot of effort into teaching  us something. I am not the one to judge if he is fully right in everything he says, but I'm grateful for all the people who contribute.


  5. 1 hour ago, David Heffernan said:

    This is what you mean by friendliness, respect, tact is it? Perhaps I'm missing the point.

    Yes, I certainly do. To mourn over a "noble mind" that has gone astray is certainly nothing that would make many people feel offended. (In German it's "ein großer Geist" which I like even better). If you feel this is without friendliness, respect or tact then please! go ahead and try using it yourself!

    39 minutes ago, Anders Melander said:

    What entitles you to be the judge of that? I don't think I have ever seen David "discipline" anyone (himself included) that didn't deserve it.

    I'm not a judge, I express a personal opinion. And, with due respect, I intend to continue doing so. In order to prevent me from living in a world with "judges" and "disciplining" people, if they "deserve" it. I cannot believe you actually mean what your second sentence implies.


  6. 1 hour ago, David Heffernan said:

    Interesting contribution. Thanks.

    Yes, another one of those sarcastic remarks that are so characteristic for you. But neither great merits as a Delphi programmer nor the sophisticated use of Oxford English entitle you to treat people the way you do, especially on stackoverflow. The slightest slip and you are cracking down on the poor devils, and I might be wrong, but in my opinion it has gotten worse in the recent years. This is still a community of human beings, after all, and they should be treated as such. Friendliness, respect, tactfulness and even a certain warmth are never wrong, even with programmatical sinners and wrongdoers.

×