In this section we exemplify how all concepts described in Section B are integrated together to implement a simple pArray data structure. The stl valarray container is a fixed size data structure optimized for storing and accessing data based on one di- mensional indices. The stapl pArray is the parallel equivalent of the stl valarray, providing an efficient interface to access data elements using indices. More informa- tion about the complete interface is included in Chapter IX.
Global Identifiers (GIDs) and Domains: For the pArray, the GIDs are the indices of the elements. The pArray domain is the universe of GIDsthat identify its elements and is represented as an integer range corresponding to the indices of the
elements (e.g., 1DRange(0,12) ). The pArray’s domain is a total ordered domain that specifies how elements are traversed by iterators of the default view. The pArray con- structors accept an unsigned integer as an argument (N ) that internally is converted into a finite order domain (1DRange(0,n)) and the resulting index space and order of the elements will be as specified by the domain. It is trivial to extend the interface to have the pArray with an arbitrary domain, e.g., p array<>(Domain(5,12)). This will declare a pArray whose first and last elements have indices 5 and 11, respectively. In Figure 10, the pArray has the range [0, 12) as its domain.
Partition The pArray is a static container, e.g., we can use blocked partitions using a block size as an argument. Assuming N is the size of the domain to be parti- tioned, this partition creates N/block size sub-domains of size block size, except the last one which may be smaller. Other partitions for pArray are balanced partitions, that will divide the elements of the domain into the specified number of sub-domains, each of whose size is N/#sub domains. Explicit partitions are built by explicitly enumerating the sub-domains. The stapl pArray can be built with any of these partitions. An important feature of stapl is that the well-defined partition interface enables advanced users to implement their own partitions.
In Figure 10 we show the pArray with a blocked partition with blocks of size 3. The corresponding sub-domains that this partition strategy (split) generates for the input domain OD = ([0, 12), ≤) are:
P = {OD0 = [0, 3), OD1 = [3, 6), OD2 = [6, 9), OD3 = [9, 12)}
Partition Mapper: A partition is mapped onto a set of locations using a partition-mapper, which maps a sub-domain identifiers to a location. Any of the mappers introduced in Section B.5 can be used with the pArray data structure. Ad- ditional mappers with more information about the machine and interconnect can be implemented by users provided the interface included in Table IX is implemented. In
Figure 10 we show the blocked partition P = {OD0, OD1, OD2, OD3} being mapped
onto available locations in a cyclic fashion. Thus sub-domain OD0 is mapped to
location 0, OD1 is mapped to location 1, OD2 is mapped to location 0 and OD3 is
mapped to location 1.
Storage bContainer: The pArray associates with every sub-domain of the par- tition a bContainer for data storage. The bContainers are implemented as stl valarrays. In Figure 10 we show the pContainer with two location managers in- stances, one in each location were the pContainer’s data will reside. Each location manager handles the bContainers for the sub-domains that were determined by the partition and partition mapper.
1 v a l u e p a r r a y : : s e t e l e m e n t (GID , v a l u e ) { 2 b c i d = d i s t r i b u t i o n m a n a g e r . p a r t i t i o n . map(GID) 3 l o c a t i o n = d i s t r i b u t i o n m a n a g e r . p a r t i t i o n m a p p e r . map( b c i d ) 4 i f l o c a t i o n i s l o c a l 5 return l o c a t i o n m a n a g e r . b c o n t a i n e r ( b c i d ) . s e t (GID , v a l u e ) 6 e l s e // s e t r e m o t e l y t h e e l e m e n t
7 return a s y n c r m i ( l o c , &s e t ( ) , GID , v a l u e ) ;
Fig. 11. Pseudocode of pArray set() method.
The simplified code for the pArray method set element is shown in Figure 11 to illustrate how the pArray modules interact. The complete method performs ad- ditional actions as described in this chapter, Section B.6 and Chapter VI, Section B. The runtime cost of the methods in the pArray interface has three main con- stituents: the time to decide the location and the bContainer in which the element
p_container_base p_container_static p_container_indexed pArray/pMatrix p_container_base p_container_dynamic p_container_sequence pList p_container_base p_container_dynamic p_container_associative p_container_base p_container_dynamic p_container_sequence pVector p_container_base p_container_dynamic p_container_relation pGraph pMap pSet pHashMap/Set
(a) (b) (c)
(d) (e)
p_container_indexed
Fig. 12. pContainers inheritance. The most derived classes inherit all the methods of the base classes. A dotted line denotes that other classes are inheritted as explained in Chapters XI and XII.
is stored (Figure 11, lines 2-3), the communication time to get/send the required information (Figure 11, line 7), and the time it takes to perform the operation within a bContainer, which is currently an STL valarray (Figure 11, line 5).