Natools

Check-in [db5f3c6f57]
Login
Overview
Comment:parallelism: add a new framework with a task-local accumulator
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: db5f3c6f57519ccce4a93348d4299718ebe74552
User & Date: nat on 2016-10-13 21:47:26
Other Links: manifest | tags
Context
2016-10-14
21:01
tools/smaz: use the new parallelization framework check-in: 1cdd0709b0 user: nat tags: trunk
2016-10-13
21:47
parallelism: add a new framework with a task-local accumulator check-in: db5f3c6f57 user: nat tags: trunk
2016-10-12
17:50
tools/smaz: new command-line option to enable parallel dictionary eval check-in: adcca90a65 user: nat tags: trunk
Changes

Modified src/natools-parallelism.adb from [c6d04588a4] to [cc644ffa6c].

61
62
63
64
65
66
67























































68
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+


      Workers : array (1 .. Task_Count) of Worker;
      pragma Unreferenced (Workers);
   begin
      null;
   end Single_Accumulator_Run;



   procedure Per_Task_Accumulator_Run
     (Global : in out Global_State;
      Task_Count : in Positive)
   is
      protected State is
         procedure Get_Next_Job
           (Job : out Job_Description;
            Terminated : out Boolean);

         procedure Gather (Result : in Task_Result);
      end State;

      task type Worker is
      end Worker;

      protected body State is

         procedure Get_Next_Job
           (Job : out Job_Description;
            Terminated : out Boolean) is
         begin
            Get_Next_Job (Global, Job, Terminated);
         end Get_Next_Job;

         procedure Gather (Result : in Task_Result)  is
         begin
            Gather_Result (Global, Result);
         end Gather;

      end State;

      task body Worker is
         Job : Job_Description;
         Result : Task_Result;
         Terminated : Boolean;
      begin
         Initialize (Result);

         loop
            State.Get_Next_Job (Job, Terminated);
            exit when Terminated;
            Do_Job (Result, Job);
         end loop;

         State.Gather (Result);
      end Worker;

      Workers : array (1 .. Task_Count) of Worker;
      pragma Unreferenced (Workers);
   begin
      null;
   end Per_Task_Accumulator_Run;

end Natools.Parallelism;

Modified src/natools-parallelism.ads from [35466a7f3f] to [079b1d7834].

46
47
48
49
50
51
52




































53
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

        return Boolean is <>;
         --  Check whether there is still a job to do

   procedure Single_Accumulator_Run
     (Global : in out Global_State;
      Task_Count : in Positive);



   generic
      type Global_State (<>) is limited private;
         --  State common to all jobs, only accessed from protected subprograms

      type Task_Result is limited private;
         --  Accumulated result in a single task

      type Job_Description is limited private;
         --  Parameters for a given job

      with procedure Initialize (Result : in out Task_Result) is <>;
         --  Initialize Result for the current task

      with procedure Get_Next_Job
        (Global : in out Global_State;
         Job : out Job_Description;
         Terminated : out Boolean) is <>;
         --  If there is a next job available from Global, set Terminated
         --  to False and initialize Job, otherwise set Terminated to True.

      with procedure Do_Job
        (Result : in out Task_Result;
         Job : in Job_Description) is <>;
         --  Perform the job in parallel

      with procedure Gather_Result
        (Global : in out Global_State;
         Partial : in Task_Result) is <>;
         --  Update Global with results stored in Partial

   procedure Per_Task_Accumulator_Run
     (Global : in out Global_State;
      Task_Count : in Positive);

end Natools.Parallelism;