# Map (parallel pattern)

> Mediated Wiki article. Canonical URL: https://mediated.wiki/source/Map_(parallel_pattern)
> Markdown URL: https://mediated.wiki/source/Map_(parallel_pattern).md
> Source: https://en.wikipedia.org/wiki/Map_(parallel_pattern)
> Source revision: 1138886435
> License: Creative Commons Attribution-ShareAlike 4.0 International (https://creativecommons.org/licenses/by-sa/4.0/)

'''Map''' is an [idiom](/source/Programming_idiom) in [parallel computing](/source/parallel_computing) where a simple operation is applied to all elements of a sequence, potentially in parallel.<ref>{{cite conference |last1=Samadi |first1=Mehrzad |first2=Davoud Anoushe |last2=Jamshidi |first3=Janghaeng |last3=Lee |first4=Scott |last4=Mahlke |title=Paraprox: Pattern-based approximation for data parallel applications |conference=Proc. 19th Int'l Conf. on Architectural support for programming languages and operating systems |url=http://cccp.eecs.umich.edu/papers/samadi-asplos14.pdf|doi=10.1145/2541940.2541948|year=2014}}</ref> It is used to solve [embarrassingly parallel](/source/embarrassingly_parallel) problems: those problems that can be decomposed into independent subtasks, requiring no communication/synchronization between the subtasks except a [join](/source/Fork%E2%80%93join_model) or [barrier](/source/Barrier_(computer_science)) at the end.

When applying the map pattern, one formulates an ''elemental function'' that captures the operation to be performed on a data item that represents a part of the problem, then applies this elemental function in one or more [threads of execution](/source/Thread_(computing)), [hyperthread](/source/hyperthread)s, [SIMD lanes](/source/SIMD_lanes) or on [multiple computers](/source/distributed_computing).

Some parallel programming systems, such as [OpenMP](/source/OpenMP) and [Cilk](/source/Cilk), have language support for the map pattern in the form of a '''parallel for loop''';<ref>{{cite web |title=Compilers and More: The Past, Present and Future of Parallel Loops |first=Michael |last=Wolfe |date=6 April 2015 |website=HPCwire |url=http://www.hpcwire.com/2015/04/06/compilers-and-more-the-past-present-and-future-of-parallel-loops/}}</ref> languages such as [OpenCL](/source/OpenCL) and [CUDA](/source/CUDA) support elemental functions (as "[kernels](/source/Compute_kernel)") at the language level. The map pattern is typically combined with other parallel design patterns. For example, map combined with category reduction gives the [MapReduce](/source/MapReduce) pattern.<ref name="spp">{{cite book |author1=Michael McCool |author2=James Reinders |author3=Arch Robison |title=Structured Parallel Programming: Patterns for Efficient Computation |isbn= 978-0124159938|publisher=Elsevier |year=2013}}</ref>{{rp|pp=106–107}}

==See also==
* [Map (higher-order function)](/source/Map_(higher-order_function))
* [Functional programming](/source/Functional_programming)
* [Algorithmic skeleton](/source/Algorithmic_skeleton)

==References==
{{reflist}}

Category:Parallel computing
Category:Software design patterns

---
Adapted from the Wikipedia article [Map (parallel pattern)](https://en.wikipedia.org/wiki/Map_(parallel_pattern)) by Wikipedia contributors ([contributor history](https://en.wikipedia.org/wiki/Map_(parallel_pattern)?action=history)). Available under [Creative Commons Attribution-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-sa/4.0/). Changes may have been made.
