6.4 Using parallel
processing with non-parallelizable code
If you cannot parallelize your code, it might still be possible to use parallel processing. The fact that the code cannot be parallelized only means that a specific implementation cannot be parallelized. It does not mean that the problem cannot be solved in a parallel way.
Most code is written to run on application processors that
run sequentially. The code uses serial algorithms and non-concurrent
data structures. Parallelizing this sort of code can be difficult
Investigate the following approaches:
- Use parallel versions
of your data structures and algorithms
Many common data structures and algorithms that
use them are non-concurrent. This prevents you from parallelizing
There are parallel versions of many common data structures
and algorithms. You might be able to use these in place of the originals
to parallelize the code.
- Solve the problem in a different
Analyze what problem the code solves.
Look at the problem and investigate alternative ways of solving
it. There might be alternative solutions that use algorithms and
data structures that are parallelizable.
To do this, think in terms of the purpose of the code and
Typically, the aim of code is to process or transform data.
It takes a certain input and produces a certain output.
Consider if the following possibilities are true:
- The data
you want to process can be divided into small data elements.
- The data elements can be placed into a concurrent data
- The data elements can be processed independently.
If all three possibilities are true, then you can probably
solve your problem with OpenCL.