countable loops and OpenMP











up vote
0
down vote

favorite












Some OpenMP related documents state that in order for a loop to be treated by OpenMP it must be “countable” providing different definitions for a loop being “countable”:



• the number of iterations in the loop must be countable
with an integer and loop use a fixed increment.
• the loop count can be “determined” ( what does it mean “determined”? )


Is it indeed the requirement of OpenMP? Or is it requirement of a specific compiler implementation of OpenMP?



Also, can the following loop - doesn't seems to be countable - be parallelized by OpenMP ( note that the question is if the code can be pararallelized and not if there is a way to create a parallel equivalent of this code )



for ( i = 0; i < cnt; )
{
x1 = 2.0 * x - 1.;
if ( x1 < 1.0 )
{
i = i + 3;
x = x*2.;
}
else // if ( x1 >= 1. )
{
i = i + 2;
x = x/2.;
}
}









share|improve this question
























  • You can't parallelize that loop as-is because the index depends on the result of the previous iteration, i.e. you have a dependency. That countable only refers to cnt being known at the instant we enter the loop and i being incremented in some trivial way.
    – Qubit
    yesterday















up vote
0
down vote

favorite












Some OpenMP related documents state that in order for a loop to be treated by OpenMP it must be “countable” providing different definitions for a loop being “countable”:



• the number of iterations in the loop must be countable
with an integer and loop use a fixed increment.
• the loop count can be “determined” ( what does it mean “determined”? )


Is it indeed the requirement of OpenMP? Or is it requirement of a specific compiler implementation of OpenMP?



Also, can the following loop - doesn't seems to be countable - be parallelized by OpenMP ( note that the question is if the code can be pararallelized and not if there is a way to create a parallel equivalent of this code )



for ( i = 0; i < cnt; )
{
x1 = 2.0 * x - 1.;
if ( x1 < 1.0 )
{
i = i + 3;
x = x*2.;
}
else // if ( x1 >= 1. )
{
i = i + 2;
x = x/2.;
}
}









share|improve this question
























  • You can't parallelize that loop as-is because the index depends on the result of the previous iteration, i.e. you have a dependency. That countable only refers to cnt being known at the instant we enter the loop and i being incremented in some trivial way.
    – Qubit
    yesterday













up vote
0
down vote

favorite









up vote
0
down vote

favorite











Some OpenMP related documents state that in order for a loop to be treated by OpenMP it must be “countable” providing different definitions for a loop being “countable”:



• the number of iterations in the loop must be countable
with an integer and loop use a fixed increment.
• the loop count can be “determined” ( what does it mean “determined”? )


Is it indeed the requirement of OpenMP? Or is it requirement of a specific compiler implementation of OpenMP?



Also, can the following loop - doesn't seems to be countable - be parallelized by OpenMP ( note that the question is if the code can be pararallelized and not if there is a way to create a parallel equivalent of this code )



for ( i = 0; i < cnt; )
{
x1 = 2.0 * x - 1.;
if ( x1 < 1.0 )
{
i = i + 3;
x = x*2.;
}
else // if ( x1 >= 1. )
{
i = i + 2;
x = x/2.;
}
}









share|improve this question















Some OpenMP related documents state that in order for a loop to be treated by OpenMP it must be “countable” providing different definitions for a loop being “countable”:



• the number of iterations in the loop must be countable
with an integer and loop use a fixed increment.
• the loop count can be “determined” ( what does it mean “determined”? )


Is it indeed the requirement of OpenMP? Or is it requirement of a specific compiler implementation of OpenMP?



Also, can the following loop - doesn't seems to be countable - be parallelized by OpenMP ( note that the question is if the code can be pararallelized and not if there is a way to create a parallel equivalent of this code )



for ( i = 0; i < cnt; )
{
x1 = 2.0 * x - 1.;
if ( x1 < 1.0 )
{
i = i + 3;
x = x*2.;
}
else // if ( x1 >= 1. )
{
i = i + 2;
x = x/2.;
}
}






parallel-processing openmp






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited yesterday









Zulan

14.9k62868




14.9k62868










asked yesterday









David Livshin

14




14












  • You can't parallelize that loop as-is because the index depends on the result of the previous iteration, i.e. you have a dependency. That countable only refers to cnt being known at the instant we enter the loop and i being incremented in some trivial way.
    – Qubit
    yesterday


















  • You can't parallelize that loop as-is because the index depends on the result of the previous iteration, i.e. you have a dependency. That countable only refers to cnt being known at the instant we enter the loop and i being incremented in some trivial way.
    – Qubit
    yesterday
















You can't parallelize that loop as-is because the index depends on the result of the previous iteration, i.e. you have a dependency. That countable only refers to cnt being known at the instant we enter the loop and i being incremented in some trivial way.
– Qubit
yesterday




You can't parallelize that loop as-is because the index depends on the result of the previous iteration, i.e. you have a dependency. That countable only refers to cnt being known at the instant we enter the loop and i being incremented in some trivial way.
– Qubit
yesterday












1 Answer
1






active

oldest

votes

















up vote
0
down vote













The OpenMP standard requires the Canonical Loop Form




The canonical form allows the iteration count of all associated loops to be computed before executing the outermost loop. The computation is performed for each loop in an integer type.




This isn't exactly restricted to integers, you may use pointer types in C and random access iterator types in C++ which are logically translated to integers.



The loop variable must not be modified within the for loop (except for the increment expression). Therefore your example is not valid OpenMP code.



Further restrictions are that the loop test must be a relation comparison <, <=, >, or >= - not != or something more complex. The increment must be constant throughout the loop. The missing increment expression in your example also invalidates it.



You can read about this in the OpenMP standard section 2.6.






share|improve this answer





















  • That is what I don't understand: what does it mean: "computed"? ( or sometimes referred as: "determined" ).
    – David Livshin
    yesterday










  • Say the loop count is something like (upper_limit - lower_limit) / increment. Computing it means that you know the value to be a specific number e.g. 42 before executing the loop.
    – Zulan
    yesterday











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53369295%2fcountable-loops-and-openmp%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote













The OpenMP standard requires the Canonical Loop Form




The canonical form allows the iteration count of all associated loops to be computed before executing the outermost loop. The computation is performed for each loop in an integer type.




This isn't exactly restricted to integers, you may use pointer types in C and random access iterator types in C++ which are logically translated to integers.



The loop variable must not be modified within the for loop (except for the increment expression). Therefore your example is not valid OpenMP code.



Further restrictions are that the loop test must be a relation comparison <, <=, >, or >= - not != or something more complex. The increment must be constant throughout the loop. The missing increment expression in your example also invalidates it.



You can read about this in the OpenMP standard section 2.6.






share|improve this answer





















  • That is what I don't understand: what does it mean: "computed"? ( or sometimes referred as: "determined" ).
    – David Livshin
    yesterday










  • Say the loop count is something like (upper_limit - lower_limit) / increment. Computing it means that you know the value to be a specific number e.g. 42 before executing the loop.
    – Zulan
    yesterday















up vote
0
down vote













The OpenMP standard requires the Canonical Loop Form




The canonical form allows the iteration count of all associated loops to be computed before executing the outermost loop. The computation is performed for each loop in an integer type.




This isn't exactly restricted to integers, you may use pointer types in C and random access iterator types in C++ which are logically translated to integers.



The loop variable must not be modified within the for loop (except for the increment expression). Therefore your example is not valid OpenMP code.



Further restrictions are that the loop test must be a relation comparison <, <=, >, or >= - not != or something more complex. The increment must be constant throughout the loop. The missing increment expression in your example also invalidates it.



You can read about this in the OpenMP standard section 2.6.






share|improve this answer





















  • That is what I don't understand: what does it mean: "computed"? ( or sometimes referred as: "determined" ).
    – David Livshin
    yesterday










  • Say the loop count is something like (upper_limit - lower_limit) / increment. Computing it means that you know the value to be a specific number e.g. 42 before executing the loop.
    – Zulan
    yesterday













up vote
0
down vote










up vote
0
down vote









The OpenMP standard requires the Canonical Loop Form




The canonical form allows the iteration count of all associated loops to be computed before executing the outermost loop. The computation is performed for each loop in an integer type.




This isn't exactly restricted to integers, you may use pointer types in C and random access iterator types in C++ which are logically translated to integers.



The loop variable must not be modified within the for loop (except for the increment expression). Therefore your example is not valid OpenMP code.



Further restrictions are that the loop test must be a relation comparison <, <=, >, or >= - not != or something more complex. The increment must be constant throughout the loop. The missing increment expression in your example also invalidates it.



You can read about this in the OpenMP standard section 2.6.






share|improve this answer












The OpenMP standard requires the Canonical Loop Form




The canonical form allows the iteration count of all associated loops to be computed before executing the outermost loop. The computation is performed for each loop in an integer type.




This isn't exactly restricted to integers, you may use pointer types in C and random access iterator types in C++ which are logically translated to integers.



The loop variable must not be modified within the for loop (except for the increment expression). Therefore your example is not valid OpenMP code.



Further restrictions are that the loop test must be a relation comparison <, <=, >, or >= - not != or something more complex. The increment must be constant throughout the loop. The missing increment expression in your example also invalidates it.



You can read about this in the OpenMP standard section 2.6.







share|improve this answer












share|improve this answer



share|improve this answer










answered yesterday









Zulan

14.9k62868




14.9k62868












  • That is what I don't understand: what does it mean: "computed"? ( or sometimes referred as: "determined" ).
    – David Livshin
    yesterday










  • Say the loop count is something like (upper_limit - lower_limit) / increment. Computing it means that you know the value to be a specific number e.g. 42 before executing the loop.
    – Zulan
    yesterday


















  • That is what I don't understand: what does it mean: "computed"? ( or sometimes referred as: "determined" ).
    – David Livshin
    yesterday










  • Say the loop count is something like (upper_limit - lower_limit) / increment. Computing it means that you know the value to be a specific number e.g. 42 before executing the loop.
    – Zulan
    yesterday
















That is what I don't understand: what does it mean: "computed"? ( or sometimes referred as: "determined" ).
– David Livshin
yesterday




That is what I don't understand: what does it mean: "computed"? ( or sometimes referred as: "determined" ).
– David Livshin
yesterday












Say the loop count is something like (upper_limit - lower_limit) / increment. Computing it means that you know the value to be a specific number e.g. 42 before executing the loop.
– Zulan
yesterday




Say the loop count is something like (upper_limit - lower_limit) / increment. Computing it means that you know the value to be a specific number e.g. 42 before executing the loop.
– Zulan
yesterday


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53369295%2fcountable-loops-and-openmp%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

'app-layout' is not a known element: how to share Component with different Modules

android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

WPF add header to Image with URL pettitions [duplicate]