The flattening transformation is an algorithm that transforms nested data parallelism into flat data parallelism. It was pioneered by Guy Blelloch as part of the NESL programming language. The flattening transformation is also sometimes called vectorization, but is completely unrelated to automatic vectorization. The original flattening algorithm was concerned solely with first-order multidimensional arrays containing primitive types, but was extended to handle higher-order and recursive data types in the work on Data Parallel Haskell.
Overview.
Flattening works by "lifting" functions to operate on arrays instead of on single values. For example, a function formula_1 is lifted to a function formula_2. This means an expression formula_3 can be replaced with an application of the lifted function: formula_4. Intuitively, flattening thus works by replacing all function applications with applications of the corresponding lifted function.
After flattening, arrays are represented as single-dimensional value vector "V" containing scalar elements, alongside auxiliary information recording the nested structure, typically in the form of a boolean flag vector "F". The flag vector indicates, for the corresponding element in the value vector, whether it is the beginning of a new "segment". For example, the two-dimensional irregular array formula_5 can be represented as the data vector formula_6 alongside the flag vector formula_7.
This flag vector is necessary in order to correctly flatten nested parallelism. For example, it is used in the flattening of prefix sum to segmented scan.
Flattening can increase the asymptotic work and space complexity of the original program, leading to a much less efficient result.
Usage.
Flattening was originally developed for vector machines such as the Connection Machine, and often produces code that is not a good fit for modern multicore CPUs. However, the principles underlying its simpler cases can be found in constructs such as the codice_1 in Google Jax.
References.
 ;templatestyles src="Reflist/styles.css" / ;