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

class object can't be private in OpenMP ? catastrophic error: **Internal compiler error

proxima
Novice
412 Views

Dear all,

 

I found an internal compiler error of ifort and I want to know how to resolve it. First of all, with the gfortran compiler, the error disappears. I attached 4 files:

1) run1_ifort.sh : my bash script to run the minimal working example (shows the error)

2) run1_gfortran.sh: same with gfortran (does not show the error)

3) test1.f90 : the minimal working example, that tries to initialize a parallel OpenMP region and allocate there a derived type (the plan is on each thread one instance). The derived type (the object F) has a procedure (F%E) which shows basically the thread number independently of the input (of cause in the main project there are other functionalities and a whole family of different extended derived types ).

4) mod1.f90 : contains the definition of the derived type F and the procedure F%E.

 

The motivation of this construct is to initialize dependent on a lot of input parameters this object F and then be able to use F%E(t) without having a large number of parameters (E(t,a,b,c,...)) which were needed to identify/initialize F. 

 

running

>> ./run1_ifort.sh

leads to

 

test1.f90: catastrophic error: **Internal compiler error: segmentation violation signal raised** Please report this error along with the circumstances in which it occurred in a Software Problem Report. Note: File and line given may not be explicit cause of this error.

compilation aborted for test1.f90 (code 1)

./run1_ifort: line 7: ./a.out: No such file or directory

rm: cannot remove 'a.out': No such file or directory

 

running

>> ./run1_gfortran.sh

leads to

 

num threads: 3

print threadnumber inside parallel region with the allocated class object

0.0000000000000000 

1.0000000000000000 

2.0000000000000000

 

what I expected (the ordering can be different).

 

I figured out, that the error disappears also if I remove the "private(F)" statement of the parallel region of OpenMP in test1.f90.

Of cause, then I get wrong results because one thread can change the internal parameter of F while initializing while the other threads try to print the "results".

 

So is there a suggestion, on how to solve it? Or a different strategy solving the original OOP problem of having a thread-safe object in Fortran (and ifort)?

 

Thanks in advance!

0 Kudos
1 Solution
jimdempseyatthecove
Black Belt
360 Views

There was another issue some time back where, allocatable objects/arrays, intended to be private would fail, however, by changing:

 

   private(...) -> firstprivate(...)

 

would correct the problem. IOW by copying in the state of the objects (unallocated) state.

 

Jim Dempsey

View solution in original post

5 Replies
jimdempseyatthecove
Black Belt
380 Views

I seem to recall (some time ago) an issue with a type with no data. Try adding

 integer :: NotUsed

to your type Field

 

Jim Dempsey

proxima
Novice
372 Views

Thanks for the suggestion, but it does not work - I get the same error message.

I tried both:

1) integer :: NotUsed=0  (initialization inside the type Field)  

2) integer :: NotUsed , but F=testfield(NotUsed=0,...) (initialization in the allocation of F)

jimdempseyatthecove
Black Belt
361 Views

There was another issue some time back where, allocatable objects/arrays, intended to be private would fail, however, by changing:

 

   private(...) -> firstprivate(...)

 

would correct the problem. IOW by copying in the state of the objects (unallocated) state.

 

Jim Dempsey

proxima
Novice
313 Views

Thank you for this solution. It fixes my problem in this example.


I cross checked it in my larger project and in principle it works there too.

BUT I found another strange difference between ifort and gfortran. In this case gfortran seems to behave wrong somehow. I just want to report this somewhere:


Since I also have/want to allocate such derived types (objects) F (see above and in example 2) outside of the parallel region, I tried to put them also in the firstprivate (already allocated).

I expected that then also the values set in the allocation would be stored on every thread like in normal variables. But gfortran can't do this ( R is a real(8) for comparison with F

 

>> run2_gfortran.sh

initialized with 1.23
before parallel region:
F= 1.2300000000000000
R= 1.0000000000000000
num threads: 3
inside parallel region:
R= 1.0000000000000000
R= 1.0000000000000000
R= 1.0000000000000000
F= 0.0000000000000000
F= 0.0000000000000000
F= 0.0000000000000000
after parallel region :
R= 1.0000000000000000
F= 1.2300000000000000

 

>> run2_ifort.sh

initialized with 1.23
before parallel region:
F= 1.23000000000000
R= 1.00000000000000
num threads: 3
inside parallel region:
R= 1.00000000000000
R= 1.00000000000000
R= 1.00000000000000
F= 1.23000000000000
F= 1.23000000000000
F= 1.23000000000000
after parallel region :
R= 1.00000000000000
F= 1.23000000000000

as I would expect.

 

So with gfortran you can use private(F) or firstprivate(F), but you have to allocate it inside the parallel region. With ifort one can only use firstprivate(F), but it is then possible to allocate it inside and outside the parallel region.

Ron_Green
Moderator
333 Views

BUG ID CMPLRIL0-34673


Reply