Jump to content

Vandrovnik

Members
  • Content Count

    523
  • Joined

  • Last visited

  • Days Won

    6

Posts posted by Vandrovnik


  1. 7 hours ago, Mike Torrettinni said:

    Interesting to know other compilers can parallelize a simple loop. I thought you need to split and parallelize manually, like Delphi.

    Can you imagine Delphi had a flag:

    
    parallel=True

    and does everything for you. I guess Numba developers saw TTask, TThread, OmniThreadLibrary... and just decided to implement a simple flag. Nice!

     

    I have tried this (will probably not work fine for MaxValue not divisible by Workers), it is 3.6 times faster than single thread on an old i7 CPU. I guess it should be possible to use IFuture<Int64>, but I do not know how to pass parameters to it...

    It is easy to use tParallel.For, but there I used tInterlocked.Add(total, num), which resulted in much worse time than single thread.


     

    const MaxValue=1000000000;
    
    type tCalcThread=class(tThread)
          public
           CalcFrom: integer;
           CalcTo: integer;
           Value: Int64;
           procedure Execute; override;
         end;
    
    procedure tCalcThread.Execute;
     var PartialTotal: Int64;
         num: integer;
     begin
     PartialTotal:=0;
     for num:=CalcFrom to CalcTo do
      if (num mod 3 = 0) or (num mod 5 = 0) Then inc(PartialTotal, num);
     Value:=PartialTotal;
    end;
    
    function PLoop32: Int64;
     const Workers = 8;
     Var total : Int64;
         Calcs: array[0..Workers-1] of tCalcThread;
         a: integer;
     begin
     total := 0;
     fillchar(Calcs, sizeof(Calcs), 0);
     try
      for a:=0 to Workers-1 do begin
       Calcs[a]:=tCalcThread.Create(true);
       Calcs[a].FreeOnTerminate:=false;
       Calcs[a].CalcFrom:=Int64(MaxValue)*a div Workers;
       Calcs[a].CalcTo:=Int64(MaxValue)*(a+1) div Workers-1;
       Calcs[a].Start;
      end;
      for a:=0 to Workers-1 do begin
       Calcs[a].WaitFor;
       inc(total, Calcs[a].Value);
      end;
     finally
      for a:=0 to Workers-1 do FreeAndNil(Calcs[a]);
     end;
     result := total;
    end;

     

    • Like 1

  2. 1 hour ago, Dalija Prasnikar said:

    For instance, this would be faster way to achieve same results:

     

    
    var
      total, num: Int64;
    begin
      total := 0;
      num := 3;
      while num <= 1000000000 do
        begin
          total := total + num;
          inc(num, 3);
        end;
    
      num := 5;
      while num <= 1000000000 do
        begin
          total := total + num;
          inc(num, 5);
        end;
    end;

    I know that this is not exactly the answer you are looking for.

     

    I think the result will not be the same - original code adds number 15 just once to the total, while your code will add it twice...

     

    • Like 3

  3. Hello,

     

    I am not able to start 1 Android app of 3 apps since migration to Delphi 11.

    I did the "Revert system files to default" on Libraries.

     

    It fails in FMX.Platform.Android, TPlatformAndroid.Create, on the line Activity.addListener(FActivityListener):

    image.thumb.png.8a8f129b66faa3648bfb5b38749a3fb5.png

     

    Please any ideas what can be wrong / how to repair it?


  4. 43 minutes ago, Anders Melander said:

    Added a translation integration API which allows the application being translated to control BTM.
    Using this integration, when a form or control is focused in the application, then the corresponding module and property is selected in BTM.
    The integration API is contained in the file amLocalization.Integration.Tracker.API.pas

    This is very interesting, please are there instructions how to prepare the application to use this tracking?


  5. Hello, Inno Setup is able to take a file which is out of the setup.exe and install it, so if they can distribute more then just one file, they can put logo.jpg etc. in the same directory (or a subdirectory, as in my example) and install would find it there.

     

    [Files]
    Source: "{src}\Licence\*.*"; DestDir: "{app}\Bin"; Flags: external comparetimestamp; Components: Licence

     

    • Like 1

  6. 15 minutes ago, dummzeuch said:

    And other calls to that procedure might actually require an input value:

     

    How should the compiler determine whether passing an uninitialized variable to procedure bla is a problem, without analyzing the procedure itself?

    OK, when we change it to this, so there is an unitialized variable:

    procedure bla(var _Value1: integer; _Value2: integer);
    begin
      if _Value2 > 0 then
        _Value1 := _Value2+1;
    end;
    
    procedure blub;
    var
      Value1: integer;
    begin
      bla(Value1, 3);
      writeln(Value1);
    end;

    What will be the value of Value1? I would prefer to get a warning in this case.


  7. 4 minutes ago, Attila Kovacs said:

    Every time you compile on every parameter, not just the one, on every single. Every time.

    How would that affect the compiler?

    Thx, not for me.

     

    And it's not even wrong. Why the hint?

     

    From my point of view, it is wrong. For "var" parameters, I expect they are already initialized. For uninitialized variables, that are used as output, there is "out".

     

    https://docwiki.embarcadero.com/RADStudio/Sydney/en/Parameters_(Delphi)

    - Out parameters are frequently used with distributed-object models like COM. In addition, you should use out parameters when you pass an uninitialized variable to a function or procedure.

    • Like 1

  8. 2 minutes ago, Attila Kovacs said:

    Really? And what if the var in the sub-roc is passed further? How deep do you want the compiler work for you? What if the decision is based on a variant? Should the compiler evaluate every outcomes? How slow should be the compiler just for your entertainment? Buy TMS FixInsight, write unit tests and first of all, develop a coding pattern which doesn't even uses such pitfalls.

     

    It does not have to look inside - it sees (immediatelly), that uninitialized variable is passed as "var" parameter. It means that I should initialize the variable, or change the procedure and use "out" parameter instead of "var".

    • Like 1

  9. 1 hour ago, Attila Kovacs said:

    It's not the compilers job to do code analysis for you?

    It helps to avoid mistakes.

     

    Here it produces a warning: ([dcc32 Warning] Test79.dpr(22): W1036 Variable 'a' might not have been initialized)

    procedure Test2;
     var a: integer;
     begin
     if a=1 then exit;
    end;

    I believe it should be consistent and produce a warning in Kryvich's example, too.

     

     


  10. 4 hours ago, Kryvich said:

    I created a minimal reproducible example for this case.

    
    program TestInitialization;
    {$APPTYPE CONSOLE}
    
    procedure Test;
    
     procedure DoStuff(var a: Integer);
     begin
      if a = 0 then
        a := 1;
     end;
    
    var
     a: Integer;
    begin
      DoStuff(a);
      Writeln(a);
    end;
    
    begin
      Test;
      Readln;
    end.

    It's strange that the compiler doesn't show a warning W1036 Variable 'a' might not have been initialized. This is definitely an oversight.

    Please will you report it and post here the link? I would vote for it.

×