
Optimal Multithreaded Batch-Parallel 2-3 Trees Wei Quan Lim National University of Singapore Keywords Parallel data structures, pointer machine, multithreading, dictionaries, 2-3 trees. Abstract This paper presents a batch-parallel 2-3 tree T in an asynchronous dynamic multithreading model that supports searches, insertions and deletions in sorted batches and has essentially optimal parallelism, even under the restrictive QRMW (queued read-modify-write) memory contention model where concurrent accesses to the same memory location are queued and serviced one by one. Specifically, if T has n items, then performing an item-sorted batch (given as a leaf-based balanced binary tree) of b operations · n ¹ º ! 1 on T takes O b log b +1 +b work and O logb+logn span (in the worst case as b;n ). This is information-theoretically work-optimal for b ≤ n, and also span-optimal for pointer-based structures. Moreover, it is easy to support optimal intersection, n union and difference of instances of T with sizes m ≤ n, namely within O¹m·log¹ m +1ºº work and O¹log m + log nº span. Furthermore, T supports other batch operations that make it a very useful building block for parallel data structures. To the author’s knowledge, T is the first parallel sorted-set data structure that can be used in an asynchronous multi-processor machine under a memory model with queued contention and yet have asymptotically optimal work and span. In fact, T is designed to have bounded contention and satisfy the claimed work and span bounds regardless of the execution schedule. Since all data structures and algorithms in this paper fit into the dynamic multithreading paradigm, all their performance bounds are directly composable with those of other data structures and algorithms in the same model. Finally, the pipelining techniques in this paper are also likely to be very useful in asynchronous parallelization of other recursive data structures. Acknowledgements I am exceedingly grateful to my family and friends for their unfailing support, and to all others who have given me valuable comments and advice. In particular, I would like to specially thank my brother Wei Zhong Lim and my supervisor Seth Gilbert for very helpful discussions and feedback. 1 Introduction The dynamic multithreading paradigm (see [7] chap. 27) is a common parallel programming model underlying many parallel languages and libraries such as Java [1], OpenMP [16], Cilk dialects [9, 15], Intel Thread Building Blocks [20] and the arXiv:1905.05254v2 [cs.DS] 3 Oct 2019 Microsoft Task Parallel Library [22]. In this paradigm, programs can use programming primitives such as threads, fork/join (also spawn/sync), parallel loops and synchronization primitives, but cannot stipulate how the subcomputations are scheduled for execution on the processors. We consider a multithreaded procedure (which can be an algorithm or a data structure operation) to be correct if and only if it has the desired behaviour regardless of the execution schedule. Moreover, we wish to obtain good bounds on the work and span of the procedure, preferably independent of the execution schedule. Unfortunately, many data structures and algorithms are designed in theoretical computation models with synchronous processors, such as the (synchronous) PRAM models, and so they can be difficult or impossible to implement in dynamic multithreading with the same asymptotic work/time bounds once we take memory contention into account, such as under the QRMW (queued read-modify-write) contention model described in Section 5, which captures both the asynchronocity and contention costs inherent in running multithreaded procedures on most real multi-processor machines. Thus it is desirable to have as many useful algorithms and data structures as possible designed in computation models compatible with dynamic multithreading. 1 One indispensable data structure is the map (or dictionary) data structure, which supports searches/updates, inserts and deletes (collectively referred to as accesses) of items from a linearly ordered set. Balanced binary trees such as the AVL tree or the red-black tree are commonly used to implement a sequential map, taking O¹log nº worst-case cost (in the comparison model) per access for a tree with n items. A related data structure is the sorted-set data structure, which supports intersection, union and difference of any two sets. Using maps based on balanced binary trees to implement sorted-sets yields O¹min¹m;nº·logmax¹m;nºº worst-case cost of each set operation where m;n are the sizes of the input sets. The obvious question is whether we can have an efficient multithreaded parallel map, or an efficient multithreaded sorted-set, or both. In this paper we describe a pointer-based multithreaded batch-parallel 2-3 tree T that is both information-theoretically work-optimal and span-optimal even under the QRMW contention model. Here the input batch is given as a leaf-based balanced · n binary tree. Specifically, performing a sorted batch of b accesses on an instance of T with n items takes O b log b +1 +b work and O¹logb+lognº span. This is superior to the work and span bounds of the PVW 2-3 tree [18] despite not having the luxury of lock-step synchronous processors. Furthermore, since T is a multithreaded data structure whose performance bounds are independent of the schedule, it is trivially composable, which means that we can use T as a black-box data structure in any multithreaded algorithm and easily obtain composable performance bounds. Indeed, the parallel working-set map in [2] and the parallel finger structure in [12] both rely such a parallel 2-3 tree as a key building block. 2 Related Work To illustrate the difficulty of converting data structures designed in the PRAM models to efficient multithreaded implementations, consider the PVW 2-3 tree [18] that supports performing an item-sorted batch of searches, insertions or deletions, which was designed in the EREW PRAM model. Performing a sorted batch of searches in the PVW 2-3 tree involves splitting the batch into contiguous subbatches and pushing them down the tree in non-overlapping waves. This is easy with synchronous processors, but it is non-trivial to translate that pipelining technique to an asynchronous setting with queued memory contention, since a naive use of locking to prevent overlapping waves would cause the worst-case span to increase from O¹logb+lognº to O¹logb·lognº. Section 6.1 shows how this can be done. But performing a sorted batch of b insertions or deletions on the PVW 2-3 tree with n items involves spawning O¹logbº non-overlapping waves of structural changes from the bottom of the 2-3 tree upwards to the root, and for this there does not seem any way to eliminate the reliance on the processors’ lock-step synchronicity. Other map data structures in the PRAM models include parallel B-trees by Higham et al. [14], parallel red-black trees by Park et al. [17] and parallel ¹a;bº-trees by Akhremtsev et al. [3], all of which crucially rely on lock-step synchronous processors as well. A different approach of pipelining using futures by Blelloch et al. [6] yields an implementation of insertion into a variant of PVW 2-3 trees that requires not only a CREW/EREW PRAM but also a unit-time plus-scan (all-prefix-sums) operation. The · n ¹ · º multithreaded parallel sorted-sets presented by Blelloch et al. in [4] take O b log b +1 work but up to Θ logb logn span per operation between two sets of sizes n;b where n ≥ b. The span was reduced to O¹logb+lognº by Blelloch et al. in [5], but p that algorithm as written relies on O¹1º-time concurrent reads and may take Ω¹ nº span in a queued memory contention model. This paper shows that, using special pipelining schemes, it is actually possible to design a multithreaded batch-parallel 2-3 · n ¹ º tree that takes O b log b +1 +b work and O logb+logn span, even if only bounded memory contention is permitted. The techniques shown here can likely be adapted to pipeline top-down operations on many other tree-based data structures. 2 3 Main Results This paper presents, to the author’s best knowledge, the first multithreaded sorted-set data structure that can be run on an asynchronous parallel pointer machine and achieves optimal work and span bounds even under queued memory contention. Specifically, the underlying data structure T is a pointer-based batch-parallel 2-3 tree that works in the QRMW contention model · n ¹ º (see Section 5) and supports performing an item-sorted batch of b accesses within O b log b +1 +b work and O logb+logn span (in the worst case as b;n ! 1)(Section 7.3). Here we of course assume that we are given an O¹1º-step comparison function on pairs of items (i.e. the comparison model), but there is no loss of generality. This is information-theoretically work-optimal for b ≤ n, and also span-optimal in the parallel pointer machine model. Furthermore, the input batch can be any balanced binary tree, including even another instance of T, and hence T can be used to implement optimal persistent sorted n sets supporting intersection, union and difference of sets with sizes m ≤ n in O¹m·log¹ m +1ºº work and O¹logm+lognº span (Section 8). T also supports performing an unsorted batch of b searches within O¹b · lognº work and O¹logb · lognº span (Section 7.2), which is useful when b n. Additionally, T supports performing a reverse-indexing on an unsorted batch of b direct pointers · n ¹ º to distinct items in it, which yields a sorted batch of those items within O b log b +b work and O logn span (Section 7.4).
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages26 Page
-
File Size-