Automatic Mapping of Task and Data Parallel Programs for Efficient Execution on Multicomputers Jaspal Subhlok November 1993 CMU-CS-93-212 School of Computer ScienceCarnegie Mellon University Pittsburgh, PA 15213 Abstract For a wide variety of applications, both task and data parallelism must be exploited to achieve the best possibleperformance on a multicomputer. Recent research has underlined the importance of exploiting task and data parallelism in a single compiler framework, and such a compiler can map a single source program in many different waysonto a parallel machine. There are several complex tradeoffs between task and data parallelism, depending on the characteristics of the program to be executed and the performance parameters of the target parallel machine. Thismakes it very difficult for a programmer to select a good mapping for a task and data parallel program. In this paper we isolate and examine specific characteristics of executing programs that determine the performance for differentmappings on a parallel machine, and present an automatic system to obtain good mappings. The process consists of two steps: First, an instrumented input program is executed a fixed number of times with different mappings, to buildan execution model of the program. Next, the model is analyzed to obtain a good final mapping of the program onto the processors of the parallel machine. The current implementation is static, feedback driven, although the approachcan be extended to a dynamic system. We demonstrate the system with an example program that is a model for many applications in the domains of signal processing and image processing. This research was sponsored by The Defense Advanced Research Projects Agency, Information Science and Technology Office, under the title "Research on Parallel Computing", ARPA Order No. 7330, issued by DARPA/CMO under Contract MDA972-90- C-0035.The views and conclusions contained in this document are those of the author and should not be interpreted as representing the official policies, either expressed or implied, of the U.S. government. Keywords: Parallel programming, task parallelism, parallelizing compilers, load balancing, automatic mapping,processor allocation 1 Introduction Many applications can be naturally expressed as collections of coarse grain tasks, possibly with data parallelism insidethem. The Fx compiler at Carnegie Mellon is designed to allow the programmer to express and exploit task and data parallelism, and we have demonstrated the power and value of this approach [12]. In this paper, we address theproblem of mapping a task and data parallel program to achieve the best performance. There are several reasons to support task parallelism, in addition to data parallelism, in a parallelizing compiler.For many applications, particularly in the areas of digital signal processing and image processing, the problem sizes are relatively small and fixed, and not enough data parallelism is available to effectively use the large number ofprocessors of a massively parallel machine. Even when adequate data parallelism is available, a data parallel mapping may not be the most efficient way to execute a program. A purely data parallel approach forces all computations tobe performed on a fixed set of processors, whose number typically varies from tens to thousands. However, it is the amount and nature of parallelism and communication, that determine how well a computation scales as the number ofprocessors is increased. A complete application often consists of a series of computations with different computation and communication requirements. For best performance, it may be necessary to assign different sets of processors todifferent computations, and execute several different computations simultaneously. Using task and data parallelism together, it is possible to map an application in a variety of ways onto a parallelmachine. Consider an application with three coarse grain, pipelined, data parallel computation stages, with each execution of a computation stage corresponding to a task. A set of mappings for such an application is shown inFigure 1. Figure 1(a) shows a pure data parallel mapping, where all processors participate in all computation stages. Figure 1(b) shows a pure task parallel mapping, where a subset of processors is dedicated to each computation stage.It may be possible to have multiple copies of the data parallel mapping executing on different sets of processors, as shown in Figure 1(c). Finally, a mix of task and data parallelism, with replication is shown in Figure 1(d). a) Data Parallel Mapping b) Task Parallel Mapping d) Combination of ReplicatedData and Task Parallel Mappingc) Replicated Data ParallelMapping Figure 1: Combinations of Data and Task parallel mappings 1 The fundamental question that we are addressing in this paper is: "Which of the many mappings that are feasiblewhen data and task parallelism are used together is optimal, and how can this be determined automatically ?" A key determinant of performance is communication locality within each data parallel stage, but it has to be tradedoff against processor usage, memory requirements, and inter-task communication cost. Communication locality can be improved by executing each task on a small number of processors, but this makes it difficult to load balance and keep allprocessors busy, implies a higher memory requirement per processor, and possibly a higher inter-task communication cost, due to a finer task granularity.Our solution is to build an execution model of the application using timing information from trial executions, and analyze it to predict the most efficient mapping. Our current implementation is static and feedback driven, and isapplicable to programs for which sample data sets can capture the general execution behavior. In a dynamic system, the scope is extended to other programs where recent execution history is a good predictor of future execution behavior. 2 Overview 2.1 Programming and compiling task parallelism The Fx compiler supports task and data parallelism [12]. The base language is Fortran 77 augmented with Fortran 90array syntax, and data layout statements based on Fortran D and High Performance Fortran. Data parallelism is expressed using array syntax and parallel loops. The main concepts in the Fx compiler are language independent, andFortran was chosen for convenience and user acceptance. The current target machine is an iWarp processor array [2]. Task parallelism is expressed in special code regions called parallel sections. The body of a parallel section islimited to calls to subroutines called task-subroutines, with each execution instance representing a parallel task, andloops to represent multiple instances. Each task-subroutine call is followed by input and output directives, whichdefine the interface of the task subroutine to the calling routine, that is, they list the variables in the calling routine that are accessed and modified in the called task-subroutine. The entries in the input and output lists can be scalars, arrayslices, or whole arrays. The task-subroutines may have data parallelism inside them. A parallel section of an example program is shown in Figure 2. C$ begin parallel do i = 1,10 call src(A,B) C$ output: A,B call p1(A) C$ input: A C$ output: A call p2(B) C$ input: B C$ output: B call sink(A,B) C$ input: A,B enddo C$ end parallel A src sink p1 p2 A B B M1 M2 M2 M1 M2 Task dependence graph and partitioning into modules Replication and Machine Mapping Figure 2: Compilation of task parallelism The compiler can map and schedule instances of task-subroutines in any way, as long as sequential execution resultsare guaranteed1. During compilation, first the input and output directives are analyzed and a task level data dependence and communication graph is built. Next, the task-subroutines are grouped into modules. All task-subroutines in thesame module are mapped to the same set of processors. The modules may be replicated to generate multiple modulesinstances, with each instance receiving and sending data sets in round robin fashion. Finally a subset of the processor array is assigned to each module instance. 1Assuming that input and output parameters are specified correctly 2 Figure 2 shows the application of these steps on a small example program. The task level dependence graph isbuilt from the program and then partitioned into modules M1 and M2. Module M2 is replicated to two instances, and the program is mapped onto the machine. 2.2 Automatic Mapping Parallel Machine ParallelizingCompiler AutomaticMapping Tool SourceProgram ExecutionStatistics Multiple compiledand instrumented programs MappingInformation Figure 3: Automatic Mapping System The subject of this paper is automation of the mapping process discussed in the previous subsection, which is otherwisedriven by user assertions. The structure of the automatic mapping tool and process is shown in Figure 3. The programmer provides a source program with data parallel and task parallel constructs, as well as a sample data set.The mapping tool and the parallelizing compiler generate multiple instrumented versions of the program, which are then executed on the parallel machine, generating runtime statistics. The mapping tool uses these statistics to build aninternal execution model of the program, and analyzes it to generate the final mapping information. This information is provided to the parallelizing compiler to generate a final parallel program for execution. 3 Execution model for task and data parallel programs An Fx parallel program consists of a set of data parallel task-subroutines, that are related by data dependences betweenthem. Every active task-subroutine is in one of the following states: 1. Waiting for a sender to be ready to send input. 2. Receiving input. 3. Executing. 4. Waiting for a receiver to be ready to receive output. 5. Sending output. By measuring the time it spends in each of these states, for different mappings, we can determine the fundamentalexecution properties of a task-subroutine, which can in turn be used to predict the execution behavior for other mappings. In this section, we present an execution model for task-subroutines, which consists of parameterizedequations for execution time, memory requirement , and inter-task communication time. 3 3.1 Execution time The execution time of a task-subroutine on a set of processors is mainly determined by the total amount of computation,the amount of available parallelism, and the communication cost incurred in exploiting the parallelism. Thus, the execution time o/x of task-subroutine T executing on P processors can be expressed as: o/x(P) = C0x + (C1x=P) + (C2x \Lambda P) The values of the Cix parameter describes the execution time characteristics of a specific task-subroutine. The constantterm C0x reflects the time spent on sequential computation in the program, as well as the fixed part of the communicationcost. The second term represents the time spent in parallel computation, which decreases linearly with the number of processors. The last term represents the part of the communication cost that varies with the number of processors, asthe parallelism in communication increases, but the granularity of communication becomes finer. 3.2 Inter-task communication time The transfer of data between a pair of task-subroutines is of two different forms. If the two task-subroutines are mappedon the same set of processors, the data transfer is a potential local redistribution of data. If the task-subroutines are mapped on different sets of processors, there is movement of data from one processor subarray to another processorsubarray. In both cases, the cost is dependent on the volume of the data to be transferred, and the number of processors involved. Increasing the number of processors implies a potentially higher degree of parallelism in communication,but may also increase the associated overhead. We model the data transfer cost between task-subroutines executing on the same set of P processors (data parallelstyle) as: o/dp(P) = C0dp + (C1dp \Lambda P) And for a pair of task subroutines executing on P1 and P2 processors respectively (task parallel style) as: o/tp(P1; P2) = C0tp + (C1tp \Lambda P1) + (C2tp \Lambda P2) 3.3 Memory requirement The memory requirement of a task-subroutine is an important parameter. In a multicomputer that has nodes with afixed amount of uniform storage, the memory requirement determines the set of feasible mappings. In the presence of a memory hierarchy, the memory requirement plays an important role in determining overall performance.The memory requirement is closely related to the way a parallelizing compiler allocates and manages memory. We outline the main memory requirements of a parallel program, and state how they are managed by our compilationsystem: 1. Global and system variables: Allocated for the duration of execution. 2. Local variables: Allocated on the stack as execution proceeds. 3. Compiler buffers and variables: Allocated dynamically on the heap as execution proceeds. Global and system variables are allocated identically for all modules and processors. Local variables are allocatedat run time on the stack as the task-subroutines are executed. Sufficient memory for the communication and other buffers is allocated on entry to a subroutine, and deallocated on exit. If an array argument is to be redistributed as aresult of a a subroutine call, a compiler variable related to the size of the argument is allocated for the duration of the execution of the subroutine. If the argument is to be transferred from a task-subroutine that belongs to another module,such a compiler variable is not needed, since the argument is placed in the appropriate distribution on transfer between modules.Consider the memory requirement of a processor that is executing a module M with task-subroutines T1; T2; :::Tn.If the local memory requirement of task-subroutine T i is _Tilm and the global memory requirement for the program is _gm, then the total memory requirement _total for module M is: _total = _gm + maxi=1 ;n( _Tilm) 4 max is taken since local memory for subroutines is allocated on stack. If a module is executing on a set of P processors,memory required per processor to hold global variables is: _gm(P) = C0gm + (C1gm=P) where C0gm and C1gm represent the memory requirement due to replicated and distributed variables respectively.The memory requirement of individual task-subroutines is dependent on arguments that are redistributed on subroutine entry. If the task subroutine that sends the argument is part of the same module, then additional memoryis allocated for redistribution. If a task-subroutine has k arguments that are potentially redistributed on entry, then theper processor memory requirement for holding local variables and parameters can be modeled as: _lm(P) = C0lm + (C1lm=P) + k X i=1 (( bi \Lambda Ciarg)=P) where C0m and C1m=P represent the memory requirements of local replicated and distributed variables respectively, Ciargis the size of the ith redistributable argument and bi is 1 if the task-subroutine from which the argument is sent is in thesame module as T, and 0 otherwise. 4 Deriving the execution model parameters We restate the parameterized equations for task execution time and inter-task communication time, from the previoussection: o/x(P) = C0x + (C1x=P) + (C2x \Lambda P) (1) o/dp(P) = C0dp + (C1dp \Lambda P) (2) o/tp(P1; P2) = C0tp + (C1tp \Lambda P1) + (C2tp \Lambda P2) (3) We have to determine the actual Cix, Cidp and Citp parameters for each task-subroutine. Consider equation (1). Byexecuting a task-subroutine three times on different number of processors, and measuring the execution time, we obtain three equations in three unknowns, which can be solved in a straightforward way to obtain all Cix values. Similarly,by measuring the data transfer time for two different executions for equation (2), and three different executions for equation (3), the unknown parameters can be determined by solving systems of linear equations.We omit the details of the derivation of memory requirement parameters, and simply state that they can be inferred using compile time information and measurements of stack and heap allocations, made during execution with twodifferent mappings. Lemma 1 All the parameters of the execution model described in Section 3 can be obtained by executing a programat most 5 times. Proof: The parameters for data parallel and task parallel communication can be obtained (for instance) by executingthe program in pure data parallel mode twice and in pure task parallel mode three times, that is 5 distinct executions. The parameters for execution time and memory requirement each require two different executions and can be includedin the set of 5 executions stated above. We wish to point out that the final parameterized equations only approximate the real behavior of the program. Inpractice, however, they provide sufficient information for the mapping process. 5 Building modules from tasks Once the parameters of the execution model for a program are established, it is possible to predict the total executiontime for any program mapping. The objective is to find the optimal mapping for a given program on a given set of processors. To establish the mapping of a program onto a set of processors, the following decisions have to be made: 1. Partitioning of task-subroutines into modules. 5 2. Possible replication of modules. 3. Allocation of processors to module instances. In this section, we address the problem of partitioning task-subroutines into modules. We initially place everytask-subroutine in a module by itself, and then selectively merge pairs of modules, whenever it is considered profitable. We restate that all task-subroutines in the same module are mapped to the same set of processors.One reason why the mapping problem is difficult is that the three subproblems listed above are interdependent, that is, the optimal solution for each depends on the solutions of others. We present a set of results that address theproblem of partitioning tasks into modules, with some assurance that the final mapping obtained from this partitioning is close to optimal. In the next section, we address replication of modules and processor allocation. 5.1 Theoretical complexity It is fairly easy to show that the problem of optimally mapping a set of parallel tasks to a set of processors is in a classof multiprocessor scheduling problems that are NP-hard. For this purpose, we consider a parallel machine with only two processors, and assume that there are no memory or dependence constraints. The restricted optimization problemobtained can be stated as follows: Given a set of tasks T1; T2; :::Tn, with execution time o/ (i) for task Ti. Divide the tasks into two groups such thatthe maximum of the sum of the two execution times in the two sets is minimized. This problem can be shown to be NP-hard by transforming the Partition problem [7] to the above problem. 5.2 Pair of tasks We first consider a pair of task-subroutines that are assigned to different modules, and examine the performanceimplications of merging the modules. There are several reasons why it may be profitable to assign a pair of tasksubroutines to different modules: ffl More processors may be used effectively by two different modules than one. ffl Replication and processor assignment decisions for the task-subroutines are decoupled, allowing more flexibility. ffl Individual memory requirements for each module may be lower than the memory requirement of a single mergedmodule, allowing each instance to fit in a smaller number of processors and improving communication locality. However, the cost of transferring data between task-subroutines can increase when they belong to different modules,and are mapped on different parts of the processor array. In particular, when the distribution of an array item is the same for the two task-subroutines, the data transfer cost is zero when they belong to the same module, but can besignificant when they are in different modules. It is possible to make the decision on merging the modules in a provably correct way, if the following conditionholds for the corresponding task-subroutines: 1. The task-subroutine scales linearly, including inter-task communication cost, or 2. The task-subroutine can be replicated, and the total number of processors available is much greater than theminimum number needed to map the subroutine. This condition allows us to assign fixed execution speed (per processor), with task-subroutines. If a task-subroutinescales perfectly, then this is trivial. Otherwise, we pick the fastest feasible execution rate, which corresponds to execution with the smallest number of processors that the task-subroutine can execute on, since that provides the bestcommunication locality. Under this condition, the following lemma holds: Lemma 2 Consider a program consisting of two task-subroutines T1 and T2, which can be mapped to individual modules M1 and M2, or a single module M12. Let the minimum number of processors required to fit the data sets of corresponding modules be P1, P2 and P12. The criterion for placing both the task-subroutines in the same module is: (P1o/ 1x + P2o/ 2x )=(P12o/ 12x ) ? 1 where o/ 1x , o/ 2x and o/ 12x are the execution times (including communication) of the corresponding modules, on P1, P2 and P12 processors, respectively. 6 The result is obtained by comparing the predicted speeds of execution for the two cases, and is our basis for dividingtask-subroutines into modules. The condition is verified in a quantitative sense, and in our experience, usually holds. An iterative approach is used when the lemma cannot be used directly. 5.3 Task graphs We now address the problem of partitioning a task graph, which is required to be acyclic, except for self dependences.The result from last section can be used to make pairwise decisions, but the order in which the pairs are chosen can influence the final partitioning. Consider the task graph in Figure 4. Task-subroutines T1, T2 and T3 require a minimum T1 T3T2 P1 = 6 P2 = 12 P3 = 6 Optimal Partition: {(T1, T3), (T2)} Other Partitions : {(T1,T2),(T3)},{(T1,T2,T3)} Arrow thickness reflects volume of communication Figure 4: Partitioning a task graph into modules of 6, 12 and 6 processors, respectively, to execute. For simplicity, we assume that the minimum number of processorsrequired to execute a module is the maximum of the processors required for individual subroutines inside the module. Also, suppose T3 is a communication intensive task-subroutine that does not scale well, while others scale linearly,and the volume of communication along the edge T1->T3 is the only major inter-task communication cost, which isnon-existent if those two task-subroutines are mapped to the same module. The optimal partitioning into modules is f(T1; T3); (T2)g, which is obtained if we examine T1 and T3 first, and mergethem into a module. However if we examine T1 and T2 first, we may merge them, and then the possible partitioningsare f(T1; T2); (T3)g, which implies that the cost of communication from T1->T3 has to be paid, or (T1; T2; T3) whichimplies that T3, that does not scale well, will be forced to use at least 12 processors per instance instead of 6, which iswasteful. In general, the problem is that we may combine a set of compute intensive routines in one module first (with limitedbenefit), which may leave a communication intensive routine with limited choices. Based on these observations, we use the following heuristic to pick a pair of modules for a potential merger: ffl Higher priority to modules that do not scale well as number of processors is increased. ffl Higher priority to pairs of modules that need roughly the same number of processors, since the decision influencesother decisions less. The pairwise selection method discussed here is effective for task graphs that are trees and our tool set uses it. Weare motivated by the fact that a large class of applications lead to task graphs that are trees, often just straight line graphs. There is some additional complexity involved in the partitioning of acyclic task graphs that are not trees, andwe expect to address that in future publications. An obvious alternate approach is to exhaustively try all orders and use the best results obtained. Although thisapproach does not seem appealing, it can be used effectively in many situations, since task graphs in a data and task parallel program often contain only a few nodes. 7 6 Mapping modules to processors Once the task-subroutines have been partitioned into modules, we divide the processors among the modules, and replicate the modules when legal and profitable. Replication means executing multiple instances of modules ondifferent parts of the processor array, and is legal when none of the task-parameters in the module has a self dependence, or carries state between instances. The multiple module instances share work by processing data-sets in a round robinfashion. Our procedure is as follows: 1. Divide the processors among modules based on the best estimate of their execution rate. 2. Map the modules onto the processor array, replicating whenever it is possible and profitable. 6.1 Allocating processors to modules The objective of processor allocation is that every module should execute in approximately the same amount of time,thus minimizing load imbalance. The execution time of a module containing a set of task-subroutines, including the communication time, on P processors, can be modeled as: o/ Mx (P) = C0x + (C1x=P) + (C2x \Lambda P) + X Ci x \Lambda Pi where each term in the summation refers to communication with another module. The parameters can be computeddirectly from the parameters of the task-subroutines that constitute the module. The summation term involves the number of processors allocated to other modules that this module communicates with. On per processor basis, the bestperformance is achieved when an instance of the module executes on the smallest number of processors. Thus, if each instance of the module requires at least P0 processors to execute, and the modules that it communicates with are alsoassumed to execute on the smallest set of processors ( Pi0), the execution time corresponding to the best per processorperformance is: o/ Mx (P0) = C0x + (C1x=P0) + (C2x \Lambda P0) + X Ci x \Lambda Pi0 which is a constant. And the execution rate of module M is: X (M) = 1=(o/Mx (P0) \Lambda P0) in datasets/second/processor.Once fixed per processor execution rates are assigned to modules, the problem of finding an optimal allocation can be stated as: Given a set of modules M1; M2; :::Mk, with execution rate X (Mi) for module Mi, divide the available processors P into k sets P1; P2; :::Pk, such that maxi=1 ;k(Pi \Lambda X (Mi)) is minimized.We first solve the problem exactly assuming Pis are allowed rational, i.e. non integral values. We assign anarbitrary value to (say) P 0, then solve for P1 ; P2; :::Pk using Pi \Lambda X (Mi) = P0 \Lambda X (M0) and scaling all Pi values suchthat Pk i=1(Pi) = P. Actual numbers of processors assigned to each module, of course, must be integers. Once a rationalsolution is known, we simply find an approximate integer solution that is close to the rational solution. As in the last section, the processor assignment procedure is based on finding a fixed, per processor, executionrates for modules. When this is not possible, an iterative approach is used. 6.2 Replication and processor assignment As stated before, replication of a module is legal if none of the task-subroutines in it has a self cycle. Even whenreplication is legal, it may not be feasible or desirable for the following reasons. ffl Enough processors may not be available. ffl When the communication paradigm requires reservation of machine resources (e.g. long lived connections insome parallel machines and networks), sufficient resources may not be available. ffl A large number of module instances increase the possibility of slowdown due to sharing of communicationresources. 8 We make the actual replication decisions heuristically, taking the above factors into account. We omit the details,but typically the result is that the communication intensive routines that cannot use a large number of processors in one instance effectively, are more likely to be replicated, while subroutines that scale well are less likely to be replicated.Finally, we have to assign the physical processors to module instances. This is done such that the sharing of communication resources between modules is minimized. In our current implementation, module instances can bemapped only to rectangular subarrays of processors. It may be useful to re-execute the program with the predicted mapping, and collect information for fine tuning. Weexpect to be able to comment on the importance of this step with more experience. 7 Application to an example program We illustrate the process of automatic mapping by demonstrating how our toolset maps an example program onto a64 processor iWarp array. The program consists of a 512 point 2DFFT, implemented as a sequence of 1DFFTs with a transpose between them, followed by a statistical analysis routine. The three task-subroutines corresponding to thecomputation stages are colffts, rowffts and hist (for column FFTs, row FFTs and Histograms), respectively.Figure 5 shows the structure of the computation, and a task-subroutine call level code for the program. C$ begin parallel do i = 1,m call colffts(A) C$ output: A call rowffts(A) C$ input: A C$ output: A call hist(A) C$ input: A enddo C$ end parallel AAcolffts rowffts hist Figure 5: Structure of the example program The first two task-subroutines are completely parallel, while the third task-subroutine, hist, contains significantcommunication. This example was chosen because it demonstrates the tradeoffs between different mapping styles, and more important, it reflects the structure of a large class of applications in digital signal processing and imageprocessing. 7.1 Obtaining execution parameters The program is executed for a set of different mappings, and the instrumentation generates timing information forthe execution of the task-subroutines, and for communication between them. The mappings used for this example are shown in Figure 6. In accordance with Lemma 1, these 5 mappings are sufficient to derive the parameters of theprogram model presented in section 3. The measured execution and communication times are tabulated in Figure 7. Analysis of these measurements using the methods discussed in section 4, yields the execution parameters of theprogram. The execution times of the task-subroutines in terms of the number of processors are as follows: o/ 1x (P) = \Gamma 0:97 + (0:011 \Lambda P) + (600:4=P) o/ 2x (P) = \Gamma 6:42 + (0:072 \Lambda P) + (639:0=P) o/ 3x (P) = 15:27 + (0:231 \Lambda P) + (252:2=P) The estimated execution time function is plotted in Figure 8 and shows that the FFT stages scale very well, whilethe histogram stage does not. This reflects the computations in the task-subroutines - the first two are data parallel, while the third is communication intensive. 9 T1 T2 T3 P1=12, P2=16, P3=32 P1=16, P2=32, P3=12 P1=32, P2=12, P3=16 P1,P2,P3=32P1,P2,P3=64 Figure 6: Mappings for analyzing the example program Processors Execution Time (10 \Gamma 2secs :)T1 T2 T3 12 49.18 47.67 39.06 32 18.12 15.82 30.54 64 9.11 8.16 34.00 Processors Communication Time (10 \Gamma 2secs :)(send-task -> Data Parallel Task Parallel recv-task) T1->T2 T2->T3) T1->T2 T2->T3 32->32 4.18 0.08 * * 64->64 2.50 0.06 * * 12->16 * * 9.57 9.61 16->32 * * 9.65 9.63 32->12 * * 9.80 9.95 Figure 7: Timings from evaluation runs of the example program The communication parameters, also derived from the measurements in Figure 7, are as follows: o/ 1 \Gamma ?2dp (P) = 5 :86 \Gamma (0:052 \Lambda P) o/ 2 \Gamma ?3dp (P) = 0 :10 \Gamma (0:001 \Lambda P) o/ 1 \Gamma ?2tp (P1 ; P2) = 9:39 + (0:012 \Lambda P1) + (0:002 \Lambda P2) o/ 2 \Gamma ?3tp (P2 ; P3) = 9:46 + (0:016 \Lambda P2) \Gamma (0:003 \Lambda P3) We note that there is some cost of data parallel communication between task-subroutines T1 and T2, but practically 10 0 10 20 30 40 50 60 10 20 30 40 50 60 Execution time (x10 msecs) Processors colfftsrowffts hist Figure 8: Scaling of example program subroutines none between T2 and T3. This is because the former involves a matrix transpose, while the latter requires no datamovement. The task parallel communication time is practically constant. In our implementation, the communication between tasks is done systolically on a single link with a fixed bandwidth, and hence the communication time primarilydepends on the volume of data being transferred, which is the same in all cases. We omit the details of the memory requirement analysis and state the final results. A processor in our targetmachine (iWarp) has a fixed amount of main memory. The minimum number of processors required to fit the data set of each of the three task-subroutines is 10, which is the same since the main data structure is the same array. However,when task-subroutine T1 is mapped to the same module as T2 or T3, a minimum of 20 processors are required, sincememory for the original and the transposed array must be allocated. 7.2 Modules from tasks We initially put each task-subroutine in a module by itself, and compare pairs of modules that have a communicationedge between them, to determine if the modules should be merged. In the example program, we have modules M1,M 2 and M3 containing the three task-subroutines. Using the priority system discussed in 5.3, we first examine the pair(M 2 ; M3), since M3 contains the least scalable task-subroutine. Using Lemma 2, we compute: (P2o/ M2x + P3o/ M3x )=(P23o/ M23x ) = 1:189 ? 1 where P2; P3 = 10, P23 = 10 and execution times are computed from the equations for the corresponding modules.Since the above expression > 1, we conclude that the modules should be combined, yielding a new module M23.The execution parameters of M 23 are obtained by adding the execution parameters of P2 and P3 and the data parallelcommunication parameters for communication between them. We obtain: M23x (P) = 8:95 + (0:302 \Lambda P) + (891:2=P) As before, we test if the modules M1 and M23 should be merged and obtain: (P1o/M1x + P23o/M23x )=(P123o/ M123x ) = :945 ! 1 11 and therefore the modules are not combined. Thus the final assignment of task-parameters to modules is: M1 = f(T1)g M23 = f(T2; T3)g 7.3 Allocation of processors The processors are allocated on the basis of the relative execution speed for the minimum number of processors thatthe modules run on, including the communication time. In this case, we have: (o/ M1x + o/ M1tp )=(o/ M23x + o/ M23tp ) = 1 : 1:57 And for a 64 processor machine, we get P1 = 24:9 ss 25 P23 = 39:1 ss 39 7.4 Replication The replication decisions are based on the scalability of different modules - the less scalable are prioritized. Wemeasure the execution time for running each module on all the processors allocated to it, and with only half of the processors allocated, and pick the module which shows the least speedup. For our example, we get: o/ M1x (12:5)=o/M1x (25) = 2:02 o/ M23x (19:5)=o/M23x (39) = 1:39 Hence module M23 is selected for replication. It has 39 processors allocated, and each instance needs at least 10, sowe overallocate, and have four instances, each executing on 10 processors, consuming 40 processors. The remaining 24 processors are allocated to module M1. Since module M1 shows nearly linear speedup, it is not replicated.Figure 9 summarizes the steps in mapping the example program, and shows the final mapping. Figure 10 compares the performance of this mapping to other mappings. 8 Discussion We are using the results of this research for developing several applications with the Fx compiler. We obtained fourfold improvement over a fully data parallel Narrowband tracking radar benchmark [11], mainly because the data parallel version could use only a small number of cells effectively. Other applications under development include SAR(Synthetic Aperture Radar), Multibaseline Stereo, and MRI (Magnetic Resonance Imaging). While the discussion of these applications is beyond the scope of this paper, they all have multiple stages with different computationrequirements, similar to the model program discussed in section 7. The main limitation of our approach is that it can be used only for programs where the history of execution is a goodindicator of the future computation and communication requirements. In the current implementation, the mapping is fixed during execution, and cannot change with runtime behavior. While our approach is not applicable to programswhose runtime behavior is completely unpredicatable, it can be adapted for programs where the runtime behavior can change, but recent history is still a good predictor of near future. We are planning to develop an implementation thatsupports dynamic remapping based on changes in runtime behavior. While this will add considerable complexity to the system, the fundamental approach remains the same.We have selected a fairly simple execution model and many refinements are possible. We model the execution time as a quadratic functions, and the communication times as linear functions. We also ignore several secondaryeffects, for instance, the effect on performance due to sharing of the global machine resources. Our guiding principle has been to develop a simple model and implementation that can be used effectively and conveniently for developingapplications. We expect experience to guide us into refinement of the automatic mapping tool. Plans for future research include development of an interactive tool to guide program mapping, and to port theimplementation to other parallel computers and high speed networks. We are also in the process of identifying more applications which can profit from an integrated task and data parallel compiler. 12 rffts histcffts rffts histcffts cffts rffts hist rffts hist rffts hist rffts hist Tasks grouped Replication Task and Data parallel program in modules rowffts & hist rowffts & hist colffts rowffts & hist rowffts & hist Final mapping onto processors Figure 9: Mapping steps and the final mapping of the example program Program Mapping Performance(data-sets/sec.) Data Parallel 1.44 Best Task Parallel 2.06 Best Predicted 2.82(as shown) Figure 10: Relative performance of the final mapping 9 Related Work Compilation and optimization of programs for private memory parallel computers has been a very active area ofresearch for several years. Several parallelizing compilers have been developed for data parallel programs, including Fortran D [13] and Vienna Fortran [3], and for task parallel programs [8, 9]. Recent research shows that a largeclass of applications contain task and data parallelism [6] and it is important to exploit them in a single compiler framework [4, 5, 12]. There is also a large body of literature on, partitioning, load balancing and scheduling of parallelprograms [1, 10]. We have addressed the specific partitioning and load balancing issues that arise when task and data parallelism arecombined in a parallelizing compiler, including memory requirement issues that are important but often ignored, and developed a practical system to efficiently compile and map task and data parallel programs. An alternate approach,taken in Jade [8] is to express all parallelism as coarse grain tasks, and make scheduling decisions at runtime. This is particularly useful when runtime behavior is unpredictable, but may entail a higher overhead. Most applications havecomponents that have simple data parallelism, and we believe that it is extremely important to use an optimizing data parallel compiler for integrated task and data parallel systems, and statically schedule and optimize computations andcommunication whenever feasible. 13 10 Conclusions We have examined the fundamental characteristics of task and data parallel programs that determine their performance,and presented an execution model for such applications. We used this model and analysis techniques to build a tool to automatically map parallel programs onto a parallel machine. We are using this tool to develop a class of applicationsthat need to exploit task and data parallelism for efficient execution. References [1] BOKHARI, S. Assignment Problems in Parallel and Distributed Computing. Kluwer Academic Publishers, 1987. [2] BORKAR, S., COHN, R., COX, G., GROSS, T., KUNG, H. T., LAM, M., MOORE, M. L. B., MOORE, W., PETERSON,C., S USMAN, J., SUTTON, J., URBANSKI, J., AND WEBB, J. Supporting systolic and memory communication iniWarp. In Proceedings of the 17th Annual International Symposium on Computer Architecture (Seattle, WA, May1990), pp. 70-81. [3] CHAPMAN, B., MEHROTRA, P., AND ZIMA, H. Programming in Vienna Fortran. Scientific Programming 1, 1(Aug. 1992), 31-50. [4] CHEUNG, A., AND REEVES, A. Function-parallel computation in a data-parallel environment. In Proceedings of the 1993 International Conference on Parallel Processing (St Charles, IL, August 1993). [5] FOSTER, I., AND CHANDY, K. Fortran M: A language for modular parallel programming. Tech. Rep. MCS-P327-0992, Argonne National Laboratory, June 1992. [6] FOX, G. The architecture of problems and portable parallel software systems. Tech. Rep. CRPC-TR91172,Northeast Parallel Architectures Center, 1991. [7] GAREY, M., AND JOHNSON, D. Computers and Intractibility: A Guide to the Theory of NP-Completeness. W.H.Freeman and Company, San Fransisco, 1979. [8] LAM, M., AND RINARD, M. Coarse-grain parallel programming in Jade. In Proceedings of the Third ACMSIGPLAN Symposium on Principles and Practice of Parallel Programming (Williamsburg, VA, April 1991). [9] PRINTZ, H. Automatic Mapping of Large Signal Processing Systems to a Parallel Ma chine. PhD thesis, Schoolof Computer Science, Carnegie Mellon University, 1991. Also available as report CMU-CS-91-101. [10] SARKAR, V. Partitioning and Scheduling Parallel Programs for Multiprocessors. The MIT Press, Cambridge,MA, 1989. [11] SHAW, G., GABEL, R., MARTINEZ, D., ROCCO, A., POHLIG, S., GERBER, A., NOONAN, J., AND TEITELBAUM, K.Multiprocessors for radar signal processing. Tech. Rep. 961, MIT Lincoln Laboratory, Nov. 1992. [12] SUBHLOK, J., STICHNOTH, J., O'HALLARON, D., AND GROSS, T. Exploiting task and data parallelism on amulticomputer. In ACM SIGPLAN Symposium on Principles and Practice of Parallel Programming (May 1993). [13] TSENG, C., HIRANANDANI, S., AND KENNEDY, K. Preliminary experiences with the Fortran D compiler. In Proceedings of Supercomputing '93 (Portland, OR, November 1993). 14