Page 129 - Computer_Science_F5
P. 129
Computer Science (ii) Spatial decomposition: Divides parallel execution, as multiple processing
data based on spatial properties, like units can independently evaluate pure
breaking a large image into smaller functions without encountering conflicts.
Functional programming can unlock
tiles for parallel image processing.
parallelism through recussion and higher-
FOR ONLINE READING ONLY
Data partitioning is used in scientific order fuctions.
simulations, big data analytics, and (a) Functional programming heavily
machine learning. utilizes recursion, where a function
calls itself. This can be structured
Load balancing to achieve parallel processing, with
A crucial aspect of data partitioning each recursive call potentially being
is ensuring roughly equal work is handled by a different processing unit.
distributed across processing units. (b) Higher-order functions are functions
This prevents some cores from staying that operate on other functions.
idle while others are overloaded. Load Higher-order functions offer powerful
balancing can adjust task distribution tools for parallel processing. These
during execution for optimal utilisation functions can be designed to efficiently
of processing units. distribute tasks across multiple cores
for processing independent data
(d) Functional programming elements.
While traditional programming languages
often focus on changing data over time, Functional programming as a technique
functional programming offers a unique to DLP offers several benefits including;
approach to DLP. Imagine a team of (a) Simplified reasoning: Immutability
chefs preparing a banquet. In a traditional and pure functions lead to simpler
approach, each chef might modify the same program logic, making it easier to
ingredients (data) repeatedly to create reason about potential race conditions
various dishes. Functional programming, or conflicts that can arise during
however, takes a different perspective of parallel execution.
DLP. Functional programming emphasises (b) Improved concurrency: The emphasis
the creation of immutable data structures. on immutability and pure functions
This means data cannot be changed once naturally promotes thread safety,
created, promoting a more predictable enabling smoother parallel processing
and thread-safe environment for parallel without data corruption risks.
processing. Functional programming (c) Declarative style: Functional
promotes the use of pure functions. These programming leans towards
functions always produce the same output a declarative style, where the
for a given input, regardless of external programmer specifies what needs to
factors. This characteristic is important for be done rather than how. This allows
120
for Advanced Secondary Schools
Computer Science Form 5.indd 120 23/07/2024 12:33