pyccel / pyccel

Python extension language using accelerators
MIT License
352 stars 61 forks source link

OpenMP pragma space between hash symbol and dollar symbol lead to an error #1227

Open rakati opened 2 years ago

rakati commented 2 years ago

Describe the bug One of the errors that you may get if you turn on python formatting in your editor, is Unclassifiable statement in Fortran with OpenMP. even if your try to copy code from the Pyccel OpenMP tutorials, on saving the file, the Python format will add a space between the # comment symbol and comment text, so in our case, a space will be added between # and $ omp parallel [clauses]. To Reproduce Provide code to reproduce the behavior:

# ...
# $ omp parallel for
for i in range(n):
    a[i] = i * i
# $ omp end parallel
# ...

Provide the generated code, or the error message:

  12 |     !$ omp parallel for
      |       1
Error: Unclassifiable statement at (1)

Expected behavior for the above example, the OpenMP pragma for Fortran doesn't accept space between !$ and omp, so removing space between # and $ in the python code will generate the correct code for Fortran, !$omp parallel ...

Language Fortran

Additional description Pyccel should take care of extra spaces added or need to be added.

yguclu commented 2 years ago

Could you not add an exception rule to your text editor?

nhamidn commented 2 years ago

i think with the space it will be considered as a comment, but i don't know the space between ! and $ it's removed in the generated fortran code!

rakati commented 2 years ago

Could you not add an exception rule to your text editor?

I did when I realized the problem, but I think it's hard to detect these kinds of problems, and this is why we should handle this case.

rakati commented 2 years ago

i think with the space it will be considered as a comment, but i don't know the space between ! and $ it's removed in the generated fortran code!

Pyccel didn't consider it as a comment, and generated OpenMP code but with a bug.