Data parallelism is a form of parallelization of computing across multiple processors in parallel computing environments. Data parallelism focuses on distributing the data across different parallel computing nodes. It contrasts to task parallelism as another form of parallelism.
In a multiprocessor system executing a single set of instructions (SIMD), data parallelism is achieved when each processor performs the sames task on different pieces of distributed data. In some situations, a single execution thread controls operations on all pieces of data. In others, different threads control the operation, but they execute the same code.
For instance, consider a 2-processor system (CPUs A and B) in a parallel environment, and we wish to do a task on some data
d. It is possible to tell CPU A to do that task on one part of
d and CPU B on another part simultaneously, thereby reducing the duration of the execution. The data can be assigned using conditional statements as described below. As a specific example, consider adding two matrices. In a data parallel implementation, CPU A could add all elements from the top half of the matrices, while CPU B could add all elements from the bottom half of the matrices. Since the two processors work in parallel, the job of performing matrix addition would take one half the time of performing the same operation in serial using one CPU alone.
Data parallelism emphasizes the distributed (parallelized) nature of the data, as opposed to the processing (task parallelism). Most real programs fall somewhere on a continuum between task parallelism and data parallelism.
if CPU = "a" lower_limit := 1 upper_limit := round(d.length/2) else if CPU = "b" lower_limit := round(d.length/2) + 1 upper_limit := d.length for i from lower_limit to upper_limit by 1 foo(d[i])
If the above example program is executed on a 2-processor system the runtime environment may execute it as follows:
- In an SPMD system, both CPUs will execute the code.
- In a parallel environment, both will have access to
- A mechanism is presumed to be in place whereby each CPU will create its own copy of
upper_limitthat is independent of the other.
ifclause differentiates between the CPUs. CPU
"a"will read true on the
if; and CPU
"b"will read true on the
else if, thus having their own values of
- Now, both CPUs execute
foo(d[i]), but since each CPU has different values of the limits, they operate on different parts of
dsimultaneously, thereby distributing the task among themselves. Obviously, this will be faster than doing it on a single CPU.
This concept can be generalized to any number of processors. However, when the number of processors increases, it may be helpful to restructure the program in a similar way (where
cpuid is an integer between 1 and the number of CPUs, and acts as a unique identifier for every CPU):
for i from cpuid to d.length by number_of_cpus foo(d[i])
For example, on a 2-processor system CPU A (
cpuid 1) will operate on odd entries and CPU B (
cpuid 2) will operate on even entries.
- Active message
- Instruction level parallelism
- Scalable parallelism
- Thread level parallelism
- Parallel programming model
- Some input data (e.g. when
d.lengthevaluates to 1 and
roundrounds towards zero [this is just an example, there are no requirements on what type of rounding is used]) will lead to
lower_limitbeing greater than
upper_limit, it's assumed that the loop will exit immediately (i.e. zero iterations will occur) when this happens.