Programming in Manticore, a Heterogenous Parallel Functional Language [chapter]

Matthew Fluet, Lars Bergstrom, Nic Ford, Mike Rainey, John Reppy, Adam Shaw, Yingqi Xiao
2010 Lecture Notes in Computer Science  
The Manticore project is an effort to design and implement a new functional language for parallel programming. Unlike many earlier parallel languages, Manticore is a heterogeneous language that supports parallelism at multiple levels. Specifically, the Manticore language combines Concurrent ML-style explicit concurrency with fine-grain, implicitly threaded, parallel constructs. These lectures will introduce the Manticore language and explore a variety of programs written to take advantage of
more » ... erogeneous parallelism. At the explicit-concurrency level, Manticore supports the creation distinct threads of control and the coordination of threads through first-class synchronous-message passing. Message-passing synchronization, in contrast to shared-memory synchronization, fits naturally with the functional-programming paradigm. At the implicit-parallelism level, Manticore supports a diverse collection of parallel constructs for different granularities of work. Many of these constructs are inspired by common functional-programming idioms. In addition to describing the basic mechanisms, we will present a number of useful programming techniques that are enabled by these mechanisms. Finally, we will briefly discuss some of the implementation techniques used to execute Manticore programs on commodity multicore computers. Explicitly-Threaded Parallelism The explicit concurrent programming mechanisms presented in Manticore serve two purposes: they support concurrent programming, which is an important feature for systems programming [42] , and they support explicit parallel programming. Like CML, Manticore supports threads that are explicitly created using the spawn primitive. Threads do not share mutable state (as there is no mutable state in the sequential core language); rather they use synchronous message passing over typed channels to 3 communicate and synchronize. Additionally, we use CML communication mechanisms to represent the interface to imperative features such as input/output. Section 3 explores this programming paradigm in more detail. The main intellectual contribution of CML's design is an abstraction mechanism, called first-class synchronous operations, for building synchronization and communication abstractions. This mechanism allows programmers to encapsulate complicated communication and synchronization protocols as first-class abstractions, called event values, which encourages a modular style of programming where the actual underlying channels used to communicate with a given thread are hidden behind data and type abstraction. Events can range from simple message-passing operations to client-server protocols to protocols in a distributed system. CML has been used successfully in a number of systems, including a multithreaded GUI toolkit [34], a distributed tuplespace implementation [71], a system for implementing partitioned applications in a distributed setting [81], and a higher-level library for software checkpointing [82] . CML-style primitives have also been added to a number of other languages, including HASKELL [72], JAVA [22] , OCAML [47], and SCHEME [29] . We believe that this history demonstrates the effectiveness of CML's approach to concurrency. Implicitly-Threaded Parallelism Manticore provides implicitly-threaded parallel versions of a number of sequential forms. These constructs can be viewed as hints to the compiler about which computations are good candidates for parallel execution; the semantics of (most of) these constructs is sequential and the compiler and/or runtime system may choose to execute them in a single thread. 1 Having a sequential semantics is useful in two ways: it provides the programmer with a deterministic programming model and it formalizes the expected behavior of the compiler. Specifically, the compiler must verify that the individual sub-computations in a parallel computation do not send or receive messages before executing the computation in parallel. Furthermore, if a sub-computation raises an exception, the runtime code must delay delivery of that exception until it has verified that all sequentially prior computations have terminated. Both of these restrictions require program analysis to implement efficiently. Section 4 explores this programming paradigm in more detail. Here, we briefly introduce the implicitly parallel mechanisms: Parallel arrays Support for parallel computations over arrays and matrices is common in parallel languages. In Manticore, we support such computations using the nested parallel array mechanism inspired by NESL [7, 6, 8] and developed further by Nepal [15, 16, 49] . The key operations involving parallel arrays are parallel comprehensions, which allow the consise expressions of parallel loops that consume arrays and return a new array, and parallel reductions, which allow the concise expression of parallel loops that consume arrays and return scalars.
doi:10.1007/978-3-642-17685-2_4 fatcat:krgpjp2ts5f7xllnoldgdtcdma