Using OpenMP to Parallelize Loops
OpenMP places some restrictions on the types of loops that can be parallelized. The runtime library needs to be able to determine the start points and end points for the work assigned to each thread. Consequently, the following constraints are needed:
n The loop has to be a for loop of this form:
for (init expression; test expression; increment expression)
n The loop variable needs to be of one of the following types: a signed or unsigned integer, a C pointer, or a C++ random access iterator.
n The loop variable needs to be initialized to one end of the range.
n The variable needs to be incremented (or decremented) by a loop invariant increment.
n The test expression needs to be one of >, >=, <, or <=. The comparison needs to be with a loop invariant value.
Under these conditions, it is possible for the runtime to take the loop and partition the iteration ranges to the threads completing the work. Loops that do not adhere to these specifications will need to be restructured before they can be parallelized using an OpenMP parallel for construct.
Copyright © 2018-2021 BrainKart.com; All Rights Reserved. (BS) Developed by Therithal info, Chennai.