THREADPRIVATE and BLOCK DATA in Fortran

General OpenMP discussion
Forum rules
The OpenMP Forums are now closed to new posts. Please visit Stack Overflow if you are in need of help: https://stackoverflow.com/questions/tagged/openmp
Locked
kfurutaka
Posts: 3
Joined: Mon Aug 10, 2015 1:35 am

THREADPRIVATE and BLOCK DATA in Fortran

Post by kfurutaka »

Dear OpenMP expert,

I have an old Fortran(77+) program which was made parallel using OpenMP.
It could be compiled using older version of (perhaps around v4.8) GNU gfortran, but recently it can't; the compilation failed with the following message:

Code: Select all

 Error: !$OMP THREADPRIVATE statement is not allowed inside of BLOCK DATA at (1)
At present I use the following version of gfortran on linux boxes, which is claimed to fully implement OpenMP 4.0, according to https://gcc.gnu.org/wiki/GFortran/News#gfortran_5

Code: Select all

GNU Fortran (GCC) 5.1.1 20150618 (Red Hat 5.1.1-4)
Copyright (C) 2015 Free Software Foundation, Inc.
My question is... Is the use of the THREADPRIVATE directive in BLOCK DATA really illegal? If so, where can I find the reason(s)/base(s) of the error in the OpenMP specification? :?:
I learned OpenMP by reading "Parallel Programming in OpenMP" by Rohit Chandra et al; in section '4.4.1 The threadprivate Directive' of the book it reads (p106)
... in Fortran, a threadprivate variable would be intialized only if the program contained block data statements providing initial values for the common blocks.
and I never thought it was wrong to do so (and the statements were compiled without any problems using the older versions of GNU gfortran!). :cry:
By the way, it was compiled without any problems using recent versions of Intel Fortran (v14.?).

Any advices/comments are welcome...

Thanks in advance,
Kazuyoshi

MarkB
Posts: 808
Joined: Thu Jan 08, 2009 10:12 am
Location: EPCC, University of Edinburgh

Re: THREADPRIVATE and BLOCK DATA in Fortran

Post by MarkB »

I see no such restriction in the standard.

It might be worth asking over at GNU, but a similar complaint http://comments.gmane.org/gmane.comp.gcc.fortran/44211 received no response.

kfurutaka
Posts: 3
Joined: Mon Aug 10, 2015 1:35 am

Re: THREADPRIVATE and BLOCK DATA in Fortran

Post by kfurutaka »

Dear MarkB, thanks for your response.
MarkB wrote:I see no such restriction in the standard.
Then, it's a "rule" peculiar to gfortran, right?
MarkB wrote:It might be worth asking over at GNU, but a similar complaint http://comments.gmane.org/gmane.comp.gcc.fortran/44211 received no response.
Well, he's my colleague and we're talking about the same code, and as you said, he got absolutely no responses. :oops:

If placing the threadprivate directive inside a block data does NOT break the rule/specification, one of the things we should do is to ask gfortran developers to correct the issue, but... :roll:

Thanks...

Kazuyoshi

kfurutaka
Posts: 3
Joined: Mon Aug 10, 2015 1:35 am

Re: THREADPRIVATE and BLOCK DATA in Fortran

Post by kfurutaka »

Reading the source of gcc-5.2.0 (gcc/fortran/parse.c), it seems to me that it is more of OpenMP-directive parse issue of gfortran than of Fortran/OpenMP rules/specification:

Code: Select all

   3158   else if (gfc_current_state () == COMP_BLOCK_DATA)
   3159     /* Fortran 2008, C1116.  */
   3160     switch (st)
   3161       {
   3162         case ST_DATA_DECL:
   3163         case ST_COMMON:
   3164         case ST_DATA:
   3165         case ST_TYPE:
   3166         case ST_END_BLOCK_DATA:
   3167         case ST_ATTR_DECL:
   3168         case ST_EQUIVALENCE:
   3169         case ST_PARAMETER:
   3170         case ST_IMPLICIT:
   3171         case ST_IMPLICIT_NONE:
   3172         case ST_DERIVED_DECL:
   3173         case ST_USE:
   3174           break;
   3175 
   3176         case ST_NONE:
   3177           break;
   3178           
   3179         default:
   3180           gfc_error ("%s statement is not allowed inside of BLOCK DATA at %C",
   3181                      gfc_ascii_statement (st));
   3182           reject_statement ();
   3183           break;
   3184       }
   3185   
Here, the "!$OMP THREADPRIVATE statement" was treated as that of Fortran and compared to the allowed statements in the block data, and was rejected by the default: case...
I know almost nothing of GCC internals and, though not impossible, it will take a very long time if I'll try to fix it by myself... :cry:

Kazuyoshi

Locked