Improper indentation of OpenMP conditional compilation specification lines
indent, beautify and relabel Fortran source, generates dependencies
Brought to you by:
willem_vermin
According to the OpenMP API specifications [v5.2, §3.3.2 Free Source Form Conditional Compilation Sentinel] !$ is the conditional compilation sentinel in free form source files and can be used as:
!$ iam = omp_get_thread_num()
But the current version of findent (4.1.3) does not indent these lines correctly.
Example:
[input]
if (condition) !$omp parallel !$ num_threads = omp_get_num_threads() !$omp end parallel end if
[current behaviour]
if (condition) !$omp parallel !$ num_threads = omp_get_num_threads() !$omp end parallel end if
[desired output]
if (condition) !$omp parallel !$ num_threads = omp_get_num_threads() !$omp end parallel end if
You forgot the THEN after the first line, but adding that does not change the output.
In the following I run findent with no flags.
When I run your example, (with added THEN), I get this:
The 'num_threads line was already correctly indented, so we see no change there. I get no leading space in lines 2 and 4. Strange.
Findent indents after the !$ sentinel, see the following example:
Findent indents this thusly:
Does this answer your question?
Thanks for your quick response. I guess my confusion arises from the fact that the indentation is done after the
!$
sentinel but before the!$omp
. So my code turns into something like:Is there any way to make this consistent (to have indentation before both)?
Personally, I find the way findent handles !$ lines results in a better readable code than adding indent before !$. And I like to have the !$omp lines starting in column 1: these lines are not indented by findent.
Your suggestion would entail the following to be done by findent:
change a line like
into
!$ continue
and then, indent this line as a whole, also indent !$omp lines, whether they start in column 1 or not. This is not a trivial change, practice learned me that there always nasty issues with continuation lines and such. Nevertheless, I will investigate the matter and let you know.
I have a solution for you that does not involve changing findent itself:
Create a script "myfindent":
Given the following Fortran source:
the following output is produced by "myfindent":
(one could say that the handling of continuation lines could be better...)
while findent produces:
Thanks for your helps. I think I should be able to modify it to align the !$ and add space afterwards.