Domanda

it's me again. So i have a problem with concurrency in Ada. Basically part of my program looks like that:

for i in 1..it loop

    for x in 1..A loop
        for y in 1..B
            --tab(x,y):=...
        end loop;
    end loop;

    for x in 1..A loop
        for y in 1..B
            --tab(x,y):=...
        end loop;
    end loop;

end loop;

Inside this loops are some calculations. What i intend to do is to make these two 'inside' loops work concurrently. Either one element from loop 1, then one element element from loop 2 or little less 'symmetric'. But generally i want it to look like that: first iteration, two 'inside' loops work concurrently, all operations finish, iteration finishes. Second iteration same and so on.. My questions is: can i do it with ENTRY and ACCEPT statements? Or will this require something more? If You could just point me the right solution, because i've seen many examples but none suiting my issue.

È stato utile?

Soluzione

If the two inner loops really don't share any data, you can do it loke this:

task First;
task Second;

task body First is
   ...
begin
   for i in 1 .. it loop
      for x in 1 .. A loop
         for y in 1 .. B loop
             ...
         end loop;
      end loop;
   end loop;
end First;

task body Second is
   ...
begin
   for i in 1 .. it loop
      for x in 1 .. A loop
         for y in 1 .. B loop
             ...
         end loop;
      end loop;
   end loop;
end Second;

Altri suggerimenti

You may want to limit the amount of tasks to the amount of cores supported by the system. See this example on calculating pi: https://github.com/AdaDoom3/OldStuff/blob/master/time_pi.adb

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top