Ada-Rapporteur-Group / User-Community-Input

Ada User Community Input Working Group - Github Mirror Prototype
26 stars 1 forks source link

Constructing aggregates in parallel #51

Open ARG-Editor opened 1 year ago

ARG-Editor commented 1 year ago

This issue continues an unfinished topic from Ada 2022. This issue was created to fulfill the ARG resolution of November 10, 2022.


Ada 2012 adds the capability to assign aggregates to a container, and extends the syntax for arrays to allow iterator syntax to define the aggregate to be assigned to an array.

Ada 2012 also introduces syntax for parallel constructs that can make better use of the available cores of a multicore platform for tackling problems of a divide and conquer nature.

One area where the parallel keyword is not currently supported in Ada is for aggregate iterator syntax.

Certain objects or results in Ada can be time consuming to produce. If a collection of such objects needs to be created, such as by initializing an array or container, it can be time consuming to create the aggregate assignment for the collection. It would be desirable in those cases to also allow the parallel keyword to be applied to the aggregate iterator to improve the performance of the assignment.

This can be useful in cases where the creation of the elements of the container can be calculated independently from each other, and where such calculations do not make use of all the available CPUs.

Some examples for use cases include calculating the square roots of an array of big numbers, and remote computing situations such as obtaining compilation times from an array of remote compilation engines for various targets.

Additionally, we eliminated the combiner from the Reduce operation as all of the examples that we could imagine seemed better written as an aggregate. However, this eliminated the possibility of doing the reduction in parallel. For a large, complex reduction, parallel execution can greatly reduce (pun intended) execution times.

AI12-0349-1 was created for this topic for Ada 2022, but it was introduced too late to finish in time and it was left for future work.

Implementation would be straightforward for arrays. For containers, we could either add an additional operation to support parallel execution, or (perhaps better), only allow it for aggregates that are constructed with an index of some sort. (That is, not allowing parallel aggregate iterators for Add_Unnamed aggregates, which necessarily are constructed sequentially by adding elements in sequence). The AI proposes the former, but the latter would be substantially simpler and would allow the likely use cases.

sttaft commented 1 year ago

Here is a link to AI12-0349-1. As pointed out above, for array aggregates, the transformation is straightforward, since we already provide for chunked parallel iteration, and concurrent assignment to distinct elements of an array has been supported since Ada 83, so long as the components are independent (which would seem to be a requirement for a parallel array aggregate).

Similarly, a parallel record aggregate would seemed to impose few problems, again presuming the components are independent, once the discriminants have been evaluated and the object allocated.

However, as mentioned above, a parallel container aggregate would require what would be effectively protected operations on the container, so would not be appropriate for "normal" containers. Hence generalizing this to container aggregates would be dependent on the notion of synchronized containers, and so should probably be part of a separate AI on that topic.