omp pragmas not working for nested for loops
vandana96 opened this issue · comments
vandana96 commented
Hello,
C code:
#pragma omp parallel for
for (int c0 = 0; c0 <= 199; c0 += 1)
{
#pragma omp parallel for
for (int c1 = c0; c1 <= c0 + 99; c1 += 1)
{
for(int c2 = 0; c2 <= 10; c2 += 1){
Statement
}
}
}
Corresponding ctree code:
from ctree import *
from ctypes import *
from ctree.c.nodes import *
import logging
from ctree.omp.nodes import *
from ctree.omp.macros import *
ast = OmpParallelFor(), For(Assign(SymbolRef("c0", c_int()), Constant(0)),
LtE(SymbolRef("c0"), Constant(199)),
Assign(SymbolRef("c0"), Add(SymbolRef("c0"), Constant(1))),
#PostInc(SymbolRef("c0")),
OmpParallelFor(), For(Assign(SymbolRef("c1", c_int()), SymbolRef("c0")),
LtE(SymbolRef("c1"), Add(SymbolRef("c0"), Constant(99))),
Assign(SymbolRef("c1"), Add(SymbolRef("c1"), Constant(1))),
#PostInc(SymbolRef("c1")),
For(Assign(SymbolRef("c2", c_int()), Constant(0)),
LtE(SymbolRef("c2"), Constant(10)),
Assign(SymbolRef("c2"), Add(SymbolRef("c2"), Constant(1))),
#PostInc(SymbolRef("c2")),
[
])))
print (ast[0], ast[1])
Output Observed:
#pragma omp parallel for
#pragma for (int c1 = c0; c1 <= c0 + 99; c1 = c1 + 1) {
for (int c2 = 0; c2 <= 10; c2 = c2 + 1) {
};
}
for (int c0 = 0; c0 <= 199; c0 = c0 + 1) {
#pragma omp parallel for
}
Can you please let me know how to solve this issue?
Lenny Truong commented
# test.py
from ctree import *
from ctypes import *
from ctree.c.nodes import *
import logging
from ctree.omp.nodes import *
from ctree.omp.macros import *
ast = CFile("test", [OmpParallelFor(),
For(Assign(SymbolRef("c0", c_int()), Constant(0)),
LtE(SymbolRef("c0"), Constant(199)),
Assign(SymbolRef("c0"), Add(SymbolRef("c0"), Constant(1))),
[OmpParallelFor(),
For(Assign(SymbolRef("c1", c_int()), SymbolRef("c0")),
LtE(SymbolRef("c1"), Add(SymbolRef("c0"), Constant(99))),
Assign(SymbolRef("c1"), Add(SymbolRef("c1"), Constant(1))),
[For(Assign(SymbolRef("c2", c_int()), Constant(0)),
LtE(SymbolRef("c2"), Constant(10)),
Assign(SymbolRef("c2"),
Add(SymbolRef("c2"), Constant(1))),
[SymbolRef("Statement")])])])])
print(ast)
// <file: test.c>
#pragma omp parallel for
for (int c0 = 0; c0 <= 199; c0 = c0 + 1) {
#pragma omp parallel for
for (int c1 = c0; c1 <= c0 + 99; c1 = c1 + 1) {
for (int c2 = 0; c2 <= 10; c2 = c2 + 1) {
Statement;
}
}
}
Put it in a file, use lists for blocks of statements (i.e. inner block of a for loop, as well as a CFile)
vandana96 commented
Thank you