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

Allocatable private array in openmp parallel do directive

houidef_a_
Beginner
555 Views

Hi,  I have a problem and I did not find a solution : I want to use parallelism in the free code  , but a problem occurred in the allocation of arrays: 

PROGRAM LMTART

USE PARA_CONTROL
    use omp_lib
    INTEGER I,J
    real, allocatable, dimension(:) :: a
    PARA_FIRST=.True.
    !$OMP PARALLEL  DEFAULT(firstprivate) 
    !$OMP DO
    DO I = 1, 10
    if(PARA_FIRST) then
    allocate(a(100))
    DO J = 1, 10
    a(j)=j    
    ENDDO
    endif
    write(*,*) (a(J),J=1,10)
    PARA_FIRST=.False.
    ENDDO
    !$OMP END DO
    !$OMP END PARALLEL

   END

It should be noted that : do not  reserved  the table "a" before entering in the  DO  directive

0 Kudos
8 Replies
pbkenned1
Employee
555 Views

Please provide more description than 'a problem occurred'.  Compilation problem? Runtime problem?  Probably the code compiles (but I can't be sure since it depends on module PARA_CONTROL), so I suppose this is a runtime problem.  Please provide details.  I don't see suspicious, other than a race condition on the write() statement.

Patrick

0 Kudos
houidef_a_
Beginner
555 Views

..this code fails with a message error saying "allocatable array is already allocated",  code not works!

0 Kudos
houidef_a_
Beginner
555 Views

Please Help me !!!!!!!!!!!!!!

0 Kudos
pbkenned1
Employee
555 Views

We have to be able to reproduce (or at least understand) your issue before we can help you.

What version of the compiler are you using? 

Is logical variable PARA_FIRST modified outside of the code you showed us?  If so, you may need to provide the source for module PARA_CONTROL, along with the code that is modifying PARA_FIRST.

 

If I define PARA_FIRST as a local variable, all is well with ifort-14.0.3:

 

$ cat U520439.f90
PROGRAM LMTART

!!!USE PARA_CONTROL

     use omp_lib
     implicit none
     INTEGER I,J
     logical PARA_FIRST
     real, allocatable, dimension(:) :: a

     PARA_FIRST=.True.
     !$OMP PARALLEL  DEFAULT(firstprivate)
     !$OMP DO
     DO I = 1, 10
     if(PARA_FIRST) then
     allocate(a(100))
     DO J = 1, 10
     a(j)=j
     ENDDO
     endif
     write(*,*) (a(J),J=1,10)
     PARA_FIRST=.False.
     ENDDO
     !$OMP END DO
     !$OMP END PARALLEL
   END

 

$ ifort -V
Intel(R) Fortran Intel(R) 64 Compiler XE for applications running on Intel(R) 64, Version 14.0.3.174 Build 20140422
Copyright (C) 1985-2014 Intel Corporation.  All rights reserved.

$ ifort -openmp U520439.f90 && ./a.out
   1.000000       2.000000       3.000000       4.000000       5.000000
   6.000000       7.000000       8.000000       9.000000       10.00000
   1.000000       2.000000       3.000000       4.000000       5.000000
   6.000000       7.000000       8.000000       9.000000       10.00000
   1.000000       2.000000       3.000000       4.000000       5.000000
   6.000000       7.000000       8.000000       9.000000       10.00000
   1.000000       2.000000       3.000000       4.000000       5.000000
   6.000000       7.000000       8.000000       9.000000       10.00000
   1.000000       2.000000       3.000000       4.000000       5.000000
   6.000000       7.000000       8.000000       9.000000       10.00000
   1.000000       2.000000       3.000000       4.000000       5.000000
   6.000000       7.000000       8.000000       9.000000       10.00000
   1.000000       2.000000       3.000000       4.000000       5.000000
   6.000000       7.000000       8.000000       9.000000       10.00000
   1.000000       2.000000       3.000000       4.000000       5.000000
   6.000000       7.000000       8.000000       9.000000       10.00000
   1.000000       2.000000       3.000000       4.000000       5.000000
   6.000000       7.000000       8.000000       9.000000       10.00000
   1.000000       2.000000       3.000000       4.000000       5.000000
   6.000000       7.000000       8.000000       9.000000       10.00000
$

 

Patrick

0 Kudos
houidef_a_
Beginner
555 Views

Patrick Kennedy , work ,goooooooooooooood hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh!!!!!

Where is the problem????

0 Kudos
houidef_a_
Beginner
555 Views

Note :Where is deallocate procedure !!!! deallocate procedure is the problem ?

0 Kudos
pbkenned1
Employee
555 Views

If you allocate something in a PARALLEL region, it is automatically deallocated at the end of the parallel region, so deallocation is not the problem in the code you have shown us. 

Patrick

0 Kudos
houidef_a_
Beginner
555 Views
0 Kudos
Reply