2

I am facing an awkward situation. I am trying to run a Fortran 90 program in Linux with ifort and since it has OpenMP directives I compile it with the -openmp-report1 option to see that whether the blocks have been successfully parallelized.

The problem is that gedit doesn't recognize the OpenMP directive:

!$omp parallel do etc....

it treats it as a comment. Anyone has an idea about it? I also tried:

C$omp parallel do etc...

but in that case it produces a compile-time error. Do I have to enable an option in gedit in order to recognize the OpenMP directives?

I faced the same problem in emacs.

I note that I run successfully the same program with Intel Visual Fortran. In Visual Studio OpenMP directives are properly recognized.

davidism
  • 121,510
  • 29
  • 395
  • 339

1 Answers1

1

First of all, you need to define a new style in the <styles> section of your language specification:

<style>
  <!-- ... -->
  <style id="openmp-directives" _name="OpenMP directives" map-to="def:preprocessor"/>
</styles>

Next, add a corresponding <context> to the <definitions> section:

<definitions>
  <!-- ... -->
  <context id="openmp-directives" style-ref="openmp-directives" end-at-line-end="true">
    <start extended="true">
      ((^[Cc])|^\s*!)\$
    </start>
  </context>
  <!-- ... -->
</definitions>

Activate the evaluation of the new style:

<definitions>
  <!-- ... -->
  <context id="fortran" class="no-spell-check">
    <include>
      <context ref="openmp-directives"/>
    </include>
  </context>
  <!-- ... -->
</definitions>

Finally, as @VladimirF pointed out, you need to tell GtkSourceView to not treat the directives as comments.

Locate the <context id="line-comment" ...> and change

<start>!|(^[Cc](\b|[^OoAaYyHh]))</start>

to

 <start>(![^$])|(^[Cc](\s|[^$OoAaYyHh]))|(^[Cc]$)</start>

I just proposed this patch to GtkSourceView here.

Alexander Vogt
  • 17,879
  • 13
  • 52
  • 68
  • Just FYI: This patch has been [merged upstream](https://git.gnome.org/browse/gtksourceview/commit/?id=85787b25dfc418ef3d3572f17b74228793e99225)... – Alexander Vogt May 19 '14 at 08:45
  • Since when has `!$` become an OpenMP sentinel? The only standard-recognised sentinel in free-format sources is `!$omp` (+ case variations) with `*$omp` and `c$omp` additionally recognised in fixed-format files. The sentinel must appear as a single word with no intervening spaces. In fixed-format sources the sentinel must start at position 1. – Hristo Iliev Oct 24 '14 at 16:07
  • @HristoIliev `!$` can be used for Fortran statements that are only validated when OpenMP is enabled... Otherwise, they are treated as comments. See [here](https://gcc.gnu.org/onlinedocs/gfortran/OpenMP.html). – Alexander Vogt Oct 24 '14 at 18:24
  • One learns new things every day. Thank you! Anyway, `!$` starts a conditionally compiled statement, not an OpenMP directive as stated in the example file (part of the commit you have linked to). – Hristo Iliev Oct 24 '14 at 18:33