[fpc-pascal] Common OpenMP syntax?

Steve Williams stevewilliams at kromestudios.com
Wed Jul 26 11:27:30 CEST 2006


Michael Van Canneyt wrote:
> Which is why I think that it's better to have them as local functions,
> instead of having to introduce a lot of new functions.
>
> Local functions are very pascal-ish. C doesn't have it, which is why they can't use it.
> Let's use the language features to their full extent.
>   

  *procedure* SubDomain (*var* x       : *array of* Float;
                           istart  : Integer;
                           ipoints : Integer)
  *var*
     i : Integer;
  *begin*
     *for* i := 0 *to* ipoints - 1 *do*
        x[istart + i] := 123.456;
  *end* /{SubDomain}/;
  
  *procedure* Sub (*var* x : *array of* Float);
  /// Variables declared here should have /|*shared*|/ context./
  /// This would include the function's parameters then.../

    *procedure* SubTask(*var* x : *array of* Float);
    *var*
      /// Variables declared here have /|*private*|/ context./
      iam     : Integer;
      nt      : Integer;
      ipoints : Integer;
    *parallel*
      iam := OMP.Get_Thread_Num;  /// OMP library calls./
      nt  := OMP.Get_Num_Threads;
        
      ipoints := Length (x) *div* nt; /// size of partition/
      istart  := iam * ipoints;     /// starting array index/
        
      *if* iam = Pred (nt) *then*
        ipoints := Length (x) - istart; /// last thread may do more/
        
      SubDomain (x, istart, ipoints);
    *end*;

  *begin*
    SubTask(x);
  *end* /{Sub}/;
  
  *var*
     arr = *array*[0 .. 9999] *of* Float;
  *begin* / // Main program/
     Sub (arr);
  *end*.



-- 
Sly



This message and its attachments may contain legally privileged or confidential information. This message is intended for the use of the individual or entity to which it is addressed. If you are not the addressee indicated in this message, or the employee or agent responsible for delivering the message to the intended recipient, you may not copy or deliver this message or its attachments to anyone. Rather, you should permanently delete this message and its attachments and kindly notify the sender by reply e-mail. Any content of this message and its attachments, which does not relate to the official business of the sending company must be taken not to have been sent or endorsed by the sending company or any of its related entities. No warranty is made that the e-mail or attachment(s) are free from computer virus or other defect.



More information about the fpc-pascal mailing list