Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Optional OpenMP-Directives

Benedikt_R_
Beginner
803 Views

Hi

I want to put OpenMP-directives and OpenACC-directives in one program.

In the OpenACC-program some OpenMP-directives shall be ignored (when there is an equivalent OpenACC-directive) but others shall be used (when the code has to run on CPU)

In the non-OpenAcc-program all OpenMP-directives shall be used.

I tried to opt out OpenMP by a define. The following example is minimalist:

#ifndef _OPENACC
#define MYOMP !$OMP
#else
#define MYOMP C
#endif
      PROGRAM MAIN
      OPTION EXPLICIT
      INTEGER a(1000),i
       
MYOMP PARALLEL DO
      DO I=1,1000
        a(i) = 0
      END DO
MYOMP END PARALLEL DO
      END
Compile with ifort 15 on Windows: ifort test.for /openmp /fpp

The compiler/preprocessor removes the !$OMP-directive. Obviously its treats as a comment.
Any Advice?
Benedikt

Output of compiler:
Intel(R) Visual Fortran Compiler XE for applications running on IA-32, Version 15.0.0.108 Build 20140726
Copyright (C) 1985-2014 Intel Corporation.  All rights reserved.

test.for(10): error #5082: Syntax error, found END-OF-STATEMENT when expecting one of: ( % [ : . = =>
      PARALLEL DO
-----------------^
test.for(14): error #5082: Syntax error, found IDENTIFIER 'PARALLELDO' when expecting one of: <END-OF-STATEMENT> ; BLOCK PROGRAM BLOCKDATA MODULE TYPE FUNCTION SUBROUTINE ...
      END PARALLEL DO
----------^
test.for(14): error #8731: An END BLOCK occurred without a corresponding BLOCK statement.
      END PARALLEL DO
------^
test.for(10): error #6218: This statement is positioned incorrectly and/or has syntax errors.
      PARALLEL DO
-----------------^
compilation aborted for test.for (code 1)

 

0 Kudos
3 Replies
jimdempseyatthecove
Honored Contributor III
803 Views

Try replacing the "C" with "!" in your second define.

Or better yet replace "C" with "!.not.$OMP"

You may have an issue that C must be on column 1 in order to be considered a comment, whereas ! can appear anywhere on the line.

Jim Dempsey

0 Kudos
Benedikt_R_
Beginner
803 Views

@Jim: Sorry for being to unspecific:
The problem is not the "#define MYOMP C"-line. The problem is the "#define MYOMP !$OMP" line.

The output of the preprocessor did not contain "!$OMP", since the preprocessor thinks of this as an comment.

I found a solution on my own: I added the compilerswitch
/allow:nofpp-comments

Benedikt

0 Kudos
jimdempseyatthecove
Honored Contributor III
803 Views

Ah... overlooked that option.

Jim Dempsey

0 Kudos
Reply